@fuel-ts/account 0.0.0-rc-2130-20240422142413 → 0.0.0-rc-2021-20240422173414
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/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +3380 -1998
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +786 -518
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +663 -396
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts.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/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +46 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +8 -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 +4111 -2491
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +765 -515
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +655 -405
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -16
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");
|
@@ -75,24 +76,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
75
76
|
var coinQuantityfy = (coinQuantityLike) => {
|
76
77
|
let assetId;
|
77
78
|
let amount;
|
78
|
-
let
|
79
|
+
let max;
|
79
80
|
if (Array.isArray(coinQuantityLike)) {
|
80
81
|
amount = coinQuantityLike[0];
|
81
82
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
82
|
-
|
83
|
+
max = coinQuantityLike[2] ?? void 0;
|
83
84
|
} else {
|
84
85
|
amount = coinQuantityLike.amount;
|
85
86
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
86
|
-
|
87
|
+
max = coinQuantityLike.max ?? void 0;
|
87
88
|
}
|
88
89
|
const bnAmount = (0, import_math.bn)(amount);
|
89
90
|
return {
|
90
91
|
assetId: (0, import_utils.hexlify)(assetId),
|
91
92
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
92
|
-
max:
|
93
|
+
max: max ? (0, import_math.bn)(max) : 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,12 @@ 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");
|
116
|
+
var import_ethers = require("ethers");
|
115
117
|
var import_graphql_request = require("graphql-request");
|
116
118
|
var import_ramda3 = require("ramda");
|
117
119
|
|
@@ -119,14 +121,10 @@ var import_ramda3 = require("ramda");
|
|
119
121
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
120
122
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
121
123
|
fragment receiptFragment on Receipt {
|
122
|
-
|
123
|
-
id
|
124
|
-
}
|
124
|
+
id
|
125
125
|
pc
|
126
126
|
is
|
127
|
-
to
|
128
|
-
id
|
129
|
-
}
|
127
|
+
to
|
130
128
|
toAddress
|
131
129
|
amount
|
132
130
|
assetId
|
@@ -164,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
164
162
|
id
|
165
163
|
}
|
166
164
|
time
|
165
|
+
receipts {
|
166
|
+
...receiptFragment
|
167
|
+
}
|
167
168
|
programState {
|
168
169
|
returnType
|
169
170
|
data
|
170
171
|
}
|
172
|
+
receipts {
|
173
|
+
...receiptFragment
|
174
|
+
}
|
171
175
|
}
|
172
176
|
... on FailureStatus {
|
173
177
|
block {
|
@@ -175,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
175
179
|
}
|
176
180
|
time
|
177
181
|
reason
|
182
|
+
receipts {
|
183
|
+
...receiptFragment
|
184
|
+
}
|
178
185
|
}
|
179
186
|
... on SqueezedOutStatus {
|
180
187
|
reason
|
181
188
|
}
|
182
189
|
}
|
183
|
-
`;
|
190
|
+
${ReceiptFragmentFragmentDoc}`;
|
184
191
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
185
192
|
fragment transactionFragment on Transaction {
|
186
193
|
id
|
187
194
|
rawPayload
|
188
|
-
gasPrice
|
189
|
-
receipts {
|
190
|
-
...receiptFragment
|
191
|
-
}
|
192
195
|
status {
|
193
196
|
...transactionStatusFragment
|
194
197
|
}
|
195
198
|
}
|
196
|
-
${
|
197
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
199
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
198
200
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
199
201
|
fragment inputEstimatePredicatesFragment on Input {
|
200
202
|
... on InputCoin {
|
@@ -212,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
212
214
|
}
|
213
215
|
}
|
214
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}`;
|
215
257
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
216
258
|
fragment coinFragment on Coin {
|
217
259
|
__typename
|
@@ -219,7 +261,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
219
261
|
owner
|
220
262
|
amount
|
221
263
|
assetId
|
222
|
-
maturity
|
223
264
|
blockCreated
|
224
265
|
txCreatedIdx
|
225
266
|
}
|
@@ -258,26 +299,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
258
299
|
messageBlockHeader {
|
259
300
|
id
|
260
301
|
daHeight
|
302
|
+
consensusParametersVersion
|
303
|
+
stateTransitionBytecodeVersion
|
261
304
|
transactionsCount
|
305
|
+
messageReceiptCount
|
262
306
|
transactionsRoot
|
307
|
+
messageOutboxRoot
|
308
|
+
eventInboxRoot
|
263
309
|
height
|
264
310
|
prevRoot
|
265
311
|
time
|
266
312
|
applicationHash
|
267
|
-
messageReceiptRoot
|
268
|
-
messageReceiptCount
|
269
313
|
}
|
270
314
|
commitBlockHeader {
|
271
315
|
id
|
272
316
|
daHeight
|
317
|
+
consensusParametersVersion
|
318
|
+
stateTransitionBytecodeVersion
|
273
319
|
transactionsCount
|
320
|
+
messageReceiptCount
|
274
321
|
transactionsRoot
|
322
|
+
messageOutboxRoot
|
323
|
+
eventInboxRoot
|
275
324
|
height
|
276
325
|
prevRoot
|
277
326
|
time
|
278
327
|
applicationHash
|
279
|
-
messageReceiptRoot
|
280
|
-
messageReceiptCount
|
281
328
|
}
|
282
329
|
sender
|
283
330
|
recipient
|
@@ -296,8 +343,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
296
343
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
297
344
|
fragment blockFragment on Block {
|
298
345
|
id
|
346
|
+
height
|
299
347
|
header {
|
300
|
-
height
|
301
348
|
time
|
302
349
|
}
|
303
350
|
transactions {
|
@@ -355,6 +402,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
355
402
|
`;
|
356
403
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
357
404
|
fragment GasCostsFragment on GasCosts {
|
405
|
+
version {
|
406
|
+
... on Version {
|
407
|
+
value
|
408
|
+
}
|
409
|
+
}
|
358
410
|
add
|
359
411
|
addi
|
360
412
|
aloc
|
@@ -367,7 +419,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
367
419
|
cb
|
368
420
|
cfei
|
369
421
|
cfsi
|
370
|
-
croo
|
371
422
|
div
|
372
423
|
divi
|
373
424
|
ecr1
|
@@ -450,6 +501,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
450
501
|
ccp {
|
451
502
|
...DependentCostFragment
|
452
503
|
}
|
504
|
+
croo {
|
505
|
+
...DependentCostFragment
|
506
|
+
}
|
453
507
|
csiz {
|
454
508
|
...DependentCostFragment
|
455
509
|
}
|
@@ -509,6 +563,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
509
563
|
${DependentCostFragmentFragmentDoc}`;
|
510
564
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
511
565
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
+
version {
|
567
|
+
... on Version {
|
568
|
+
value
|
569
|
+
}
|
570
|
+
}
|
512
571
|
txParams {
|
513
572
|
...TxParametersFragment
|
514
573
|
}
|
@@ -568,18 +627,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
568
627
|
fragment nodeInfoFragment on NodeInfo {
|
569
628
|
utxoValidation
|
570
629
|
vmBacktrace
|
571
|
-
minGasPrice
|
572
630
|
maxTx
|
573
631
|
maxDepth
|
574
632
|
nodeVersion
|
575
|
-
peers {
|
576
|
-
id
|
577
|
-
addresses
|
578
|
-
clientVersion
|
579
|
-
blockHeight
|
580
|
-
lastHeartbeatMs
|
581
|
-
appScore
|
582
|
-
}
|
583
633
|
}
|
584
634
|
`;
|
585
635
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -614,13 +664,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
614
664
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
615
665
|
transaction(id: $transactionId) {
|
616
666
|
...transactionFragment
|
617
|
-
receipts {
|
618
|
-
...receiptFragment
|
619
|
-
}
|
620
667
|
}
|
621
668
|
}
|
622
|
-
${TransactionFragmentFragmentDoc}
|
623
|
-
${ReceiptFragmentFragmentDoc}`;
|
669
|
+
${TransactionFragmentFragmentDoc}`;
|
624
670
|
var GetTransactionsDocument = import_graphql_tag.default`
|
625
671
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
626
672
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -748,6 +794,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
748
794
|
}
|
749
795
|
}
|
750
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
|
+
`;
|
751
811
|
var GetBalancesDocument = import_graphql_tag.default`
|
752
812
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
753
813
|
balances(
|
@@ -802,12 +862,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
802
862
|
}
|
803
863
|
`;
|
804
864
|
var DryRunDocument = import_graphql_tag.default`
|
805
|
-
mutation dryRun($
|
806
|
-
dryRun(
|
807
|
-
...
|
865
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
866
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
867
|
+
...dryRunTransactionExecutionStatusFragment
|
808
868
|
}
|
809
869
|
}
|
810
|
-
${
|
870
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
811
871
|
var SubmitDocument = import_graphql_tag.default`
|
812
872
|
mutation submit($encodedTransaction: HexString!) {
|
813
873
|
submit(tx: $encodedTransaction) {
|
@@ -890,6 +950,12 @@ function getSdk(requester) {
|
|
890
950
|
getBalance(variables, options) {
|
891
951
|
return requester(GetBalanceDocument, variables, options);
|
892
952
|
},
|
953
|
+
getLatestGasPrice(variables, options) {
|
954
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
+
},
|
956
|
+
estimateGasPrice(variables, options) {
|
957
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
+
},
|
893
959
|
getBalances(variables, options) {
|
894
960
|
return requester(GetBalancesDocument, variables, options);
|
895
961
|
},
|
@@ -1083,10 +1149,9 @@ var inputify = (value) => {
|
|
1083
1149
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1084
1150
|
},
|
1085
1151
|
witnessIndex: value.witnessIndex,
|
1086
|
-
maturity: value.maturity ?? 0,
|
1087
1152
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1088
|
-
predicateLength: predicate.length,
|
1089
|
-
predicateDataLength: predicateData.length,
|
1153
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1154
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1090
1155
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1091
1156
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1092
1157
|
};
|
@@ -1117,8 +1182,8 @@ var inputify = (value) => {
|
|
1117
1182
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1118
1183
|
witnessIndex: value.witnessIndex,
|
1119
1184
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1120
|
-
predicateLength: predicate.length,
|
1121
|
-
predicateDataLength: predicateData.length,
|
1185
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1186
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1122
1187
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1123
1188
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1124
1189
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1234,8 +1299,8 @@ function assembleReceiptByType(receipt) {
|
|
1234
1299
|
case "CALL" /* Call */: {
|
1235
1300
|
const callReceipt = {
|
1236
1301
|
type: import_transactions3.ReceiptType.Call,
|
1237
|
-
from: hexOrZero(receipt.
|
1238
|
-
to: hexOrZero(receipt?.to
|
1302
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1303
|
+
to: hexOrZero(receipt?.to),
|
1239
1304
|
amount: (0, import_math4.bn)(receipt.amount),
|
1240
1305
|
assetId: hexOrZero(receipt.assetId),
|
1241
1306
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1249,7 +1314,7 @@ function assembleReceiptByType(receipt) {
|
|
1249
1314
|
case "RETURN" /* Return */: {
|
1250
1315
|
const returnReceipt = {
|
1251
1316
|
type: import_transactions3.ReceiptType.Return,
|
1252
|
-
id: hexOrZero(receipt.
|
1317
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1253
1318
|
val: (0, import_math4.bn)(receipt.val),
|
1254
1319
|
pc: (0, import_math4.bn)(receipt.pc),
|
1255
1320
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1259,7 +1324,7 @@ function assembleReceiptByType(receipt) {
|
|
1259
1324
|
case "RETURN_DATA" /* ReturnData */: {
|
1260
1325
|
const returnDataReceipt = {
|
1261
1326
|
type: import_transactions3.ReceiptType.ReturnData,
|
1262
|
-
id: hexOrZero(receipt.
|
1327
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1263
1328
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1264
1329
|
len: (0, import_math4.bn)(receipt.len),
|
1265
1330
|
digest: hexOrZero(receipt.digest),
|
@@ -1271,7 +1336,7 @@ function assembleReceiptByType(receipt) {
|
|
1271
1336
|
case "PANIC" /* Panic */: {
|
1272
1337
|
const panicReceipt = {
|
1273
1338
|
type: import_transactions3.ReceiptType.Panic,
|
1274
|
-
id: hexOrZero(receipt.
|
1339
|
+
id: hexOrZero(receipt.id),
|
1275
1340
|
reason: (0, import_math4.bn)(receipt.reason),
|
1276
1341
|
pc: (0, import_math4.bn)(receipt.pc),
|
1277
1342
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1282,7 +1347,7 @@ function assembleReceiptByType(receipt) {
|
|
1282
1347
|
case "REVERT" /* Revert */: {
|
1283
1348
|
const revertReceipt = {
|
1284
1349
|
type: import_transactions3.ReceiptType.Revert,
|
1285
|
-
id: hexOrZero(receipt.
|
1350
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1286
1351
|
val: (0, import_math4.bn)(receipt.ra),
|
1287
1352
|
pc: (0, import_math4.bn)(receipt.pc),
|
1288
1353
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1292,7 +1357,7 @@ function assembleReceiptByType(receipt) {
|
|
1292
1357
|
case "LOG" /* Log */: {
|
1293
1358
|
const logReceipt = {
|
1294
1359
|
type: import_transactions3.ReceiptType.Log,
|
1295
|
-
id: hexOrZero(receipt.
|
1360
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1296
1361
|
val0: (0, import_math4.bn)(receipt.ra),
|
1297
1362
|
val1: (0, import_math4.bn)(receipt.rb),
|
1298
1363
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1305,7 +1370,7 @@ function assembleReceiptByType(receipt) {
|
|
1305
1370
|
case "LOG_DATA" /* LogData */: {
|
1306
1371
|
const logDataReceipt = {
|
1307
1372
|
type: import_transactions3.ReceiptType.LogData,
|
1308
|
-
id: hexOrZero(receipt.
|
1373
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1309
1374
|
val0: (0, import_math4.bn)(receipt.ra),
|
1310
1375
|
val1: (0, import_math4.bn)(receipt.rb),
|
1311
1376
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1319,8 +1384,8 @@ function assembleReceiptByType(receipt) {
|
|
1319
1384
|
case "TRANSFER" /* Transfer */: {
|
1320
1385
|
const transferReceipt = {
|
1321
1386
|
type: import_transactions3.ReceiptType.Transfer,
|
1322
|
-
from: hexOrZero(receipt.
|
1323
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1387
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1388
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1324
1389
|
amount: (0, import_math4.bn)(receipt.amount),
|
1325
1390
|
assetId: hexOrZero(receipt.assetId),
|
1326
1391
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1331,8 +1396,8 @@ function assembleReceiptByType(receipt) {
|
|
1331
1396
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1332
1397
|
const transferOutReceipt = {
|
1333
1398
|
type: import_transactions3.ReceiptType.TransferOut,
|
1334
|
-
from: hexOrZero(receipt.
|
1335
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1399
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1400
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1336
1401
|
amount: (0, import_math4.bn)(receipt.amount),
|
1337
1402
|
assetId: hexOrZero(receipt.assetId),
|
1338
1403
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1375,7 +1440,7 @@ function assembleReceiptByType(receipt) {
|
|
1375
1440
|
return receiptMessageOut;
|
1376
1441
|
}
|
1377
1442
|
case "MINT" /* Mint */: {
|
1378
|
-
const contractId = hexOrZero(receipt.
|
1443
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1379
1444
|
const subId = hexOrZero(receipt.subId);
|
1380
1445
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1381
1446
|
const mintReceipt = {
|
@@ -1390,7 +1455,7 @@ function assembleReceiptByType(receipt) {
|
|
1390
1455
|
return mintReceipt;
|
1391
1456
|
}
|
1392
1457
|
case "BURN" /* Burn */: {
|
1393
|
-
const contractId = hexOrZero(receipt.
|
1458
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1394
1459
|
const subId = hexOrZero(receipt.subId);
|
1395
1460
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1396
1461
|
const burnReceipt = {
|
@@ -1416,7 +1481,6 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1416
1481
|
var import_math5 = require("@fuel-ts/math");
|
1417
1482
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1418
1483
|
var import_utils6 = require("@fuel-ts/utils");
|
1419
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1420
1484
|
var getGasUsedFromReceipts = (receipts) => {
|
1421
1485
|
const scriptResult = receipts.filter(
|
1422
1486
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1437,18 +1501,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1437
1501
|
}
|
1438
1502
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1439
1503
|
const witnessCache = [];
|
1440
|
-
const
|
1504
|
+
const chargeableInputs = inputs.filter((input) => {
|
1505
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1506
|
+
if (isCoinOrMessage) {
|
1507
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1508
|
+
return true;
|
1509
|
+
}
|
1510
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1511
|
+
witnessCache.push(input.witnessIndex);
|
1512
|
+
return true;
|
1513
|
+
}
|
1514
|
+
}
|
1515
|
+
return false;
|
1516
|
+
});
|
1517
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1518
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1441
1519
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1442
1520
|
return total.add(
|
1443
|
-
|
1521
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1444
1522
|
);
|
1445
1523
|
}
|
1446
|
-
|
1447
|
-
|
1448
|
-
return total.add(gasCosts.ecr1);
|
1449
|
-
}
|
1450
|
-
return total;
|
1451
|
-
}, (0, import_math5.bn)());
|
1524
|
+
return total.add(gasCosts.ecr1);
|
1525
|
+
}, (0, import_math5.bn)(0));
|
1452
1526
|
return totalGas;
|
1453
1527
|
}
|
1454
1528
|
function getMinGas(params) {
|
@@ -1460,12 +1534,20 @@ function getMinGas(params) {
|
|
1460
1534
|
return minGas;
|
1461
1535
|
}
|
1462
1536
|
function getMaxGas(params) {
|
1463
|
-
const {
|
1537
|
+
const {
|
1538
|
+
gasPerByte,
|
1539
|
+
witnessesLength,
|
1540
|
+
witnessLimit,
|
1541
|
+
minGas,
|
1542
|
+
gasLimit = (0, import_math5.bn)(0),
|
1543
|
+
maxGasPerTx
|
1544
|
+
} = params;
|
1464
1545
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1465
1546
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1466
1547
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1467
1548
|
}
|
1468
|
-
|
1549
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1550
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1469
1551
|
}
|
1470
1552
|
function calculateMetadataGasForTxCreate({
|
1471
1553
|
gasCosts,
|
@@ -1487,6 +1569,10 @@ function calculateMetadataGasForTxScript({
|
|
1487
1569
|
}) {
|
1488
1570
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1489
1571
|
}
|
1572
|
+
var calculateGasFee = (params) => {
|
1573
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1574
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1575
|
+
};
|
1490
1576
|
|
1491
1577
|
// src/providers/utils/json.ts
|
1492
1578
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1623,7 +1709,7 @@ var witnessify = (value) => {
|
|
1623
1709
|
// src/providers/transaction-request/transaction-request.ts
|
1624
1710
|
var BaseTransactionRequest = class {
|
1625
1711
|
/** Gas price for transaction */
|
1626
|
-
|
1712
|
+
tip;
|
1627
1713
|
/** Block until which tx cannot be included */
|
1628
1714
|
maturity;
|
1629
1715
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1642,7 +1728,7 @@ var BaseTransactionRequest = class {
|
|
1642
1728
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1643
1729
|
*/
|
1644
1730
|
constructor({
|
1645
|
-
|
1731
|
+
tip,
|
1646
1732
|
maturity,
|
1647
1733
|
maxFee,
|
1648
1734
|
witnessLimit,
|
@@ -1650,7 +1736,7 @@ var BaseTransactionRequest = class {
|
|
1650
1736
|
outputs,
|
1651
1737
|
witnesses
|
1652
1738
|
} = {}) {
|
1653
|
-
this.
|
1739
|
+
this.tip = (0, import_math7.bn)(tip);
|
1654
1740
|
this.maturity = maturity ?? 0;
|
1655
1741
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1656
1742
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1661,9 +1747,9 @@ var BaseTransactionRequest = class {
|
|
1661
1747
|
static getPolicyMeta(req) {
|
1662
1748
|
let policyTypes = 0;
|
1663
1749
|
const policies = [];
|
1664
|
-
if (req.
|
1665
|
-
policyTypes += import_transactions6.PolicyType.
|
1666
|
-
policies.push({ data: req.
|
1750
|
+
if (req.tip) {
|
1751
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1752
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1667
1753
|
}
|
1668
1754
|
if (req.witnessLimit) {
|
1669
1755
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1850,10 +1936,10 @@ var BaseTransactionRequest = class {
|
|
1850
1936
|
* @param predicate - Predicate bytes.
|
1851
1937
|
* @param predicateData - Predicate data bytes.
|
1852
1938
|
*/
|
1853
|
-
addCoinInput(coin
|
1939
|
+
addCoinInput(coin) {
|
1854
1940
|
const { assetId, owner, amount } = coin;
|
1855
1941
|
let witnessIndex;
|
1856
|
-
if (predicate) {
|
1942
|
+
if (coin.predicate) {
|
1857
1943
|
witnessIndex = 0;
|
1858
1944
|
} else {
|
1859
1945
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1868,8 +1954,7 @@ var BaseTransactionRequest = class {
|
|
1868
1954
|
amount,
|
1869
1955
|
assetId,
|
1870
1956
|
txPointer: "0x00000000000000000000000000000000",
|
1871
|
-
witnessIndex
|
1872
|
-
predicate: predicate?.bytes
|
1957
|
+
witnessIndex
|
1873
1958
|
};
|
1874
1959
|
this.pushInput(input);
|
1875
1960
|
this.addChangeOutput(owner, assetId);
|
@@ -1882,11 +1967,11 @@ var BaseTransactionRequest = class {
|
|
1882
1967
|
* @param predicate - Predicate bytes.
|
1883
1968
|
* @param predicateData - Predicate data bytes.
|
1884
1969
|
*/
|
1885
|
-
addMessageInput(message
|
1970
|
+
addMessageInput(message) {
|
1886
1971
|
const { recipient, sender, amount } = message;
|
1887
1972
|
const assetId = import_configs7.BaseAssetId;
|
1888
1973
|
let witnessIndex;
|
1889
|
-
if (predicate) {
|
1974
|
+
if (message.predicate) {
|
1890
1975
|
witnessIndex = 0;
|
1891
1976
|
} else {
|
1892
1977
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1900,8 +1985,7 @@ var BaseTransactionRequest = class {
|
|
1900
1985
|
sender: sender.toB256(),
|
1901
1986
|
recipient: recipient.toB256(),
|
1902
1987
|
amount,
|
1903
|
-
witnessIndex
|
1904
|
-
predicate: predicate?.bytes
|
1988
|
+
witnessIndex
|
1905
1989
|
};
|
1906
1990
|
this.pushInput(input);
|
1907
1991
|
this.addChangeOutput(recipient, assetId);
|
@@ -1932,32 +2016,6 @@ var BaseTransactionRequest = class {
|
|
1932
2016
|
resources.forEach((resource) => this.addResource(resource));
|
1933
2017
|
return this;
|
1934
2018
|
}
|
1935
|
-
/**
|
1936
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1937
|
-
* outputs from the related assetIds.
|
1938
|
-
*
|
1939
|
-
* @param resources - The resources to add.
|
1940
|
-
* @returns This transaction.
|
1941
|
-
*/
|
1942
|
-
addPredicateResource(resource, predicate) {
|
1943
|
-
if (isCoin(resource)) {
|
1944
|
-
this.addCoinInput(resource, predicate);
|
1945
|
-
} else {
|
1946
|
-
this.addMessageInput(resource, predicate);
|
1947
|
-
}
|
1948
|
-
return this;
|
1949
|
-
}
|
1950
|
-
/**
|
1951
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1952
|
-
* from the related assetIds.
|
1953
|
-
*
|
1954
|
-
* @param resources - The resources to add.
|
1955
|
-
* @returns This transaction.
|
1956
|
-
*/
|
1957
|
-
addPredicateResources(resources, predicate) {
|
1958
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1959
|
-
return this;
|
1960
|
-
}
|
1961
2019
|
/**
|
1962
2020
|
* Adds a coin output to the transaction.
|
1963
2021
|
*
|
@@ -2037,7 +2095,7 @@ var BaseTransactionRequest = class {
|
|
2037
2095
|
}
|
2038
2096
|
calculateMaxGas(chainInfo, minGas) {
|
2039
2097
|
const { consensusParameters } = chainInfo;
|
2040
|
-
const { gasPerByte } = consensusParameters;
|
2098
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2041
2099
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2042
2100
|
(acc, wit) => acc + wit.dataLength,
|
2043
2101
|
0
|
@@ -2046,7 +2104,8 @@ var BaseTransactionRequest = class {
|
|
2046
2104
|
gasPerByte,
|
2047
2105
|
minGas,
|
2048
2106
|
witnessesLength,
|
2049
|
-
witnessLimit: this.witnessLimit
|
2107
|
+
witnessLimit: this.witnessLimit,
|
2108
|
+
maxGasPerTx
|
2050
2109
|
});
|
2051
2110
|
}
|
2052
2111
|
/**
|
@@ -2064,17 +2123,20 @@ var BaseTransactionRequest = class {
|
|
2064
2123
|
});
|
2065
2124
|
const updateAssetInput = (assetId, quantity) => {
|
2066
2125
|
const assetInput = findAssetInput(assetId);
|
2126
|
+
let usedQuantity = quantity;
|
2127
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2128
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2129
|
+
}
|
2067
2130
|
if (assetInput && "assetId" in assetInput) {
|
2068
2131
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2069
|
-
assetInput.amount =
|
2132
|
+
assetInput.amount = usedQuantity;
|
2070
2133
|
} else {
|
2071
2134
|
this.addResources([
|
2072
2135
|
{
|
2073
2136
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2074
|
-
amount:
|
2137
|
+
amount: usedQuantity,
|
2075
2138
|
assetId,
|
2076
2139
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2077
|
-
maturity: 0,
|
2078
2140
|
blockCreated: (0, import_math7.bn)(1),
|
2079
2141
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2080
2142
|
}
|
@@ -2106,7 +2168,7 @@ var BaseTransactionRequest = class {
|
|
2106
2168
|
toJSON() {
|
2107
2169
|
return normalizeJSON(this);
|
2108
2170
|
}
|
2109
|
-
|
2171
|
+
updatePredicateGasUsed(inputs) {
|
2110
2172
|
this.inputs.forEach((i) => {
|
2111
2173
|
let correspondingInput;
|
2112
2174
|
switch (i.type) {
|
@@ -2128,6 +2190,15 @@ var BaseTransactionRequest = class {
|
|
2128
2190
|
}
|
2129
2191
|
});
|
2130
2192
|
}
|
2193
|
+
shiftPredicateData() {
|
2194
|
+
this.inputs.forEach((input) => {
|
2195
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2196
|
+
input.predicateData = input.paddPredicateData(
|
2197
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2198
|
+
);
|
2199
|
+
}
|
2200
|
+
});
|
2201
|
+
}
|
2131
2202
|
};
|
2132
2203
|
|
2133
2204
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2274,9 +2345,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2274
2345
|
return {
|
2275
2346
|
type: import_transactions8.TransactionType.Create,
|
2276
2347
|
...baseTransaction,
|
2277
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2278
2348
|
bytecodeWitnessIndex,
|
2279
|
-
storageSlotsCount: storageSlots.length,
|
2349
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2280
2350
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2281
2351
|
storageSlots
|
2282
2352
|
};
|
@@ -2399,8 +2469,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2399
2469
|
type: import_transactions9.TransactionType.Script,
|
2400
2470
|
scriptGasLimit: this.gasLimit,
|
2401
2471
|
...super.getBaseTransaction(),
|
2402
|
-
scriptLength: script.length,
|
2403
|
-
scriptDataLength: scriptData.length,
|
2472
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2473
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2404
2474
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2405
2475
|
script: (0, import_utils15.hexlify)(script),
|
2406
2476
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2464,7 +2534,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2464
2534
|
}
|
2465
2535
|
calculateMaxGas(chainInfo, minGas) {
|
2466
2536
|
const { consensusParameters } = chainInfo;
|
2467
|
-
const { gasPerByte } = consensusParameters;
|
2537
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2468
2538
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2469
2539
|
(acc, wit) => acc + wit.dataLength,
|
2470
2540
|
0
|
@@ -2474,7 +2544,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2474
2544
|
minGas,
|
2475
2545
|
witnessesLength,
|
2476
2546
|
witnessLimit: this.witnessLimit,
|
2477
|
-
gasLimit: this.gasLimit
|
2547
|
+
gasLimit: this.gasLimit,
|
2548
|
+
maxGasPerTx
|
2478
2549
|
});
|
2479
2550
|
}
|
2480
2551
|
/**
|
@@ -2549,15 +2620,32 @@ var transactionRequestify = (obj) => {
|
|
2549
2620
|
}
|
2550
2621
|
}
|
2551
2622
|
};
|
2623
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2624
|
+
(acc, input) => {
|
2625
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2626
|
+
acc.utxos.push(input.id);
|
2627
|
+
}
|
2628
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2629
|
+
acc.messages.push(input.nonce);
|
2630
|
+
}
|
2631
|
+
return acc;
|
2632
|
+
},
|
2633
|
+
{
|
2634
|
+
utxos: [],
|
2635
|
+
messages: []
|
2636
|
+
}
|
2637
|
+
);
|
2552
2638
|
|
2553
2639
|
// src/providers/transaction-response/transaction-response.ts
|
2554
2640
|
var import_errors13 = require("@fuel-ts/errors");
|
2555
|
-
var
|
2556
|
-
var
|
2557
|
-
var
|
2641
|
+
var import_math15 = require("@fuel-ts/math");
|
2642
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2643
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2558
2644
|
|
2559
2645
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2560
|
-
var
|
2646
|
+
var import_math14 = require("@fuel-ts/math");
|
2647
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2648
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2561
2649
|
|
2562
2650
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2563
2651
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2565,9 +2653,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2565
2653
|
var import_utils16 = require("@fuel-ts/utils");
|
2566
2654
|
var calculateTransactionFee = (params) => {
|
2567
2655
|
const {
|
2568
|
-
|
2656
|
+
gasPrice,
|
2569
2657
|
rawPayload,
|
2570
|
-
|
2658
|
+
tip,
|
2659
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2571
2660
|
} = params;
|
2572
2661
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2573
2662
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2577,8 +2666,7 @@ var calculateTransactionFee = (params) => {
|
|
2577
2666
|
return {
|
2578
2667
|
fee: (0, import_math11.bn)(0),
|
2579
2668
|
minFee: (0, import_math11.bn)(0),
|
2580
|
-
maxFee: (0, import_math11.bn)(0)
|
2581
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2669
|
+
maxFee: (0, import_math11.bn)(0)
|
2582
2670
|
};
|
2583
2671
|
}
|
2584
2672
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2610,7 +2698,6 @@ var calculateTransactionFee = (params) => {
|
|
2610
2698
|
metadataGas,
|
2611
2699
|
txBytesSize: transactionBytes.length
|
2612
2700
|
});
|
2613
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2614
2701
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2615
2702
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2616
2703
|
const maxGas = getMaxGas({
|
@@ -2618,17 +2705,25 @@ var calculateTransactionFee = (params) => {
|
|
2618
2705
|
minGas,
|
2619
2706
|
witnessesLength,
|
2620
2707
|
gasLimit,
|
2621
|
-
witnessLimit
|
2708
|
+
witnessLimit,
|
2709
|
+
maxGasPerTx
|
2710
|
+
});
|
2711
|
+
const minFee = calculateGasFee({
|
2712
|
+
gasPrice,
|
2713
|
+
gas: minGas,
|
2714
|
+
priceFactor: gasPriceFactor,
|
2715
|
+
tip
|
2716
|
+
});
|
2717
|
+
const maxFee = calculateGasFee({
|
2718
|
+
gasPrice,
|
2719
|
+
gas: maxGas,
|
2720
|
+
priceFactor: gasPriceFactor,
|
2721
|
+
tip
|
2622
2722
|
});
|
2623
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2624
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2625
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2626
|
-
const fee = minFee.add(feeFromGasUsed);
|
2627
2723
|
return {
|
2628
|
-
fee,
|
2629
2724
|
minFee,
|
2630
2725
|
maxFee,
|
2631
|
-
|
2726
|
+
fee: maxFee
|
2632
2727
|
};
|
2633
2728
|
};
|
2634
2729
|
|
@@ -3195,10 +3290,12 @@ function assembleTransactionSummary(params) {
|
|
3195
3290
|
gqlTransactionStatus,
|
3196
3291
|
abiMap = {},
|
3197
3292
|
maxInputs,
|
3198
|
-
gasCosts
|
3293
|
+
gasCosts,
|
3294
|
+
maxGasPerTx,
|
3295
|
+
gasPrice
|
3199
3296
|
} = params;
|
3200
3297
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3201
|
-
const rawPayload = (0,
|
3298
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3202
3299
|
const operations = getOperations({
|
3203
3300
|
transactionType: transaction.type,
|
3204
3301
|
inputs: transaction.inputs || [],
|
@@ -3209,11 +3306,14 @@ function assembleTransactionSummary(params) {
|
|
3209
3306
|
maxInputs
|
3210
3307
|
});
|
3211
3308
|
const typeName = getTransactionTypeName(transaction.type);
|
3309
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3212
3310
|
const { fee } = calculateTransactionFee({
|
3213
|
-
|
3311
|
+
gasPrice,
|
3214
3312
|
rawPayload,
|
3313
|
+
tip,
|
3215
3314
|
consensusParameters: {
|
3216
3315
|
gasCosts,
|
3316
|
+
maxGasPerTx,
|
3217
3317
|
feeParams: {
|
3218
3318
|
gasPerByte,
|
3219
3319
|
gasPriceFactor
|
@@ -3225,7 +3325,7 @@ function assembleTransactionSummary(params) {
|
|
3225
3325
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3226
3326
|
let date;
|
3227
3327
|
if (time) {
|
3228
|
-
date =
|
3328
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3229
3329
|
}
|
3230
3330
|
const transactionSummary = {
|
3231
3331
|
id,
|
@@ -3253,12 +3353,12 @@ function assembleTransactionSummary(params) {
|
|
3253
3353
|
|
3254
3354
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3255
3355
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3256
|
-
var
|
3356
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3257
3357
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3258
3358
|
return receipts.reduce((logs, receipt) => {
|
3259
|
-
if (receipt.type ===
|
3359
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3260
3360
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3261
|
-
const data = receipt.type ===
|
3361
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3262
3362
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3263
3363
|
logs.push(decodedLog);
|
3264
3364
|
}
|
@@ -3273,7 +3373,7 @@ var TransactionResponse = class {
|
|
3273
3373
|
/** Current provider */
|
3274
3374
|
provider;
|
3275
3375
|
/** Gas used on the transaction */
|
3276
|
-
gasUsed = (0,
|
3376
|
+
gasUsed = (0, import_math15.bn)(0);
|
3277
3377
|
/** The graphql Transaction with receipts object. */
|
3278
3378
|
gqlTransaction;
|
3279
3379
|
abis;
|
@@ -3331,8 +3431,8 @@ var TransactionResponse = class {
|
|
3331
3431
|
* @returns The decoded transaction.
|
3332
3432
|
*/
|
3333
3433
|
decodeTransaction(transactionWithReceipts) {
|
3334
|
-
return new
|
3335
|
-
(0,
|
3434
|
+
return new import_transactions18.TransactionCoder().decode(
|
3435
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3336
3436
|
0
|
3337
3437
|
)?.[0];
|
3338
3438
|
}
|
@@ -3351,20 +3451,27 @@ var TransactionResponse = class {
|
|
3351
3451
|
const decodedTransaction = this.decodeTransaction(
|
3352
3452
|
transaction
|
3353
3453
|
);
|
3354
|
-
|
3355
|
-
|
3454
|
+
let txReceipts = [];
|
3455
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3456
|
+
txReceipts = transaction.status.receipts;
|
3457
|
+
}
|
3458
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3459
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3460
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3356
3461
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3357
3462
|
const transactionSummary = assembleTransactionSummary({
|
3358
3463
|
id: this.id,
|
3359
3464
|
receipts,
|
3360
3465
|
transaction: decodedTransaction,
|
3361
|
-
transactionBytes: (0,
|
3466
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3362
3467
|
gqlTransactionStatus: transaction.status,
|
3363
3468
|
gasPerByte,
|
3364
3469
|
gasPriceFactor,
|
3365
3470
|
abiMap: contractsAbiMap,
|
3366
3471
|
maxInputs,
|
3367
|
-
gasCosts
|
3472
|
+
gasCosts,
|
3473
|
+
maxGasPerTx,
|
3474
|
+
gasPrice
|
3368
3475
|
});
|
3369
3476
|
return transactionSummary;
|
3370
3477
|
}
|
@@ -3491,29 +3598,29 @@ var processGqlChain = (chain) => {
|
|
3491
3598
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3492
3599
|
return {
|
3493
3600
|
name,
|
3494
|
-
baseChainHeight: (0,
|
3601
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3495
3602
|
consensusParameters: {
|
3496
|
-
contractMaxSize: (0,
|
3497
|
-
maxInputs: (0,
|
3498
|
-
maxOutputs: (0,
|
3499
|
-
maxWitnesses: (0,
|
3500
|
-
maxGasPerTx: (0,
|
3501
|
-
maxScriptLength: (0,
|
3502
|
-
maxScriptDataLength: (0,
|
3503
|
-
maxStorageSlots: (0,
|
3504
|
-
maxPredicateLength: (0,
|
3505
|
-
maxPredicateDataLength: (0,
|
3506
|
-
maxGasPerPredicate: (0,
|
3507
|
-
gasPriceFactor: (0,
|
3508
|
-
gasPerByte: (0,
|
3509
|
-
maxMessageDataLength: (0,
|
3510
|
-
chainId: (0,
|
3603
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3604
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3605
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3606
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3607
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3608
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3609
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3610
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3611
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3612
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3613
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3614
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3615
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3616
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3617
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3511
3618
|
gasCosts
|
3512
3619
|
},
|
3513
3620
|
gasCosts,
|
3514
3621
|
latestBlock: {
|
3515
3622
|
id: latestBlock.id,
|
3516
|
-
height: (0,
|
3623
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3517
3624
|
time: latestBlock.header.time,
|
3518
3625
|
transactions: latestBlock.transactions.map((i) => ({
|
3519
3626
|
id: i.id
|
@@ -3607,10 +3714,8 @@ var _Provider = class {
|
|
3607
3714
|
* Returns some helpful parameters related to gas fees.
|
3608
3715
|
*/
|
3609
3716
|
getGasConfig() {
|
3610
|
-
const { minGasPrice } = this.getNode();
|
3611
3717
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3612
3718
|
return {
|
3613
|
-
minGasPrice,
|
3614
3719
|
maxGasPerTx,
|
3615
3720
|
maxGasPerPredicate,
|
3616
3721
|
gasPriceFactor,
|
@@ -3686,6 +3791,21 @@ var _Provider = class {
|
|
3686
3791
|
} = await this.operations.getVersion();
|
3687
3792
|
return nodeVersion;
|
3688
3793
|
}
|
3794
|
+
/**
|
3795
|
+
* @hidden
|
3796
|
+
*
|
3797
|
+
* Returns the network configuration of the connected Fuel node.
|
3798
|
+
*
|
3799
|
+
* @returns A promise that resolves to the network configuration object
|
3800
|
+
*/
|
3801
|
+
async getNetwork() {
|
3802
|
+
const {
|
3803
|
+
name,
|
3804
|
+
consensusParameters: { chainId }
|
3805
|
+
} = await this.getChain();
|
3806
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
3807
|
+
return Promise.resolve(network);
|
3808
|
+
}
|
3689
3809
|
/**
|
3690
3810
|
* Returns the block number.
|
3691
3811
|
*
|
@@ -3693,7 +3813,7 @@ var _Provider = class {
|
|
3693
3813
|
*/
|
3694
3814
|
async getBlockNumber() {
|
3695
3815
|
const { chain } = await this.operations.getChain();
|
3696
|
-
return (0,
|
3816
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3697
3817
|
}
|
3698
3818
|
/**
|
3699
3819
|
* Returns the chain information.
|
@@ -3703,13 +3823,11 @@ var _Provider = class {
|
|
3703
3823
|
async fetchNode() {
|
3704
3824
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3705
3825
|
const processedNodeInfo = {
|
3706
|
-
maxDepth: (0,
|
3707
|
-
maxTx: (0,
|
3708
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3826
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
3827
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3709
3828
|
nodeVersion: nodeInfo.nodeVersion,
|
3710
3829
|
utxoValidation: nodeInfo.utxoValidation,
|
3711
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3712
|
-
peers: nodeInfo.peers
|
3830
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3713
3831
|
};
|
3714
3832
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3715
3833
|
return processedNodeInfo;
|
@@ -3751,9 +3869,9 @@ var _Provider = class {
|
|
3751
3869
|
if (estimateTxDependencies) {
|
3752
3870
|
await this.estimateTxDependencies(transactionRequest);
|
3753
3871
|
}
|
3754
|
-
const encodedTransaction = (0,
|
3872
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3755
3873
|
let abis;
|
3756
|
-
if (transactionRequest.type ===
|
3874
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3757
3875
|
abis = transactionRequest.abis;
|
3758
3876
|
}
|
3759
3877
|
if (awaitExecution) {
|
@@ -3794,15 +3912,14 @@ var _Provider = class {
|
|
3794
3912
|
if (estimateTxDependencies) {
|
3795
3913
|
return this.estimateTxDependencies(transactionRequest);
|
3796
3914
|
}
|
3797
|
-
const encodedTransaction = (0,
|
3798
|
-
const { dryRun:
|
3799
|
-
encodedTransaction,
|
3915
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3916
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3917
|
+
encodedTransactions: encodedTransaction,
|
3800
3918
|
utxoValidation: utxoValidation || false
|
3801
3919
|
});
|
3802
|
-
const receipts =
|
3803
|
-
|
3804
|
-
|
3805
|
-
};
|
3920
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3921
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3922
|
+
return { receipts, dryrunStatus: status };
|
3806
3923
|
}
|
3807
3924
|
/**
|
3808
3925
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3813,13 +3930,13 @@ var _Provider = class {
|
|
3813
3930
|
async estimatePredicates(transactionRequest) {
|
3814
3931
|
const shouldEstimatePredicates = Boolean(
|
3815
3932
|
transactionRequest.inputs.find(
|
3816
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3933
|
+
(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()
|
3817
3934
|
)
|
3818
3935
|
);
|
3819
3936
|
if (!shouldEstimatePredicates) {
|
3820
3937
|
return transactionRequest;
|
3821
3938
|
}
|
3822
|
-
const encodedTransaction = (0,
|
3939
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3823
3940
|
const response = await this.operations.estimatePredicates({
|
3824
3941
|
encodedTransaction
|
3825
3942
|
});
|
@@ -3828,7 +3945,7 @@ var _Provider = class {
|
|
3828
3945
|
} = response;
|
3829
3946
|
if (inputs) {
|
3830
3947
|
inputs.forEach((input, index) => {
|
3831
|
-
if ("predicateGasUsed" in input && (0,
|
3948
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
3832
3949
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3833
3950
|
}
|
3834
3951
|
});
|
@@ -3841,31 +3958,31 @@ var _Provider = class {
|
|
3841
3958
|
* If there are missing variable outputs,
|
3842
3959
|
* `addVariableOutputs` is called on the transaction.
|
3843
3960
|
*
|
3844
|
-
* @privateRemarks
|
3845
|
-
* TODO: Investigate support for missing contract IDs
|
3846
|
-
* TODO: Add support for missing output messages
|
3847
3961
|
*
|
3848
3962
|
* @param transactionRequest - The transaction request object.
|
3849
3963
|
* @returns A promise.
|
3850
3964
|
*/
|
3851
3965
|
async estimateTxDependencies(transactionRequest) {
|
3852
|
-
if (transactionRequest.type ===
|
3966
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
3853
3967
|
return {
|
3854
3968
|
receipts: [],
|
3855
3969
|
outputVariables: 0,
|
3856
3970
|
missingContractIds: []
|
3857
3971
|
};
|
3858
3972
|
}
|
3859
|
-
await this.estimatePredicates(transactionRequest);
|
3860
3973
|
let receipts = [];
|
3861
3974
|
const missingContractIds = [];
|
3862
3975
|
let outputVariables = 0;
|
3976
|
+
let dryrunStatus;
|
3863
3977
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3864
|
-
const {
|
3865
|
-
|
3978
|
+
const {
|
3979
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3980
|
+
} = await this.operations.dryRun({
|
3981
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3866
3982
|
utxoValidation: false
|
3867
3983
|
});
|
3868
|
-
receipts =
|
3984
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3985
|
+
dryrunStatus = status;
|
3869
3986
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3870
3987
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3871
3988
|
if (hasMissingOutputs) {
|
@@ -3875,6 +3992,10 @@ var _Provider = class {
|
|
3875
3992
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3876
3993
|
missingContractIds.push(contractId);
|
3877
3994
|
});
|
3995
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3996
|
+
transactionRequest
|
3997
|
+
});
|
3998
|
+
transactionRequest.maxFee = maxFee;
|
3878
3999
|
} else {
|
3879
4000
|
break;
|
3880
4001
|
}
|
@@ -3882,37 +4003,139 @@ var _Provider = class {
|
|
3882
4003
|
return {
|
3883
4004
|
receipts,
|
3884
4005
|
outputVariables,
|
3885
|
-
missingContractIds
|
4006
|
+
missingContractIds,
|
4007
|
+
dryrunStatus
|
3886
4008
|
};
|
3887
4009
|
}
|
4010
|
+
/**
|
4011
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4012
|
+
*
|
4013
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4014
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4015
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4016
|
+
*
|
4017
|
+
* @param transactionRequests - Array of transaction request objects.
|
4018
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4019
|
+
*/
|
4020
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4021
|
+
const results = transactionRequests.map(() => ({
|
4022
|
+
receipts: [],
|
4023
|
+
outputVariables: 0,
|
4024
|
+
missingContractIds: [],
|
4025
|
+
dryrunStatus: void 0
|
4026
|
+
}));
|
4027
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4028
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4029
|
+
allRequests.forEach((req, index) => {
|
4030
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4031
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4032
|
+
}
|
4033
|
+
});
|
4034
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4035
|
+
let attempt = 0;
|
4036
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4037
|
+
const encodedTransactions = transactionsToProcess.map(
|
4038
|
+
(index) => serializedTransactionsMap.get(index)
|
4039
|
+
);
|
4040
|
+
const dryRunResults = await this.operations.dryRun({
|
4041
|
+
encodedTransactions,
|
4042
|
+
utxoValidation: false
|
4043
|
+
});
|
4044
|
+
const nextRoundTransactions = [];
|
4045
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4046
|
+
const currentResultIndex = transactionsToProcess[i];
|
4047
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4048
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4049
|
+
results[currentResultIndex].dryrunStatus = status;
|
4050
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4051
|
+
results[currentResultIndex].receipts
|
4052
|
+
);
|
4053
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4054
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4055
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4056
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4057
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4058
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4059
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4060
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4061
|
+
});
|
4062
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4063
|
+
transactionRequest: requestToProcess
|
4064
|
+
});
|
4065
|
+
requestToProcess.maxFee = maxFee;
|
4066
|
+
serializedTransactionsMap.set(
|
4067
|
+
currentResultIndex,
|
4068
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4069
|
+
);
|
4070
|
+
nextRoundTransactions.push(currentResultIndex);
|
4071
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4072
|
+
}
|
4073
|
+
}
|
4074
|
+
transactionsToProcess = nextRoundTransactions;
|
4075
|
+
attempt += 1;
|
4076
|
+
}
|
4077
|
+
return results;
|
4078
|
+
}
|
4079
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4080
|
+
if (estimateTxDependencies) {
|
4081
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4082
|
+
}
|
4083
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4084
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4085
|
+
encodedTransactions,
|
4086
|
+
utxoValidation: utxoValidation || false
|
4087
|
+
});
|
4088
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4089
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4090
|
+
return { receipts, dryrunStatus: status };
|
4091
|
+
});
|
4092
|
+
return results;
|
4093
|
+
}
|
3888
4094
|
/**
|
3889
4095
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3890
4096
|
* @param transactionRequest - The transaction request object.
|
3891
4097
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3892
4098
|
*/
|
3893
|
-
estimateTxGasAndFee(params) {
|
4099
|
+
async estimateTxGasAndFee(params) {
|
3894
4100
|
const { transactionRequest } = params;
|
3895
|
-
|
4101
|
+
let { gasPrice } = params;
|
3896
4102
|
const chainInfo = this.getChain();
|
3897
|
-
const
|
3898
|
-
transactionRequest.gasPrice = gasPrice;
|
4103
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3899
4104
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3900
|
-
|
3901
|
-
|
4105
|
+
if (!gasPrice) {
|
4106
|
+
gasPrice = await this.estimateGasPrice(10);
|
4107
|
+
}
|
4108
|
+
const minFee = calculateGasFee({
|
4109
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4110
|
+
gas: minGas,
|
4111
|
+
priceFactor: gasPriceFactor,
|
4112
|
+
tip: transactionRequest.tip
|
4113
|
+
}).add(1);
|
4114
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4115
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4116
|
+
gasLimit = transactionRequest.gasLimit;
|
3902
4117
|
if (transactionRequest.gasLimit.eq(0)) {
|
3903
4118
|
transactionRequest.gasLimit = minGas;
|
3904
4119
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3905
4120
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3906
4121
|
);
|
4122
|
+
gasLimit = transactionRequest.gasLimit;
|
3907
4123
|
}
|
3908
4124
|
}
|
3909
4125
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3910
|
-
const maxFee =
|
4126
|
+
const maxFee = calculateGasFee({
|
4127
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4128
|
+
gas: maxGas,
|
4129
|
+
priceFactor: gasPriceFactor,
|
4130
|
+
tip: transactionRequest.tip
|
4131
|
+
}).add(1);
|
3911
4132
|
return {
|
3912
4133
|
minGas,
|
3913
4134
|
minFee,
|
3914
4135
|
maxGas,
|
3915
|
-
maxFee
|
4136
|
+
maxFee,
|
4137
|
+
gasPrice,
|
4138
|
+
gasLimit
|
3916
4139
|
};
|
3917
4140
|
}
|
3918
4141
|
/**
|
@@ -3930,15 +4153,17 @@ var _Provider = class {
|
|
3930
4153
|
if (estimateTxDependencies) {
|
3931
4154
|
return this.estimateTxDependencies(transactionRequest);
|
3932
4155
|
}
|
3933
|
-
const
|
3934
|
-
const { dryRun:
|
3935
|
-
|
4156
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4157
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4158
|
+
encodedTransactions,
|
3936
4159
|
utxoValidation: true
|
3937
4160
|
});
|
3938
|
-
const
|
3939
|
-
|
3940
|
-
receipts
|
3941
|
-
|
4161
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4162
|
+
const { id, receipts, status } = dryRunStatus;
|
4163
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4164
|
+
return { id, receipts: processedReceipts, status };
|
4165
|
+
});
|
4166
|
+
return { receipts: callResult[0].receipts };
|
3942
4167
|
}
|
3943
4168
|
/**
|
3944
4169
|
* Returns a transaction cost to enable user
|
@@ -3955,77 +4180,79 @@ var _Provider = class {
|
|
3955
4180
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3956
4181
|
* @returns A promise that resolves to the transaction cost object.
|
3957
4182
|
*/
|
3958
|
-
async getTransactionCost(transactionRequestLike,
|
3959
|
-
estimateTxDependencies = true,
|
3960
|
-
estimatePredicates = true,
|
3961
|
-
resourcesOwner,
|
3962
|
-
signatureCallback
|
3963
|
-
} = {}) {
|
4183
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3964
4184
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3965
|
-
const
|
3966
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3967
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4185
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
3968
4186
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3969
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4187
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3970
4188
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4189
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
3971
4190
|
if (isScriptTransaction) {
|
3972
|
-
txRequestClone.gasLimit = (0,
|
4191
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
3973
4192
|
}
|
3974
|
-
if (
|
3975
|
-
|
3976
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3977
|
-
}
|
3978
|
-
await this.estimatePredicates(txRequestClone);
|
4193
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4194
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3979
4195
|
}
|
4196
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4197
|
+
let addedSignatures = 0;
|
3980
4198
|
if (signatureCallback && isScriptTransaction) {
|
3981
|
-
|
4199
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4200
|
+
await signatureCallback(signedRequest);
|
4201
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3982
4202
|
}
|
3983
|
-
|
3984
|
-
|
4203
|
+
await this.estimatePredicates(signedRequest);
|
4204
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4205
|
+
transactionRequest: signedRequest
|
3985
4206
|
});
|
3986
4207
|
let receipts = [];
|
3987
4208
|
let missingContractIds = [];
|
3988
4209
|
let outputVariables = 0;
|
3989
|
-
let gasUsed = (0,
|
3990
|
-
|
3991
|
-
|
4210
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4211
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4212
|
+
txRequestClone.maxFee = maxFee;
|
4213
|
+
if (isScriptTransaction) {
|
4214
|
+
txRequestClone.gasLimit = gasLimit;
|
4215
|
+
if (signatureCallback) {
|
4216
|
+
await signatureCallback(txRequestClone);
|
4217
|
+
}
|
3992
4218
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3993
4219
|
receipts = result.receipts;
|
3994
4220
|
outputVariables = result.outputVariables;
|
3995
4221
|
missingContractIds = result.missingContractIds;
|
3996
4222
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3997
4223
|
txRequestClone.gasLimit = gasUsed;
|
3998
|
-
|
3999
|
-
|
4000
|
-
|
4224
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4225
|
+
transactionRequest: txRequestClone,
|
4226
|
+
gasPrice
|
4001
4227
|
}));
|
4002
4228
|
}
|
4003
4229
|
return {
|
4004
4230
|
requiredQuantities: allQuantities,
|
4005
4231
|
receipts,
|
4006
4232
|
gasUsed,
|
4007
|
-
|
4008
|
-
gasPrice: setGasPrice,
|
4233
|
+
gasPrice,
|
4009
4234
|
minGas,
|
4010
4235
|
maxGas,
|
4011
4236
|
minFee,
|
4012
4237
|
maxFee,
|
4013
|
-
estimatedInputs: txRequestClone.inputs,
|
4014
4238
|
outputVariables,
|
4015
|
-
missingContractIds
|
4239
|
+
missingContractIds,
|
4240
|
+
addedSignatures,
|
4241
|
+
estimatedPredicates: txRequestClone.inputs
|
4016
4242
|
};
|
4017
4243
|
}
|
4018
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4244
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4019
4245
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4020
4246
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4021
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4247
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4248
|
+
quantitiesToContract
|
4249
|
+
});
|
4022
4250
|
transactionRequest.addResources(
|
4023
4251
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4024
4252
|
);
|
4025
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4026
|
-
|
4027
|
-
|
4028
|
-
);
|
4253
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4254
|
+
quantitiesToContract
|
4255
|
+
});
|
4029
4256
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4030
4257
|
return {
|
4031
4258
|
resources,
|
@@ -4041,17 +4268,16 @@ var _Provider = class {
|
|
4041
4268
|
const result = await this.operations.getCoins({
|
4042
4269
|
first: 10,
|
4043
4270
|
...paginationArgs,
|
4044
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4271
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4045
4272
|
});
|
4046
4273
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4047
4274
|
return coins.map((coin) => ({
|
4048
4275
|
id: coin.utxoId,
|
4049
4276
|
assetId: coin.assetId,
|
4050
|
-
amount: (0,
|
4277
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4051
4278
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4052
|
-
|
4053
|
-
|
4054
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4279
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4280
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4055
4281
|
}));
|
4056
4282
|
}
|
4057
4283
|
/**
|
@@ -4065,19 +4291,19 @@ var _Provider = class {
|
|
4065
4291
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4066
4292
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4067
4293
|
const excludeInput = {
|
4068
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4069
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4294
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4295
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4070
4296
|
};
|
4071
4297
|
if (this.cache) {
|
4072
4298
|
const uniqueUtxos = new Set(
|
4073
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4299
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4074
4300
|
);
|
4075
4301
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4076
4302
|
}
|
4077
4303
|
const coinsQuery = {
|
4078
4304
|
owner: ownerAddress.toB256(),
|
4079
4305
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4080
|
-
assetId: (0,
|
4306
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4081
4307
|
amount: amount.toString(10),
|
4082
4308
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4083
4309
|
})),
|
@@ -4088,9 +4314,9 @@ var _Provider = class {
|
|
4088
4314
|
switch (coin.__typename) {
|
4089
4315
|
case "MessageCoin":
|
4090
4316
|
return {
|
4091
|
-
amount: (0,
|
4317
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4092
4318
|
assetId: coin.assetId,
|
4093
|
-
daHeight: (0,
|
4319
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4094
4320
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4095
4321
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4096
4322
|
nonce: coin.nonce
|
@@ -4098,12 +4324,11 @@ var _Provider = class {
|
|
4098
4324
|
case "Coin":
|
4099
4325
|
return {
|
4100
4326
|
id: coin.utxoId,
|
4101
|
-
amount: (0,
|
4327
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4102
4328
|
assetId: coin.assetId,
|
4103
4329
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4104
|
-
|
4105
|
-
|
4106
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4330
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4331
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4107
4332
|
};
|
4108
4333
|
default:
|
4109
4334
|
return null;
|
@@ -4120,13 +4345,13 @@ var _Provider = class {
|
|
4120
4345
|
async getBlock(idOrHeight) {
|
4121
4346
|
let variables;
|
4122
4347
|
if (typeof idOrHeight === "number") {
|
4123
|
-
variables = { height: (0,
|
4348
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4124
4349
|
} else if (idOrHeight === "latest") {
|
4125
4350
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4126
4351
|
} else if (idOrHeight.length === 66) {
|
4127
4352
|
variables = { blockId: idOrHeight };
|
4128
4353
|
} else {
|
4129
|
-
variables = { blockId: (0,
|
4354
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4130
4355
|
}
|
4131
4356
|
const { block } = await this.operations.getBlock(variables);
|
4132
4357
|
if (!block) {
|
@@ -4134,7 +4359,7 @@ var _Provider = class {
|
|
4134
4359
|
}
|
4135
4360
|
return {
|
4136
4361
|
id: block.id,
|
4137
|
-
height: (0,
|
4362
|
+
height: (0, import_math16.bn)(block.height),
|
4138
4363
|
time: block.header.time,
|
4139
4364
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4140
4365
|
};
|
@@ -4149,7 +4374,7 @@ var _Provider = class {
|
|
4149
4374
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4150
4375
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4151
4376
|
id: block.id,
|
4152
|
-
height: (0,
|
4377
|
+
height: (0, import_math16.bn)(block.height),
|
4153
4378
|
time: block.header.time,
|
4154
4379
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4155
4380
|
}));
|
@@ -4164,7 +4389,7 @@ var _Provider = class {
|
|
4164
4389
|
async getBlockWithTransactions(idOrHeight) {
|
4165
4390
|
let variables;
|
4166
4391
|
if (typeof idOrHeight === "number") {
|
4167
|
-
variables = { blockHeight: (0,
|
4392
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4168
4393
|
} else if (idOrHeight === "latest") {
|
4169
4394
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4170
4395
|
} else {
|
@@ -4176,11 +4401,11 @@ var _Provider = class {
|
|
4176
4401
|
}
|
4177
4402
|
return {
|
4178
4403
|
id: block.id,
|
4179
|
-
height: (0,
|
4404
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4180
4405
|
time: block.header.time,
|
4181
4406
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4182
4407
|
transactions: block.transactions.map(
|
4183
|
-
(tx) => new
|
4408
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4184
4409
|
)
|
4185
4410
|
};
|
4186
4411
|
}
|
@@ -4195,8 +4420,8 @@ var _Provider = class {
|
|
4195
4420
|
if (!transaction) {
|
4196
4421
|
return null;
|
4197
4422
|
}
|
4198
|
-
return new
|
4199
|
-
(0,
|
4423
|
+
return new import_transactions19.TransactionCoder().decode(
|
4424
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4200
4425
|
0
|
4201
4426
|
)?.[0];
|
4202
4427
|
}
|
@@ -4223,9 +4448,9 @@ var _Provider = class {
|
|
4223
4448
|
async getContractBalance(contractId, assetId) {
|
4224
4449
|
const { contractBalance } = await this.operations.getContractBalance({
|
4225
4450
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4226
|
-
asset: (0,
|
4451
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4227
4452
|
});
|
4228
|
-
return (0,
|
4453
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4229
4454
|
}
|
4230
4455
|
/**
|
4231
4456
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4237,9 +4462,9 @@ var _Provider = class {
|
|
4237
4462
|
async getBalance(owner, assetId) {
|
4238
4463
|
const { balance } = await this.operations.getBalance({
|
4239
4464
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4240
|
-
assetId: (0,
|
4465
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4241
4466
|
});
|
4242
|
-
return (0,
|
4467
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4243
4468
|
}
|
4244
4469
|
/**
|
4245
4470
|
* Returns balances for the given owner.
|
@@ -4257,7 +4482,7 @@ var _Provider = class {
|
|
4257
4482
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4258
4483
|
return balances.map((balance) => ({
|
4259
4484
|
assetId: balance.assetId,
|
4260
|
-
amount: (0,
|
4485
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4261
4486
|
}));
|
4262
4487
|
}
|
4263
4488
|
/**
|
@@ -4275,19 +4500,19 @@ var _Provider = class {
|
|
4275
4500
|
});
|
4276
4501
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4277
4502
|
return messages.map((message) => ({
|
4278
|
-
messageId:
|
4503
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4279
4504
|
sender: message.sender,
|
4280
4505
|
recipient: message.recipient,
|
4281
4506
|
nonce: message.nonce,
|
4282
|
-
amount: (0,
|
4507
|
+
amount: (0, import_math16.bn)(message.amount),
|
4283
4508
|
data: message.data
|
4284
4509
|
}),
|
4285
4510
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4286
4511
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4287
4512
|
nonce: message.nonce,
|
4288
|
-
amount: (0,
|
4289
|
-
data:
|
4290
|
-
daHeight: (0,
|
4513
|
+
amount: (0, import_math16.bn)(message.amount),
|
4514
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4515
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4291
4516
|
}));
|
4292
4517
|
}
|
4293
4518
|
/**
|
@@ -4340,44 +4565,60 @@ var _Provider = class {
|
|
4340
4565
|
} = result.messageProof;
|
4341
4566
|
return {
|
4342
4567
|
messageProof: {
|
4343
|
-
proofIndex: (0,
|
4568
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4344
4569
|
proofSet: messageProof.proofSet
|
4345
4570
|
},
|
4346
4571
|
blockProof: {
|
4347
|
-
proofIndex: (0,
|
4572
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4348
4573
|
proofSet: blockProof.proofSet
|
4349
4574
|
},
|
4350
4575
|
messageBlockHeader: {
|
4351
4576
|
id: messageBlockHeader.id,
|
4352
|
-
daHeight: (0,
|
4353
|
-
transactionsCount: (0,
|
4577
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4578
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4354
4579
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4355
|
-
height: (0,
|
4580
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4356
4581
|
prevRoot: messageBlockHeader.prevRoot,
|
4357
4582
|
time: messageBlockHeader.time,
|
4358
4583
|
applicationHash: messageBlockHeader.applicationHash,
|
4359
|
-
|
4360
|
-
|
4584
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4585
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4586
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4587
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4588
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4361
4589
|
},
|
4362
4590
|
commitBlockHeader: {
|
4363
4591
|
id: commitBlockHeader.id,
|
4364
|
-
daHeight: (0,
|
4365
|
-
transactionsCount: (0,
|
4592
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4593
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4366
4594
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4367
|
-
height: (0,
|
4595
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4368
4596
|
prevRoot: commitBlockHeader.prevRoot,
|
4369
4597
|
time: commitBlockHeader.time,
|
4370
4598
|
applicationHash: commitBlockHeader.applicationHash,
|
4371
|
-
|
4372
|
-
|
4599
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4600
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4601
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4602
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4603
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4373
4604
|
},
|
4374
4605
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4375
4606
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4376
4607
|
nonce,
|
4377
|
-
amount: (0,
|
4608
|
+
amount: (0, import_math16.bn)(amount),
|
4378
4609
|
data
|
4379
4610
|
};
|
4380
4611
|
}
|
4612
|
+
async getLatestGasPrice() {
|
4613
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4614
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4615
|
+
}
|
4616
|
+
async estimateGasPrice(blockHorizon) {
|
4617
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4618
|
+
blockHorizon: String(blockHorizon)
|
4619
|
+
});
|
4620
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4621
|
+
}
|
4381
4622
|
/**
|
4382
4623
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4383
4624
|
*
|
@@ -4397,10 +4638,10 @@ var _Provider = class {
|
|
4397
4638
|
*/
|
4398
4639
|
async produceBlocks(amount, startTime) {
|
4399
4640
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4400
|
-
blocksToProduce: (0,
|
4401
|
-
startTimestamp: startTime ?
|
4641
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4642
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4402
4643
|
});
|
4403
|
-
return (0,
|
4644
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4404
4645
|
}
|
4405
4646
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4406
4647
|
async getTransactionResponse(transactionId) {
|
@@ -4414,7 +4655,7 @@ cacheInputs_fn = function(inputs) {
|
|
4414
4655
|
return;
|
4415
4656
|
}
|
4416
4657
|
inputs.forEach((input) => {
|
4417
|
-
if (input.type ===
|
4658
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4418
4659
|
this.cache?.set(input.id);
|
4419
4660
|
}
|
4420
4661
|
});
|
@@ -4424,9 +4665,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4424
4665
|
|
4425
4666
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4426
4667
|
var import_errors15 = require("@fuel-ts/errors");
|
4427
|
-
var
|
4428
|
-
var
|
4429
|
-
var
|
4668
|
+
var import_math17 = require("@fuel-ts/math");
|
4669
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4670
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4430
4671
|
|
4431
4672
|
// src/providers/chains.ts
|
4432
4673
|
var CHAIN_IDS = {
|
@@ -4475,17 +4716,17 @@ var assets = [
|
|
4475
4716
|
|
4476
4717
|
// src/utils/formatTransferToContractScriptData.ts
|
4477
4718
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4478
|
-
var
|
4479
|
-
var
|
4719
|
+
var import_math18 = require("@fuel-ts/math");
|
4720
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4480
4721
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4481
4722
|
var formatTransferToContractScriptData = (params) => {
|
4482
4723
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4483
4724
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4484
|
-
const encoded = numberCoder.encode(new
|
4725
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4485
4726
|
const scriptData = Uint8Array.from([
|
4486
|
-
...(0,
|
4727
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4487
4728
|
...encoded,
|
4488
|
-
...(0,
|
4729
|
+
...(0, import_utils26.arrayify)(assetId)
|
4489
4730
|
]);
|
4490
4731
|
return scriptData;
|
4491
4732
|
};
|
@@ -4670,36 +4911,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4670
4911
|
* @param fee - The estimated transaction fee.
|
4671
4912
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4672
4913
|
*/
|
4673
|
-
async fund(request,
|
4674
|
-
const
|
4675
|
-
|
4914
|
+
async fund(request, params) {
|
4915
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4916
|
+
const txRequest = request;
|
4917
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4918
|
+
amount: (0, import_math19.bn)(fee),
|
4676
4919
|
assetId: import_configs12.BaseAssetId,
|
4677
|
-
coinQuantities
|
4920
|
+
coinQuantities: requiredQuantities
|
4678
4921
|
});
|
4679
4922
|
const quantitiesDict = {};
|
4680
|
-
|
4923
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4681
4924
|
quantitiesDict[assetId] = {
|
4682
4925
|
required: amount,
|
4683
|
-
owned: (0,
|
4926
|
+
owned: (0, import_math19.bn)(0)
|
4684
4927
|
};
|
4685
4928
|
});
|
4686
|
-
|
4687
|
-
const cachedMessages = [];
|
4688
|
-
const owner = this.address.toB256();
|
4689
|
-
request.inputs.forEach((input) => {
|
4929
|
+
txRequest.inputs.forEach((input) => {
|
4690
4930
|
const isResource = "amount" in input;
|
4691
4931
|
if (isResource) {
|
4692
4932
|
const isCoin2 = "owner" in input;
|
4693
4933
|
if (isCoin2) {
|
4694
4934
|
const assetId = String(input.assetId);
|
4695
|
-
if (
|
4696
|
-
const amount = (0,
|
4935
|
+
if (quantitiesDict[assetId]) {
|
4936
|
+
const amount = (0, import_math19.bn)(input.amount);
|
4697
4937
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4698
|
-
cachedUtxos.push(input.id);
|
4699
4938
|
}
|
4700
|
-
} else if (input.
|
4939
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4701
4940
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4702
|
-
cachedMessages.push(input.nonce);
|
4703
4941
|
}
|
4704
4942
|
}
|
4705
4943
|
});
|
@@ -4714,12 +4952,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4714
4952
|
});
|
4715
4953
|
const needsToBeFunded = missingQuantities.length;
|
4716
4954
|
if (needsToBeFunded) {
|
4717
|
-
const
|
4718
|
-
|
4719
|
-
|
4720
|
-
|
4721
|
-
|
4955
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4956
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4957
|
+
txRequest.addResources(resources);
|
4958
|
+
}
|
4959
|
+
txRequest.shiftPredicateData();
|
4960
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4961
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4962
|
+
if (addedSignatures) {
|
4963
|
+
Array.from({ length: addedSignatures }).forEach(
|
4964
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4965
|
+
);
|
4722
4966
|
}
|
4967
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4968
|
+
transactionRequest: requestToBeReEstimate
|
4969
|
+
});
|
4970
|
+
txRequest.maxFee = maxFee;
|
4971
|
+
return txRequest;
|
4723
4972
|
}
|
4724
4973
|
/**
|
4725
4974
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4727,28 +4976,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4727
4976
|
* @param destination - The address of the destination.
|
4728
4977
|
* @param amount - The amount of coins to transfer.
|
4729
4978
|
* @param assetId - The asset ID of the coins to transfer.
|
4730
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4979
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4731
4980
|
* @returns A promise that resolves to the prepared transaction request.
|
4732
4981
|
*/
|
4733
4982
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4734
|
-
const
|
4735
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4736
|
-
const request = new ScriptTransactionRequest(params);
|
4983
|
+
const request = new ScriptTransactionRequest(txParams);
|
4737
4984
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4738
|
-
const
|
4985
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4739
4986
|
estimateTxDependencies: true,
|
4740
4987
|
resourcesOwner: this
|
4741
4988
|
});
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
await this.fund(request,
|
4751
|
-
request.updatePredicateInputs(estimatedInputs);
|
4989
|
+
if ("gasLimit" in txParams) {
|
4990
|
+
this.validateGas({
|
4991
|
+
gasUsed: txCost.gasUsed,
|
4992
|
+
gasLimit: request.gasLimit
|
4993
|
+
});
|
4994
|
+
}
|
4995
|
+
request.gasLimit = txCost.gasUsed;
|
4996
|
+
request.maxFee = txCost.maxFee;
|
4997
|
+
await this.fund(request, txCost);
|
4752
4998
|
return request;
|
4753
4999
|
}
|
4754
5000
|
/**
|
@@ -4761,7 +5007,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4761
5007
|
* @returns A promise that resolves to the transaction response.
|
4762
5008
|
*/
|
4763
5009
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4764
|
-
if ((0,
|
5010
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4765
5011
|
throw new import_errors16.FuelError(
|
4766
5012
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4767
5013
|
"Transfer amount must be a positive number."
|
@@ -4780,38 +5026,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4780
5026
|
* @returns A promise that resolves to the transaction response.
|
4781
5027
|
*/
|
4782
5028
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4783
|
-
if ((0,
|
5029
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4784
5030
|
throw new import_errors16.FuelError(
|
4785
5031
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4786
5032
|
"Transfer amount must be a positive number."
|
4787
5033
|
);
|
4788
5034
|
}
|
4789
5035
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4790
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4791
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4792
5036
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4793
5037
|
hexlifiedContractId: contractAddress.toB256(),
|
4794
|
-
amountToTransfer: (0,
|
5038
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
4795
5039
|
assetId
|
4796
5040
|
});
|
4797
5041
|
const request = new ScriptTransactionRequest({
|
4798
|
-
...
|
5042
|
+
...txParams,
|
4799
5043
|
script,
|
4800
5044
|
scriptData
|
4801
5045
|
});
|
4802
5046
|
request.addContractInputAndOutput(contractAddress);
|
4803
|
-
const
|
4804
|
-
|
4805
|
-
[{ amount: (0,
|
4806
|
-
);
|
4807
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4808
|
-
this.validateGas({
|
4809
|
-
gasUsed,
|
4810
|
-
gasPrice: request.gasPrice,
|
4811
|
-
gasLimit: request.gasLimit,
|
4812
|
-
minGasPrice
|
5047
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5048
|
+
resourcesOwner: this,
|
5049
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
4813
5050
|
});
|
4814
|
-
|
5051
|
+
if (txParams.gasLimit) {
|
5052
|
+
this.validateGas({
|
5053
|
+
gasUsed: txCost.gasUsed,
|
5054
|
+
gasLimit: request.gasLimit
|
5055
|
+
});
|
5056
|
+
}
|
5057
|
+
request.gasLimit = txCost.gasUsed;
|
5058
|
+
request.maxFee = txCost.maxFee;
|
5059
|
+
await this.fund(request, txCost);
|
4815
5060
|
return this.sendTransaction(request);
|
4816
5061
|
}
|
4817
5062
|
/**
|
@@ -4823,34 +5068,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4823
5068
|
* @returns A promise that resolves to the transaction response.
|
4824
5069
|
*/
|
4825
5070
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4826
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4827
5071
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4828
|
-
const recipientDataArray = (0,
|
5072
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
4829
5073
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4830
5074
|
);
|
4831
|
-
const amountDataArray = (0,
|
4832
|
-
"0x".concat((0,
|
5075
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5076
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4833
5077
|
);
|
4834
5078
|
const script = new Uint8Array([
|
4835
|
-
...(0,
|
5079
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4836
5080
|
...recipientDataArray,
|
4837
5081
|
...amountDataArray
|
4838
5082
|
]);
|
4839
|
-
const params = { script,
|
5083
|
+
const params = { script, ...txParams };
|
4840
5084
|
const request = new ScriptTransactionRequest(params);
|
4841
|
-
const
|
4842
|
-
const
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
});
|
4853
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5085
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5086
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5087
|
+
if (txParams.gasLimit) {
|
5088
|
+
this.validateGas({
|
5089
|
+
gasUsed: txCost.gasUsed,
|
5090
|
+
gasLimit: request.gasLimit
|
5091
|
+
});
|
5092
|
+
}
|
5093
|
+
request.maxFee = txCost.maxFee;
|
5094
|
+
request.gasLimit = txCost.gasUsed;
|
5095
|
+
await this.fund(request, txCost);
|
4854
5096
|
return this.sendTransaction(request);
|
4855
5097
|
}
|
4856
5098
|
async signMessage(message) {
|
@@ -4908,18 +5150,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4908
5150
|
}
|
4909
5151
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4910
5152
|
}
|
4911
|
-
validateGas({
|
4912
|
-
gasUsed,
|
4913
|
-
gasPrice,
|
4914
|
-
gasLimit,
|
4915
|
-
minGasPrice
|
4916
|
-
}) {
|
4917
|
-
if (minGasPrice.gt(gasPrice)) {
|
4918
|
-
throw new import_errors16.FuelError(
|
4919
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4920
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4921
|
-
);
|
4922
|
-
}
|
5153
|
+
validateGas({ gasUsed, gasLimit }) {
|
4923
5154
|
if (gasUsed.gt(gasLimit)) {
|
4924
5155
|
throw new import_errors16.FuelError(
|
4925
5156
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -4933,8 +5164,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4933
5164
|
var import_address5 = require("@fuel-ts/address");
|
4934
5165
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4935
5166
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4936
|
-
var
|
4937
|
-
var
|
5167
|
+
var import_math20 = require("@fuel-ts/math");
|
5168
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4938
5169
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4939
5170
|
var Signer = class {
|
4940
5171
|
address;
|
@@ -4953,10 +5184,10 @@ var Signer = class {
|
|
4953
5184
|
privateKey = `0x${privateKey}`;
|
4954
5185
|
}
|
4955
5186
|
}
|
4956
|
-
const privateKeyBytes = (0,
|
4957
|
-
this.privateKey = (0,
|
4958
|
-
this.publicKey = (0,
|
4959
|
-
this.compressedPublicKey = (0,
|
5187
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5188
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5189
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5190
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4960
5191
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4961
5192
|
}
|
4962
5193
|
/**
|
@@ -4970,11 +5201,11 @@ var Signer = class {
|
|
4970
5201
|
* @returns hashed signature
|
4971
5202
|
*/
|
4972
5203
|
sign(data) {
|
4973
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4974
|
-
const r = (0,
|
4975
|
-
const s = (0,
|
5204
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5205
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5206
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4976
5207
|
s[0] |= (signature.recovery || 0) << 7;
|
4977
|
-
return (0,
|
5208
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4978
5209
|
}
|
4979
5210
|
/**
|
4980
5211
|
* Add point on the current elliptic curve
|
@@ -4983,8 +5214,8 @@ var Signer = class {
|
|
4983
5214
|
* @returns compressed point on the curve
|
4984
5215
|
*/
|
4985
5216
|
addPoint(point) {
|
4986
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4987
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5217
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5218
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
4988
5219
|
const result = p0.add(p1);
|
4989
5220
|
return `0x${result.toHex(true)}`;
|
4990
5221
|
}
|
@@ -4996,16 +5227,16 @@ var Signer = class {
|
|
4996
5227
|
* @returns public key from signature from the
|
4997
5228
|
*/
|
4998
5229
|
static recoverPublicKey(data, signature) {
|
4999
|
-
const signedMessageBytes = (0,
|
5230
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5000
5231
|
const r = signedMessageBytes.slice(0, 32);
|
5001
5232
|
const s = signedMessageBytes.slice(32, 64);
|
5002
5233
|
const recoveryParam = (s[0] & 128) >> 7;
|
5003
5234
|
s[0] &= 127;
|
5004
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5235
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5005
5236
|
recoveryParam
|
5006
5237
|
);
|
5007
|
-
const publicKey = sig.recoverPublicKey((0,
|
5008
|
-
return (0,
|
5238
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5239
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5009
5240
|
}
|
5010
5241
|
/**
|
5011
5242
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5024,7 +5255,7 @@ var Signer = class {
|
|
5024
5255
|
* @returns random 32-byte hashed
|
5025
5256
|
*/
|
5026
5257
|
static generatePrivateKey(entropy) {
|
5027
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5258
|
+
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);
|
5028
5259
|
}
|
5029
5260
|
/**
|
5030
5261
|
* Extended publicKey from a compact publicKey
|
@@ -5033,8 +5264,8 @@ var Signer = class {
|
|
5033
5264
|
* @returns extended publicKey
|
5034
5265
|
*/
|
5035
5266
|
static extendPublicKey(publicKey) {
|
5036
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5037
|
-
return (0,
|
5267
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5268
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5038
5269
|
}
|
5039
5270
|
};
|
5040
5271
|
|
@@ -5042,7 +5273,7 @@ var Signer = class {
|
|
5042
5273
|
var import_address6 = require("@fuel-ts/address");
|
5043
5274
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5044
5275
|
var import_errors17 = require("@fuel-ts/errors");
|
5045
|
-
var
|
5276
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5046
5277
|
var import_uuid = require("uuid");
|
5047
5278
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5048
5279
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5125,7 +5356,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5125
5356
|
);
|
5126
5357
|
}
|
5127
5358
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5128
|
-
const privateKey = (0,
|
5359
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5129
5360
|
return privateKey;
|
5130
5361
|
}
|
5131
5362
|
|
@@ -5170,7 +5401,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5170
5401
|
*/
|
5171
5402
|
async signMessage(message) {
|
5172
5403
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5173
|
-
return (0,
|
5404
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5174
5405
|
}
|
5175
5406
|
/**
|
5176
5407
|
* Signs a transaction with the wallet's private key.
|
@@ -5183,7 +5414,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5183
5414
|
const chainId = this.provider.getChainId();
|
5184
5415
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5185
5416
|
const signature = await this.signer().sign(hashedTransaction);
|
5186
|
-
return (0,
|
5417
|
+
return (0, import_utils30.hexlify)(signature);
|
5187
5418
|
}
|
5188
5419
|
/**
|
5189
5420
|
* Populates a transaction with the witnesses signature.
|
@@ -5203,7 +5434,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5203
5434
|
* @param transactionRequestLike - The transaction request to send.
|
5204
5435
|
* @returns A promise that resolves to the TransactionResponse object.
|
5205
5436
|
*/
|
5206
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5437
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5207
5438
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5208
5439
|
if (estimateTxDependencies) {
|
5209
5440
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5242,17 +5473,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5242
5473
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5243
5474
|
|
5244
5475
|
// src/hdwallet/hdwallet.ts
|
5245
|
-
var import_crypto5 = require("@fuel-ts/crypto");
|
5246
5476
|
var import_errors20 = require("@fuel-ts/errors");
|
5247
5477
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5248
|
-
var
|
5249
|
-
var
|
5478
|
+
var import_math21 = require("@fuel-ts/math");
|
5479
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5480
|
+
var import_ethers3 = require("ethers");
|
5250
5481
|
|
5251
5482
|
// src/mnemonic/mnemonic.ts
|
5252
5483
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5253
5484
|
var import_errors19 = require("@fuel-ts/errors");
|
5254
5485
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5255
|
-
var
|
5486
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5487
|
+
var import_ethers2 = require("ethers");
|
5256
5488
|
|
5257
5489
|
// src/wordlists/words/english.ts
|
5258
5490
|
var english = [
|
@@ -7309,7 +7541,7 @@ var english = [
|
|
7309
7541
|
// src/mnemonic/utils.ts
|
7310
7542
|
var import_errors18 = require("@fuel-ts/errors");
|
7311
7543
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7312
|
-
var
|
7544
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7313
7545
|
function toUtf8Bytes(stri) {
|
7314
7546
|
const str = stri.normalize("NFKD");
|
7315
7547
|
const result = [];
|
@@ -7376,14 +7608,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7376
7608
|
}
|
7377
7609
|
}
|
7378
7610
|
const checksumBits = entropy.length / 4;
|
7379
|
-
const checksum = (0,
|
7611
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7380
7612
|
indices[indices.length - 1] <<= checksumBits;
|
7381
7613
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7382
7614
|
return indices;
|
7383
7615
|
}
|
7384
7616
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7385
7617
|
const size = Math.ceil(11 * words.length / 8);
|
7386
|
-
const entropy = (0,
|
7618
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7387
7619
|
let offset = 0;
|
7388
7620
|
for (let i = 0; i < words.length; i += 1) {
|
7389
7621
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7403,7 +7635,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7403
7635
|
const entropyBits = 32 * words.length / 3;
|
7404
7636
|
const checksumBits = words.length / 3;
|
7405
7637
|
const checksumMask = getUpperMask(checksumBits);
|
7406
|
-
const checksum = (0,
|
7638
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7407
7639
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7408
7640
|
throw new import_errors18.FuelError(
|
7409
7641
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7478,7 +7710,7 @@ var Mnemonic = class {
|
|
7478
7710
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7479
7711
|
const words = getWords(phrase);
|
7480
7712
|
assertMnemonic(words);
|
7481
|
-
return (0,
|
7713
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7482
7714
|
}
|
7483
7715
|
/**
|
7484
7716
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7486,7 +7718,7 @@ var Mnemonic = class {
|
|
7486
7718
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7487
7719
|
*/
|
7488
7720
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7489
|
-
const entropyBytes = (0,
|
7721
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7490
7722
|
assertWordList(wordlist);
|
7491
7723
|
assertEntropy(entropyBytes);
|
7492
7724
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7500,7 +7732,7 @@ var Mnemonic = class {
|
|
7500
7732
|
assertMnemonic(getWords(phrase));
|
7501
7733
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7502
7734
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7503
|
-
return (0,
|
7735
|
+
return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7504
7736
|
}
|
7505
7737
|
/**
|
7506
7738
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7555,14 +7787,14 @@ var Mnemonic = class {
|
|
7555
7787
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7556
7788
|
*/
|
7557
7789
|
static masterKeysFromSeed(seed) {
|
7558
|
-
const seedArray = (0,
|
7790
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7559
7791
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7560
7792
|
throw new import_errors19.FuelError(
|
7561
7793
|
import_errors19.ErrorCode.INVALID_SEED,
|
7562
7794
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7563
7795
|
);
|
7564
7796
|
}
|
7565
|
-
return (0,
|
7797
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7566
7798
|
}
|
7567
7799
|
/**
|
7568
7800
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7573,22 +7805,22 @@ var Mnemonic = class {
|
|
7573
7805
|
*/
|
7574
7806
|
static seedToExtendedKey(seed, testnet = false) {
|
7575
7807
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7576
|
-
const prefix = (0,
|
7808
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7577
7809
|
const depth = "0x00";
|
7578
7810
|
const fingerprint = "0x00000000";
|
7579
7811
|
const index = "0x00000000";
|
7580
7812
|
const chainCode = masterKey.slice(32);
|
7581
7813
|
const privateKey = masterKey.slice(0, 32);
|
7582
|
-
const extendedKey = (0,
|
7814
|
+
const extendedKey = (0, import_utils32.concat)([
|
7583
7815
|
prefix,
|
7584
7816
|
depth,
|
7585
7817
|
fingerprint,
|
7586
7818
|
index,
|
7587
7819
|
chainCode,
|
7588
|
-
(0,
|
7820
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7589
7821
|
]);
|
7590
|
-
const checksum = (0,
|
7591
|
-
return (0,
|
7822
|
+
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7823
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7592
7824
|
}
|
7593
7825
|
/**
|
7594
7826
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7603,7 +7835,7 @@ var Mnemonic = class {
|
|
7603
7835
|
* @returns A randomly generated mnemonic
|
7604
7836
|
*/
|
7605
7837
|
static generate(size = 32, extraEntropy = "") {
|
7606
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7838
|
+
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);
|
7607
7839
|
return Mnemonic.entropyToMnemonic(entropy);
|
7608
7840
|
}
|
7609
7841
|
};
|
@@ -7611,12 +7843,12 @@ var mnemonic_default = Mnemonic;
|
|
7611
7843
|
|
7612
7844
|
// src/hdwallet/hdwallet.ts
|
7613
7845
|
var HARDENED_INDEX = 2147483648;
|
7614
|
-
var MainnetPRV2 = (0,
|
7615
|
-
var MainnetPUB = (0,
|
7616
|
-
var TestnetPRV2 = (0,
|
7617
|
-
var TestnetPUB = (0,
|
7846
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7847
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7848
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7849
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7618
7850
|
function base58check(data) {
|
7619
|
-
return (0,
|
7851
|
+
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)]));
|
7620
7852
|
}
|
7621
7853
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7622
7854
|
if (isPublic) {
|
@@ -7625,11 +7857,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7625
7857
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7626
7858
|
}
|
7627
7859
|
function isPublicExtendedKey(extendedKey) {
|
7628
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7860
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
7629
7861
|
}
|
7630
7862
|
function isValidExtendedKey(extendedKey) {
|
7631
7863
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7632
|
-
(0,
|
7864
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
7633
7865
|
);
|
7634
7866
|
}
|
7635
7867
|
function parsePath(path2, depth = 0) {
|
@@ -7647,8 +7879,8 @@ function parsePath(path2, depth = 0) {
|
|
7647
7879
|
var HDWallet = class {
|
7648
7880
|
depth = 0;
|
7649
7881
|
index = 0;
|
7650
|
-
fingerprint = (0,
|
7651
|
-
parentFingerprint = (0,
|
7882
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7883
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7652
7884
|
privateKey;
|
7653
7885
|
publicKey;
|
7654
7886
|
chainCode;
|
@@ -7660,8 +7892,8 @@ var HDWallet = class {
|
|
7660
7892
|
constructor(config) {
|
7661
7893
|
if (config.privateKey) {
|
7662
7894
|
const signer = new Signer(config.privateKey);
|
7663
|
-
this.publicKey = (0,
|
7664
|
-
this.privateKey = (0,
|
7895
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7896
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7665
7897
|
} else {
|
7666
7898
|
if (!config.publicKey) {
|
7667
7899
|
throw new import_errors20.FuelError(
|
@@ -7669,10 +7901,10 @@ var HDWallet = class {
|
|
7669
7901
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7670
7902
|
);
|
7671
7903
|
}
|
7672
|
-
this.publicKey = (0,
|
7904
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7673
7905
|
}
|
7674
7906
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7675
|
-
this.fingerprint = (0,
|
7907
|
+
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
7676
7908
|
this.depth = config.depth || this.depth;
|
7677
7909
|
this.index = config.index || this.index;
|
7678
7910
|
this.chainCode = config.chainCode;
|
@@ -7688,9 +7920,9 @@ var HDWallet = class {
|
|
7688
7920
|
* @returns A new instance of HDWallet on the derived index
|
7689
7921
|
*/
|
7690
7922
|
deriveIndex(index) {
|
7691
|
-
const privateKey = this.privateKey && (0,
|
7692
|
-
const publicKey = (0,
|
7693
|
-
const chainCode = (0,
|
7923
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
7924
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
7925
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
7694
7926
|
const data = new Uint8Array(37);
|
7695
7927
|
if (index & HARDENED_INDEX) {
|
7696
7928
|
if (!privateKey) {
|
@@ -7701,15 +7933,15 @@ var HDWallet = class {
|
|
7701
7933
|
}
|
7702
7934
|
data.set(privateKey, 1);
|
7703
7935
|
} else {
|
7704
|
-
data.set((0,
|
7936
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7705
7937
|
}
|
7706
|
-
data.set((0,
|
7707
|
-
const bytes = (0,
|
7938
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
7939
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7708
7940
|
const IL = bytes.slice(0, 32);
|
7709
7941
|
const IR = bytes.slice(32);
|
7710
7942
|
if (privateKey) {
|
7711
7943
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7712
|
-
const ki = (0,
|
7944
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7713
7945
|
return new HDWallet({
|
7714
7946
|
privateKey: ki,
|
7715
7947
|
chainCode: IR,
|
@@ -7718,7 +7950,7 @@ var HDWallet = class {
|
|
7718
7950
|
parentFingerprint: this.fingerprint
|
7719
7951
|
});
|
7720
7952
|
}
|
7721
|
-
const signer = new Signer((0,
|
7953
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
7722
7954
|
const Ki = signer.addPoint(publicKey);
|
7723
7955
|
return new HDWallet({
|
7724
7956
|
publicKey: Ki,
|
@@ -7753,12 +7985,12 @@ var HDWallet = class {
|
|
7753
7985
|
);
|
7754
7986
|
}
|
7755
7987
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7756
|
-
const depth = (0,
|
7988
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7757
7989
|
const parentFingerprint = this.parentFingerprint;
|
7758
|
-
const index = (0,
|
7990
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
7759
7991
|
const chainCode = this.chainCode;
|
7760
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7761
|
-
const extendedKey = (0,
|
7992
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7993
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7762
7994
|
return base58check(extendedKey);
|
7763
7995
|
}
|
7764
7996
|
/**
|
@@ -7770,14 +8002,13 @@ var HDWallet = class {
|
|
7770
8002
|
static fromSeed(seed) {
|
7771
8003
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7772
8004
|
return new HDWallet({
|
7773
|
-
chainCode: (0,
|
7774
|
-
privateKey: (0,
|
8005
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8006
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
7775
8007
|
});
|
7776
8008
|
}
|
7777
8009
|
static fromExtendedKey(extendedKey) {
|
7778
|
-
|
7779
|
-
|
7780
|
-
const bytes = (0, import_utils35.arrayify)(decoded);
|
8010
|
+
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8011
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
7781
8012
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7782
8013
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7783
8014
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7786,9 +8017,9 @@ var HDWallet = class {
|
|
7786
8017
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7787
8018
|
}
|
7788
8019
|
const depth = bytes[4];
|
7789
|
-
const parentFingerprint = (0,
|
7790
|
-
const index = parseInt((0,
|
7791
|
-
const chainCode = (0,
|
8020
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8021
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8022
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7792
8023
|
const key = bytes.slice(45, 78);
|
7793
8024
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7794
8025
|
throw new import_errors20.FuelError(
|
@@ -7975,20 +8206,21 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7975
8206
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7976
8207
|
|
7977
8208
|
// src/test-utils/seedTestWallet.ts
|
7978
|
-
var
|
8209
|
+
var import_crypto5 = require("@fuel-ts/crypto");
|
7979
8210
|
var seedTestWallet = async (wallet, quantities) => {
|
7980
8211
|
const genesisWallet = new WalletUnlocked(
|
7981
|
-
process.env.GENESIS_SECRET || (0,
|
8212
|
+
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7982
8213
|
wallet.provider
|
7983
8214
|
);
|
7984
|
-
const
|
7985
|
-
|
7986
|
-
|
7987
|
-
|
7988
|
-
gasPrice: minGasPrice
|
8215
|
+
const request = new ScriptTransactionRequest();
|
8216
|
+
quantities.forEach((quantity) => {
|
8217
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8218
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7989
8219
|
});
|
7990
|
-
|
7991
|
-
|
8220
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8221
|
+
request.gasLimit = txCost.gasUsed;
|
8222
|
+
request.maxFee = txCost.maxFee;
|
8223
|
+
await genesisWallet.fund(request, txCost);
|
7992
8224
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
7993
8225
|
};
|
7994
8226
|
|
@@ -8003,11 +8235,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8003
8235
|
|
8004
8236
|
// src/test-utils/launchNode.ts
|
8005
8237
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8006
|
-
var
|
8007
|
-
var import_utils36 = require("@fuel-ts/utils");
|
8238
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8008
8239
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8009
8240
|
var import_child_process = require("child_process");
|
8010
|
-
var
|
8241
|
+
var import_crypto6 = require("crypto");
|
8242
|
+
var import_ethers4 = require("ethers");
|
8011
8243
|
var import_fs = require("fs");
|
8012
8244
|
var import_os = __toESM(require("os"));
|
8013
8245
|
var import_path = __toESM(require("path"));
|
@@ -8056,13 +8288,13 @@ var launchNode = async ({
|
|
8056
8288
|
// eslint-disable-next-line no-async-promise-executor
|
8057
8289
|
new Promise(async (resolve, reject) => {
|
8058
8290
|
const remainingArgs = extractRemainingArgs(args, [
|
8059
|
-
"--
|
8291
|
+
"--snapshot",
|
8060
8292
|
"--consensus-key",
|
8061
8293
|
"--db-type",
|
8062
8294
|
"--poa-instant"
|
8063
8295
|
]);
|
8064
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8065
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8296
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8297
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
|
8066
8298
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8067
8299
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8068
8300
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8079,37 +8311,55 @@ var launchNode = async ({
|
|
8079
8311
|
})).toString();
|
8080
8312
|
let chainConfigPathToUse;
|
8081
8313
|
const prefix = basePath || import_os.default.tmpdir();
|
8082
|
-
const suffix = basePath ? "" : (0,
|
8083
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8314
|
+
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8315
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "chainConfigs");
|
8084
8316
|
if (chainConfigPath) {
|
8085
8317
|
chainConfigPathToUse = chainConfigPath;
|
8086
8318
|
} else {
|
8087
8319
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8088
8320
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8089
8321
|
}
|
8090
|
-
|
8091
|
-
|
8322
|
+
let { stateConfigJson } = import_utils35.defaultChainConfigs;
|
8323
|
+
const { chainConfigJson, metadataJson } = import_utils35.defaultChainConfigs;
|
8324
|
+
stateConfigJson = {
|
8325
|
+
...stateConfigJson,
|
8326
|
+
coins: [
|
8327
|
+
...stateConfigJson.coins.map((coin) => ({
|
8328
|
+
...coin,
|
8329
|
+
amount: "18446744073709551615"
|
8330
|
+
}))
|
8331
|
+
],
|
8332
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8333
|
+
...message,
|
8334
|
+
amount: "18446744073709551615"
|
8335
|
+
}))
|
8336
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8337
|
+
};
|
8092
8338
|
if (!process.env.GENESIS_SECRET) {
|
8093
8339
|
const pk = Signer.generatePrivateKey();
|
8094
8340
|
const signer = new Signer(pk);
|
8095
|
-
process.env.GENESIS_SECRET = (0,
|
8096
|
-
|
8097
|
-
|
8098
|
-
|
8099
|
-
|
8100
|
-
|
8101
|
-
|
8102
|
-
|
8103
|
-
|
8104
|
-
|
8105
|
-
|
8106
|
-
}
|
8107
|
-
]
|
8108
|
-
}
|
8109
|
-
};
|
8341
|
+
process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
|
8342
|
+
stateConfigJson.coins.push({
|
8343
|
+
tx_id: (0, import_utils35.hexlify)((0, import_ethers4.randomBytes)(34)),
|
8344
|
+
owner: signer.address.toHexString(),
|
8345
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8346
|
+
amount: "18446744073709551615",
|
8347
|
+
asset_id: import_configs13.BaseAssetId,
|
8348
|
+
output_index: 0,
|
8349
|
+
tx_pointer_block_height: 0,
|
8350
|
+
tx_pointer_tx_idx: 0
|
8351
|
+
});
|
8110
8352
|
}
|
8111
|
-
|
8112
|
-
|
8353
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8354
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8355
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8356
|
+
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8357
|
+
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8358
|
+
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8359
|
+
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8360
|
+
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8361
|
+
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8362
|
+
chainConfigPathToUse = tempDirPath;
|
8113
8363
|
}
|
8114
8364
|
const child = (0, import_child_process.spawn)(
|
8115
8365
|
command,
|
@@ -8118,10 +8368,10 @@ var launchNode = async ({
|
|
8118
8368
|
["--ip", ipToUse],
|
8119
8369
|
["--port", portToUse],
|
8120
8370
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8121
|
-
["--min-gas-price", "
|
8371
|
+
["--min-gas-price", "1"],
|
8122
8372
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8123
8373
|
["--consensus-key", consensusKey],
|
8124
|
-
["--
|
8374
|
+
["--snapshot", chainConfigPathToUse],
|
8125
8375
|
"--vm-backtrace",
|
8126
8376
|
"--utxo-validation",
|
8127
8377
|
"--debug",
|
@@ -8180,7 +8430,7 @@ var launchNodeAndGetWallets = async ({
|
|
8180
8430
|
walletCount = 10
|
8181
8431
|
} = {}) => {
|
8182
8432
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8183
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8433
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8184
8434
|
const wallets = await generateWallets(walletCount, provider);
|
8185
8435
|
const cleanup = () => {
|
8186
8436
|
closeNode();
|