@fuel-ts/account 0.0.0-rc-2021-20240419013807 → 0.0.0-rc-1976-20240419063349
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 +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +604 -830
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +601 -833
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +444 -675
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +329 -911
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -37
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +29 -9
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1118 -1579
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +600 -811
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +456 -667
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -58,42 +58,39 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
58
|
|
59
59
|
// src/wallet/base-wallet-unlocked.ts
|
60
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
61
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
|
-
var import_configs12 = require("@fuel-ts/address/configs");
|
66
65
|
var import_errors16 = require("@fuel-ts/errors");
|
67
66
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
|
-
var
|
69
|
-
var
|
70
|
-
var import_ramda4 = require("ramda");
|
67
|
+
var import_math18 = require("@fuel-ts/math");
|
68
|
+
var import_utils28 = require("@fuel-ts/utils");
|
71
69
|
|
72
70
|
// src/providers/coin-quantity.ts
|
73
|
-
var import_configs = require("@fuel-ts/address/configs");
|
74
71
|
var import_math = require("@fuel-ts/math");
|
75
72
|
var import_utils = require("@fuel-ts/utils");
|
76
73
|
var coinQuantityfy = (coinQuantityLike) => {
|
77
74
|
let assetId;
|
78
75
|
let amount;
|
79
|
-
let
|
76
|
+
let max2;
|
80
77
|
if (Array.isArray(coinQuantityLike)) {
|
81
78
|
amount = coinQuantityLike[0];
|
82
|
-
assetId = coinQuantityLike[1]
|
83
|
-
|
79
|
+
assetId = coinQuantityLike[1];
|
80
|
+
max2 = coinQuantityLike[2];
|
84
81
|
} else {
|
85
82
|
amount = coinQuantityLike.amount;
|
86
|
-
assetId = coinQuantityLike.assetId
|
87
|
-
|
83
|
+
assetId = coinQuantityLike.assetId;
|
84
|
+
max2 = coinQuantityLike.max ?? void 0;
|
88
85
|
}
|
89
86
|
const bnAmount = (0, import_math.bn)(amount);
|
90
87
|
return {
|
91
88
|
assetId: (0, import_utils.hexlify)(assetId),
|
92
89
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
93
|
-
max:
|
90
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
94
91
|
};
|
95
92
|
};
|
96
|
-
var
|
93
|
+
var addAmountToAsset = (params) => {
|
97
94
|
const { amount, assetId } = params;
|
98
95
|
const coinQuantities = [...params.coinQuantities];
|
99
96
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -108,11 +105,11 @@ var addAmountToCoinQuantities = (params) => {
|
|
108
105
|
// src/providers/provider.ts
|
109
106
|
var import_address3 = require("@fuel-ts/address");
|
110
107
|
var import_errors14 = require("@fuel-ts/errors");
|
111
|
-
var
|
112
|
-
var
|
113
|
-
var
|
108
|
+
var import_math15 = require("@fuel-ts/math");
|
109
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
110
|
+
var import_utils23 = require("@fuel-ts/utils");
|
114
111
|
var import_versions = require("@fuel-ts/versions");
|
115
|
-
var
|
112
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
116
113
|
var import_ethers = require("ethers");
|
117
114
|
var import_graphql_request = require("graphql-request");
|
118
115
|
var import_ramda3 = require("ramda");
|
@@ -121,10 +118,14 @@ var import_ramda3 = require("ramda");
|
|
121
118
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
122
119
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
123
120
|
fragment receiptFragment on Receipt {
|
124
|
-
|
121
|
+
contract {
|
122
|
+
id
|
123
|
+
}
|
125
124
|
pc
|
126
125
|
is
|
127
|
-
to
|
126
|
+
to {
|
127
|
+
id
|
128
|
+
}
|
128
129
|
toAddress
|
129
130
|
amount
|
130
131
|
assetId
|
@@ -162,16 +163,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
162
163
|
id
|
163
164
|
}
|
164
165
|
time
|
165
|
-
receipts {
|
166
|
-
...receiptFragment
|
167
|
-
}
|
168
166
|
programState {
|
169
167
|
returnType
|
170
168
|
data
|
171
169
|
}
|
172
|
-
receipts {
|
173
|
-
...receiptFragment
|
174
|
-
}
|
175
170
|
}
|
176
171
|
... on FailureStatus {
|
177
172
|
block {
|
@@ -179,24 +174,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
179
174
|
}
|
180
175
|
time
|
181
176
|
reason
|
182
|
-
receipts {
|
183
|
-
...receiptFragment
|
184
|
-
}
|
185
177
|
}
|
186
178
|
... on SqueezedOutStatus {
|
187
179
|
reason
|
188
180
|
}
|
189
181
|
}
|
190
|
-
|
182
|
+
`;
|
191
183
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
192
184
|
fragment transactionFragment on Transaction {
|
193
185
|
id
|
194
186
|
rawPayload
|
187
|
+
gasPrice
|
188
|
+
receipts {
|
189
|
+
...receiptFragment
|
190
|
+
}
|
195
191
|
status {
|
196
192
|
...transactionStatusFragment
|
197
193
|
}
|
198
194
|
}
|
199
|
-
${
|
195
|
+
${ReceiptFragmentFragmentDoc}
|
196
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
200
197
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
201
198
|
fragment inputEstimatePredicatesFragment on Input {
|
202
199
|
... on InputCoin {
|
@@ -214,46 +211,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
214
211
|
}
|
215
212
|
}
|
216
213
|
${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}`;
|
257
214
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
258
215
|
fragment coinFragment on Coin {
|
259
216
|
__typename
|
@@ -261,6 +218,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
261
218
|
owner
|
262
219
|
amount
|
263
220
|
assetId
|
221
|
+
maturity
|
264
222
|
blockCreated
|
265
223
|
txCreatedIdx
|
266
224
|
}
|
@@ -299,32 +257,26 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
299
257
|
messageBlockHeader {
|
300
258
|
id
|
301
259
|
daHeight
|
302
|
-
consensusParametersVersion
|
303
|
-
stateTransitionBytecodeVersion
|
304
260
|
transactionsCount
|
305
|
-
messageReceiptCount
|
306
261
|
transactionsRoot
|
307
|
-
messageOutboxRoot
|
308
|
-
eventInboxRoot
|
309
262
|
height
|
310
263
|
prevRoot
|
311
264
|
time
|
312
265
|
applicationHash
|
266
|
+
messageReceiptRoot
|
267
|
+
messageReceiptCount
|
313
268
|
}
|
314
269
|
commitBlockHeader {
|
315
270
|
id
|
316
271
|
daHeight
|
317
|
-
consensusParametersVersion
|
318
|
-
stateTransitionBytecodeVersion
|
319
272
|
transactionsCount
|
320
|
-
messageReceiptCount
|
321
273
|
transactionsRoot
|
322
|
-
messageOutboxRoot
|
323
|
-
eventInboxRoot
|
324
274
|
height
|
325
275
|
prevRoot
|
326
276
|
time
|
327
277
|
applicationHash
|
278
|
+
messageReceiptRoot
|
279
|
+
messageReceiptCount
|
328
280
|
}
|
329
281
|
sender
|
330
282
|
recipient
|
@@ -343,8 +295,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
343
295
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
344
296
|
fragment blockFragment on Block {
|
345
297
|
id
|
346
|
-
height
|
347
298
|
header {
|
299
|
+
height
|
348
300
|
time
|
349
301
|
}
|
350
302
|
transactions {
|
@@ -402,11 +354,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
402
354
|
`;
|
403
355
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
404
356
|
fragment GasCostsFragment on GasCosts {
|
405
|
-
version {
|
406
|
-
... on Version {
|
407
|
-
value
|
408
|
-
}
|
409
|
-
}
|
410
357
|
add
|
411
358
|
addi
|
412
359
|
aloc
|
@@ -419,6 +366,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
419
366
|
cb
|
420
367
|
cfei
|
421
368
|
cfsi
|
369
|
+
croo
|
422
370
|
div
|
423
371
|
divi
|
424
372
|
ecr1
|
@@ -501,9 +449,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
501
449
|
ccp {
|
502
450
|
...DependentCostFragment
|
503
451
|
}
|
504
|
-
croo {
|
505
|
-
...DependentCostFragment
|
506
|
-
}
|
507
452
|
csiz {
|
508
453
|
...DependentCostFragment
|
509
454
|
}
|
@@ -563,11 +508,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
563
508
|
${DependentCostFragmentFragmentDoc}`;
|
564
509
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
565
510
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
-
version {
|
567
|
-
... on Version {
|
568
|
-
value
|
569
|
-
}
|
570
|
-
}
|
571
511
|
txParams {
|
572
512
|
...TxParametersFragment
|
573
513
|
}
|
@@ -627,9 +567,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
627
567
|
fragment nodeInfoFragment on NodeInfo {
|
628
568
|
utxoValidation
|
629
569
|
vmBacktrace
|
570
|
+
minGasPrice
|
630
571
|
maxTx
|
631
572
|
maxDepth
|
632
573
|
nodeVersion
|
574
|
+
peers {
|
575
|
+
id
|
576
|
+
addresses
|
577
|
+
clientVersion
|
578
|
+
blockHeight
|
579
|
+
lastHeartbeatMs
|
580
|
+
appScore
|
581
|
+
}
|
633
582
|
}
|
634
583
|
`;
|
635
584
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -664,9 +613,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
664
613
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
665
614
|
transaction(id: $transactionId) {
|
666
615
|
...transactionFragment
|
616
|
+
receipts {
|
617
|
+
...receiptFragment
|
618
|
+
}
|
667
619
|
}
|
668
620
|
}
|
669
|
-
${TransactionFragmentFragmentDoc}
|
621
|
+
${TransactionFragmentFragmentDoc}
|
622
|
+
${ReceiptFragmentFragmentDoc}`;
|
670
623
|
var GetTransactionsDocument = import_graphql_tag.default`
|
671
624
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
672
625
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -794,20 +747,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
794
747
|
}
|
795
748
|
}
|
796
749
|
${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
|
-
`;
|
811
750
|
var GetBalancesDocument = import_graphql_tag.default`
|
812
751
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
813
752
|
balances(
|
@@ -862,12 +801,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
862
801
|
}
|
863
802
|
`;
|
864
803
|
var DryRunDocument = import_graphql_tag.default`
|
865
|
-
mutation dryRun($
|
866
|
-
dryRun(
|
867
|
-
...
|
804
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
805
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
806
|
+
...receiptFragment
|
868
807
|
}
|
869
808
|
}
|
870
|
-
${
|
809
|
+
${ReceiptFragmentFragmentDoc}`;
|
871
810
|
var SubmitDocument = import_graphql_tag.default`
|
872
811
|
mutation submit($encodedTransaction: HexString!) {
|
873
812
|
submit(tx: $encodedTransaction) {
|
@@ -950,12 +889,6 @@ function getSdk(requester) {
|
|
950
889
|
getBalance(variables, options) {
|
951
890
|
return requester(GetBalanceDocument, variables, options);
|
952
891
|
},
|
953
|
-
getLatestGasPrice(variables, options) {
|
954
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
-
},
|
956
|
-
estimateGasPrice(variables, options) {
|
957
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
-
},
|
959
892
|
getBalances(variables, options) {
|
960
893
|
return requester(GetBalancesDocument, variables, options);
|
961
894
|
},
|
@@ -1126,7 +1059,7 @@ var MemoryCache = class {
|
|
1126
1059
|
|
1127
1060
|
// src/providers/transaction-request/input.ts
|
1128
1061
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1129
|
-
var
|
1062
|
+
var import_configs = require("@fuel-ts/address/configs");
|
1130
1063
|
var import_errors3 = require("@fuel-ts/errors");
|
1131
1064
|
var import_math2 = require("@fuel-ts/math");
|
1132
1065
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1149,9 +1082,10 @@ var inputify = (value) => {
|
|
1149
1082
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1150
1083
|
},
|
1151
1084
|
witnessIndex: value.witnessIndex,
|
1085
|
+
maturity: value.maturity ?? 0,
|
1152
1086
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1153
|
-
predicateLength:
|
1154
|
-
predicateDataLength:
|
1087
|
+
predicateLength: predicate.length,
|
1088
|
+
predicateDataLength: predicateData.length,
|
1155
1089
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1156
1090
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1157
1091
|
};
|
@@ -1159,10 +1093,10 @@ var inputify = (value) => {
|
|
1159
1093
|
case import_transactions.InputType.Contract: {
|
1160
1094
|
return {
|
1161
1095
|
type: import_transactions.InputType.Contract,
|
1162
|
-
txID:
|
1096
|
+
txID: import_configs.ZeroBytes32,
|
1163
1097
|
outputIndex: 0,
|
1164
|
-
balanceRoot:
|
1165
|
-
stateRoot:
|
1098
|
+
balanceRoot: import_configs.ZeroBytes32,
|
1099
|
+
stateRoot: import_configs.ZeroBytes32,
|
1166
1100
|
txPointer: {
|
1167
1101
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1168
1102
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1182,8 +1116,8 @@ var inputify = (value) => {
|
|
1182
1116
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1183
1117
|
witnessIndex: value.witnessIndex,
|
1184
1118
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1185
|
-
predicateLength:
|
1186
|
-
predicateDataLength:
|
1119
|
+
predicateLength: predicate.length,
|
1120
|
+
predicateDataLength: predicateData.length,
|
1187
1121
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1188
1122
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1189
1123
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1200,7 +1134,7 @@ var inputify = (value) => {
|
|
1200
1134
|
};
|
1201
1135
|
|
1202
1136
|
// src/providers/transaction-request/output.ts
|
1203
|
-
var
|
1137
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1204
1138
|
var import_errors4 = require("@fuel-ts/errors");
|
1205
1139
|
var import_math3 = require("@fuel-ts/math");
|
1206
1140
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1220,8 +1154,8 @@ var outputify = (value) => {
|
|
1220
1154
|
return {
|
1221
1155
|
type: import_transactions2.OutputType.Contract,
|
1222
1156
|
inputIndex: value.inputIndex,
|
1223
|
-
balanceRoot:
|
1224
|
-
stateRoot:
|
1157
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1158
|
+
stateRoot: import_configs2.ZeroBytes32
|
1225
1159
|
};
|
1226
1160
|
}
|
1227
1161
|
case import_transactions2.OutputType.Change: {
|
@@ -1235,9 +1169,9 @@ var outputify = (value) => {
|
|
1235
1169
|
case import_transactions2.OutputType.Variable: {
|
1236
1170
|
return {
|
1237
1171
|
type: import_transactions2.OutputType.Variable,
|
1238
|
-
to:
|
1172
|
+
to: import_configs2.ZeroBytes32,
|
1239
1173
|
amount: (0, import_math3.bn)(0),
|
1240
|
-
assetId:
|
1174
|
+
assetId: import_configs2.ZeroBytes32
|
1241
1175
|
};
|
1242
1176
|
}
|
1243
1177
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1259,7 +1193,7 @@ var outputify = (value) => {
|
|
1259
1193
|
// src/providers/transaction-request/transaction-request.ts
|
1260
1194
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1261
1195
|
var import_address = require("@fuel-ts/address");
|
1262
|
-
var
|
1196
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1263
1197
|
var import_crypto = require("@fuel-ts/crypto");
|
1264
1198
|
var import_math7 = require("@fuel-ts/math");
|
1265
1199
|
var import_transactions6 = require("@fuel-ts/transactions");
|
@@ -1269,13 +1203,13 @@ var import_utils9 = require("@fuel-ts/utils");
|
|
1269
1203
|
var isCoin = (resource) => "id" in resource;
|
1270
1204
|
|
1271
1205
|
// src/providers/utils/receipts.ts
|
1272
|
-
var
|
1206
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1273
1207
|
var import_errors5 = require("@fuel-ts/errors");
|
1274
1208
|
var import_math4 = require("@fuel-ts/math");
|
1275
1209
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1276
|
-
var
|
1210
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
1277
1211
|
var import_utils5 = require("@fuel-ts/utils");
|
1278
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1212
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1279
1213
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1280
1214
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1281
1215
|
(memo, receipt) => {
|
@@ -1292,15 +1226,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1292
1226
|
missingOutputContractIds: []
|
1293
1227
|
}
|
1294
1228
|
);
|
1295
|
-
var hexOrZero = (hex) => hex ||
|
1229
|
+
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
1296
1230
|
function assembleReceiptByType(receipt) {
|
1297
1231
|
const { receiptType } = receipt;
|
1298
1232
|
switch (receiptType) {
|
1299
1233
|
case "CALL" /* Call */: {
|
1300
1234
|
const callReceipt = {
|
1301
1235
|
type: import_transactions3.ReceiptType.Call,
|
1302
|
-
from: hexOrZero(receipt.id
|
1303
|
-
to: hexOrZero(receipt?.to),
|
1236
|
+
from: hexOrZero(receipt.contract?.id),
|
1237
|
+
to: hexOrZero(receipt?.to?.id),
|
1304
1238
|
amount: (0, import_math4.bn)(receipt.amount),
|
1305
1239
|
assetId: hexOrZero(receipt.assetId),
|
1306
1240
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1314,7 +1248,7 @@ function assembleReceiptByType(receipt) {
|
|
1314
1248
|
case "RETURN" /* Return */: {
|
1315
1249
|
const returnReceipt = {
|
1316
1250
|
type: import_transactions3.ReceiptType.Return,
|
1317
|
-
id: hexOrZero(receipt.id
|
1251
|
+
id: hexOrZero(receipt.contract?.id),
|
1318
1252
|
val: (0, import_math4.bn)(receipt.val),
|
1319
1253
|
pc: (0, import_math4.bn)(receipt.pc),
|
1320
1254
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1324,7 +1258,7 @@ function assembleReceiptByType(receipt) {
|
|
1324
1258
|
case "RETURN_DATA" /* ReturnData */: {
|
1325
1259
|
const returnDataReceipt = {
|
1326
1260
|
type: import_transactions3.ReceiptType.ReturnData,
|
1327
|
-
id: hexOrZero(receipt.id
|
1261
|
+
id: hexOrZero(receipt.contract?.id),
|
1328
1262
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1329
1263
|
len: (0, import_math4.bn)(receipt.len),
|
1330
1264
|
digest: hexOrZero(receipt.digest),
|
@@ -1336,7 +1270,7 @@ function assembleReceiptByType(receipt) {
|
|
1336
1270
|
case "PANIC" /* Panic */: {
|
1337
1271
|
const panicReceipt = {
|
1338
1272
|
type: import_transactions3.ReceiptType.Panic,
|
1339
|
-
id: hexOrZero(receipt.id),
|
1273
|
+
id: hexOrZero(receipt.contract?.id),
|
1340
1274
|
reason: (0, import_math4.bn)(receipt.reason),
|
1341
1275
|
pc: (0, import_math4.bn)(receipt.pc),
|
1342
1276
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1347,7 +1281,7 @@ function assembleReceiptByType(receipt) {
|
|
1347
1281
|
case "REVERT" /* Revert */: {
|
1348
1282
|
const revertReceipt = {
|
1349
1283
|
type: import_transactions3.ReceiptType.Revert,
|
1350
|
-
id: hexOrZero(receipt.id
|
1284
|
+
id: hexOrZero(receipt.contract?.id),
|
1351
1285
|
val: (0, import_math4.bn)(receipt.ra),
|
1352
1286
|
pc: (0, import_math4.bn)(receipt.pc),
|
1353
1287
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1357,7 +1291,7 @@ function assembleReceiptByType(receipt) {
|
|
1357
1291
|
case "LOG" /* Log */: {
|
1358
1292
|
const logReceipt = {
|
1359
1293
|
type: import_transactions3.ReceiptType.Log,
|
1360
|
-
id: hexOrZero(receipt.id
|
1294
|
+
id: hexOrZero(receipt.contract?.id),
|
1361
1295
|
val0: (0, import_math4.bn)(receipt.ra),
|
1362
1296
|
val1: (0, import_math4.bn)(receipt.rb),
|
1363
1297
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1370,7 +1304,7 @@ function assembleReceiptByType(receipt) {
|
|
1370
1304
|
case "LOG_DATA" /* LogData */: {
|
1371
1305
|
const logDataReceipt = {
|
1372
1306
|
type: import_transactions3.ReceiptType.LogData,
|
1373
|
-
id: hexOrZero(receipt.id
|
1307
|
+
id: hexOrZero(receipt.contract?.id),
|
1374
1308
|
val0: (0, import_math4.bn)(receipt.ra),
|
1375
1309
|
val1: (0, import_math4.bn)(receipt.rb),
|
1376
1310
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1384,8 +1318,8 @@ function assembleReceiptByType(receipt) {
|
|
1384
1318
|
case "TRANSFER" /* Transfer */: {
|
1385
1319
|
const transferReceipt = {
|
1386
1320
|
type: import_transactions3.ReceiptType.Transfer,
|
1387
|
-
from: hexOrZero(receipt.id
|
1388
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1321
|
+
from: hexOrZero(receipt.contract?.id),
|
1322
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1389
1323
|
amount: (0, import_math4.bn)(receipt.amount),
|
1390
1324
|
assetId: hexOrZero(receipt.assetId),
|
1391
1325
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1396,8 +1330,8 @@ function assembleReceiptByType(receipt) {
|
|
1396
1330
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1397
1331
|
const transferOutReceipt = {
|
1398
1332
|
type: import_transactions3.ReceiptType.TransferOut,
|
1399
|
-
from: hexOrZero(receipt.id
|
1400
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1333
|
+
from: hexOrZero(receipt.contract?.id),
|
1334
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1401
1335
|
amount: (0, import_math4.bn)(receipt.amount),
|
1402
1336
|
assetId: hexOrZero(receipt.assetId),
|
1403
1337
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1440,7 +1374,7 @@ function assembleReceiptByType(receipt) {
|
|
1440
1374
|
return receiptMessageOut;
|
1441
1375
|
}
|
1442
1376
|
case "MINT" /* Mint */: {
|
1443
|
-
const contractId = hexOrZero(receipt.id
|
1377
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1444
1378
|
const subId = hexOrZero(receipt.subId);
|
1445
1379
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1446
1380
|
const mintReceipt = {
|
@@ -1455,7 +1389,7 @@ function assembleReceiptByType(receipt) {
|
|
1455
1389
|
return mintReceipt;
|
1456
1390
|
}
|
1457
1391
|
case "BURN" /* Burn */: {
|
1458
|
-
const contractId = hexOrZero(receipt.id
|
1392
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1459
1393
|
const subId = hexOrZero(receipt.subId);
|
1460
1394
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1461
1395
|
const burnReceipt = {
|
@@ -1481,6 +1415,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1481
1415
|
var import_math5 = require("@fuel-ts/math");
|
1482
1416
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1483
1417
|
var import_utils6 = require("@fuel-ts/utils");
|
1418
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1484
1419
|
var getGasUsedFromReceipts = (receipts) => {
|
1485
1420
|
const scriptResult = receipts.filter(
|
1486
1421
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1501,28 +1436,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1501
1436
|
}
|
1502
1437
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1503
1438
|
const witnessCache = [];
|
1504
|
-
const
|
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) => {
|
1439
|
+
const totalGas = inputs.reduce((total, input) => {
|
1519
1440
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1520
1441
|
return total.add(
|
1521
|
-
|
1442
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1522
1443
|
);
|
1523
1444
|
}
|
1524
|
-
|
1525
|
-
|
1445
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1446
|
+
witnessCache.push(input.witnessIndex);
|
1447
|
+
return total.add(gasCosts.ecr1);
|
1448
|
+
}
|
1449
|
+
return total;
|
1450
|
+
}, (0, import_math5.bn)());
|
1526
1451
|
return totalGas;
|
1527
1452
|
}
|
1528
1453
|
function getMinGas(params) {
|
@@ -1534,20 +1459,12 @@ function getMinGas(params) {
|
|
1534
1459
|
return minGas;
|
1535
1460
|
}
|
1536
1461
|
function getMaxGas(params) {
|
1537
|
-
const {
|
1538
|
-
gasPerByte,
|
1539
|
-
witnessesLength,
|
1540
|
-
witnessLimit,
|
1541
|
-
minGas,
|
1542
|
-
gasLimit = (0, import_math5.bn)(0),
|
1543
|
-
maxGasPerTx
|
1544
|
-
} = params;
|
1462
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1545
1463
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1546
1464
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1547
1465
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1548
1466
|
}
|
1549
|
-
|
1550
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1467
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1551
1468
|
}
|
1552
1469
|
function calculateMetadataGasForTxCreate({
|
1553
1470
|
gasCosts,
|
@@ -1569,10 +1486,6 @@ function calculateMetadataGasForTxScript({
|
|
1569
1486
|
}) {
|
1570
1487
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1571
1488
|
}
|
1572
|
-
var calculateGasFee = (params) => {
|
1573
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1574
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1575
|
-
};
|
1576
1489
|
|
1577
1490
|
// src/providers/utils/json.ts
|
1578
1491
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1618,16 +1531,16 @@ function sleep(time) {
|
|
1618
1531
|
var import_errors7 = require("@fuel-ts/errors");
|
1619
1532
|
var import_math6 = require("@fuel-ts/math");
|
1620
1533
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1621
|
-
var
|
1534
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1622
1535
|
var assemblePanicError = (status) => {
|
1623
1536
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1624
1537
|
const reason = status.reason;
|
1625
|
-
if (
|
1538
|
+
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1626
1539
|
errorMessage = `${errorMessage}
|
1627
1540
|
|
1628
1541
|
You can read more about this error at:
|
1629
1542
|
|
1630
|
-
${
|
1543
|
+
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1631
1544
|
}
|
1632
1545
|
return { errorMessage, reason };
|
1633
1546
|
};
|
@@ -1639,28 +1552,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1639
1552
|
if (revertReceipt) {
|
1640
1553
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1641
1554
|
switch (reasonHex) {
|
1642
|
-
case
|
1555
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1643
1556
|
reason = "require";
|
1644
1557
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1645
1558
|
break;
|
1646
1559
|
}
|
1647
|
-
case
|
1560
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1648
1561
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1649
1562
|
reason = "assert_eq";
|
1650
1563
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1651
1564
|
break;
|
1652
1565
|
}
|
1653
|
-
case
|
1566
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1654
1567
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1655
1568
|
reason = "assert_ne";
|
1656
1569
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1657
1570
|
break;
|
1658
1571
|
}
|
1659
|
-
case
|
1572
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1660
1573
|
reason = "assert";
|
1661
1574
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1662
1575
|
break;
|
1663
|
-
case
|
1576
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1664
1577
|
reason = "MissingOutputChange";
|
1665
1578
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1666
1579
|
break;
|
@@ -1709,7 +1622,7 @@ var witnessify = (value) => {
|
|
1709
1622
|
// src/providers/transaction-request/transaction-request.ts
|
1710
1623
|
var BaseTransactionRequest = class {
|
1711
1624
|
/** Gas price for transaction */
|
1712
|
-
|
1625
|
+
gasPrice;
|
1713
1626
|
/** Block until which tx cannot be included */
|
1714
1627
|
maturity;
|
1715
1628
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1722,34 +1635,38 @@ var BaseTransactionRequest = class {
|
|
1722
1635
|
outputs = [];
|
1723
1636
|
/** List of witnesses */
|
1724
1637
|
witnesses = [];
|
1638
|
+
/** Base asset ID - should be fetched from the chain */
|
1639
|
+
baseAssetId;
|
1725
1640
|
/**
|
1726
1641
|
* Constructor for initializing a base transaction request.
|
1727
1642
|
*
|
1728
1643
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1729
1644
|
*/
|
1730
1645
|
constructor({
|
1731
|
-
|
1646
|
+
gasPrice,
|
1732
1647
|
maturity,
|
1733
1648
|
maxFee,
|
1734
1649
|
witnessLimit,
|
1735
1650
|
inputs,
|
1736
1651
|
outputs,
|
1737
|
-
witnesses
|
1738
|
-
|
1739
|
-
|
1652
|
+
witnesses,
|
1653
|
+
baseAssetId
|
1654
|
+
}) {
|
1655
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1740
1656
|
this.maturity = maturity ?? 0;
|
1741
1657
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1742
1658
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1743
1659
|
this.inputs = inputs ?? [];
|
1744
1660
|
this.outputs = outputs ?? [];
|
1745
1661
|
this.witnesses = witnesses ?? [];
|
1662
|
+
this.baseAssetId = baseAssetId;
|
1746
1663
|
}
|
1747
1664
|
static getPolicyMeta(req) {
|
1748
1665
|
let policyTypes = 0;
|
1749
1666
|
const policies = [];
|
1750
|
-
if (req.
|
1751
|
-
policyTypes += import_transactions6.PolicyType.
|
1752
|
-
policies.push({ data: req.
|
1667
|
+
if (req.gasPrice) {
|
1668
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1669
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1753
1670
|
}
|
1754
1671
|
if (req.witnessLimit) {
|
1755
1672
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1835,7 +1752,7 @@ var BaseTransactionRequest = class {
|
|
1835
1752
|
* @returns The index of the created witness.
|
1836
1753
|
*/
|
1837
1754
|
addEmptyWitness() {
|
1838
|
-
this.addWitness((0, import_utils9.concat)([
|
1755
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1839
1756
|
return this.witnesses.length - 1;
|
1840
1757
|
}
|
1841
1758
|
/**
|
@@ -1936,10 +1853,10 @@ var BaseTransactionRequest = class {
|
|
1936
1853
|
* @param predicate - Predicate bytes.
|
1937
1854
|
* @param predicateData - Predicate data bytes.
|
1938
1855
|
*/
|
1939
|
-
addCoinInput(coin) {
|
1856
|
+
addCoinInput(coin, predicate) {
|
1940
1857
|
const { assetId, owner, amount } = coin;
|
1941
1858
|
let witnessIndex;
|
1942
|
-
if (
|
1859
|
+
if (predicate) {
|
1943
1860
|
witnessIndex = 0;
|
1944
1861
|
} else {
|
1945
1862
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1954,7 +1871,8 @@ var BaseTransactionRequest = class {
|
|
1954
1871
|
amount,
|
1955
1872
|
assetId,
|
1956
1873
|
txPointer: "0x00000000000000000000000000000000",
|
1957
|
-
witnessIndex
|
1874
|
+
witnessIndex,
|
1875
|
+
predicate: predicate?.bytes
|
1958
1876
|
};
|
1959
1877
|
this.pushInput(input);
|
1960
1878
|
this.addChangeOutput(owner, assetId);
|
@@ -1965,13 +1883,11 @@ var BaseTransactionRequest = class {
|
|
1965
1883
|
*
|
1966
1884
|
* @param message - Message resource.
|
1967
1885
|
* @param predicate - Predicate bytes.
|
1968
|
-
* @param predicateData - Predicate data bytes.
|
1969
1886
|
*/
|
1970
|
-
addMessageInput(message) {
|
1887
|
+
addMessageInput(message, predicate) {
|
1971
1888
|
const { recipient, sender, amount } = message;
|
1972
|
-
const assetId = import_configs7.BaseAssetId;
|
1973
1889
|
let witnessIndex;
|
1974
|
-
if (
|
1890
|
+
if (predicate) {
|
1975
1891
|
witnessIndex = 0;
|
1976
1892
|
} else {
|
1977
1893
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1985,10 +1901,11 @@ var BaseTransactionRequest = class {
|
|
1985
1901
|
sender: sender.toB256(),
|
1986
1902
|
recipient: recipient.toB256(),
|
1987
1903
|
amount,
|
1988
|
-
witnessIndex
|
1904
|
+
witnessIndex,
|
1905
|
+
predicate: predicate?.bytes
|
1989
1906
|
};
|
1990
1907
|
this.pushInput(input);
|
1991
|
-
this.addChangeOutput(recipient,
|
1908
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1992
1909
|
}
|
1993
1910
|
/**
|
1994
1911
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2016,6 +1933,32 @@ var BaseTransactionRequest = class {
|
|
2016
1933
|
resources.forEach((resource) => this.addResource(resource));
|
2017
1934
|
return this;
|
2018
1935
|
}
|
1936
|
+
/**
|
1937
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1938
|
+
* outputs from the related assetIds.
|
1939
|
+
*
|
1940
|
+
* @param resources - The resources to add.
|
1941
|
+
* @returns This transaction.
|
1942
|
+
*/
|
1943
|
+
addPredicateResource(resource, predicate) {
|
1944
|
+
if (isCoin(resource)) {
|
1945
|
+
this.addCoinInput(resource, predicate);
|
1946
|
+
} else {
|
1947
|
+
this.addMessageInput(resource, predicate);
|
1948
|
+
}
|
1949
|
+
return this;
|
1950
|
+
}
|
1951
|
+
/**
|
1952
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1953
|
+
* from the related assetIds.
|
1954
|
+
*
|
1955
|
+
* @param resources - The resources to add.
|
1956
|
+
* @returns This transaction.
|
1957
|
+
*/
|
1958
|
+
addPredicateResources(resources, predicate) {
|
1959
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1960
|
+
return this;
|
1961
|
+
}
|
2019
1962
|
/**
|
2020
1963
|
* Adds a coin output to the transaction.
|
2021
1964
|
*
|
@@ -2023,12 +1966,12 @@ var BaseTransactionRequest = class {
|
|
2023
1966
|
* @param amount - Amount of coin.
|
2024
1967
|
* @param assetId - Asset ID of coin.
|
2025
1968
|
*/
|
2026
|
-
addCoinOutput(to, amount, assetId
|
1969
|
+
addCoinOutput(to, amount, assetId) {
|
2027
1970
|
this.pushOutput({
|
2028
1971
|
type: import_transactions6.OutputType.Coin,
|
2029
1972
|
to: (0, import_address.addressify)(to).toB256(),
|
2030
1973
|
amount,
|
2031
|
-
assetId
|
1974
|
+
assetId: assetId ?? this.baseAssetId
|
2032
1975
|
});
|
2033
1976
|
return this;
|
2034
1977
|
}
|
@@ -2055,7 +1998,7 @@ var BaseTransactionRequest = class {
|
|
2055
1998
|
* @param to - Address of the owner.
|
2056
1999
|
* @param assetId - Asset ID of coin.
|
2057
2000
|
*/
|
2058
|
-
addChangeOutput(to, assetId
|
2001
|
+
addChangeOutput(to, assetId) {
|
2059
2002
|
const changeOutput = this.getChangeOutputs().find(
|
2060
2003
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2061
2004
|
);
|
@@ -2063,7 +2006,7 @@ var BaseTransactionRequest = class {
|
|
2063
2006
|
this.pushOutput({
|
2064
2007
|
type: import_transactions6.OutputType.Change,
|
2065
2008
|
to: (0, import_address.addressify)(to).toB256(),
|
2066
|
-
assetId
|
2009
|
+
assetId: assetId ?? this.baseAssetId
|
2067
2010
|
});
|
2068
2011
|
}
|
2069
2012
|
}
|
@@ -2095,7 +2038,7 @@ var BaseTransactionRequest = class {
|
|
2095
2038
|
}
|
2096
2039
|
calculateMaxGas(chainInfo, minGas) {
|
2097
2040
|
const { consensusParameters } = chainInfo;
|
2098
|
-
const { gasPerByte
|
2041
|
+
const { gasPerByte } = consensusParameters;
|
2099
2042
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2100
2043
|
(acc, wit) => acc + wit.dataLength,
|
2101
2044
|
0
|
@@ -2104,8 +2047,7 @@ var BaseTransactionRequest = class {
|
|
2104
2047
|
gasPerByte,
|
2105
2048
|
minGas,
|
2106
2049
|
witnessesLength,
|
2107
|
-
witnessLimit: this.witnessLimit
|
2108
|
-
maxGasPerTx
|
2050
|
+
witnessLimit: this.witnessLimit
|
2109
2051
|
});
|
2110
2052
|
}
|
2111
2053
|
/**
|
@@ -2123,27 +2065,24 @@ var BaseTransactionRequest = class {
|
|
2123
2065
|
});
|
2124
2066
|
const updateAssetInput = (assetId, quantity) => {
|
2125
2067
|
const assetInput = findAssetInput(assetId);
|
2126
|
-
let usedQuantity = quantity;
|
2127
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2128
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2129
|
-
}
|
2130
2068
|
if (assetInput && "assetId" in assetInput) {
|
2131
2069
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2132
|
-
assetInput.amount =
|
2070
|
+
assetInput.amount = quantity;
|
2133
2071
|
} else {
|
2134
2072
|
this.addResources([
|
2135
2073
|
{
|
2136
2074
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2137
|
-
amount:
|
2075
|
+
amount: quantity,
|
2138
2076
|
assetId,
|
2139
2077
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2078
|
+
maturity: 0,
|
2140
2079
|
blockCreated: (0, import_math7.bn)(1),
|
2141
2080
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2142
2081
|
}
|
2143
2082
|
]);
|
2144
2083
|
}
|
2145
2084
|
};
|
2146
|
-
updateAssetInput(
|
2085
|
+
updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
|
2147
2086
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2148
2087
|
}
|
2149
2088
|
/**
|
@@ -2168,7 +2107,7 @@ var BaseTransactionRequest = class {
|
|
2168
2107
|
toJSON() {
|
2169
2108
|
return normalizeJSON(this);
|
2170
2109
|
}
|
2171
|
-
|
2110
|
+
updatePredicateInputs(inputs) {
|
2172
2111
|
this.inputs.forEach((i) => {
|
2173
2112
|
let correspondingInput;
|
2174
2113
|
switch (i.type) {
|
@@ -2190,25 +2129,16 @@ var BaseTransactionRequest = class {
|
|
2190
2129
|
}
|
2191
2130
|
});
|
2192
2131
|
}
|
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
|
-
}
|
2202
2132
|
};
|
2203
2133
|
|
2204
2134
|
// src/providers/transaction-request/create-transaction-request.ts
|
2205
|
-
var
|
2135
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2206
2136
|
var import_math9 = require("@fuel-ts/math");
|
2207
2137
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2208
2138
|
var import_utils13 = require("@fuel-ts/utils");
|
2209
2139
|
|
2210
2140
|
// src/providers/transaction-request/hash-transaction.ts
|
2211
|
-
var
|
2141
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2212
2142
|
var import_hasher = require("@fuel-ts/hasher");
|
2213
2143
|
var import_math8 = require("@fuel-ts/math");
|
2214
2144
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2217,7 +2147,7 @@ var import_ramda2 = require("ramda");
|
|
2217
2147
|
function hashTransaction(transactionRequest, chainId) {
|
2218
2148
|
const transaction = transactionRequest.toTransaction();
|
2219
2149
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2220
|
-
transaction.receiptsRoot =
|
2150
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2221
2151
|
}
|
2222
2152
|
transaction.inputs = transaction.inputs.map((input) => {
|
2223
2153
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2239,10 +2169,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2239
2169
|
blockHeight: 0,
|
2240
2170
|
txIndex: 0
|
2241
2171
|
};
|
2242
|
-
inputClone.txID =
|
2172
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2243
2173
|
inputClone.outputIndex = 0;
|
2244
|
-
inputClone.balanceRoot =
|
2245
|
-
inputClone.stateRoot =
|
2174
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2175
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2246
2176
|
return inputClone;
|
2247
2177
|
}
|
2248
2178
|
default:
|
@@ -2253,8 +2183,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2253
2183
|
const outputClone = (0, import_ramda2.clone)(output);
|
2254
2184
|
switch (outputClone.type) {
|
2255
2185
|
case import_transactions7.OutputType.Contract: {
|
2256
|
-
outputClone.balanceRoot =
|
2257
|
-
outputClone.stateRoot =
|
2186
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2187
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2258
2188
|
return outputClone;
|
2259
2189
|
}
|
2260
2190
|
case import_transactions7.OutputType.Change: {
|
@@ -2262,9 +2192,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2262
2192
|
return outputClone;
|
2263
2193
|
}
|
2264
2194
|
case import_transactions7.OutputType.Variable: {
|
2265
|
-
outputClone.to =
|
2195
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2266
2196
|
outputClone.amount = (0, import_math8.bn)(0);
|
2267
|
-
outputClone.assetId =
|
2197
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2268
2198
|
return outputClone;
|
2269
2199
|
}
|
2270
2200
|
default:
|
@@ -2322,15 +2252,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2322
2252
|
*
|
2323
2253
|
* @param createTransactionRequestLike - The initial values for the instance
|
2324
2254
|
*/
|
2325
|
-
constructor({
|
2326
|
-
bytecodeWitnessIndex,
|
2327
|
-
salt,
|
2328
|
-
storageSlots,
|
2329
|
-
...rest
|
2330
|
-
} = {}) {
|
2255
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2331
2256
|
super(rest);
|
2332
2257
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2333
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2258
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2334
2259
|
this.storageSlots = [...storageSlots ?? []];
|
2335
2260
|
}
|
2336
2261
|
/**
|
@@ -2345,9 +2270,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2345
2270
|
return {
|
2346
2271
|
type: import_transactions8.TransactionType.Create,
|
2347
2272
|
...baseTransaction,
|
2273
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2348
2274
|
bytecodeWitnessIndex,
|
2349
|
-
storageSlotsCount:
|
2350
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2275
|
+
storageSlotsCount: storageSlots.length,
|
2276
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2351
2277
|
storageSlots
|
2352
2278
|
};
|
2353
2279
|
}
|
@@ -2397,7 +2323,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2397
2323
|
// src/providers/transaction-request/script-transaction-request.ts
|
2398
2324
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2399
2325
|
var import_address2 = require("@fuel-ts/address");
|
2400
|
-
var
|
2326
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2401
2327
|
var import_math10 = require("@fuel-ts/math");
|
2402
2328
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2403
2329
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2450,7 +2376,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2450
2376
|
*
|
2451
2377
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2452
2378
|
*/
|
2453
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2379
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2454
2380
|
super(rest);
|
2455
2381
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2456
2382
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2469,9 +2395,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2469
2395
|
type: import_transactions9.TransactionType.Script,
|
2470
2396
|
scriptGasLimit: this.gasLimit,
|
2471
2397
|
...super.getBaseTransaction(),
|
2472
|
-
scriptLength:
|
2473
|
-
scriptDataLength:
|
2474
|
-
receiptsRoot:
|
2398
|
+
scriptLength: script.length,
|
2399
|
+
scriptDataLength: scriptData.length,
|
2400
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2475
2401
|
script: (0, import_utils15.hexlify)(script),
|
2476
2402
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2477
2403
|
};
|
@@ -2534,7 +2460,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2534
2460
|
}
|
2535
2461
|
calculateMaxGas(chainInfo, minGas) {
|
2536
2462
|
const { consensusParameters } = chainInfo;
|
2537
|
-
const { gasPerByte
|
2463
|
+
const { gasPerByte } = consensusParameters;
|
2538
2464
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2539
2465
|
(acc, wit) => acc + wit.dataLength,
|
2540
2466
|
0
|
@@ -2544,8 +2470,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2544
2470
|
minGas,
|
2545
2471
|
witnessesLength,
|
2546
2472
|
witnessLimit: this.witnessLimit,
|
2547
|
-
gasLimit: this.gasLimit
|
2548
|
-
maxGasPerTx
|
2473
|
+
gasLimit: this.gasLimit
|
2549
2474
|
});
|
2550
2475
|
}
|
2551
2476
|
/**
|
@@ -2620,32 +2545,15 @@ var transactionRequestify = (obj) => {
|
|
2620
2545
|
}
|
2621
2546
|
}
|
2622
2547
|
};
|
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
|
-
);
|
2638
2548
|
|
2639
2549
|
// src/providers/transaction-response/transaction-response.ts
|
2640
2550
|
var import_errors13 = require("@fuel-ts/errors");
|
2641
|
-
var
|
2642
|
-
var
|
2643
|
-
var
|
2551
|
+
var import_math14 = require("@fuel-ts/math");
|
2552
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2553
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2644
2554
|
|
2645
2555
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2646
|
-
var
|
2647
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2648
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2556
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2649
2557
|
|
2650
2558
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2651
2559
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2653,10 +2561,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2653
2561
|
var import_utils16 = require("@fuel-ts/utils");
|
2654
2562
|
var calculateTransactionFee = (params) => {
|
2655
2563
|
const {
|
2656
|
-
|
2564
|
+
gasUsed,
|
2657
2565
|
rawPayload,
|
2658
|
-
|
2659
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2566
|
+
consensusParameters: { gasCosts, feeParams }
|
2660
2567
|
} = params;
|
2661
2568
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2662
2569
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2666,7 +2573,8 @@ var calculateTransactionFee = (params) => {
|
|
2666
2573
|
return {
|
2667
2574
|
fee: (0, import_math11.bn)(0),
|
2668
2575
|
minFee: (0, import_math11.bn)(0),
|
2669
|
-
maxFee: (0, import_math11.bn)(0)
|
2576
|
+
maxFee: (0, import_math11.bn)(0),
|
2577
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2670
2578
|
};
|
2671
2579
|
}
|
2672
2580
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2698,6 +2606,7 @@ var calculateTransactionFee = (params) => {
|
|
2698
2606
|
metadataGas,
|
2699
2607
|
txBytesSize: transactionBytes.length
|
2700
2608
|
});
|
2609
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2701
2610
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2702
2611
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2703
2612
|
const maxGas = getMaxGas({
|
@@ -2705,30 +2614,22 @@ var calculateTransactionFee = (params) => {
|
|
2705
2614
|
minGas,
|
2706
2615
|
witnessesLength,
|
2707
2616
|
gasLimit,
|
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
|
2617
|
+
witnessLimit
|
2722
2618
|
});
|
2619
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2620
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2621
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2622
|
+
const fee = minFee.add(feeFromGasUsed);
|
2723
2623
|
return {
|
2624
|
+
fee,
|
2724
2625
|
minFee,
|
2725
2626
|
maxFee,
|
2726
|
-
|
2627
|
+
feeFromGasUsed
|
2727
2628
|
};
|
2728
2629
|
};
|
2729
2630
|
|
2730
2631
|
// src/providers/transaction-summary/operations.ts
|
2731
|
-
var
|
2632
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2732
2633
|
var import_errors11 = require("@fuel-ts/errors");
|
2733
2634
|
var import_math13 = require("@fuel-ts/math");
|
2734
2635
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3026,7 +2927,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3026
2927
|
const { to: toAddress, assetId, amount } = receipt;
|
3027
2928
|
let { from: fromAddress } = receipt;
|
3028
2929
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3029
|
-
if (
|
2930
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3030
2931
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3031
2932
|
fromAddress = change?.to || fromAddress;
|
3032
2933
|
}
|
@@ -3290,12 +3191,10 @@ function assembleTransactionSummary(params) {
|
|
3290
3191
|
gqlTransactionStatus,
|
3291
3192
|
abiMap = {},
|
3292
3193
|
maxInputs,
|
3293
|
-
gasCosts
|
3294
|
-
maxGasPerTx,
|
3295
|
-
gasPrice
|
3194
|
+
gasCosts
|
3296
3195
|
} = params;
|
3297
3196
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3298
|
-
const rawPayload = (0,
|
3197
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3299
3198
|
const operations = getOperations({
|
3300
3199
|
transactionType: transaction.type,
|
3301
3200
|
inputs: transaction.inputs || [],
|
@@ -3306,14 +3205,11 @@ function assembleTransactionSummary(params) {
|
|
3306
3205
|
maxInputs
|
3307
3206
|
});
|
3308
3207
|
const typeName = getTransactionTypeName(transaction.type);
|
3309
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3310
3208
|
const { fee } = calculateTransactionFee({
|
3311
|
-
|
3209
|
+
gasUsed,
|
3312
3210
|
rawPayload,
|
3313
|
-
tip,
|
3314
3211
|
consensusParameters: {
|
3315
3212
|
gasCosts,
|
3316
|
-
maxGasPerTx,
|
3317
3213
|
feeParams: {
|
3318
3214
|
gasPerByte,
|
3319
3215
|
gasPriceFactor
|
@@ -3325,7 +3221,7 @@ function assembleTransactionSummary(params) {
|
|
3325
3221
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3326
3222
|
let date;
|
3327
3223
|
if (time) {
|
3328
|
-
date =
|
3224
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3329
3225
|
}
|
3330
3226
|
const transactionSummary = {
|
3331
3227
|
id,
|
@@ -3353,12 +3249,12 @@ function assembleTransactionSummary(params) {
|
|
3353
3249
|
|
3354
3250
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3355
3251
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3356
|
-
var
|
3252
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3357
3253
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3358
3254
|
return receipts.reduce((logs, receipt) => {
|
3359
|
-
if (receipt.type ===
|
3255
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3360
3256
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3361
|
-
const data = receipt.type ===
|
3257
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3362
3258
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3363
3259
|
logs.push(decodedLog);
|
3364
3260
|
}
|
@@ -3373,7 +3269,7 @@ var TransactionResponse = class {
|
|
3373
3269
|
/** Current provider */
|
3374
3270
|
provider;
|
3375
3271
|
/** Gas used on the transaction */
|
3376
|
-
gasUsed = (0,
|
3272
|
+
gasUsed = (0, import_math14.bn)(0);
|
3377
3273
|
/** The graphql Transaction with receipts object. */
|
3378
3274
|
gqlTransaction;
|
3379
3275
|
abis;
|
@@ -3431,8 +3327,8 @@ var TransactionResponse = class {
|
|
3431
3327
|
* @returns The decoded transaction.
|
3432
3328
|
*/
|
3433
3329
|
decodeTransaction(transactionWithReceipts) {
|
3434
|
-
return new
|
3435
|
-
(0,
|
3330
|
+
return new import_transactions17.TransactionCoder().decode(
|
3331
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3436
3332
|
0
|
3437
3333
|
)?.[0];
|
3438
3334
|
}
|
@@ -3451,27 +3347,20 @@ var TransactionResponse = class {
|
|
3451
3347
|
const decodedTransaction = this.decodeTransaction(
|
3452
3348
|
transaction
|
3453
3349
|
);
|
3454
|
-
|
3455
|
-
|
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();
|
3350
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3351
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3461
3352
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3462
3353
|
const transactionSummary = assembleTransactionSummary({
|
3463
3354
|
id: this.id,
|
3464
3355
|
receipts,
|
3465
3356
|
transaction: decodedTransaction,
|
3466
|
-
transactionBytes: (0,
|
3357
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3467
3358
|
gqlTransactionStatus: transaction.status,
|
3468
3359
|
gasPerByte,
|
3469
3360
|
gasPriceFactor,
|
3470
3361
|
abiMap: contractsAbiMap,
|
3471
3362
|
maxInputs,
|
3472
|
-
gasCosts
|
3473
|
-
maxGasPerTx,
|
3474
|
-
gasPrice
|
3363
|
+
gasCosts
|
3475
3364
|
});
|
3476
3365
|
return transactionSummary;
|
3477
3366
|
}
|
@@ -3598,29 +3487,30 @@ var processGqlChain = (chain) => {
|
|
3598
3487
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3599
3488
|
return {
|
3600
3489
|
name,
|
3601
|
-
baseChainHeight: (0,
|
3490
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3602
3491
|
consensusParameters: {
|
3603
|
-
contractMaxSize: (0,
|
3604
|
-
maxInputs: (0,
|
3605
|
-
maxOutputs: (0,
|
3606
|
-
maxWitnesses: (0,
|
3607
|
-
maxGasPerTx: (0,
|
3608
|
-
maxScriptLength: (0,
|
3609
|
-
maxScriptDataLength: (0,
|
3610
|
-
maxStorageSlots: (0,
|
3611
|
-
maxPredicateLength: (0,
|
3612
|
-
maxPredicateDataLength: (0,
|
3613
|
-
maxGasPerPredicate: (0,
|
3614
|
-
gasPriceFactor: (0,
|
3615
|
-
gasPerByte: (0,
|
3616
|
-
maxMessageDataLength: (0,
|
3617
|
-
chainId: (0,
|
3492
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3493
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3494
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3495
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3496
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3497
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3498
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3499
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3500
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3501
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3502
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3503
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3504
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3505
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3506
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3507
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3618
3508
|
gasCosts
|
3619
3509
|
},
|
3620
3510
|
gasCosts,
|
3621
3511
|
latestBlock: {
|
3622
3512
|
id: latestBlock.id,
|
3623
|
-
height: (0,
|
3513
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3624
3514
|
time: latestBlock.header.time,
|
3625
3515
|
transactions: latestBlock.transactions.map((i) => ({
|
3626
3516
|
id: i.id
|
@@ -3714,8 +3604,10 @@ var _Provider = class {
|
|
3714
3604
|
* Returns some helpful parameters related to gas fees.
|
3715
3605
|
*/
|
3716
3606
|
getGasConfig() {
|
3607
|
+
const { minGasPrice } = this.getNode();
|
3717
3608
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3718
3609
|
return {
|
3610
|
+
minGasPrice,
|
3719
3611
|
maxGasPerTx,
|
3720
3612
|
maxGasPerPredicate,
|
3721
3613
|
gasPriceFactor,
|
@@ -3813,7 +3705,7 @@ var _Provider = class {
|
|
3813
3705
|
*/
|
3814
3706
|
async getBlockNumber() {
|
3815
3707
|
const { chain } = await this.operations.getChain();
|
3816
|
-
return (0,
|
3708
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3817
3709
|
}
|
3818
3710
|
/**
|
3819
3711
|
* Returns the chain information.
|
@@ -3823,11 +3715,13 @@ var _Provider = class {
|
|
3823
3715
|
async fetchNode() {
|
3824
3716
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3825
3717
|
const processedNodeInfo = {
|
3826
|
-
maxDepth: (0,
|
3827
|
-
maxTx: (0,
|
3718
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3719
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3720
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3828
3721
|
nodeVersion: nodeInfo.nodeVersion,
|
3829
3722
|
utxoValidation: nodeInfo.utxoValidation,
|
3830
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3723
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3724
|
+
peers: nodeInfo.peers
|
3831
3725
|
};
|
3832
3726
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3833
3727
|
return processedNodeInfo;
|
@@ -3853,6 +3747,17 @@ var _Provider = class {
|
|
3853
3747
|
} = this.getChain();
|
3854
3748
|
return chainId.toNumber();
|
3855
3749
|
}
|
3750
|
+
/**
|
3751
|
+
* Returns the base asset ID
|
3752
|
+
*
|
3753
|
+
* @returns A promise that resolves to the base asset ID
|
3754
|
+
*/
|
3755
|
+
getBaseAssetId() {
|
3756
|
+
const {
|
3757
|
+
consensusParameters: { baseAssetId }
|
3758
|
+
} = this.getChain();
|
3759
|
+
return baseAssetId;
|
3760
|
+
}
|
3856
3761
|
/**
|
3857
3762
|
* Submits a transaction to the chain to be executed.
|
3858
3763
|
*
|
@@ -3869,9 +3774,9 @@ var _Provider = class {
|
|
3869
3774
|
if (estimateTxDependencies) {
|
3870
3775
|
await this.estimateTxDependencies(transactionRequest);
|
3871
3776
|
}
|
3872
|
-
const encodedTransaction = (0,
|
3777
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3873
3778
|
let abis;
|
3874
|
-
if (transactionRequest.type ===
|
3779
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3875
3780
|
abis = transactionRequest.abis;
|
3876
3781
|
}
|
3877
3782
|
if (awaitExecution) {
|
@@ -3912,14 +3817,15 @@ var _Provider = class {
|
|
3912
3817
|
if (estimateTxDependencies) {
|
3913
3818
|
return this.estimateTxDependencies(transactionRequest);
|
3914
3819
|
}
|
3915
|
-
const encodedTransaction = (0,
|
3916
|
-
const { dryRun:
|
3917
|
-
|
3820
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3821
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3822
|
+
encodedTransaction,
|
3918
3823
|
utxoValidation: utxoValidation || false
|
3919
3824
|
});
|
3920
|
-
const
|
3921
|
-
|
3922
|
-
|
3825
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3826
|
+
return {
|
3827
|
+
receipts
|
3828
|
+
};
|
3923
3829
|
}
|
3924
3830
|
/**
|
3925
3831
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3930,13 +3836,13 @@ var _Provider = class {
|
|
3930
3836
|
async estimatePredicates(transactionRequest) {
|
3931
3837
|
const shouldEstimatePredicates = Boolean(
|
3932
3838
|
transactionRequest.inputs.find(
|
3933
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3839
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
|
3934
3840
|
)
|
3935
3841
|
);
|
3936
3842
|
if (!shouldEstimatePredicates) {
|
3937
3843
|
return transactionRequest;
|
3938
3844
|
}
|
3939
|
-
const encodedTransaction = (0,
|
3845
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3940
3846
|
const response = await this.operations.estimatePredicates({
|
3941
3847
|
encodedTransaction
|
3942
3848
|
});
|
@@ -3945,7 +3851,7 @@ var _Provider = class {
|
|
3945
3851
|
} = response;
|
3946
3852
|
if (inputs) {
|
3947
3853
|
inputs.forEach((input, index) => {
|
3948
|
-
if ("predicateGasUsed" in input && (0,
|
3854
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3949
3855
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3950
3856
|
}
|
3951
3857
|
});
|
@@ -3958,31 +3864,31 @@ var _Provider = class {
|
|
3958
3864
|
* If there are missing variable outputs,
|
3959
3865
|
* `addVariableOutputs` is called on the transaction.
|
3960
3866
|
*
|
3867
|
+
* @privateRemarks
|
3868
|
+
* TODO: Investigate support for missing contract IDs
|
3869
|
+
* TODO: Add support for missing output messages
|
3961
3870
|
*
|
3962
3871
|
* @param transactionRequest - The transaction request object.
|
3963
3872
|
* @returns A promise.
|
3964
3873
|
*/
|
3965
3874
|
async estimateTxDependencies(transactionRequest) {
|
3966
|
-
if (transactionRequest.type ===
|
3875
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3967
3876
|
return {
|
3968
3877
|
receipts: [],
|
3969
3878
|
outputVariables: 0,
|
3970
3879
|
missingContractIds: []
|
3971
3880
|
};
|
3972
3881
|
}
|
3882
|
+
await this.estimatePredicates(transactionRequest);
|
3973
3883
|
let receipts = [];
|
3974
3884
|
const missingContractIds = [];
|
3975
3885
|
let outputVariables = 0;
|
3976
|
-
let dryrunStatus;
|
3977
3886
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3978
|
-
const {
|
3979
|
-
|
3980
|
-
} = await this.operations.dryRun({
|
3981
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3887
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3888
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3982
3889
|
utxoValidation: false
|
3983
3890
|
});
|
3984
|
-
receipts =
|
3985
|
-
dryrunStatus = status;
|
3891
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3986
3892
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3987
3893
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3988
3894
|
if (hasMissingOutputs) {
|
@@ -3992,10 +3898,6 @@ var _Provider = class {
|
|
3992
3898
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3993
3899
|
missingContractIds.push(contractId);
|
3994
3900
|
});
|
3995
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3996
|
-
transactionRequest
|
3997
|
-
});
|
3998
|
-
transactionRequest.maxFee = maxFee;
|
3999
3901
|
} else {
|
4000
3902
|
break;
|
4001
3903
|
}
|
@@ -4003,139 +3905,37 @@ var _Provider = class {
|
|
4003
3905
|
return {
|
4004
3906
|
receipts,
|
4005
3907
|
outputVariables,
|
4006
|
-
missingContractIds
|
4007
|
-
dryrunStatus
|
3908
|
+
missingContractIds
|
4008
3909
|
};
|
4009
3910
|
}
|
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
|
-
}
|
4094
3911
|
/**
|
4095
3912
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4096
3913
|
* @param transactionRequest - The transaction request object.
|
4097
3914
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4098
3915
|
*/
|
4099
|
-
|
3916
|
+
estimateTxGasAndFee(params) {
|
4100
3917
|
const { transactionRequest } = params;
|
4101
|
-
|
3918
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4102
3919
|
const chainInfo = this.getChain();
|
4103
|
-
const
|
3920
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3921
|
+
transactionRequest.gasPrice = gasPrice;
|
4104
3922
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4105
|
-
|
4106
|
-
|
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;
|
3923
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3924
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4117
3925
|
if (transactionRequest.gasLimit.eq(0)) {
|
4118
3926
|
transactionRequest.gasLimit = minGas;
|
4119
3927
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4120
3928
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4121
3929
|
);
|
4122
|
-
gasLimit = transactionRequest.gasLimit;
|
4123
3930
|
}
|
4124
3931
|
}
|
4125
3932
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4126
|
-
const maxFee =
|
4127
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4128
|
-
gas: maxGas,
|
4129
|
-
priceFactor: gasPriceFactor,
|
4130
|
-
tip: transactionRequest.tip
|
4131
|
-
}).add(1);
|
3933
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4132
3934
|
return {
|
4133
3935
|
minGas,
|
4134
3936
|
minFee,
|
4135
3937
|
maxGas,
|
4136
|
-
maxFee
|
4137
|
-
gasPrice,
|
4138
|
-
gasLimit
|
3938
|
+
maxFee
|
4139
3939
|
};
|
4140
3940
|
}
|
4141
3941
|
/**
|
@@ -4153,17 +3953,15 @@ var _Provider = class {
|
|
4153
3953
|
if (estimateTxDependencies) {
|
4154
3954
|
return this.estimateTxDependencies(transactionRequest);
|
4155
3955
|
}
|
4156
|
-
const
|
4157
|
-
const { dryRun:
|
4158
|
-
|
3956
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3957
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3958
|
+
encodedTransaction,
|
4159
3959
|
utxoValidation: true
|
4160
3960
|
});
|
4161
|
-
const
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
});
|
4166
|
-
return { receipts: callResult[0].receipts };
|
3961
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3962
|
+
return {
|
3963
|
+
receipts
|
3964
|
+
};
|
4167
3965
|
}
|
4168
3966
|
/**
|
4169
3967
|
* Returns a transaction cost to enable user
|
@@ -4180,79 +3978,77 @@ var _Provider = class {
|
|
4180
3978
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4181
3979
|
* @returns A promise that resolves to the transaction cost object.
|
4182
3980
|
*/
|
4183
|
-
async getTransactionCost(transactionRequestLike,
|
3981
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3982
|
+
estimateTxDependencies = true,
|
3983
|
+
estimatePredicates = true,
|
3984
|
+
resourcesOwner,
|
3985
|
+
signatureCallback
|
3986
|
+
} = {}) {
|
4184
3987
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4185
|
-
const
|
3988
|
+
const { minGasPrice } = this.getGasConfig();
|
3989
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3990
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4186
3991
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4187
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3992
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4188
3993
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4189
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4190
3994
|
if (isScriptTransaction) {
|
4191
|
-
txRequestClone.gasLimit = (0,
|
3995
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4192
3996
|
}
|
4193
|
-
if (
|
4194
|
-
resourcesOwner
|
3997
|
+
if (estimatePredicates) {
|
3998
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3999
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4000
|
+
}
|
4001
|
+
await this.estimatePredicates(txRequestClone);
|
4195
4002
|
}
|
4196
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4197
|
-
let addedSignatures = 0;
|
4198
4003
|
if (signatureCallback && isScriptTransaction) {
|
4199
|
-
|
4200
|
-
await signatureCallback(signedRequest);
|
4201
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4004
|
+
await signatureCallback(txRequestClone);
|
4202
4005
|
}
|
4203
|
-
|
4204
|
-
|
4205
|
-
transactionRequest: signedRequest
|
4006
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4007
|
+
transactionRequest: txRequestClone
|
4206
4008
|
});
|
4207
4009
|
let receipts = [];
|
4208
4010
|
let missingContractIds = [];
|
4209
4011
|
let outputVariables = 0;
|
4210
|
-
let gasUsed = (0,
|
4211
|
-
|
4212
|
-
|
4213
|
-
if (isScriptTransaction) {
|
4214
|
-
txRequestClone.gasLimit = gasLimit;
|
4215
|
-
if (signatureCallback) {
|
4216
|
-
await signatureCallback(txRequestClone);
|
4217
|
-
}
|
4012
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4013
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4014
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4218
4015
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4219
4016
|
receipts = result.receipts;
|
4220
4017
|
outputVariables = result.outputVariables;
|
4221
4018
|
missingContractIds = result.missingContractIds;
|
4222
4019
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4223
4020
|
txRequestClone.gasLimit = gasUsed;
|
4224
|
-
|
4225
|
-
|
4226
|
-
|
4021
|
+
txRequestClone.gasPrice = setGasPrice;
|
4022
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4023
|
+
transactionRequest: txRequestClone
|
4227
4024
|
}));
|
4228
4025
|
}
|
4229
4026
|
return {
|
4230
4027
|
requiredQuantities: allQuantities,
|
4231
4028
|
receipts,
|
4232
4029
|
gasUsed,
|
4233
|
-
|
4030
|
+
minGasPrice,
|
4031
|
+
gasPrice: setGasPrice,
|
4234
4032
|
minGas,
|
4235
4033
|
maxGas,
|
4236
4034
|
minFee,
|
4237
4035
|
maxFee,
|
4036
|
+
estimatedInputs: txRequestClone.inputs,
|
4238
4037
|
outputVariables,
|
4239
|
-
missingContractIds
|
4240
|
-
addedSignatures,
|
4241
|
-
estimatedPredicates: txRequestClone.inputs
|
4038
|
+
missingContractIds
|
4242
4039
|
};
|
4243
4040
|
}
|
4244
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4041
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4245
4042
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4246
4043
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4247
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4248
|
-
quantitiesToContract
|
4249
|
-
});
|
4044
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4250
4045
|
transactionRequest.addResources(
|
4251
4046
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4252
4047
|
);
|
4253
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4254
|
-
|
4255
|
-
|
4048
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4049
|
+
transactionRequest,
|
4050
|
+
forwardingQuantities
|
4051
|
+
);
|
4256
4052
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4257
4053
|
return {
|
4258
4054
|
resources,
|
@@ -4268,16 +4064,17 @@ var _Provider = class {
|
|
4268
4064
|
const result = await this.operations.getCoins({
|
4269
4065
|
first: 10,
|
4270
4066
|
...paginationArgs,
|
4271
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4067
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4272
4068
|
});
|
4273
4069
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4274
4070
|
return coins.map((coin) => ({
|
4275
4071
|
id: coin.utxoId,
|
4276
4072
|
assetId: coin.assetId,
|
4277
|
-
amount: (0,
|
4073
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4278
4074
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4279
|
-
|
4280
|
-
|
4075
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4076
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4077
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4281
4078
|
}));
|
4282
4079
|
}
|
4283
4080
|
/**
|
@@ -4291,19 +4088,19 @@ var _Provider = class {
|
|
4291
4088
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4292
4089
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4293
4090
|
const excludeInput = {
|
4294
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4295
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4091
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4092
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4296
4093
|
};
|
4297
4094
|
if (this.cache) {
|
4298
4095
|
const uniqueUtxos = new Set(
|
4299
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4096
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4300
4097
|
);
|
4301
4098
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4302
4099
|
}
|
4303
4100
|
const coinsQuery = {
|
4304
4101
|
owner: ownerAddress.toB256(),
|
4305
4102
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4306
|
-
assetId: (0,
|
4103
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4307
4104
|
amount: amount.toString(10),
|
4308
4105
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4309
4106
|
})),
|
@@ -4314,9 +4111,9 @@ var _Provider = class {
|
|
4314
4111
|
switch (coin.__typename) {
|
4315
4112
|
case "MessageCoin":
|
4316
4113
|
return {
|
4317
|
-
amount: (0,
|
4114
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4318
4115
|
assetId: coin.assetId,
|
4319
|
-
daHeight: (0,
|
4116
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4320
4117
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4321
4118
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4322
4119
|
nonce: coin.nonce
|
@@ -4324,11 +4121,12 @@ var _Provider = class {
|
|
4324
4121
|
case "Coin":
|
4325
4122
|
return {
|
4326
4123
|
id: coin.utxoId,
|
4327
|
-
amount: (0,
|
4124
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4328
4125
|
assetId: coin.assetId,
|
4329
4126
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4330
|
-
|
4331
|
-
|
4127
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4128
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4129
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4332
4130
|
};
|
4333
4131
|
default:
|
4334
4132
|
return null;
|
@@ -4345,13 +4143,13 @@ var _Provider = class {
|
|
4345
4143
|
async getBlock(idOrHeight) {
|
4346
4144
|
let variables;
|
4347
4145
|
if (typeof idOrHeight === "number") {
|
4348
|
-
variables = { height: (0,
|
4146
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4349
4147
|
} else if (idOrHeight === "latest") {
|
4350
4148
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4351
4149
|
} else if (idOrHeight.length === 66) {
|
4352
4150
|
variables = { blockId: idOrHeight };
|
4353
4151
|
} else {
|
4354
|
-
variables = { blockId: (0,
|
4152
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4355
4153
|
}
|
4356
4154
|
const { block } = await this.operations.getBlock(variables);
|
4357
4155
|
if (!block) {
|
@@ -4359,7 +4157,7 @@ var _Provider = class {
|
|
4359
4157
|
}
|
4360
4158
|
return {
|
4361
4159
|
id: block.id,
|
4362
|
-
height: (0,
|
4160
|
+
height: (0, import_math15.bn)(block.header.height),
|
4363
4161
|
time: block.header.time,
|
4364
4162
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4365
4163
|
};
|
@@ -4374,7 +4172,7 @@ var _Provider = class {
|
|
4374
4172
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4375
4173
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4376
4174
|
id: block.id,
|
4377
|
-
height: (0,
|
4175
|
+
height: (0, import_math15.bn)(block.header.height),
|
4378
4176
|
time: block.header.time,
|
4379
4177
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4380
4178
|
}));
|
@@ -4389,7 +4187,7 @@ var _Provider = class {
|
|
4389
4187
|
async getBlockWithTransactions(idOrHeight) {
|
4390
4188
|
let variables;
|
4391
4189
|
if (typeof idOrHeight === "number") {
|
4392
|
-
variables = { blockHeight: (0,
|
4190
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4393
4191
|
} else if (idOrHeight === "latest") {
|
4394
4192
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4395
4193
|
} else {
|
@@ -4401,11 +4199,11 @@ var _Provider = class {
|
|
4401
4199
|
}
|
4402
4200
|
return {
|
4403
4201
|
id: block.id,
|
4404
|
-
height: (0,
|
4202
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4405
4203
|
time: block.header.time,
|
4406
4204
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4407
4205
|
transactions: block.transactions.map(
|
4408
|
-
(tx) => new
|
4206
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4409
4207
|
)
|
4410
4208
|
};
|
4411
4209
|
}
|
@@ -4420,8 +4218,8 @@ var _Provider = class {
|
|
4420
4218
|
if (!transaction) {
|
4421
4219
|
return null;
|
4422
4220
|
}
|
4423
|
-
return new
|
4424
|
-
(0,
|
4221
|
+
return new import_transactions18.TransactionCoder().decode(
|
4222
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4425
4223
|
0
|
4426
4224
|
)?.[0];
|
4427
4225
|
}
|
@@ -4448,9 +4246,9 @@ var _Provider = class {
|
|
4448
4246
|
async getContractBalance(contractId, assetId) {
|
4449
4247
|
const { contractBalance } = await this.operations.getContractBalance({
|
4450
4248
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4451
|
-
asset: (0,
|
4249
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4452
4250
|
});
|
4453
|
-
return (0,
|
4251
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4454
4252
|
}
|
4455
4253
|
/**
|
4456
4254
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4462,9 +4260,9 @@ var _Provider = class {
|
|
4462
4260
|
async getBalance(owner, assetId) {
|
4463
4261
|
const { balance } = await this.operations.getBalance({
|
4464
4262
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4465
|
-
assetId: (0,
|
4263
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4466
4264
|
});
|
4467
|
-
return (0,
|
4265
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4468
4266
|
}
|
4469
4267
|
/**
|
4470
4268
|
* Returns balances for the given owner.
|
@@ -4482,7 +4280,7 @@ var _Provider = class {
|
|
4482
4280
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4483
4281
|
return balances.map((balance) => ({
|
4484
4282
|
assetId: balance.assetId,
|
4485
|
-
amount: (0,
|
4283
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4486
4284
|
}));
|
4487
4285
|
}
|
4488
4286
|
/**
|
@@ -4500,19 +4298,19 @@ var _Provider = class {
|
|
4500
4298
|
});
|
4501
4299
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4502
4300
|
return messages.map((message) => ({
|
4503
|
-
messageId:
|
4301
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4504
4302
|
sender: message.sender,
|
4505
4303
|
recipient: message.recipient,
|
4506
4304
|
nonce: message.nonce,
|
4507
|
-
amount: (0,
|
4305
|
+
amount: (0, import_math15.bn)(message.amount),
|
4508
4306
|
data: message.data
|
4509
4307
|
}),
|
4510
4308
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4511
4309
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4512
4310
|
nonce: message.nonce,
|
4513
|
-
amount: (0,
|
4514
|
-
data:
|
4515
|
-
daHeight: (0,
|
4311
|
+
amount: (0, import_math15.bn)(message.amount),
|
4312
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4313
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4516
4314
|
}));
|
4517
4315
|
}
|
4518
4316
|
/**
|
@@ -4565,60 +4363,44 @@ var _Provider = class {
|
|
4565
4363
|
} = result.messageProof;
|
4566
4364
|
return {
|
4567
4365
|
messageProof: {
|
4568
|
-
proofIndex: (0,
|
4366
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4569
4367
|
proofSet: messageProof.proofSet
|
4570
4368
|
},
|
4571
4369
|
blockProof: {
|
4572
|
-
proofIndex: (0,
|
4370
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4573
4371
|
proofSet: blockProof.proofSet
|
4574
4372
|
},
|
4575
4373
|
messageBlockHeader: {
|
4576
4374
|
id: messageBlockHeader.id,
|
4577
|
-
daHeight: (0,
|
4578
|
-
transactionsCount: (0,
|
4375
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4376
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4579
4377
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4580
|
-
height: (0,
|
4378
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4581
4379
|
prevRoot: messageBlockHeader.prevRoot,
|
4582
4380
|
time: messageBlockHeader.time,
|
4583
4381
|
applicationHash: messageBlockHeader.applicationHash,
|
4584
|
-
|
4585
|
-
|
4586
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4587
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4588
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4382
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4383
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4589
4384
|
},
|
4590
4385
|
commitBlockHeader: {
|
4591
4386
|
id: commitBlockHeader.id,
|
4592
|
-
daHeight: (0,
|
4593
|
-
transactionsCount: (0,
|
4387
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4388
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4594
4389
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4595
|
-
height: (0,
|
4390
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4596
4391
|
prevRoot: commitBlockHeader.prevRoot,
|
4597
4392
|
time: commitBlockHeader.time,
|
4598
4393
|
applicationHash: commitBlockHeader.applicationHash,
|
4599
|
-
|
4600
|
-
|
4601
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4602
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4603
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4394
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4395
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4604
4396
|
},
|
4605
4397
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4606
4398
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4607
4399
|
nonce,
|
4608
|
-
amount: (0,
|
4400
|
+
amount: (0, import_math15.bn)(amount),
|
4609
4401
|
data
|
4610
4402
|
};
|
4611
4403
|
}
|
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
|
-
}
|
4622
4404
|
/**
|
4623
4405
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4624
4406
|
*
|
@@ -4638,10 +4420,10 @@ var _Provider = class {
|
|
4638
4420
|
*/
|
4639
4421
|
async produceBlocks(amount, startTime) {
|
4640
4422
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4641
|
-
blocksToProduce: (0,
|
4642
|
-
startTimestamp: startTime ?
|
4423
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4424
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4643
4425
|
});
|
4644
|
-
return (0,
|
4426
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4645
4427
|
}
|
4646
4428
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4647
4429
|
async getTransactionResponse(transactionId) {
|
@@ -4655,7 +4437,7 @@ cacheInputs_fn = function(inputs) {
|
|
4655
4437
|
return;
|
4656
4438
|
}
|
4657
4439
|
inputs.forEach((input) => {
|
4658
|
-
if (input.type ===
|
4440
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4659
4441
|
this.cache?.set(input.id);
|
4660
4442
|
}
|
4661
4443
|
});
|
@@ -4665,9 +4447,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4665
4447
|
|
4666
4448
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4667
4449
|
var import_errors15 = require("@fuel-ts/errors");
|
4668
|
-
var
|
4669
|
-
var
|
4670
|
-
var
|
4450
|
+
var import_math16 = require("@fuel-ts/math");
|
4451
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4452
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4671
4453
|
|
4672
4454
|
// src/providers/chains.ts
|
4673
4455
|
var CHAIN_IDS = {
|
@@ -4716,17 +4498,17 @@ var assets = [
|
|
4716
4498
|
|
4717
4499
|
// src/utils/formatTransferToContractScriptData.ts
|
4718
4500
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4719
|
-
var
|
4720
|
-
var
|
4501
|
+
var import_math17 = require("@fuel-ts/math");
|
4502
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4721
4503
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4722
4504
|
var formatTransferToContractScriptData = (params) => {
|
4723
4505
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4724
4506
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4725
|
-
const encoded = numberCoder.encode(new
|
4507
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4726
4508
|
const scriptData = Uint8Array.from([
|
4727
|
-
...(0,
|
4509
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4728
4510
|
...encoded,
|
4729
|
-
...(0,
|
4511
|
+
...(0, import_utils27.arrayify)(assetId)
|
4730
4512
|
]);
|
4731
4513
|
return scriptData;
|
4732
4514
|
};
|
@@ -4873,8 +4655,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4873
4655
|
* @param assetId - The asset ID to check the balance for.
|
4874
4656
|
* @returns A promise that resolves to the balance amount.
|
4875
4657
|
*/
|
4876
|
-
async getBalance(assetId
|
4877
|
-
const
|
4658
|
+
async getBalance(assetId) {
|
4659
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4660
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4878
4661
|
return amount;
|
4879
4662
|
}
|
4880
4663
|
/**
|
@@ -4911,33 +4694,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4911
4694
|
* @param fee - The estimated transaction fee.
|
4912
4695
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4913
4696
|
*/
|
4914
|
-
async fund(request,
|
4915
|
-
const
|
4916
|
-
const
|
4917
|
-
|
4918
|
-
|
4919
|
-
|
4920
|
-
coinQuantities: requiredQuantities
|
4697
|
+
async fund(request, coinQuantities, fee) {
|
4698
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4699
|
+
const updatedQuantities = addAmountToAsset({
|
4700
|
+
amount: (0, import_math18.bn)(fee),
|
4701
|
+
assetId: baseAssetId,
|
4702
|
+
coinQuantities
|
4921
4703
|
});
|
4922
4704
|
const quantitiesDict = {};
|
4923
|
-
|
4705
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4924
4706
|
quantitiesDict[assetId] = {
|
4925
4707
|
required: amount,
|
4926
|
-
owned: (0,
|
4708
|
+
owned: (0, import_math18.bn)(0)
|
4927
4709
|
};
|
4928
4710
|
});
|
4929
|
-
|
4711
|
+
const cachedUtxos = [];
|
4712
|
+
const cachedMessages = [];
|
4713
|
+
const owner = this.address.toB256();
|
4714
|
+
request.inputs.forEach((input) => {
|
4930
4715
|
const isResource = "amount" in input;
|
4931
4716
|
if (isResource) {
|
4932
4717
|
const isCoin2 = "owner" in input;
|
4933
4718
|
if (isCoin2) {
|
4934
4719
|
const assetId = String(input.assetId);
|
4935
|
-
if (quantitiesDict[assetId]) {
|
4936
|
-
const amount = (0,
|
4720
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4721
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4937
4722
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4723
|
+
cachedUtxos.push(input.id);
|
4938
4724
|
}
|
4939
|
-
} else if (input.amount && quantitiesDict[
|
4940
|
-
quantitiesDict[
|
4725
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4726
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4727
|
+
cachedMessages.push(input.nonce);
|
4941
4728
|
}
|
4942
4729
|
}
|
4943
4730
|
});
|
@@ -4952,23 +4739,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4952
4739
|
});
|
4953
4740
|
const needsToBeFunded = missingQuantities.length;
|
4954
4741
|
if (needsToBeFunded) {
|
4955
|
-
const
|
4956
|
-
|
4957
|
-
|
4958
|
-
|
4959
|
-
|
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
|
-
);
|
4742
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4743
|
+
messages: cachedMessages,
|
4744
|
+
utxos: cachedUtxos
|
4745
|
+
});
|
4746
|
+
request.addResources(resources);
|
4966
4747
|
}
|
4967
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4968
|
-
transactionRequest: requestToBeReEstimate
|
4969
|
-
});
|
4970
|
-
txRequest.maxFee = maxFee;
|
4971
|
-
return txRequest;
|
4972
4748
|
}
|
4973
4749
|
/**
|
4974
4750
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4976,25 +4752,30 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4976
4752
|
* @param destination - The address of the destination.
|
4977
4753
|
* @param amount - The amount of coins to transfer.
|
4978
4754
|
* @param assetId - The asset ID of the coins to transfer.
|
4979
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4755
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4980
4756
|
* @returns A promise that resolves to the prepared transaction request.
|
4981
4757
|
*/
|
4982
|
-
async createTransfer(destination, amount, assetId
|
4983
|
-
const
|
4984
|
-
|
4985
|
-
const
|
4758
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4759
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4760
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4761
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4762
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4763
|
+
const request = new ScriptTransactionRequest(params);
|
4764
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4765
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4986
4766
|
estimateTxDependencies: true,
|
4987
4767
|
resourcesOwner: this
|
4988
4768
|
});
|
4989
|
-
|
4990
|
-
|
4991
|
-
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4996
|
-
|
4997
|
-
await this.fund(request,
|
4769
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4770
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4771
|
+
this.validateGas({
|
4772
|
+
gasUsed,
|
4773
|
+
gasPrice: request.gasPrice,
|
4774
|
+
gasLimit: request.gasLimit,
|
4775
|
+
minGasPrice
|
4776
|
+
});
|
4777
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4778
|
+
request.updatePredicateInputs(estimatedInputs);
|
4998
4779
|
return request;
|
4999
4780
|
}
|
5000
4781
|
/**
|
@@ -5006,14 +4787,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5006
4787
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5007
4788
|
* @returns A promise that resolves to the transaction response.
|
5008
4789
|
*/
|
5009
|
-
async transfer(destination, amount, assetId
|
5010
|
-
if ((0,
|
4790
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4791
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5011
4792
|
throw new import_errors16.FuelError(
|
5012
4793
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5013
4794
|
"Transfer amount must be a positive number."
|
5014
4795
|
);
|
5015
4796
|
}
|
5016
|
-
const
|
4797
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4798
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5017
4799
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5018
4800
|
}
|
5019
4801
|
/**
|
@@ -5025,38 +4807,41 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5025
4807
|
* @param txParams - The optional transaction parameters.
|
5026
4808
|
* @returns A promise that resolves to the transaction response.
|
5027
4809
|
*/
|
5028
|
-
async transferToContract(contractId, amount, assetId
|
5029
|
-
if ((0,
|
4810
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4811
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5030
4812
|
throw new import_errors16.FuelError(
|
5031
4813
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5032
4814
|
"Transfer amount must be a positive number."
|
5033
4815
|
);
|
5034
4816
|
}
|
5035
4817
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4818
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4819
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4820
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4821
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5036
4822
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5037
4823
|
hexlifiedContractId: contractAddress.toB256(),
|
5038
|
-
amountToTransfer: (0,
|
5039
|
-
assetId
|
4824
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4825
|
+
assetId: assetIdToTransfer
|
5040
4826
|
});
|
5041
4827
|
const request = new ScriptTransactionRequest({
|
5042
|
-
...
|
4828
|
+
...params,
|
5043
4829
|
script,
|
5044
4830
|
scriptData
|
5045
4831
|
});
|
5046
4832
|
request.addContractInputAndOutput(contractAddress);
|
5047
|
-
const
|
5048
|
-
|
5049
|
-
|
4833
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4834
|
+
request,
|
4835
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
4836
|
+
);
|
4837
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4838
|
+
this.validateGas({
|
4839
|
+
gasUsed,
|
4840
|
+
gasPrice: request.gasPrice,
|
4841
|
+
gasLimit: request.gasLimit,
|
4842
|
+
minGasPrice
|
5050
4843
|
});
|
5051
|
-
|
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);
|
4844
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5060
4845
|
return this.sendTransaction(request);
|
5061
4846
|
}
|
5062
4847
|
/**
|
@@ -5068,31 +4853,40 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5068
4853
|
* @returns A promise that resolves to the transaction response.
|
5069
4854
|
*/
|
5070
4855
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4856
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4857
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5071
4858
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5072
|
-
const recipientDataArray = (0,
|
4859
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5073
4860
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5074
4861
|
);
|
5075
|
-
const amountDataArray = (0,
|
5076
|
-
"0x".concat((0,
|
4862
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4863
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5077
4864
|
);
|
5078
4865
|
const script = new Uint8Array([
|
5079
|
-
...(0,
|
4866
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5080
4867
|
...recipientDataArray,
|
5081
4868
|
...amountDataArray
|
5082
4869
|
]);
|
5083
|
-
const params = {
|
4870
|
+
const params = {
|
4871
|
+
script,
|
4872
|
+
gasPrice: minGasPrice,
|
4873
|
+
baseAssetId,
|
4874
|
+
...txParams
|
4875
|
+
};
|
5084
4876
|
const request = new ScriptTransactionRequest(params);
|
5085
|
-
const
|
5086
|
-
const
|
5087
|
-
|
5088
|
-
|
5089
|
-
|
5090
|
-
|
5091
|
-
|
5092
|
-
|
5093
|
-
|
5094
|
-
|
5095
|
-
|
4877
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
|
4878
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4879
|
+
request,
|
4880
|
+
forwardingQuantities
|
4881
|
+
);
|
4882
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4883
|
+
this.validateGas({
|
4884
|
+
gasUsed,
|
4885
|
+
gasPrice: request.gasPrice,
|
4886
|
+
gasLimit: request.gasLimit,
|
4887
|
+
minGasPrice
|
4888
|
+
});
|
4889
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5096
4890
|
return this.sendTransaction(request);
|
5097
4891
|
}
|
5098
4892
|
async signMessage(message) {
|
@@ -5150,7 +4944,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5150
4944
|
}
|
5151
4945
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5152
4946
|
}
|
5153
|
-
validateGas({
|
4947
|
+
validateGas({
|
4948
|
+
gasUsed,
|
4949
|
+
gasPrice,
|
4950
|
+
gasLimit,
|
4951
|
+
minGasPrice
|
4952
|
+
}) {
|
4953
|
+
if (minGasPrice.gt(gasPrice)) {
|
4954
|
+
throw new import_errors16.FuelError(
|
4955
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4956
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4957
|
+
);
|
4958
|
+
}
|
5154
4959
|
if (gasUsed.gt(gasLimit)) {
|
5155
4960
|
throw new import_errors16.FuelError(
|
5156
4961
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5164,8 +4969,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5164
4969
|
var import_address5 = require("@fuel-ts/address");
|
5165
4970
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5166
4971
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5167
|
-
var
|
5168
|
-
var
|
4972
|
+
var import_math19 = require("@fuel-ts/math");
|
4973
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5169
4974
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5170
4975
|
var Signer = class {
|
5171
4976
|
address;
|
@@ -5184,10 +4989,10 @@ var Signer = class {
|
|
5184
4989
|
privateKey = `0x${privateKey}`;
|
5185
4990
|
}
|
5186
4991
|
}
|
5187
|
-
const privateKeyBytes = (0,
|
5188
|
-
this.privateKey = (0,
|
5189
|
-
this.publicKey = (0,
|
5190
|
-
this.compressedPublicKey = (0,
|
4992
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4993
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4994
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4995
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5191
4996
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5192
4997
|
}
|
5193
4998
|
/**
|
@@ -5201,11 +5006,11 @@ var Signer = class {
|
|
5201
5006
|
* @returns hashed signature
|
5202
5007
|
*/
|
5203
5008
|
sign(data) {
|
5204
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5205
|
-
const r = (0,
|
5206
|
-
const s = (0,
|
5009
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5010
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5011
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5207
5012
|
s[0] |= (signature.recovery || 0) << 7;
|
5208
|
-
return (0,
|
5013
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5209
5014
|
}
|
5210
5015
|
/**
|
5211
5016
|
* Add point on the current elliptic curve
|
@@ -5214,8 +5019,8 @@ var Signer = class {
|
|
5214
5019
|
* @returns compressed point on the curve
|
5215
5020
|
*/
|
5216
5021
|
addPoint(point) {
|
5217
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5218
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5022
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5023
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5219
5024
|
const result = p0.add(p1);
|
5220
5025
|
return `0x${result.toHex(true)}`;
|
5221
5026
|
}
|
@@ -5227,16 +5032,16 @@ var Signer = class {
|
|
5227
5032
|
* @returns public key from signature from the
|
5228
5033
|
*/
|
5229
5034
|
static recoverPublicKey(data, signature) {
|
5230
|
-
const signedMessageBytes = (0,
|
5035
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5231
5036
|
const r = signedMessageBytes.slice(0, 32);
|
5232
5037
|
const s = signedMessageBytes.slice(32, 64);
|
5233
5038
|
const recoveryParam = (s[0] & 128) >> 7;
|
5234
5039
|
s[0] &= 127;
|
5235
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5040
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5236
5041
|
recoveryParam
|
5237
5042
|
);
|
5238
|
-
const publicKey = sig.recoverPublicKey((0,
|
5239
|
-
return (0,
|
5043
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5044
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5240
5045
|
}
|
5241
5046
|
/**
|
5242
5047
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5255,7 +5060,7 @@ var Signer = class {
|
|
5255
5060
|
* @returns random 32-byte hashed
|
5256
5061
|
*/
|
5257
5062
|
static generatePrivateKey(entropy) {
|
5258
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5063
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5259
5064
|
}
|
5260
5065
|
/**
|
5261
5066
|
* Extended publicKey from a compact publicKey
|
@@ -5264,8 +5069,8 @@ var Signer = class {
|
|
5264
5069
|
* @returns extended publicKey
|
5265
5070
|
*/
|
5266
5071
|
static extendPublicKey(publicKey) {
|
5267
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5268
|
-
return (0,
|
5072
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5073
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5269
5074
|
}
|
5270
5075
|
};
|
5271
5076
|
|
@@ -5273,7 +5078,7 @@ var Signer = class {
|
|
5273
5078
|
var import_address6 = require("@fuel-ts/address");
|
5274
5079
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5275
5080
|
var import_errors17 = require("@fuel-ts/errors");
|
5276
|
-
var
|
5081
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5277
5082
|
var import_uuid = require("uuid");
|
5278
5083
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5279
5084
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5356,7 +5161,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5356
5161
|
);
|
5357
5162
|
}
|
5358
5163
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5359
|
-
const privateKey = (0,
|
5164
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5360
5165
|
return privateKey;
|
5361
5166
|
}
|
5362
5167
|
|
@@ -5401,7 +5206,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5401
5206
|
*/
|
5402
5207
|
async signMessage(message) {
|
5403
5208
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5404
|
-
return (0,
|
5209
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5405
5210
|
}
|
5406
5211
|
/**
|
5407
5212
|
* Signs a transaction with the wallet's private key.
|
@@ -5414,7 +5219,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5414
5219
|
const chainId = this.provider.getChainId();
|
5415
5220
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5416
5221
|
const signature = await this.signer().sign(hashedTransaction);
|
5417
|
-
return (0,
|
5222
|
+
return (0, import_utils31.hexlify)(signature);
|
5418
5223
|
}
|
5419
5224
|
/**
|
5420
5225
|
* Populates a transaction with the witnesses signature.
|
@@ -5434,7 +5239,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5434
5239
|
* @param transactionRequestLike - The transaction request to send.
|
5435
5240
|
* @returns A promise that resolves to the TransactionResponse object.
|
5436
5241
|
*/
|
5437
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5242
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5438
5243
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5439
5244
|
if (estimateTxDependencies) {
|
5440
5245
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5475,15 +5280,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5475
5280
|
// src/hdwallet/hdwallet.ts
|
5476
5281
|
var import_errors20 = require("@fuel-ts/errors");
|
5477
5282
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5478
|
-
var
|
5479
|
-
var
|
5283
|
+
var import_math20 = require("@fuel-ts/math");
|
5284
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5480
5285
|
var import_ethers3 = require("ethers");
|
5481
5286
|
|
5482
5287
|
// src/mnemonic/mnemonic.ts
|
5483
5288
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5484
5289
|
var import_errors19 = require("@fuel-ts/errors");
|
5485
5290
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5486
|
-
var
|
5291
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5487
5292
|
var import_ethers2 = require("ethers");
|
5488
5293
|
|
5489
5294
|
// src/wordlists/words/english.ts
|
@@ -7541,7 +7346,7 @@ var english = [
|
|
7541
7346
|
// src/mnemonic/utils.ts
|
7542
7347
|
var import_errors18 = require("@fuel-ts/errors");
|
7543
7348
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7544
|
-
var
|
7349
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7545
7350
|
function toUtf8Bytes(stri) {
|
7546
7351
|
const str = stri.normalize("NFKD");
|
7547
7352
|
const result = [];
|
@@ -7608,14 +7413,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7608
7413
|
}
|
7609
7414
|
}
|
7610
7415
|
const checksumBits = entropy.length / 4;
|
7611
|
-
const checksum = (0,
|
7416
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7612
7417
|
indices[indices.length - 1] <<= checksumBits;
|
7613
7418
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7614
7419
|
return indices;
|
7615
7420
|
}
|
7616
7421
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7617
7422
|
const size = Math.ceil(11 * words.length / 8);
|
7618
|
-
const entropy = (0,
|
7423
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7619
7424
|
let offset = 0;
|
7620
7425
|
for (let i = 0; i < words.length; i += 1) {
|
7621
7426
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7635,7 +7440,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7635
7440
|
const entropyBits = 32 * words.length / 3;
|
7636
7441
|
const checksumBits = words.length / 3;
|
7637
7442
|
const checksumMask = getUpperMask(checksumBits);
|
7638
|
-
const checksum = (0,
|
7443
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7639
7444
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7640
7445
|
throw new import_errors18.FuelError(
|
7641
7446
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7710,7 +7515,7 @@ var Mnemonic = class {
|
|
7710
7515
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7711
7516
|
const words = getWords(phrase);
|
7712
7517
|
assertMnemonic(words);
|
7713
|
-
return (0,
|
7518
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7714
7519
|
}
|
7715
7520
|
/**
|
7716
7521
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7718,7 +7523,7 @@ var Mnemonic = class {
|
|
7718
7523
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7719
7524
|
*/
|
7720
7525
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7721
|
-
const entropyBytes = (0,
|
7526
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7722
7527
|
assertWordList(wordlist);
|
7723
7528
|
assertEntropy(entropyBytes);
|
7724
7529
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7787,14 +7592,14 @@ var Mnemonic = class {
|
|
7787
7592
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7788
7593
|
*/
|
7789
7594
|
static masterKeysFromSeed(seed) {
|
7790
|
-
const seedArray = (0,
|
7595
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7791
7596
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7792
7597
|
throw new import_errors19.FuelError(
|
7793
7598
|
import_errors19.ErrorCode.INVALID_SEED,
|
7794
7599
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7795
7600
|
);
|
7796
7601
|
}
|
7797
|
-
return (0,
|
7602
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7798
7603
|
}
|
7799
7604
|
/**
|
7800
7605
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7805,22 +7610,22 @@ var Mnemonic = class {
|
|
7805
7610
|
*/
|
7806
7611
|
static seedToExtendedKey(seed, testnet = false) {
|
7807
7612
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7808
|
-
const prefix = (0,
|
7613
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7809
7614
|
const depth = "0x00";
|
7810
7615
|
const fingerprint = "0x00000000";
|
7811
7616
|
const index = "0x00000000";
|
7812
7617
|
const chainCode = masterKey.slice(32);
|
7813
7618
|
const privateKey = masterKey.slice(0, 32);
|
7814
|
-
const extendedKey = (0,
|
7619
|
+
const extendedKey = (0, import_utils33.concat)([
|
7815
7620
|
prefix,
|
7816
7621
|
depth,
|
7817
7622
|
fingerprint,
|
7818
7623
|
index,
|
7819
7624
|
chainCode,
|
7820
|
-
(0,
|
7625
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7821
7626
|
]);
|
7822
7627
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7823
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7628
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7824
7629
|
}
|
7825
7630
|
/**
|
7826
7631
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7835,7 +7640,7 @@ var Mnemonic = class {
|
|
7835
7640
|
* @returns A randomly generated mnemonic
|
7836
7641
|
*/
|
7837
7642
|
static generate(size = 32, extraEntropy = "") {
|
7838
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7643
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7839
7644
|
return Mnemonic.entropyToMnemonic(entropy);
|
7840
7645
|
}
|
7841
7646
|
};
|
@@ -7843,12 +7648,12 @@ var mnemonic_default = Mnemonic;
|
|
7843
7648
|
|
7844
7649
|
// src/hdwallet/hdwallet.ts
|
7845
7650
|
var HARDENED_INDEX = 2147483648;
|
7846
|
-
var MainnetPRV2 = (0,
|
7847
|
-
var MainnetPUB = (0,
|
7848
|
-
var TestnetPRV2 = (0,
|
7849
|
-
var TestnetPUB = (0,
|
7651
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7652
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7653
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7654
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7850
7655
|
function base58check(data) {
|
7851
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7656
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7852
7657
|
}
|
7853
7658
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7854
7659
|
if (isPublic) {
|
@@ -7857,11 +7662,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7857
7662
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7858
7663
|
}
|
7859
7664
|
function isPublicExtendedKey(extendedKey) {
|
7860
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7665
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7861
7666
|
}
|
7862
7667
|
function isValidExtendedKey(extendedKey) {
|
7863
7668
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7864
|
-
(0,
|
7669
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7865
7670
|
);
|
7866
7671
|
}
|
7867
7672
|
function parsePath(path2, depth = 0) {
|
@@ -7879,8 +7684,8 @@ function parsePath(path2, depth = 0) {
|
|
7879
7684
|
var HDWallet = class {
|
7880
7685
|
depth = 0;
|
7881
7686
|
index = 0;
|
7882
|
-
fingerprint = (0,
|
7883
|
-
parentFingerprint = (0,
|
7687
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7688
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7884
7689
|
privateKey;
|
7885
7690
|
publicKey;
|
7886
7691
|
chainCode;
|
@@ -7892,8 +7697,8 @@ var HDWallet = class {
|
|
7892
7697
|
constructor(config) {
|
7893
7698
|
if (config.privateKey) {
|
7894
7699
|
const signer = new Signer(config.privateKey);
|
7895
|
-
this.publicKey = (0,
|
7896
|
-
this.privateKey = (0,
|
7700
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7701
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7897
7702
|
} else {
|
7898
7703
|
if (!config.publicKey) {
|
7899
7704
|
throw new import_errors20.FuelError(
|
@@ -7901,7 +7706,7 @@ var HDWallet = class {
|
|
7901
7706
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7902
7707
|
);
|
7903
7708
|
}
|
7904
|
-
this.publicKey = (0,
|
7709
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7905
7710
|
}
|
7906
7711
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7907
7712
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7920,9 +7725,9 @@ var HDWallet = class {
|
|
7920
7725
|
* @returns A new instance of HDWallet on the derived index
|
7921
7726
|
*/
|
7922
7727
|
deriveIndex(index) {
|
7923
|
-
const privateKey = this.privateKey && (0,
|
7924
|
-
const publicKey = (0,
|
7925
|
-
const chainCode = (0,
|
7728
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7729
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7730
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7926
7731
|
const data = new Uint8Array(37);
|
7927
7732
|
if (index & HARDENED_INDEX) {
|
7928
7733
|
if (!privateKey) {
|
@@ -7933,15 +7738,15 @@ var HDWallet = class {
|
|
7933
7738
|
}
|
7934
7739
|
data.set(privateKey, 1);
|
7935
7740
|
} else {
|
7936
|
-
data.set((0,
|
7741
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7937
7742
|
}
|
7938
|
-
data.set((0,
|
7939
|
-
const bytes = (0,
|
7743
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7744
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7940
7745
|
const IL = bytes.slice(0, 32);
|
7941
7746
|
const IR = bytes.slice(32);
|
7942
7747
|
if (privateKey) {
|
7943
7748
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7944
|
-
const ki = (0,
|
7749
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7945
7750
|
return new HDWallet({
|
7946
7751
|
privateKey: ki,
|
7947
7752
|
chainCode: IR,
|
@@ -7950,7 +7755,7 @@ var HDWallet = class {
|
|
7950
7755
|
parentFingerprint: this.fingerprint
|
7951
7756
|
});
|
7952
7757
|
}
|
7953
|
-
const signer = new Signer((0,
|
7758
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7954
7759
|
const Ki = signer.addPoint(publicKey);
|
7955
7760
|
return new HDWallet({
|
7956
7761
|
publicKey: Ki,
|
@@ -7985,12 +7790,12 @@ var HDWallet = class {
|
|
7985
7790
|
);
|
7986
7791
|
}
|
7987
7792
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7988
|
-
const depth = (0,
|
7793
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7989
7794
|
const parentFingerprint = this.parentFingerprint;
|
7990
|
-
const index = (0,
|
7795
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7991
7796
|
const chainCode = this.chainCode;
|
7992
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7993
|
-
const extendedKey = (0,
|
7797
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7798
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7994
7799
|
return base58check(extendedKey);
|
7995
7800
|
}
|
7996
7801
|
/**
|
@@ -8002,13 +7807,13 @@ var HDWallet = class {
|
|
8002
7807
|
static fromSeed(seed) {
|
8003
7808
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8004
7809
|
return new HDWallet({
|
8005
|
-
chainCode: (0,
|
8006
|
-
privateKey: (0,
|
7810
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7811
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8007
7812
|
});
|
8008
7813
|
}
|
8009
7814
|
static fromExtendedKey(extendedKey) {
|
8010
7815
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8011
|
-
const bytes = (0,
|
7816
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8012
7817
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8013
7818
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8014
7819
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8017,9 +7822,9 @@ var HDWallet = class {
|
|
8017
7822
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8018
7823
|
}
|
8019
7824
|
const depth = bytes[4];
|
8020
|
-
const parentFingerprint = (0,
|
8021
|
-
const index = parseInt((0,
|
8022
|
-
const chainCode = (0,
|
7825
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7826
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7827
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8023
7828
|
const key = bytes.slice(45, 78);
|
8024
7829
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8025
7830
|
throw new import_errors20.FuelError(
|
@@ -8212,15 +8017,16 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8212
8017
|
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
8213
8018
|
wallet.provider
|
8214
8019
|
);
|
8215
|
-
const
|
8216
|
-
|
8217
|
-
|
8218
|
-
|
8020
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
8021
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
8022
|
+
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
8023
|
+
const request = new ScriptTransactionRequest({
|
8024
|
+
baseAssetId,
|
8025
|
+
gasLimit: 1e4,
|
8026
|
+
gasPrice: minGasPrice
|
8219
8027
|
});
|
8220
|
-
|
8221
|
-
request.
|
8222
|
-
request.maxFee = txCost.maxFee;
|
8223
|
-
await genesisWallet.fund(request, txCost);
|
8028
|
+
request.addResources(resources);
|
8029
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8224
8030
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8225
8031
|
};
|
8226
8032
|
|
@@ -8234,12 +8040,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8234
8040
|
};
|
8235
8041
|
|
8236
8042
|
// src/test-utils/launchNode.ts
|
8237
|
-
var
|
8238
|
-
var
|
8043
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
8044
|
+
var import_math21 = require("@fuel-ts/math");
|
8045
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8239
8046
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8240
8047
|
var import_child_process = require("child_process");
|
8241
8048
|
var import_crypto6 = require("crypto");
|
8242
|
-
var import_ethers4 = require("ethers");
|
8243
8049
|
var import_fs = require("fs");
|
8244
8050
|
var import_os = __toESM(require("os"));
|
8245
8051
|
var import_path = __toESM(require("path"));
|
@@ -8288,13 +8094,13 @@ var launchNode = async ({
|
|
8288
8094
|
// eslint-disable-next-line no-async-promise-executor
|
8289
8095
|
new Promise(async (resolve, reject) => {
|
8290
8096
|
const remainingArgs = extractRemainingArgs(args, [
|
8291
|
-
"--
|
8097
|
+
"--chain",
|
8292
8098
|
"--consensus-key",
|
8293
8099
|
"--db-type",
|
8294
8100
|
"--poa-instant"
|
8295
8101
|
]);
|
8296
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8297
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8102
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8103
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8298
8104
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8299
8105
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8300
8106
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8312,54 +8118,36 @@ var launchNode = async ({
|
|
8312
8118
|
let chainConfigPathToUse;
|
8313
8119
|
const prefix = basePath || import_os.default.tmpdir();
|
8314
8120
|
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8315
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix
|
8121
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8316
8122
|
if (chainConfigPath) {
|
8317
8123
|
chainConfigPathToUse = chainConfigPath;
|
8318
8124
|
} else {
|
8319
8125
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8320
8126
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8321
8127
|
}
|
8322
|
-
|
8323
|
-
|
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
|
-
};
|
8128
|
+
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8129
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8338
8130
|
if (!process.env.GENESIS_SECRET) {
|
8339
8131
|
const pk = Signer.generatePrivateKey();
|
8340
8132
|
const signer = new Signer(pk);
|
8341
|
-
process.env.GENESIS_SECRET = (0,
|
8342
|
-
|
8343
|
-
|
8344
|
-
|
8345
|
-
|
8346
|
-
|
8347
|
-
|
8348
|
-
|
8349
|
-
|
8350
|
-
|
8351
|
-
|
8133
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8134
|
+
chainConfig = {
|
8135
|
+
...import_utils36.defaultChainConfig,
|
8136
|
+
initial_state: {
|
8137
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8138
|
+
coins: [
|
8139
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8140
|
+
{
|
8141
|
+
owner: signer.address.toHexString(),
|
8142
|
+
amount: (0, import_math21.toHex)(1e9),
|
8143
|
+
asset_id: import_utils36.defaultChainConfig?.consensus_parameters?.base_asset_id ?? import_configs11.ZeroBytes32
|
8144
|
+
}
|
8145
|
+
]
|
8146
|
+
}
|
8147
|
+
};
|
8352
8148
|
}
|
8353
|
-
|
8354
|
-
|
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;
|
8149
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8150
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8363
8151
|
}
|
8364
8152
|
const child = (0, import_child_process.spawn)(
|
8365
8153
|
command,
|
@@ -8368,10 +8156,10 @@ var launchNode = async ({
|
|
8368
8156
|
["--ip", ipToUse],
|
8369
8157
|
["--port", portToUse],
|
8370
8158
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8371
|
-
["--min-gas-price", "
|
8159
|
+
["--min-gas-price", "0"],
|
8372
8160
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8373
8161
|
["--consensus-key", consensusKey],
|
8374
|
-
["--
|
8162
|
+
["--chain", chainConfigPathToUse],
|
8375
8163
|
"--vm-backtrace",
|
8376
8164
|
"--utxo-validation",
|
8377
8165
|
"--debug",
|
@@ -8418,9 +8206,10 @@ var launchNode = async ({
|
|
8418
8206
|
})
|
8419
8207
|
);
|
8420
8208
|
var generateWallets = async (count, provider) => {
|
8209
|
+
const baseAssetId = provider.getBaseAssetId();
|
8421
8210
|
const wallets = [];
|
8422
8211
|
for (let i = 0; i < count; i += 1) {
|
8423
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8212
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8424
8213
|
wallets.push(wallet);
|
8425
8214
|
}
|
8426
8215
|
return wallets;
|
@@ -8430,7 +8219,7 @@ var launchNodeAndGetWallets = async ({
|
|
8430
8219
|
walletCount = 10
|
8431
8220
|
} = {}) => {
|
8432
8221
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8433
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8222
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8434
8223
|
const wallets = await generateWallets(walletCount, provider);
|
8435
8224
|
const cleanup = () => {
|
8436
8225
|
closeNode();
|