@fuel-ts/account 0.0.0-rc-2021-20240409111335 → 0.0.0-rc-1976-20240409134753
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 +616 -868
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +610 -848
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +453 -690
- 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 +328 -894
- 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/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -45
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +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.global.js +1117 -1583
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +607 -824
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +465 -682
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/test-utils.js
CHANGED
@@ -58,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,12 +105,12 @@ 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
|
116
|
-
var
|
112
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
113
|
+
var import_ethers = require("ethers");
|
117
114
|
var import_graphql_request = require("graphql-request");
|
118
115
|
var import_ramda3 = require("ramda");
|
119
116
|
|
@@ -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
|
}
|
@@ -305,6 +263,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
305
263
|
prevRoot
|
306
264
|
time
|
307
265
|
applicationHash
|
266
|
+
messageReceiptRoot
|
308
267
|
messageReceiptCount
|
309
268
|
}
|
310
269
|
commitBlockHeader {
|
@@ -316,6 +275,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
316
275
|
prevRoot
|
317
276
|
time
|
318
277
|
applicationHash
|
278
|
+
messageReceiptRoot
|
319
279
|
messageReceiptCount
|
320
280
|
}
|
321
281
|
sender
|
@@ -335,8 +295,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
335
295
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
336
296
|
fragment blockFragment on Block {
|
337
297
|
id
|
338
|
-
height
|
339
298
|
header {
|
299
|
+
height
|
340
300
|
time
|
341
301
|
}
|
342
302
|
transactions {
|
@@ -394,11 +354,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
394
354
|
`;
|
395
355
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
396
356
|
fragment GasCostsFragment on GasCosts {
|
397
|
-
version {
|
398
|
-
... on Version {
|
399
|
-
value
|
400
|
-
}
|
401
|
-
}
|
402
357
|
add
|
403
358
|
addi
|
404
359
|
aloc
|
@@ -411,6 +366,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
411
366
|
cb
|
412
367
|
cfei
|
413
368
|
cfsi
|
369
|
+
croo
|
414
370
|
div
|
415
371
|
divi
|
416
372
|
ecr1
|
@@ -493,9 +449,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
493
449
|
ccp {
|
494
450
|
...DependentCostFragment
|
495
451
|
}
|
496
|
-
croo {
|
497
|
-
...DependentCostFragment
|
498
|
-
}
|
499
452
|
csiz {
|
500
453
|
...DependentCostFragment
|
501
454
|
}
|
@@ -555,11 +508,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
555
508
|
${DependentCostFragmentFragmentDoc}`;
|
556
509
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
557
510
|
fragment consensusParametersFragment on ConsensusParameters {
|
558
|
-
version {
|
559
|
-
... on Version {
|
560
|
-
value
|
561
|
-
}
|
562
|
-
}
|
563
511
|
txParams {
|
564
512
|
...TxParametersFragment
|
565
513
|
}
|
@@ -619,9 +567,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
619
567
|
fragment nodeInfoFragment on NodeInfo {
|
620
568
|
utxoValidation
|
621
569
|
vmBacktrace
|
570
|
+
minGasPrice
|
622
571
|
maxTx
|
623
572
|
maxDepth
|
624
573
|
nodeVersion
|
574
|
+
peers {
|
575
|
+
id
|
576
|
+
addresses
|
577
|
+
clientVersion
|
578
|
+
blockHeight
|
579
|
+
lastHeartbeatMs
|
580
|
+
appScore
|
581
|
+
}
|
625
582
|
}
|
626
583
|
`;
|
627
584
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -656,9 +613,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
656
613
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
657
614
|
transaction(id: $transactionId) {
|
658
615
|
...transactionFragment
|
616
|
+
receipts {
|
617
|
+
...receiptFragment
|
618
|
+
}
|
659
619
|
}
|
660
620
|
}
|
661
|
-
${TransactionFragmentFragmentDoc}
|
621
|
+
${TransactionFragmentFragmentDoc}
|
622
|
+
${ReceiptFragmentFragmentDoc}`;
|
662
623
|
var GetTransactionsDocument = import_graphql_tag.default`
|
663
624
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
664
625
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -786,20 +747,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
786
747
|
}
|
787
748
|
}
|
788
749
|
${BalanceFragmentFragmentDoc}`;
|
789
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
790
|
-
query getLatestGasPrice {
|
791
|
-
latestGasPrice {
|
792
|
-
gasPrice
|
793
|
-
}
|
794
|
-
}
|
795
|
-
`;
|
796
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
797
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
798
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
799
|
-
gasPrice
|
800
|
-
}
|
801
|
-
}
|
802
|
-
`;
|
803
750
|
var GetBalancesDocument = import_graphql_tag.default`
|
804
751
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
805
752
|
balances(
|
@@ -854,12 +801,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
854
801
|
}
|
855
802
|
`;
|
856
803
|
var DryRunDocument = import_graphql_tag.default`
|
857
|
-
mutation dryRun($
|
858
|
-
dryRun(
|
859
|
-
...
|
804
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
805
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
806
|
+
...receiptFragment
|
860
807
|
}
|
861
808
|
}
|
862
|
-
${
|
809
|
+
${ReceiptFragmentFragmentDoc}`;
|
863
810
|
var SubmitDocument = import_graphql_tag.default`
|
864
811
|
mutation submit($encodedTransaction: HexString!) {
|
865
812
|
submit(tx: $encodedTransaction) {
|
@@ -942,12 +889,6 @@ function getSdk(requester) {
|
|
942
889
|
getBalance(variables, options) {
|
943
890
|
return requester(GetBalanceDocument, variables, options);
|
944
891
|
},
|
945
|
-
getLatestGasPrice(variables, options) {
|
946
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
947
|
-
},
|
948
|
-
estimateGasPrice(variables, options) {
|
949
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
950
|
-
},
|
951
892
|
getBalances(variables, options) {
|
952
893
|
return requester(GetBalancesDocument, variables, options);
|
953
894
|
},
|
@@ -1021,9 +962,7 @@ var _FuelGraphqlSubscriber = class {
|
|
1021
962
|
} catch (e) {
|
1022
963
|
throw new import_errors.FuelError(
|
1023
964
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
1024
|
-
`Error while parsing stream data response: ${text}
|
1025
|
-
|
1026
|
-
Thrown error: ${e}`
|
965
|
+
`Error while parsing stream data response: ${text}`
|
1027
966
|
);
|
1028
967
|
}
|
1029
968
|
if (Array.isArray(errors)) {
|
@@ -1110,7 +1049,7 @@ var MemoryCache = class {
|
|
1110
1049
|
};
|
1111
1050
|
|
1112
1051
|
// src/providers/transaction-request/input.ts
|
1113
|
-
var
|
1052
|
+
var import_configs = require("@fuel-ts/address/configs");
|
1114
1053
|
var import_errors3 = require("@fuel-ts/errors");
|
1115
1054
|
var import_math2 = require("@fuel-ts/math");
|
1116
1055
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1124,7 +1063,7 @@ var inputify = (value) => {
|
|
1124
1063
|
return {
|
1125
1064
|
type: import_transactions.InputType.Coin,
|
1126
1065
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1127
|
-
outputIndex: (0,
|
1066
|
+
outputIndex: (0, import_utils3.arrayify)(value.id)[32],
|
1128
1067
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1129
1068
|
amount: (0, import_math2.bn)(value.amount),
|
1130
1069
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1133,9 +1072,10 @@ var inputify = (value) => {
|
|
1133
1072
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1134
1073
|
},
|
1135
1074
|
witnessIndex: value.witnessIndex,
|
1075
|
+
maturity: value.maturity ?? 0,
|
1136
1076
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1137
|
-
predicateLength:
|
1138
|
-
predicateDataLength:
|
1077
|
+
predicateLength: predicate.length,
|
1078
|
+
predicateDataLength: predicateData.length,
|
1139
1079
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1140
1080
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1141
1081
|
};
|
@@ -1143,10 +1083,10 @@ var inputify = (value) => {
|
|
1143
1083
|
case import_transactions.InputType.Contract: {
|
1144
1084
|
return {
|
1145
1085
|
type: import_transactions.InputType.Contract,
|
1146
|
-
txID:
|
1086
|
+
txID: import_configs.ZeroBytes32,
|
1147
1087
|
outputIndex: 0,
|
1148
|
-
balanceRoot:
|
1149
|
-
stateRoot:
|
1088
|
+
balanceRoot: import_configs.ZeroBytes32,
|
1089
|
+
stateRoot: import_configs.ZeroBytes32,
|
1150
1090
|
txPointer: {
|
1151
1091
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1152
1092
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1166,8 +1106,8 @@ var inputify = (value) => {
|
|
1166
1106
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1167
1107
|
witnessIndex: value.witnessIndex,
|
1168
1108
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1169
|
-
predicateLength:
|
1170
|
-
predicateDataLength:
|
1109
|
+
predicateLength: predicate.length,
|
1110
|
+
predicateDataLength: predicateData.length,
|
1171
1111
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1172
1112
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1173
1113
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1184,7 +1124,7 @@ var inputify = (value) => {
|
|
1184
1124
|
};
|
1185
1125
|
|
1186
1126
|
// src/providers/transaction-request/output.ts
|
1187
|
-
var
|
1127
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1188
1128
|
var import_errors4 = require("@fuel-ts/errors");
|
1189
1129
|
var import_math3 = require("@fuel-ts/math");
|
1190
1130
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1204,8 +1144,8 @@ var outputify = (value) => {
|
|
1204
1144
|
return {
|
1205
1145
|
type: import_transactions2.OutputType.Contract,
|
1206
1146
|
inputIndex: value.inputIndex,
|
1207
|
-
balanceRoot:
|
1208
|
-
stateRoot:
|
1147
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1148
|
+
stateRoot: import_configs2.ZeroBytes32
|
1209
1149
|
};
|
1210
1150
|
}
|
1211
1151
|
case import_transactions2.OutputType.Change: {
|
@@ -1219,9 +1159,9 @@ var outputify = (value) => {
|
|
1219
1159
|
case import_transactions2.OutputType.Variable: {
|
1220
1160
|
return {
|
1221
1161
|
type: import_transactions2.OutputType.Variable,
|
1222
|
-
to:
|
1162
|
+
to: import_configs2.ZeroBytes32,
|
1223
1163
|
amount: (0, import_math3.bn)(0),
|
1224
|
-
assetId:
|
1164
|
+
assetId: import_configs2.ZeroBytes32
|
1225
1165
|
};
|
1226
1166
|
}
|
1227
1167
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1242,23 +1182,22 @@ var outputify = (value) => {
|
|
1242
1182
|
|
1243
1183
|
// src/providers/transaction-request/transaction-request.ts
|
1244
1184
|
var import_address = require("@fuel-ts/address");
|
1245
|
-
var
|
1185
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1246
1186
|
var import_math7 = require("@fuel-ts/math");
|
1247
1187
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1248
1188
|
var import_utils9 = require("@fuel-ts/utils");
|
1249
|
-
var import_ethers = require("ethers");
|
1250
1189
|
|
1251
1190
|
// src/providers/resource.ts
|
1252
1191
|
var isCoin = (resource) => "id" in resource;
|
1253
1192
|
|
1254
1193
|
// src/providers/utils/receipts.ts
|
1255
|
-
var
|
1194
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1256
1195
|
var import_errors5 = require("@fuel-ts/errors");
|
1257
1196
|
var import_math4 = require("@fuel-ts/math");
|
1258
1197
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1259
|
-
var
|
1198
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
1260
1199
|
var import_utils5 = require("@fuel-ts/utils");
|
1261
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1200
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1262
1201
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1263
1202
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1264
1203
|
(memo, receipt) => {
|
@@ -1275,15 +1214,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1275
1214
|
missingOutputContractIds: []
|
1276
1215
|
}
|
1277
1216
|
);
|
1278
|
-
var hexOrZero = (hex) => hex ||
|
1217
|
+
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
1279
1218
|
function assembleReceiptByType(receipt) {
|
1280
1219
|
const { receiptType } = receipt;
|
1281
1220
|
switch (receiptType) {
|
1282
1221
|
case "CALL" /* Call */: {
|
1283
1222
|
const callReceipt = {
|
1284
1223
|
type: import_transactions3.ReceiptType.Call,
|
1285
|
-
from: hexOrZero(receipt.id
|
1286
|
-
to: hexOrZero(receipt?.to),
|
1224
|
+
from: hexOrZero(receipt.contract?.id),
|
1225
|
+
to: hexOrZero(receipt?.to?.id),
|
1287
1226
|
amount: (0, import_math4.bn)(receipt.amount),
|
1288
1227
|
assetId: hexOrZero(receipt.assetId),
|
1289
1228
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1297,7 +1236,7 @@ function assembleReceiptByType(receipt) {
|
|
1297
1236
|
case "RETURN" /* Return */: {
|
1298
1237
|
const returnReceipt = {
|
1299
1238
|
type: import_transactions3.ReceiptType.Return,
|
1300
|
-
id: hexOrZero(receipt.id
|
1239
|
+
id: hexOrZero(receipt.contract?.id),
|
1301
1240
|
val: (0, import_math4.bn)(receipt.val),
|
1302
1241
|
pc: (0, import_math4.bn)(receipt.pc),
|
1303
1242
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1307,7 +1246,7 @@ function assembleReceiptByType(receipt) {
|
|
1307
1246
|
case "RETURN_DATA" /* ReturnData */: {
|
1308
1247
|
const returnDataReceipt = {
|
1309
1248
|
type: import_transactions3.ReceiptType.ReturnData,
|
1310
|
-
id: hexOrZero(receipt.id
|
1249
|
+
id: hexOrZero(receipt.contract?.id),
|
1311
1250
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1312
1251
|
len: (0, import_math4.bn)(receipt.len),
|
1313
1252
|
digest: hexOrZero(receipt.digest),
|
@@ -1319,7 +1258,7 @@ function assembleReceiptByType(receipt) {
|
|
1319
1258
|
case "PANIC" /* Panic */: {
|
1320
1259
|
const panicReceipt = {
|
1321
1260
|
type: import_transactions3.ReceiptType.Panic,
|
1322
|
-
id: hexOrZero(receipt.id),
|
1261
|
+
id: hexOrZero(receipt.contract?.id),
|
1323
1262
|
reason: (0, import_math4.bn)(receipt.reason),
|
1324
1263
|
pc: (0, import_math4.bn)(receipt.pc),
|
1325
1264
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1330,7 +1269,7 @@ function assembleReceiptByType(receipt) {
|
|
1330
1269
|
case "REVERT" /* Revert */: {
|
1331
1270
|
const revertReceipt = {
|
1332
1271
|
type: import_transactions3.ReceiptType.Revert,
|
1333
|
-
id: hexOrZero(receipt.id
|
1272
|
+
id: hexOrZero(receipt.contract?.id),
|
1334
1273
|
val: (0, import_math4.bn)(receipt.ra),
|
1335
1274
|
pc: (0, import_math4.bn)(receipt.pc),
|
1336
1275
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1340,7 +1279,7 @@ function assembleReceiptByType(receipt) {
|
|
1340
1279
|
case "LOG" /* Log */: {
|
1341
1280
|
const logReceipt = {
|
1342
1281
|
type: import_transactions3.ReceiptType.Log,
|
1343
|
-
id: hexOrZero(receipt.id
|
1282
|
+
id: hexOrZero(receipt.contract?.id),
|
1344
1283
|
val0: (0, import_math4.bn)(receipt.ra),
|
1345
1284
|
val1: (0, import_math4.bn)(receipt.rb),
|
1346
1285
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1353,7 +1292,7 @@ function assembleReceiptByType(receipt) {
|
|
1353
1292
|
case "LOG_DATA" /* LogData */: {
|
1354
1293
|
const logDataReceipt = {
|
1355
1294
|
type: import_transactions3.ReceiptType.LogData,
|
1356
|
-
id: hexOrZero(receipt.id
|
1295
|
+
id: hexOrZero(receipt.contract?.id),
|
1357
1296
|
val0: (0, import_math4.bn)(receipt.ra),
|
1358
1297
|
val1: (0, import_math4.bn)(receipt.rb),
|
1359
1298
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1367,8 +1306,8 @@ function assembleReceiptByType(receipt) {
|
|
1367
1306
|
case "TRANSFER" /* Transfer */: {
|
1368
1307
|
const transferReceipt = {
|
1369
1308
|
type: import_transactions3.ReceiptType.Transfer,
|
1370
|
-
from: hexOrZero(receipt.id
|
1371
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1309
|
+
from: hexOrZero(receipt.contract?.id),
|
1310
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1372
1311
|
amount: (0, import_math4.bn)(receipt.amount),
|
1373
1312
|
assetId: hexOrZero(receipt.assetId),
|
1374
1313
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1379,8 +1318,8 @@ function assembleReceiptByType(receipt) {
|
|
1379
1318
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1380
1319
|
const transferOutReceipt = {
|
1381
1320
|
type: import_transactions3.ReceiptType.TransferOut,
|
1382
|
-
from: hexOrZero(receipt.id
|
1383
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1321
|
+
from: hexOrZero(receipt.contract?.id),
|
1322
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1384
1323
|
amount: (0, import_math4.bn)(receipt.amount),
|
1385
1324
|
assetId: hexOrZero(receipt.assetId),
|
1386
1325
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1423,7 +1362,7 @@ function assembleReceiptByType(receipt) {
|
|
1423
1362
|
return receiptMessageOut;
|
1424
1363
|
}
|
1425
1364
|
case "MINT" /* Mint */: {
|
1426
|
-
const contractId = hexOrZero(receipt.id
|
1365
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1427
1366
|
const subId = hexOrZero(receipt.subId);
|
1428
1367
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1429
1368
|
const mintReceipt = {
|
@@ -1438,7 +1377,7 @@ function assembleReceiptByType(receipt) {
|
|
1438
1377
|
return mintReceipt;
|
1439
1378
|
}
|
1440
1379
|
case "BURN" /* Burn */: {
|
1441
|
-
const contractId = hexOrZero(receipt.id
|
1380
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1442
1381
|
const subId = hexOrZero(receipt.subId);
|
1443
1382
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1444
1383
|
const burnReceipt = {
|
@@ -1464,6 +1403,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1464
1403
|
var import_math5 = require("@fuel-ts/math");
|
1465
1404
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1466
1405
|
var import_utils6 = require("@fuel-ts/utils");
|
1406
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1467
1407
|
var getGasUsedFromReceipts = (receipts) => {
|
1468
1408
|
const scriptResult = receipts.filter(
|
1469
1409
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1484,28 +1424,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1484
1424
|
}
|
1485
1425
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1486
1426
|
const witnessCache = [];
|
1487
|
-
const
|
1488
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1489
|
-
if (isCoinOrMessage) {
|
1490
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1491
|
-
return true;
|
1492
|
-
}
|
1493
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1494
|
-
witnessCache.push(input.witnessIndex);
|
1495
|
-
return true;
|
1496
|
-
}
|
1497
|
-
}
|
1498
|
-
return false;
|
1499
|
-
});
|
1500
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1501
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1427
|
+
const totalGas = inputs.reduce((total, input) => {
|
1502
1428
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1503
1429
|
return total.add(
|
1504
|
-
|
1430
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1505
1431
|
);
|
1506
1432
|
}
|
1507
|
-
|
1508
|
-
|
1433
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1434
|
+
witnessCache.push(input.witnessIndex);
|
1435
|
+
return total.add(gasCosts.ecr1);
|
1436
|
+
}
|
1437
|
+
return total;
|
1438
|
+
}, (0, import_math5.bn)());
|
1509
1439
|
return totalGas;
|
1510
1440
|
}
|
1511
1441
|
function getMinGas(params) {
|
@@ -1517,20 +1447,12 @@ function getMinGas(params) {
|
|
1517
1447
|
return minGas;
|
1518
1448
|
}
|
1519
1449
|
function getMaxGas(params) {
|
1520
|
-
const {
|
1521
|
-
gasPerByte,
|
1522
|
-
witnessesLength,
|
1523
|
-
witnessLimit,
|
1524
|
-
minGas,
|
1525
|
-
gasLimit = (0, import_math5.bn)(0),
|
1526
|
-
maxGasPerTx
|
1527
|
-
} = params;
|
1450
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1528
1451
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1529
1452
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1530
1453
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1531
1454
|
}
|
1532
|
-
|
1533
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1455
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1534
1456
|
}
|
1535
1457
|
function calculateMetadataGasForTxCreate({
|
1536
1458
|
gasCosts,
|
@@ -1552,10 +1474,6 @@ function calculateMetadataGasForTxScript({
|
|
1552
1474
|
}) {
|
1553
1475
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1554
1476
|
}
|
1555
|
-
var calculateGasFee = (params) => {
|
1556
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1557
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1558
|
-
};
|
1559
1477
|
|
1560
1478
|
// src/providers/utils/json.ts
|
1561
1479
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1601,16 +1519,16 @@ function sleep(time) {
|
|
1601
1519
|
var import_errors7 = require("@fuel-ts/errors");
|
1602
1520
|
var import_math6 = require("@fuel-ts/math");
|
1603
1521
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1604
|
-
var
|
1522
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1605
1523
|
var assemblePanicError = (status) => {
|
1606
1524
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1607
1525
|
const reason = status.reason;
|
1608
|
-
if (
|
1526
|
+
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1609
1527
|
errorMessage = `${errorMessage}
|
1610
1528
|
|
1611
1529
|
You can read more about this error at:
|
1612
1530
|
|
1613
|
-
${
|
1531
|
+
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1614
1532
|
}
|
1615
1533
|
return { errorMessage, reason };
|
1616
1534
|
};
|
@@ -1622,28 +1540,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1622
1540
|
if (revertReceipt) {
|
1623
1541
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1624
1542
|
switch (reasonHex) {
|
1625
|
-
case
|
1543
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1626
1544
|
reason = "require";
|
1627
1545
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1628
1546
|
break;
|
1629
1547
|
}
|
1630
|
-
case
|
1548
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1631
1549
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1632
1550
|
reason = "assert_eq";
|
1633
1551
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1634
1552
|
break;
|
1635
1553
|
}
|
1636
|
-
case
|
1554
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1637
1555
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1638
1556
|
reason = "assert_ne";
|
1639
1557
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1640
1558
|
break;
|
1641
1559
|
}
|
1642
|
-
case
|
1560
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1643
1561
|
reason = "assert";
|
1644
1562
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1645
1563
|
break;
|
1646
|
-
case
|
1564
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1647
1565
|
reason = "MissingOutputChange";
|
1648
1566
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1649
1567
|
break;
|
@@ -1692,7 +1610,7 @@ var witnessify = (value) => {
|
|
1692
1610
|
// src/providers/transaction-request/transaction-request.ts
|
1693
1611
|
var BaseTransactionRequest = class {
|
1694
1612
|
/** Gas price for transaction */
|
1695
|
-
|
1613
|
+
gasPrice;
|
1696
1614
|
/** Block until which tx cannot be included */
|
1697
1615
|
maturity;
|
1698
1616
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1705,34 +1623,38 @@ var BaseTransactionRequest = class {
|
|
1705
1623
|
outputs = [];
|
1706
1624
|
/** List of witnesses */
|
1707
1625
|
witnesses = [];
|
1626
|
+
/** Base asset ID - should be fetched from the chain */
|
1627
|
+
baseAssetId = import_configs6.ZeroBytes32;
|
1708
1628
|
/**
|
1709
1629
|
* Constructor for initializing a base transaction request.
|
1710
1630
|
*
|
1711
1631
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1712
1632
|
*/
|
1713
1633
|
constructor({
|
1714
|
-
|
1634
|
+
gasPrice,
|
1715
1635
|
maturity,
|
1716
1636
|
maxFee,
|
1717
1637
|
witnessLimit,
|
1718
1638
|
inputs,
|
1719
1639
|
outputs,
|
1720
|
-
witnesses
|
1640
|
+
witnesses,
|
1641
|
+
baseAssetId
|
1721
1642
|
} = {}) {
|
1722
|
-
this.
|
1643
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1723
1644
|
this.maturity = maturity ?? 0;
|
1724
1645
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1725
1646
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1726
1647
|
this.inputs = inputs ?? [];
|
1727
1648
|
this.outputs = outputs ?? [];
|
1728
1649
|
this.witnesses = witnesses ?? [];
|
1650
|
+
this.baseAssetId = baseAssetId ?? import_configs6.ZeroBytes32;
|
1729
1651
|
}
|
1730
1652
|
static getPolicyMeta(req) {
|
1731
1653
|
let policyTypes = 0;
|
1732
1654
|
const policies = [];
|
1733
|
-
if (req.
|
1734
|
-
policyTypes += import_transactions6.PolicyType.
|
1735
|
-
policies.push({ data: req.
|
1655
|
+
if (req.gasPrice) {
|
1656
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1657
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1736
1658
|
}
|
1737
1659
|
if (req.witnessLimit) {
|
1738
1660
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1818,7 +1740,7 @@ var BaseTransactionRequest = class {
|
|
1818
1740
|
* @returns The index of the created witness.
|
1819
1741
|
*/
|
1820
1742
|
addEmptyWitness() {
|
1821
|
-
this.addWitness((0, import_utils9.concat)([
|
1743
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1822
1744
|
return this.witnesses.length - 1;
|
1823
1745
|
}
|
1824
1746
|
/**
|
@@ -1919,10 +1841,10 @@ var BaseTransactionRequest = class {
|
|
1919
1841
|
* @param predicate - Predicate bytes.
|
1920
1842
|
* @param predicateData - Predicate data bytes.
|
1921
1843
|
*/
|
1922
|
-
addCoinInput(coin) {
|
1844
|
+
addCoinInput(coin, predicate) {
|
1923
1845
|
const { assetId, owner, amount } = coin;
|
1924
1846
|
let witnessIndex;
|
1925
|
-
if (
|
1847
|
+
if (predicate) {
|
1926
1848
|
witnessIndex = 0;
|
1927
1849
|
} else {
|
1928
1850
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1937,7 +1859,9 @@ var BaseTransactionRequest = class {
|
|
1937
1859
|
amount,
|
1938
1860
|
assetId,
|
1939
1861
|
txPointer: "0x00000000000000000000000000000000",
|
1940
|
-
witnessIndex
|
1862
|
+
witnessIndex,
|
1863
|
+
predicate: predicate?.bytes,
|
1864
|
+
predicateData: predicate?.predicateDataBytes
|
1941
1865
|
};
|
1942
1866
|
this.pushInput(input);
|
1943
1867
|
this.addChangeOutput(owner, assetId);
|
@@ -1948,13 +1872,11 @@ var BaseTransactionRequest = class {
|
|
1948
1872
|
*
|
1949
1873
|
* @param message - Message resource.
|
1950
1874
|
* @param predicate - Predicate bytes.
|
1951
|
-
* @param predicateData - Predicate data bytes.
|
1952
1875
|
*/
|
1953
|
-
addMessageInput(message) {
|
1876
|
+
addMessageInput(message, predicate) {
|
1954
1877
|
const { recipient, sender, amount } = message;
|
1955
|
-
const assetId = import_configs7.BaseAssetId;
|
1956
1878
|
let witnessIndex;
|
1957
|
-
if (
|
1879
|
+
if (predicate) {
|
1958
1880
|
witnessIndex = 0;
|
1959
1881
|
} else {
|
1960
1882
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1968,10 +1890,12 @@ var BaseTransactionRequest = class {
|
|
1968
1890
|
sender: sender.toB256(),
|
1969
1891
|
recipient: recipient.toB256(),
|
1970
1892
|
amount,
|
1971
|
-
witnessIndex
|
1893
|
+
witnessIndex,
|
1894
|
+
predicate: predicate?.bytes,
|
1895
|
+
predicateData: predicate?.predicateDataBytes
|
1972
1896
|
};
|
1973
1897
|
this.pushInput(input);
|
1974
|
-
this.addChangeOutput(recipient,
|
1898
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1975
1899
|
}
|
1976
1900
|
/**
|
1977
1901
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1999,6 +1923,32 @@ var BaseTransactionRequest = class {
|
|
1999
1923
|
resources.forEach((resource) => this.addResource(resource));
|
2000
1924
|
return this;
|
2001
1925
|
}
|
1926
|
+
/**
|
1927
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1928
|
+
* outputs from the related assetIds.
|
1929
|
+
*
|
1930
|
+
* @param resources - The resources to add.
|
1931
|
+
* @returns This transaction.
|
1932
|
+
*/
|
1933
|
+
addPredicateResource(resource, predicate) {
|
1934
|
+
if (isCoin(resource)) {
|
1935
|
+
this.addCoinInput(resource, predicate);
|
1936
|
+
} else {
|
1937
|
+
this.addMessageInput(resource, predicate);
|
1938
|
+
}
|
1939
|
+
return this;
|
1940
|
+
}
|
1941
|
+
/**
|
1942
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1943
|
+
* from the related assetIds.
|
1944
|
+
*
|
1945
|
+
* @param resources - The resources to add.
|
1946
|
+
* @returns This transaction.
|
1947
|
+
*/
|
1948
|
+
addPredicateResources(resources, predicate) {
|
1949
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1950
|
+
return this;
|
1951
|
+
}
|
2002
1952
|
/**
|
2003
1953
|
* Adds a coin output to the transaction.
|
2004
1954
|
*
|
@@ -2006,12 +1956,12 @@ var BaseTransactionRequest = class {
|
|
2006
1956
|
* @param amount - Amount of coin.
|
2007
1957
|
* @param assetId - Asset ID of coin.
|
2008
1958
|
*/
|
2009
|
-
addCoinOutput(to, amount, assetId
|
1959
|
+
addCoinOutput(to, amount, assetId) {
|
2010
1960
|
this.pushOutput({
|
2011
1961
|
type: import_transactions6.OutputType.Coin,
|
2012
1962
|
to: (0, import_address.addressify)(to).toB256(),
|
2013
1963
|
amount,
|
2014
|
-
assetId
|
1964
|
+
assetId: assetId ?? this.baseAssetId
|
2015
1965
|
});
|
2016
1966
|
return this;
|
2017
1967
|
}
|
@@ -2038,7 +1988,7 @@ var BaseTransactionRequest = class {
|
|
2038
1988
|
* @param to - Address of the owner.
|
2039
1989
|
* @param assetId - Asset ID of coin.
|
2040
1990
|
*/
|
2041
|
-
addChangeOutput(to, assetId
|
1991
|
+
addChangeOutput(to, assetId) {
|
2042
1992
|
const changeOutput = this.getChangeOutputs().find(
|
2043
1993
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2044
1994
|
);
|
@@ -2046,7 +1996,7 @@ var BaseTransactionRequest = class {
|
|
2046
1996
|
this.pushOutput({
|
2047
1997
|
type: import_transactions6.OutputType.Change,
|
2048
1998
|
to: (0, import_address.addressify)(to).toB256(),
|
2049
|
-
assetId
|
1999
|
+
assetId: assetId ?? this.baseAssetId
|
2050
2000
|
});
|
2051
2001
|
}
|
2052
2002
|
}
|
@@ -2078,7 +2028,7 @@ var BaseTransactionRequest = class {
|
|
2078
2028
|
}
|
2079
2029
|
calculateMaxGas(chainInfo, minGas) {
|
2080
2030
|
const { consensusParameters } = chainInfo;
|
2081
|
-
const { gasPerByte
|
2031
|
+
const { gasPerByte } = consensusParameters;
|
2082
2032
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2083
2033
|
(acc, wit) => acc + wit.dataLength,
|
2084
2034
|
0
|
@@ -2087,8 +2037,7 @@ var BaseTransactionRequest = class {
|
|
2087
2037
|
gasPerByte,
|
2088
2038
|
minGas,
|
2089
2039
|
witnessesLength,
|
2090
|
-
witnessLimit: this.witnessLimit
|
2091
|
-
maxGasPerTx
|
2040
|
+
witnessLimit: this.witnessLimit
|
2092
2041
|
});
|
2093
2042
|
}
|
2094
2043
|
/**
|
@@ -2098,6 +2047,12 @@ var BaseTransactionRequest = class {
|
|
2098
2047
|
* @param quantities - CoinQuantity Array.
|
2099
2048
|
*/
|
2100
2049
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2050
|
+
let idCounter = 0;
|
2051
|
+
const generateId = () => {
|
2052
|
+
const counterString = String(idCounter++);
|
2053
|
+
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2054
|
+
return id;
|
2055
|
+
};
|
2101
2056
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2102
2057
|
if ("assetId" in input) {
|
2103
2058
|
return input.assetId === assetId;
|
@@ -2106,27 +2061,24 @@ var BaseTransactionRequest = class {
|
|
2106
2061
|
});
|
2107
2062
|
const updateAssetInput = (assetId, quantity) => {
|
2108
2063
|
const assetInput = findAssetInput(assetId);
|
2109
|
-
let usedQuantity = quantity;
|
2110
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2111
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2112
|
-
}
|
2113
2064
|
if (assetInput && "assetId" in assetInput) {
|
2114
|
-
assetInput.id = (
|
2115
|
-
assetInput.amount =
|
2065
|
+
assetInput.id = generateId();
|
2066
|
+
assetInput.amount = quantity;
|
2116
2067
|
} else {
|
2117
2068
|
this.addResources([
|
2118
2069
|
{
|
2119
|
-
id: (
|
2120
|
-
amount:
|
2070
|
+
id: generateId(),
|
2071
|
+
amount: quantity,
|
2121
2072
|
assetId,
|
2122
2073
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2074
|
+
maturity: 0,
|
2123
2075
|
blockCreated: (0, import_math7.bn)(1),
|
2124
2076
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2125
2077
|
}
|
2126
2078
|
]);
|
2127
2079
|
}
|
2128
2080
|
};
|
2129
|
-
updateAssetInput(
|
2081
|
+
updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
|
2130
2082
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2131
2083
|
}
|
2132
2084
|
/**
|
@@ -2151,7 +2103,7 @@ var BaseTransactionRequest = class {
|
|
2151
2103
|
toJSON() {
|
2152
2104
|
return normalizeJSON(this);
|
2153
2105
|
}
|
2154
|
-
|
2106
|
+
updatePredicateInputs(inputs) {
|
2155
2107
|
this.inputs.forEach((i) => {
|
2156
2108
|
let correspondingInput;
|
2157
2109
|
switch (i.type) {
|
@@ -2173,25 +2125,16 @@ var BaseTransactionRequest = class {
|
|
2173
2125
|
}
|
2174
2126
|
});
|
2175
2127
|
}
|
2176
|
-
shiftPredicateData() {
|
2177
|
-
this.inputs.forEach((input) => {
|
2178
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2179
|
-
input.predicateData = input.paddPredicateData(
|
2180
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2181
|
-
);
|
2182
|
-
}
|
2183
|
-
});
|
2184
|
-
}
|
2185
2128
|
};
|
2186
2129
|
|
2187
2130
|
// src/providers/transaction-request/create-transaction-request.ts
|
2188
|
-
var
|
2131
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2189
2132
|
var import_math9 = require("@fuel-ts/math");
|
2190
2133
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2191
2134
|
var import_utils13 = require("@fuel-ts/utils");
|
2192
2135
|
|
2193
2136
|
// src/providers/transaction-request/hash-transaction.ts
|
2194
|
-
var
|
2137
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2195
2138
|
var import_hasher = require("@fuel-ts/hasher");
|
2196
2139
|
var import_math8 = require("@fuel-ts/math");
|
2197
2140
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2200,7 +2143,7 @@ var import_ramda2 = require("ramda");
|
|
2200
2143
|
function hashTransaction(transactionRequest, chainId) {
|
2201
2144
|
const transaction = transactionRequest.toTransaction();
|
2202
2145
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2203
|
-
transaction.receiptsRoot =
|
2146
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2204
2147
|
}
|
2205
2148
|
transaction.inputs = transaction.inputs.map((input) => {
|
2206
2149
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2222,10 +2165,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2222
2165
|
blockHeight: 0,
|
2223
2166
|
txIndex: 0
|
2224
2167
|
};
|
2225
|
-
inputClone.txID =
|
2168
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2226
2169
|
inputClone.outputIndex = 0;
|
2227
|
-
inputClone.balanceRoot =
|
2228
|
-
inputClone.stateRoot =
|
2170
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2171
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2229
2172
|
return inputClone;
|
2230
2173
|
}
|
2231
2174
|
default:
|
@@ -2236,8 +2179,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2236
2179
|
const outputClone = (0, import_ramda2.clone)(output);
|
2237
2180
|
switch (outputClone.type) {
|
2238
2181
|
case import_transactions7.OutputType.Contract: {
|
2239
|
-
outputClone.balanceRoot =
|
2240
|
-
outputClone.stateRoot =
|
2182
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2183
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2241
2184
|
return outputClone;
|
2242
2185
|
}
|
2243
2186
|
case import_transactions7.OutputType.Change: {
|
@@ -2245,9 +2188,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2245
2188
|
return outputClone;
|
2246
2189
|
}
|
2247
2190
|
case import_transactions7.OutputType.Variable: {
|
2248
|
-
outputClone.to =
|
2191
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2249
2192
|
outputClone.amount = (0, import_math8.bn)(0);
|
2250
|
-
outputClone.assetId =
|
2193
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2251
2194
|
return outputClone;
|
2252
2195
|
}
|
2253
2196
|
default:
|
@@ -2313,7 +2256,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2313
2256
|
} = {}) {
|
2314
2257
|
super(rest);
|
2315
2258
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2316
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2259
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2317
2260
|
this.storageSlots = [...storageSlots ?? []];
|
2318
2261
|
}
|
2319
2262
|
/**
|
@@ -2328,9 +2271,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2328
2271
|
return {
|
2329
2272
|
type: import_transactions8.TransactionType.Create,
|
2330
2273
|
...baseTransaction,
|
2274
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2331
2275
|
bytecodeWitnessIndex,
|
2332
|
-
storageSlotsCount:
|
2333
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2276
|
+
storageSlotsCount: storageSlots.length,
|
2277
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2334
2278
|
storageSlots
|
2335
2279
|
};
|
2336
2280
|
}
|
@@ -2380,7 +2324,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2380
2324
|
// src/providers/transaction-request/script-transaction-request.ts
|
2381
2325
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2382
2326
|
var import_address2 = require("@fuel-ts/address");
|
2383
|
-
var
|
2327
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2384
2328
|
var import_math10 = require("@fuel-ts/math");
|
2385
2329
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2386
2330
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2452,9 +2396,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2452
2396
|
type: import_transactions9.TransactionType.Script,
|
2453
2397
|
scriptGasLimit: this.gasLimit,
|
2454
2398
|
...super.getBaseTransaction(),
|
2455
|
-
scriptLength:
|
2456
|
-
scriptDataLength:
|
2457
|
-
receiptsRoot:
|
2399
|
+
scriptLength: script.length,
|
2400
|
+
scriptDataLength: scriptData.length,
|
2401
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2458
2402
|
script: (0, import_utils15.hexlify)(script),
|
2459
2403
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2460
2404
|
};
|
@@ -2517,7 +2461,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2517
2461
|
}
|
2518
2462
|
calculateMaxGas(chainInfo, minGas) {
|
2519
2463
|
const { consensusParameters } = chainInfo;
|
2520
|
-
const { gasPerByte
|
2464
|
+
const { gasPerByte } = consensusParameters;
|
2521
2465
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2522
2466
|
(acc, wit) => acc + wit.dataLength,
|
2523
2467
|
0
|
@@ -2527,8 +2471,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2527
2471
|
minGas,
|
2528
2472
|
witnessesLength,
|
2529
2473
|
witnessLimit: this.witnessLimit,
|
2530
|
-
gasLimit: this.gasLimit
|
2531
|
-
maxGasPerTx
|
2474
|
+
gasLimit: this.gasLimit
|
2532
2475
|
});
|
2533
2476
|
}
|
2534
2477
|
/**
|
@@ -2603,32 +2546,15 @@ var transactionRequestify = (obj) => {
|
|
2603
2546
|
}
|
2604
2547
|
}
|
2605
2548
|
};
|
2606
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2607
|
-
(acc, input) => {
|
2608
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2609
|
-
acc.utxos.push(input.id);
|
2610
|
-
}
|
2611
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2612
|
-
acc.messages.push(input.nonce);
|
2613
|
-
}
|
2614
|
-
return acc;
|
2615
|
-
},
|
2616
|
-
{
|
2617
|
-
utxos: [],
|
2618
|
-
messages: []
|
2619
|
-
}
|
2620
|
-
);
|
2621
2549
|
|
2622
2550
|
// src/providers/transaction-response/transaction-response.ts
|
2623
2551
|
var import_errors13 = require("@fuel-ts/errors");
|
2624
|
-
var
|
2625
|
-
var
|
2626
|
-
var
|
2552
|
+
var import_math14 = require("@fuel-ts/math");
|
2553
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2554
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2627
2555
|
|
2628
2556
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2629
|
-
var
|
2630
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2631
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2557
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2632
2558
|
|
2633
2559
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2634
2560
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2636,10 +2562,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2636
2562
|
var import_utils16 = require("@fuel-ts/utils");
|
2637
2563
|
var calculateTransactionFee = (params) => {
|
2638
2564
|
const {
|
2639
|
-
|
2565
|
+
gasUsed,
|
2640
2566
|
rawPayload,
|
2641
|
-
|
2642
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2567
|
+
consensusParameters: { gasCosts, feeParams }
|
2643
2568
|
} = params;
|
2644
2569
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2645
2570
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2649,7 +2574,8 @@ var calculateTransactionFee = (params) => {
|
|
2649
2574
|
return {
|
2650
2575
|
fee: (0, import_math11.bn)(0),
|
2651
2576
|
minFee: (0, import_math11.bn)(0),
|
2652
|
-
maxFee: (0, import_math11.bn)(0)
|
2577
|
+
maxFee: (0, import_math11.bn)(0),
|
2578
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2653
2579
|
};
|
2654
2580
|
}
|
2655
2581
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2681,6 +2607,7 @@ var calculateTransactionFee = (params) => {
|
|
2681
2607
|
metadataGas,
|
2682
2608
|
txBytesSize: transactionBytes.length
|
2683
2609
|
});
|
2610
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2684
2611
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2685
2612
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2686
2613
|
const maxGas = getMaxGas({
|
@@ -2688,30 +2615,22 @@ var calculateTransactionFee = (params) => {
|
|
2688
2615
|
minGas,
|
2689
2616
|
witnessesLength,
|
2690
2617
|
gasLimit,
|
2691
|
-
witnessLimit
|
2692
|
-
maxGasPerTx
|
2693
|
-
});
|
2694
|
-
const minFee = calculateGasFee({
|
2695
|
-
gasPrice,
|
2696
|
-
gas: minGas,
|
2697
|
-
priceFactor: gasPriceFactor,
|
2698
|
-
tip
|
2699
|
-
});
|
2700
|
-
const maxFee = calculateGasFee({
|
2701
|
-
gasPrice,
|
2702
|
-
gas: maxGas,
|
2703
|
-
priceFactor: gasPriceFactor,
|
2704
|
-
tip
|
2618
|
+
witnessLimit
|
2705
2619
|
});
|
2620
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2621
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2622
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2623
|
+
const fee = minFee.add(feeFromGasUsed);
|
2706
2624
|
return {
|
2625
|
+
fee,
|
2707
2626
|
minFee,
|
2708
2627
|
maxFee,
|
2709
|
-
|
2628
|
+
feeFromGasUsed
|
2710
2629
|
};
|
2711
2630
|
};
|
2712
2631
|
|
2713
2632
|
// src/providers/transaction-summary/operations.ts
|
2714
|
-
var
|
2633
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2715
2634
|
var import_errors11 = require("@fuel-ts/errors");
|
2716
2635
|
var import_math13 = require("@fuel-ts/math");
|
2717
2636
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3009,7 +2928,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3009
2928
|
const { to: toAddress, assetId, amount } = receipt;
|
3010
2929
|
let { from: fromAddress } = receipt;
|
3011
2930
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3012
|
-
if (
|
2931
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3013
2932
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3014
2933
|
fromAddress = change?.to || fromAddress;
|
3015
2934
|
}
|
@@ -3273,12 +3192,10 @@ function assembleTransactionSummary(params) {
|
|
3273
3192
|
gqlTransactionStatus,
|
3274
3193
|
abiMap = {},
|
3275
3194
|
maxInputs,
|
3276
|
-
gasCosts
|
3277
|
-
maxGasPerTx,
|
3278
|
-
gasPrice
|
3195
|
+
gasCosts
|
3279
3196
|
} = params;
|
3280
3197
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3281
|
-
const rawPayload = (0,
|
3198
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3282
3199
|
const operations = getOperations({
|
3283
3200
|
transactionType: transaction.type,
|
3284
3201
|
inputs: transaction.inputs || [],
|
@@ -3289,14 +3206,11 @@ function assembleTransactionSummary(params) {
|
|
3289
3206
|
maxInputs
|
3290
3207
|
});
|
3291
3208
|
const typeName = getTransactionTypeName(transaction.type);
|
3292
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3293
3209
|
const { fee } = calculateTransactionFee({
|
3294
|
-
|
3210
|
+
gasUsed,
|
3295
3211
|
rawPayload,
|
3296
|
-
tip,
|
3297
3212
|
consensusParameters: {
|
3298
3213
|
gasCosts,
|
3299
|
-
maxGasPerTx,
|
3300
3214
|
feeParams: {
|
3301
3215
|
gasPerByte,
|
3302
3216
|
gasPriceFactor
|
@@ -3308,7 +3222,7 @@ function assembleTransactionSummary(params) {
|
|
3308
3222
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3309
3223
|
let date;
|
3310
3224
|
if (time) {
|
3311
|
-
date =
|
3225
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3312
3226
|
}
|
3313
3227
|
const transactionSummary = {
|
3314
3228
|
id,
|
@@ -3336,12 +3250,12 @@ function assembleTransactionSummary(params) {
|
|
3336
3250
|
|
3337
3251
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3338
3252
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3339
|
-
var
|
3253
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3340
3254
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3341
3255
|
return receipts.reduce((logs, receipt) => {
|
3342
|
-
if (receipt.type ===
|
3256
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3343
3257
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3344
|
-
const data = receipt.type ===
|
3258
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3345
3259
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3346
3260
|
logs.push(decodedLog);
|
3347
3261
|
}
|
@@ -3356,7 +3270,7 @@ var TransactionResponse = class {
|
|
3356
3270
|
/** Current provider */
|
3357
3271
|
provider;
|
3358
3272
|
/** Gas used on the transaction */
|
3359
|
-
gasUsed = (0,
|
3273
|
+
gasUsed = (0, import_math14.bn)(0);
|
3360
3274
|
/** The graphql Transaction with receipts object. */
|
3361
3275
|
gqlTransaction;
|
3362
3276
|
abis;
|
@@ -3414,8 +3328,8 @@ var TransactionResponse = class {
|
|
3414
3328
|
* @returns The decoded transaction.
|
3415
3329
|
*/
|
3416
3330
|
decodeTransaction(transactionWithReceipts) {
|
3417
|
-
return new
|
3418
|
-
(0,
|
3331
|
+
return new import_transactions17.TransactionCoder().decode(
|
3332
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3419
3333
|
0
|
3420
3334
|
)?.[0];
|
3421
3335
|
}
|
@@ -3434,27 +3348,20 @@ var TransactionResponse = class {
|
|
3434
3348
|
const decodedTransaction = this.decodeTransaction(
|
3435
3349
|
transaction
|
3436
3350
|
);
|
3437
|
-
|
3438
|
-
|
3439
|
-
txReceipts = transaction.status.receipts;
|
3440
|
-
}
|
3441
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3442
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3443
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3351
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3352
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3444
3353
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3445
3354
|
const transactionSummary = assembleTransactionSummary({
|
3446
3355
|
id: this.id,
|
3447
3356
|
receipts,
|
3448
3357
|
transaction: decodedTransaction,
|
3449
|
-
transactionBytes: (0,
|
3358
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3450
3359
|
gqlTransactionStatus: transaction.status,
|
3451
3360
|
gasPerByte,
|
3452
3361
|
gasPriceFactor,
|
3453
3362
|
abiMap: contractsAbiMap,
|
3454
3363
|
maxInputs,
|
3455
|
-
gasCosts
|
3456
|
-
maxGasPerTx,
|
3457
|
-
gasPrice
|
3364
|
+
gasCosts
|
3458
3365
|
});
|
3459
3366
|
return transactionSummary;
|
3460
3367
|
}
|
@@ -3581,29 +3488,30 @@ var processGqlChain = (chain) => {
|
|
3581
3488
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3582
3489
|
return {
|
3583
3490
|
name,
|
3584
|
-
baseChainHeight: (0,
|
3491
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3585
3492
|
consensusParameters: {
|
3586
|
-
contractMaxSize: (0,
|
3587
|
-
maxInputs: (0,
|
3588
|
-
maxOutputs: (0,
|
3589
|
-
maxWitnesses: (0,
|
3590
|
-
maxGasPerTx: (0,
|
3591
|
-
maxScriptLength: (0,
|
3592
|
-
maxScriptDataLength: (0,
|
3593
|
-
maxStorageSlots: (0,
|
3594
|
-
maxPredicateLength: (0,
|
3595
|
-
maxPredicateDataLength: (0,
|
3596
|
-
maxGasPerPredicate: (0,
|
3597
|
-
gasPriceFactor: (0,
|
3598
|
-
gasPerByte: (0,
|
3599
|
-
maxMessageDataLength: (0,
|
3600
|
-
chainId: (0,
|
3493
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3494
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3495
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3496
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3497
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3498
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3499
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3500
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3501
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3502
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3503
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3504
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3505
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3506
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3507
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3508
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3601
3509
|
gasCosts
|
3602
3510
|
},
|
3603
3511
|
gasCosts,
|
3604
3512
|
latestBlock: {
|
3605
3513
|
id: latestBlock.id,
|
3606
|
-
height: (0,
|
3514
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3607
3515
|
time: latestBlock.header.time,
|
3608
3516
|
transactions: latestBlock.transactions.map((i) => ({
|
3609
3517
|
id: i.id
|
@@ -3697,8 +3605,10 @@ var _Provider = class {
|
|
3697
3605
|
* Returns some helpful parameters related to gas fees.
|
3698
3606
|
*/
|
3699
3607
|
getGasConfig() {
|
3608
|
+
const { minGasPrice } = this.getNode();
|
3700
3609
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3701
3610
|
return {
|
3611
|
+
minGasPrice,
|
3702
3612
|
maxGasPerTx,
|
3703
3613
|
maxGasPerPredicate,
|
3704
3614
|
gasPriceFactor,
|
@@ -3786,7 +3696,7 @@ var _Provider = class {
|
|
3786
3696
|
name,
|
3787
3697
|
consensusParameters: { chainId }
|
3788
3698
|
} = await this.getChain();
|
3789
|
-
const network = new
|
3699
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
3790
3700
|
return Promise.resolve(network);
|
3791
3701
|
}
|
3792
3702
|
/**
|
@@ -3796,7 +3706,7 @@ var _Provider = class {
|
|
3796
3706
|
*/
|
3797
3707
|
async getBlockNumber() {
|
3798
3708
|
const { chain } = await this.operations.getChain();
|
3799
|
-
return (0,
|
3709
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3800
3710
|
}
|
3801
3711
|
/**
|
3802
3712
|
* Returns the chain information.
|
@@ -3806,11 +3716,13 @@ var _Provider = class {
|
|
3806
3716
|
async fetchNode() {
|
3807
3717
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3808
3718
|
const processedNodeInfo = {
|
3809
|
-
maxDepth: (0,
|
3810
|
-
maxTx: (0,
|
3719
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3720
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3721
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3811
3722
|
nodeVersion: nodeInfo.nodeVersion,
|
3812
3723
|
utxoValidation: nodeInfo.utxoValidation,
|
3813
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3724
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3725
|
+
peers: nodeInfo.peers
|
3814
3726
|
};
|
3815
3727
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3816
3728
|
return processedNodeInfo;
|
@@ -3836,6 +3748,17 @@ var _Provider = class {
|
|
3836
3748
|
} = this.getChain();
|
3837
3749
|
return chainId.toNumber();
|
3838
3750
|
}
|
3751
|
+
/**
|
3752
|
+
* Returns the base asset ID
|
3753
|
+
*
|
3754
|
+
* @returns A promise that resolves to the base asset ID
|
3755
|
+
*/
|
3756
|
+
getBaseAssetId() {
|
3757
|
+
const {
|
3758
|
+
consensusParameters: { baseAssetId }
|
3759
|
+
} = this.getChain();
|
3760
|
+
return baseAssetId;
|
3761
|
+
}
|
3839
3762
|
/**
|
3840
3763
|
* Submits a transaction to the chain to be executed.
|
3841
3764
|
*
|
@@ -3852,9 +3775,9 @@ var _Provider = class {
|
|
3852
3775
|
if (estimateTxDependencies) {
|
3853
3776
|
await this.estimateTxDependencies(transactionRequest);
|
3854
3777
|
}
|
3855
|
-
const encodedTransaction = (0,
|
3778
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3856
3779
|
let abis;
|
3857
|
-
if (transactionRequest.type ===
|
3780
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3858
3781
|
abis = transactionRequest.abis;
|
3859
3782
|
}
|
3860
3783
|
if (awaitExecution) {
|
@@ -3895,14 +3818,15 @@ var _Provider = class {
|
|
3895
3818
|
if (estimateTxDependencies) {
|
3896
3819
|
return this.estimateTxDependencies(transactionRequest);
|
3897
3820
|
}
|
3898
|
-
const encodedTransaction = (0,
|
3899
|
-
const { dryRun:
|
3900
|
-
|
3821
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3822
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3823
|
+
encodedTransaction,
|
3901
3824
|
utxoValidation: utxoValidation || false
|
3902
3825
|
});
|
3903
|
-
const
|
3904
|
-
|
3905
|
-
|
3826
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3827
|
+
return {
|
3828
|
+
receipts
|
3829
|
+
};
|
3906
3830
|
}
|
3907
3831
|
/**
|
3908
3832
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3913,13 +3837,13 @@ var _Provider = class {
|
|
3913
3837
|
async estimatePredicates(transactionRequest) {
|
3914
3838
|
const shouldEstimatePredicates = Boolean(
|
3915
3839
|
transactionRequest.inputs.find(
|
3916
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3840
|
+
(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()
|
3917
3841
|
)
|
3918
3842
|
);
|
3919
3843
|
if (!shouldEstimatePredicates) {
|
3920
3844
|
return transactionRequest;
|
3921
3845
|
}
|
3922
|
-
const encodedTransaction = (0,
|
3846
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3923
3847
|
const response = await this.operations.estimatePredicates({
|
3924
3848
|
encodedTransaction
|
3925
3849
|
});
|
@@ -3928,7 +3852,7 @@ var _Provider = class {
|
|
3928
3852
|
} = response;
|
3929
3853
|
if (inputs) {
|
3930
3854
|
inputs.forEach((input, index) => {
|
3931
|
-
if ("predicateGasUsed" in input && (0,
|
3855
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3932
3856
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3933
3857
|
}
|
3934
3858
|
});
|
@@ -3941,31 +3865,31 @@ var _Provider = class {
|
|
3941
3865
|
* If there are missing variable outputs,
|
3942
3866
|
* `addVariableOutputs` is called on the transaction.
|
3943
3867
|
*
|
3868
|
+
* @privateRemarks
|
3869
|
+
* TODO: Investigate support for missing contract IDs
|
3870
|
+
* TODO: Add support for missing output messages
|
3944
3871
|
*
|
3945
3872
|
* @param transactionRequest - The transaction request object.
|
3946
3873
|
* @returns A promise.
|
3947
3874
|
*/
|
3948
3875
|
async estimateTxDependencies(transactionRequest) {
|
3949
|
-
if (transactionRequest.type ===
|
3876
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3950
3877
|
return {
|
3951
3878
|
receipts: [],
|
3952
3879
|
outputVariables: 0,
|
3953
3880
|
missingContractIds: []
|
3954
3881
|
};
|
3955
3882
|
}
|
3883
|
+
await this.estimatePredicates(transactionRequest);
|
3956
3884
|
let receipts = [];
|
3957
3885
|
const missingContractIds = [];
|
3958
3886
|
let outputVariables = 0;
|
3959
|
-
let dryrunStatus;
|
3960
3887
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3961
|
-
const {
|
3962
|
-
|
3963
|
-
} = await this.operations.dryRun({
|
3964
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3888
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3889
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3965
3890
|
utxoValidation: false
|
3966
3891
|
});
|
3967
|
-
receipts =
|
3968
|
-
dryrunStatus = status;
|
3892
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3969
3893
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3970
3894
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3971
3895
|
if (hasMissingOutputs) {
|
@@ -3975,11 +3899,6 @@ var _Provider = class {
|
|
3975
3899
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3976
3900
|
missingContractIds.push(contractId);
|
3977
3901
|
});
|
3978
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3979
|
-
transactionRequest,
|
3980
|
-
optimizeGas: false
|
3981
|
-
});
|
3982
|
-
transactionRequest.maxFee = maxFee;
|
3983
3902
|
} else {
|
3984
3903
|
break;
|
3985
3904
|
}
|
@@ -3987,133 +3906,7 @@ var _Provider = class {
|
|
3987
3906
|
return {
|
3988
3907
|
receipts,
|
3989
3908
|
outputVariables,
|
3990
|
-
missingContractIds
|
3991
|
-
dryrunStatus
|
3992
|
-
};
|
3993
|
-
}
|
3994
|
-
/**
|
3995
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3996
|
-
*
|
3997
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3998
|
-
* further modifications are identified. The method iteratively updates these transactions
|
3999
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4000
|
-
*
|
4001
|
-
* @param transactionRequests - Array of transaction request objects.
|
4002
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4003
|
-
*/
|
4004
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4005
|
-
const results = transactionRequests.map(() => ({
|
4006
|
-
receipts: [],
|
4007
|
-
outputVariables: 0,
|
4008
|
-
missingContractIds: [],
|
4009
|
-
dryrunStatus: void 0
|
4010
|
-
}));
|
4011
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4012
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4013
|
-
allRequests.forEach((req, index) => {
|
4014
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4015
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4016
|
-
}
|
4017
|
-
});
|
4018
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4019
|
-
let attempt = 0;
|
4020
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4021
|
-
const encodedTransactions = transactionsToProcess.map(
|
4022
|
-
(index) => serializedTransactionsMap.get(index)
|
4023
|
-
);
|
4024
|
-
const dryRunResults = await this.operations.dryRun({
|
4025
|
-
encodedTransactions,
|
4026
|
-
utxoValidation: false
|
4027
|
-
});
|
4028
|
-
const nextRoundTransactions = [];
|
4029
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4030
|
-
const currentResultIndex = transactionsToProcess[i];
|
4031
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4032
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4033
|
-
results[currentResultIndex].dryrunStatus = status;
|
4034
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4035
|
-
results[currentResultIndex].receipts
|
4036
|
-
);
|
4037
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4038
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4039
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4040
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4041
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4042
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4043
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4044
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4045
|
-
});
|
4046
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4047
|
-
transactionRequest: requestToProcess,
|
4048
|
-
optimizeGas: false
|
4049
|
-
});
|
4050
|
-
requestToProcess.maxFee = maxFee;
|
4051
|
-
serializedTransactionsMap.set(
|
4052
|
-
currentResultIndex,
|
4053
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4054
|
-
);
|
4055
|
-
nextRoundTransactions.push(currentResultIndex);
|
4056
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4057
|
-
}
|
4058
|
-
}
|
4059
|
-
transactionsToProcess = nextRoundTransactions;
|
4060
|
-
attempt += 1;
|
4061
|
-
}
|
4062
|
-
return results;
|
4063
|
-
}
|
4064
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4065
|
-
if (estimateTxDependencies) {
|
4066
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4067
|
-
}
|
4068
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4069
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4070
|
-
encodedTransactions,
|
4071
|
-
utxoValidation: utxoValidation || false
|
4072
|
-
});
|
4073
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4074
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4075
|
-
return { receipts, dryrunStatus: status };
|
4076
|
-
});
|
4077
|
-
return results;
|
4078
|
-
}
|
4079
|
-
async estimateTxGasAndFee(params) {
|
4080
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4081
|
-
let { gasPrice } = params;
|
4082
|
-
const chainInfo = this.getChain();
|
4083
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4084
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4085
|
-
if (!gasPrice) {
|
4086
|
-
gasPrice = await this.estimateGasPrice(10);
|
4087
|
-
}
|
4088
|
-
const minFee = calculateGasFee({
|
4089
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4090
|
-
gas: minGas,
|
4091
|
-
priceFactor: gasPriceFactor,
|
4092
|
-
tip: transactionRequest.tip
|
4093
|
-
}).add(1);
|
4094
|
-
let gasLimit = (0, import_math16.bn)(0);
|
4095
|
-
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4096
|
-
gasLimit = transactionRequest.gasLimit;
|
4097
|
-
if (!optimizeGas) {
|
4098
|
-
transactionRequest.gasLimit = minGas;
|
4099
|
-
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4100
|
-
transactionRequest.gasLimit = gasLimit;
|
4101
|
-
}
|
4102
|
-
}
|
4103
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4104
|
-
const maxFee = calculateGasFee({
|
4105
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4106
|
-
gas: maxGas,
|
4107
|
-
priceFactor: gasPriceFactor,
|
4108
|
-
tip: transactionRequest.tip
|
4109
|
-
}).add(1);
|
4110
|
-
return {
|
4111
|
-
minGas,
|
4112
|
-
minFee,
|
4113
|
-
maxGas,
|
4114
|
-
maxFee,
|
4115
|
-
gasPrice,
|
4116
|
-
gasLimit
|
3909
|
+
missingContractIds
|
4117
3910
|
};
|
4118
3911
|
}
|
4119
3912
|
/**
|
@@ -4131,17 +3924,15 @@ var _Provider = class {
|
|
4131
3924
|
if (estimateTxDependencies) {
|
4132
3925
|
return this.estimateTxDependencies(transactionRequest);
|
4133
3926
|
}
|
4134
|
-
const
|
4135
|
-
const { dryRun:
|
4136
|
-
|
3927
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3928
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3929
|
+
encodedTransaction,
|
4137
3930
|
utxoValidation: true
|
4138
3931
|
});
|
4139
|
-
const
|
4140
|
-
|
4141
|
-
|
4142
|
-
|
4143
|
-
});
|
4144
|
-
return { receipts: callResult[0].receipts };
|
3932
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3933
|
+
return {
|
3934
|
+
receipts
|
3935
|
+
};
|
4145
3936
|
}
|
4146
3937
|
/**
|
4147
3938
|
* Returns a transaction cost to enable user
|
@@ -4158,80 +3949,80 @@ var _Provider = class {
|
|
4158
3949
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4159
3950
|
* @returns A promise that resolves to the transaction cost object.
|
4160
3951
|
*/
|
4161
|
-
async getTransactionCost(transactionRequestLike,
|
3952
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3953
|
+
estimateTxDependencies = true,
|
3954
|
+
estimatePredicates = true,
|
3955
|
+
resourcesOwner,
|
3956
|
+
signatureCallback
|
3957
|
+
} = {}) {
|
4162
3958
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4163
|
-
const
|
3959
|
+
const chainInfo = this.getChain();
|
3960
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3961
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3962
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4164
3963
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4165
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3964
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4166
3965
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
|
3966
|
+
if (estimatePredicates) {
|
3967
|
+
if (isScriptTransaction) {
|
3968
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3969
|
+
}
|
3970
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3971
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3972
|
+
}
|
3973
|
+
await this.estimatePredicates(txRequestClone);
|
4173
3974
|
}
|
4174
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4175
|
-
let addedSignatures = 0;
|
4176
3975
|
if (signatureCallback && isScriptTransaction) {
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
await this.estimatePredicates(signedRequest);
|
4182
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4183
|
-
transactionRequest: signedRequest,
|
4184
|
-
optimizeGas: false
|
4185
|
-
});
|
4186
|
-
txRequestClone.maxFee = maxFee;
|
3976
|
+
await signatureCallback(txRequestClone);
|
3977
|
+
}
|
3978
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3979
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4187
3980
|
let receipts = [];
|
4188
3981
|
let missingContractIds = [];
|
4189
3982
|
let outputVariables = 0;
|
4190
|
-
|
4191
|
-
|
4192
|
-
|
4193
|
-
if (signatureCallback) {
|
4194
|
-
await signatureCallback(txRequestClone);
|
4195
|
-
}
|
4196
|
-
txRequestClone.gasLimit = gasLimit;
|
3983
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3984
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3985
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4197
3986
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4198
3987
|
receipts = result.receipts;
|
4199
3988
|
outputVariables = result.outputVariables;
|
4200
3989
|
missingContractIds = result.missingContractIds;
|
4201
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4202
|
-
txRequestClone.gasLimit = gasUsed;
|
4203
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4204
|
-
transactionRequest: txRequestClone,
|
4205
|
-
gasPrice
|
4206
|
-
}));
|
4207
3990
|
}
|
3991
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3992
|
+
const usedFee = calculatePriceWithFactor(
|
3993
|
+
gasUsed,
|
3994
|
+
gasPrice,
|
3995
|
+
gasPriceFactor
|
3996
|
+
).normalizeZeroToOne();
|
3997
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3998
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4208
3999
|
return {
|
4209
4000
|
requiredQuantities: allQuantities,
|
4210
4001
|
receipts,
|
4211
4002
|
gasUsed,
|
4003
|
+
minGasPrice,
|
4212
4004
|
gasPrice,
|
4213
4005
|
minGas,
|
4214
4006
|
maxGas,
|
4007
|
+
usedFee,
|
4215
4008
|
minFee,
|
4216
4009
|
maxFee,
|
4010
|
+
estimatedInputs: txRequestClone.inputs,
|
4217
4011
|
outputVariables,
|
4218
|
-
missingContractIds
|
4219
|
-
addedSignatures,
|
4220
|
-
estimatedPredicates: txRequestClone.inputs
|
4012
|
+
missingContractIds
|
4221
4013
|
};
|
4222
4014
|
}
|
4223
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4015
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4224
4016
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4225
4017
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4226
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4227
|
-
quantitiesToContract
|
4228
|
-
});
|
4018
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4229
4019
|
transactionRequest.addResources(
|
4230
4020
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4231
4021
|
);
|
4232
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4233
|
-
|
4234
|
-
|
4022
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4023
|
+
transactionRequest,
|
4024
|
+
forwardingQuantities
|
4025
|
+
);
|
4235
4026
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4236
4027
|
return {
|
4237
4028
|
resources,
|
@@ -4247,16 +4038,17 @@ var _Provider = class {
|
|
4247
4038
|
const result = await this.operations.getCoins({
|
4248
4039
|
first: 10,
|
4249
4040
|
...paginationArgs,
|
4250
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4041
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4251
4042
|
});
|
4252
4043
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4253
4044
|
return coins.map((coin) => ({
|
4254
4045
|
id: coin.utxoId,
|
4255
4046
|
assetId: coin.assetId,
|
4256
|
-
amount: (0,
|
4047
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4257
4048
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4258
|
-
|
4259
|
-
|
4049
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4050
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4051
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4260
4052
|
}));
|
4261
4053
|
}
|
4262
4054
|
/**
|
@@ -4270,19 +4062,19 @@ var _Provider = class {
|
|
4270
4062
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4271
4063
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4272
4064
|
const excludeInput = {
|
4273
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4274
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4065
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4066
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4275
4067
|
};
|
4276
4068
|
if (this.cache) {
|
4277
4069
|
const uniqueUtxos = new Set(
|
4278
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4070
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4279
4071
|
);
|
4280
4072
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4281
4073
|
}
|
4282
4074
|
const coinsQuery = {
|
4283
4075
|
owner: ownerAddress.toB256(),
|
4284
4076
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4285
|
-
assetId: (0,
|
4077
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4286
4078
|
amount: amount.toString(10),
|
4287
4079
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4288
4080
|
})),
|
@@ -4293,9 +4085,9 @@ var _Provider = class {
|
|
4293
4085
|
switch (coin.__typename) {
|
4294
4086
|
case "MessageCoin":
|
4295
4087
|
return {
|
4296
|
-
amount: (0,
|
4088
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4297
4089
|
assetId: coin.assetId,
|
4298
|
-
daHeight: (0,
|
4090
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4299
4091
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4300
4092
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4301
4093
|
nonce: coin.nonce
|
@@ -4303,11 +4095,12 @@ var _Provider = class {
|
|
4303
4095
|
case "Coin":
|
4304
4096
|
return {
|
4305
4097
|
id: coin.utxoId,
|
4306
|
-
amount: (0,
|
4098
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4307
4099
|
assetId: coin.assetId,
|
4308
4100
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4309
|
-
|
4310
|
-
|
4101
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4102
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4103
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4311
4104
|
};
|
4312
4105
|
default:
|
4313
4106
|
return null;
|
@@ -4324,13 +4117,13 @@ var _Provider = class {
|
|
4324
4117
|
async getBlock(idOrHeight) {
|
4325
4118
|
let variables;
|
4326
4119
|
if (typeof idOrHeight === "number") {
|
4327
|
-
variables = { height: (0,
|
4120
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4328
4121
|
} else if (idOrHeight === "latest") {
|
4329
4122
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4330
4123
|
} else if (idOrHeight.length === 66) {
|
4331
4124
|
variables = { blockId: idOrHeight };
|
4332
4125
|
} else {
|
4333
|
-
variables = { blockId: (0,
|
4126
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4334
4127
|
}
|
4335
4128
|
const { block } = await this.operations.getBlock(variables);
|
4336
4129
|
if (!block) {
|
@@ -4338,7 +4131,7 @@ var _Provider = class {
|
|
4338
4131
|
}
|
4339
4132
|
return {
|
4340
4133
|
id: block.id,
|
4341
|
-
height: (0,
|
4134
|
+
height: (0, import_math15.bn)(block.header.height),
|
4342
4135
|
time: block.header.time,
|
4343
4136
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4344
4137
|
};
|
@@ -4353,7 +4146,7 @@ var _Provider = class {
|
|
4353
4146
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4354
4147
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4355
4148
|
id: block.id,
|
4356
|
-
height: (0,
|
4149
|
+
height: (0, import_math15.bn)(block.header.height),
|
4357
4150
|
time: block.header.time,
|
4358
4151
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4359
4152
|
}));
|
@@ -4368,7 +4161,7 @@ var _Provider = class {
|
|
4368
4161
|
async getBlockWithTransactions(idOrHeight) {
|
4369
4162
|
let variables;
|
4370
4163
|
if (typeof idOrHeight === "number") {
|
4371
|
-
variables = { blockHeight: (0,
|
4164
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4372
4165
|
} else if (idOrHeight === "latest") {
|
4373
4166
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4374
4167
|
} else {
|
@@ -4380,11 +4173,11 @@ var _Provider = class {
|
|
4380
4173
|
}
|
4381
4174
|
return {
|
4382
4175
|
id: block.id,
|
4383
|
-
height: (0,
|
4176
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4384
4177
|
time: block.header.time,
|
4385
4178
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4386
4179
|
transactions: block.transactions.map(
|
4387
|
-
(tx) => new
|
4180
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4388
4181
|
)
|
4389
4182
|
};
|
4390
4183
|
}
|
@@ -4399,8 +4192,8 @@ var _Provider = class {
|
|
4399
4192
|
if (!transaction) {
|
4400
4193
|
return null;
|
4401
4194
|
}
|
4402
|
-
return new
|
4403
|
-
(0,
|
4195
|
+
return new import_transactions18.TransactionCoder().decode(
|
4196
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4404
4197
|
0
|
4405
4198
|
)?.[0];
|
4406
4199
|
}
|
@@ -4427,9 +4220,9 @@ var _Provider = class {
|
|
4427
4220
|
async getContractBalance(contractId, assetId) {
|
4428
4221
|
const { contractBalance } = await this.operations.getContractBalance({
|
4429
4222
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4430
|
-
asset: (0,
|
4223
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4431
4224
|
});
|
4432
|
-
return (0,
|
4225
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4433
4226
|
}
|
4434
4227
|
/**
|
4435
4228
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4441,9 +4234,9 @@ var _Provider = class {
|
|
4441
4234
|
async getBalance(owner, assetId) {
|
4442
4235
|
const { balance } = await this.operations.getBalance({
|
4443
4236
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4444
|
-
assetId: (0,
|
4237
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4445
4238
|
});
|
4446
|
-
return (0,
|
4239
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4447
4240
|
}
|
4448
4241
|
/**
|
4449
4242
|
* Returns balances for the given owner.
|
@@ -4461,7 +4254,7 @@ var _Provider = class {
|
|
4461
4254
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4462
4255
|
return balances.map((balance) => ({
|
4463
4256
|
assetId: balance.assetId,
|
4464
|
-
amount: (0,
|
4257
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4465
4258
|
}));
|
4466
4259
|
}
|
4467
4260
|
/**
|
@@ -4479,19 +4272,19 @@ var _Provider = class {
|
|
4479
4272
|
});
|
4480
4273
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4481
4274
|
return messages.map((message) => ({
|
4482
|
-
messageId:
|
4275
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4483
4276
|
sender: message.sender,
|
4484
4277
|
recipient: message.recipient,
|
4485
4278
|
nonce: message.nonce,
|
4486
|
-
amount: (0,
|
4279
|
+
amount: (0, import_math15.bn)(message.amount),
|
4487
4280
|
data: message.data
|
4488
4281
|
}),
|
4489
4282
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4490
4283
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4491
4284
|
nonce: message.nonce,
|
4492
|
-
amount: (0,
|
4493
|
-
data:
|
4494
|
-
daHeight: (0,
|
4285
|
+
amount: (0, import_math15.bn)(message.amount),
|
4286
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4287
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4495
4288
|
}));
|
4496
4289
|
}
|
4497
4290
|
/**
|
@@ -4544,52 +4337,44 @@ var _Provider = class {
|
|
4544
4337
|
} = result.messageProof;
|
4545
4338
|
return {
|
4546
4339
|
messageProof: {
|
4547
|
-
proofIndex: (0,
|
4340
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4548
4341
|
proofSet: messageProof.proofSet
|
4549
4342
|
},
|
4550
4343
|
blockProof: {
|
4551
|
-
proofIndex: (0,
|
4344
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4552
4345
|
proofSet: blockProof.proofSet
|
4553
4346
|
},
|
4554
4347
|
messageBlockHeader: {
|
4555
4348
|
id: messageBlockHeader.id,
|
4556
|
-
daHeight: (0,
|
4557
|
-
transactionsCount: (0,
|
4349
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4350
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4558
4351
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4559
|
-
height: (0,
|
4352
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4560
4353
|
prevRoot: messageBlockHeader.prevRoot,
|
4561
4354
|
time: messageBlockHeader.time,
|
4562
4355
|
applicationHash: messageBlockHeader.applicationHash,
|
4563
|
-
|
4356
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4357
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4564
4358
|
},
|
4565
4359
|
commitBlockHeader: {
|
4566
4360
|
id: commitBlockHeader.id,
|
4567
|
-
daHeight: (0,
|
4568
|
-
transactionsCount: (0,
|
4361
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4362
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4569
4363
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4570
|
-
height: (0,
|
4364
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4571
4365
|
prevRoot: commitBlockHeader.prevRoot,
|
4572
4366
|
time: commitBlockHeader.time,
|
4573
4367
|
applicationHash: commitBlockHeader.applicationHash,
|
4574
|
-
|
4368
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4369
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4575
4370
|
},
|
4576
4371
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4577
4372
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4578
4373
|
nonce,
|
4579
|
-
amount: (0,
|
4374
|
+
amount: (0, import_math15.bn)(amount),
|
4580
4375
|
data
|
4581
4376
|
};
|
4582
4377
|
}
|
4583
|
-
async getLatestGasPrice() {
|
4584
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4585
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4586
|
-
}
|
4587
|
-
async estimateGasPrice(blockHorizon) {
|
4588
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4589
|
-
blockHorizon: String(blockHorizon)
|
4590
|
-
});
|
4591
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4592
|
-
}
|
4593
4378
|
/**
|
4594
4379
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4595
4380
|
*
|
@@ -4609,10 +4394,10 @@ var _Provider = class {
|
|
4609
4394
|
*/
|
4610
4395
|
async produceBlocks(amount, startTime) {
|
4611
4396
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4612
|
-
blocksToProduce: (0,
|
4613
|
-
startTimestamp: startTime ?
|
4397
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4398
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4614
4399
|
});
|
4615
|
-
return (0,
|
4400
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4616
4401
|
}
|
4617
4402
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4618
4403
|
async getTransactionResponse(transactionId) {
|
@@ -4626,7 +4411,7 @@ cacheInputs_fn = function(inputs) {
|
|
4626
4411
|
return;
|
4627
4412
|
}
|
4628
4413
|
inputs.forEach((input) => {
|
4629
|
-
if (input.type ===
|
4414
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4630
4415
|
this.cache?.set(input.id);
|
4631
4416
|
}
|
4632
4417
|
});
|
@@ -4636,9 +4421,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4636
4421
|
|
4637
4422
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4638
4423
|
var import_errors15 = require("@fuel-ts/errors");
|
4639
|
-
var
|
4640
|
-
var
|
4641
|
-
var
|
4424
|
+
var import_math16 = require("@fuel-ts/math");
|
4425
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4426
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4642
4427
|
|
4643
4428
|
// src/providers/chains.ts
|
4644
4429
|
var CHAIN_IDS = {
|
@@ -4687,17 +4472,17 @@ var assets = [
|
|
4687
4472
|
|
4688
4473
|
// src/utils/formatTransferToContractScriptData.ts
|
4689
4474
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4690
|
-
var
|
4691
|
-
var
|
4475
|
+
var import_math17 = require("@fuel-ts/math");
|
4476
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4692
4477
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4693
4478
|
var formatTransferToContractScriptData = (params) => {
|
4694
4479
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4695
4480
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4696
|
-
const encoded = numberCoder.encode(new
|
4481
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4697
4482
|
const scriptData = Uint8Array.from([
|
4698
|
-
...(0,
|
4483
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4699
4484
|
...encoded,
|
4700
|
-
...(0,
|
4485
|
+
...(0, import_utils27.arrayify)(assetId)
|
4701
4486
|
]);
|
4702
4487
|
return scriptData;
|
4703
4488
|
};
|
@@ -4844,8 +4629,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4844
4629
|
* @param assetId - The asset ID to check the balance for.
|
4845
4630
|
* @returns A promise that resolves to the balance amount.
|
4846
4631
|
*/
|
4847
|
-
async getBalance(assetId
|
4848
|
-
const
|
4632
|
+
async getBalance(assetId) {
|
4633
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4634
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4849
4635
|
return amount;
|
4850
4636
|
}
|
4851
4637
|
/**
|
@@ -4882,33 +4668,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4882
4668
|
* @param fee - The estimated transaction fee.
|
4883
4669
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4884
4670
|
*/
|
4885
|
-
async fund(request,
|
4886
|
-
const
|
4887
|
-
const
|
4888
|
-
|
4889
|
-
|
4890
|
-
|
4891
|
-
coinQuantities: requiredQuantities
|
4671
|
+
async fund(request, coinQuantities, fee) {
|
4672
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4673
|
+
const updatedQuantities = addAmountToAsset({
|
4674
|
+
amount: (0, import_math18.bn)(fee),
|
4675
|
+
assetId: baseAssetId,
|
4676
|
+
coinQuantities
|
4892
4677
|
});
|
4893
4678
|
const quantitiesDict = {};
|
4894
|
-
|
4679
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4895
4680
|
quantitiesDict[assetId] = {
|
4896
4681
|
required: amount,
|
4897
|
-
owned: (0,
|
4682
|
+
owned: (0, import_math18.bn)(0)
|
4898
4683
|
};
|
4899
4684
|
});
|
4900
|
-
|
4685
|
+
const cachedUtxos = [];
|
4686
|
+
const cachedMessages = [];
|
4687
|
+
const owner = this.address.toB256();
|
4688
|
+
request.inputs.forEach((input) => {
|
4901
4689
|
const isResource = "amount" in input;
|
4902
4690
|
if (isResource) {
|
4903
4691
|
const isCoin2 = "owner" in input;
|
4904
4692
|
if (isCoin2) {
|
4905
4693
|
const assetId = String(input.assetId);
|
4906
|
-
if (quantitiesDict[assetId]) {
|
4907
|
-
const amount = (0,
|
4694
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4695
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4908
4696
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4697
|
+
cachedUtxos.push(input.id);
|
4909
4698
|
}
|
4910
|
-
} else if (input.amount && quantitiesDict[
|
4911
|
-
quantitiesDict[
|
4699
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4700
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4701
|
+
cachedMessages.push(input.nonce);
|
4912
4702
|
}
|
4913
4703
|
}
|
4914
4704
|
});
|
@@ -4923,23 +4713,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4923
4713
|
});
|
4924
4714
|
const needsToBeFunded = missingQuantities.length;
|
4925
4715
|
if (needsToBeFunded) {
|
4926
|
-
const
|
4927
|
-
|
4928
|
-
|
4929
|
-
|
4930
|
-
|
4931
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4932
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4933
|
-
if (addedSignatures) {
|
4934
|
-
Array.from({ length: addedSignatures }).forEach(
|
4935
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4936
|
-
);
|
4716
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4717
|
+
messages: cachedMessages,
|
4718
|
+
utxos: cachedUtxos
|
4719
|
+
});
|
4720
|
+
request.addResources(resources);
|
4937
4721
|
}
|
4938
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4939
|
-
transactionRequest: requestToBeReEstimate
|
4940
|
-
});
|
4941
|
-
txRequest.maxFee = maxFee;
|
4942
|
-
return txRequest;
|
4943
4722
|
}
|
4944
4723
|
/**
|
4945
4724
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4947,25 +4726,29 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4947
4726
|
* @param destination - The address of the destination.
|
4948
4727
|
* @param amount - The amount of coins to transfer.
|
4949
4728
|
* @param assetId - The asset ID of the coins to transfer.
|
4950
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4729
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4951
4730
|
* @returns A promise that resolves to the prepared transaction request.
|
4952
4731
|
*/
|
4953
|
-
async createTransfer(destination, amount, assetId
|
4954
|
-
const
|
4955
|
-
|
4956
|
-
const
|
4732
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4733
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4734
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4735
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4736
|
+
const request = new ScriptTransactionRequest(params);
|
4737
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4738
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4957
4739
|
estimateTxDependencies: true,
|
4958
4740
|
resourcesOwner: this
|
4959
4741
|
});
|
4960
|
-
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
4966
|
-
|
4967
|
-
|
4968
|
-
await this.fund(request,
|
4742
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4743
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4744
|
+
this.validateGas({
|
4745
|
+
gasUsed,
|
4746
|
+
gasPrice: request.gasPrice,
|
4747
|
+
gasLimit: request.gasLimit,
|
4748
|
+
minGasPrice
|
4749
|
+
});
|
4750
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4751
|
+
request.updatePredicateInputs(estimatedInputs);
|
4969
4752
|
return request;
|
4970
4753
|
}
|
4971
4754
|
/**
|
@@ -4977,14 +4760,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4977
4760
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4978
4761
|
* @returns A promise that resolves to the transaction response.
|
4979
4762
|
*/
|
4980
|
-
async transfer(destination, amount, assetId
|
4981
|
-
if ((0,
|
4763
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4764
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4982
4765
|
throw new import_errors16.FuelError(
|
4983
4766
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4984
4767
|
"Transfer amount must be a positive number."
|
4985
4768
|
);
|
4986
4769
|
}
|
4987
|
-
const
|
4770
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4771
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4988
4772
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4989
4773
|
}
|
4990
4774
|
/**
|
@@ -4996,38 +4780,40 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4996
4780
|
* @param txParams - The optional transaction parameters.
|
4997
4781
|
* @returns A promise that resolves to the transaction response.
|
4998
4782
|
*/
|
4999
|
-
async transferToContract(contractId, amount, assetId
|
5000
|
-
if ((0,
|
4783
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4784
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5001
4785
|
throw new import_errors16.FuelError(
|
5002
4786
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5003
4787
|
"Transfer amount must be a positive number."
|
5004
4788
|
);
|
5005
4789
|
}
|
5006
4790
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4791
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4792
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4793
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5007
4794
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5008
4795
|
hexlifiedContractId: contractAddress.toB256(),
|
5009
|
-
amountToTransfer: (0,
|
5010
|
-
assetId
|
4796
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4797
|
+
assetId: assetIdToTransfer
|
5011
4798
|
});
|
5012
4799
|
const request = new ScriptTransactionRequest({
|
5013
|
-
...
|
4800
|
+
...params,
|
5014
4801
|
script,
|
5015
4802
|
scriptData
|
5016
4803
|
});
|
5017
4804
|
request.addContractInputAndOutput(contractAddress);
|
5018
|
-
const
|
5019
|
-
|
5020
|
-
|
4805
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4806
|
+
request,
|
4807
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
4808
|
+
);
|
4809
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4810
|
+
this.validateGas({
|
4811
|
+
gasUsed,
|
4812
|
+
gasPrice: request.gasPrice,
|
4813
|
+
gasLimit: request.gasLimit,
|
4814
|
+
minGasPrice
|
5021
4815
|
});
|
5022
|
-
|
5023
|
-
this.validateGas({
|
5024
|
-
gasUsed: txCost.gasUsed,
|
5025
|
-
gasLimit: request.gasLimit
|
5026
|
-
});
|
5027
|
-
}
|
5028
|
-
request.gasLimit = txCost.gasUsed;
|
5029
|
-
request.maxFee = txCost.maxFee;
|
5030
|
-
await this.fund(request, txCost);
|
4816
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5031
4817
|
return this.sendTransaction(request);
|
5032
4818
|
}
|
5033
4819
|
/**
|
@@ -5039,31 +4825,35 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5039
4825
|
* @returns A promise that resolves to the transaction response.
|
5040
4826
|
*/
|
5041
4827
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4828
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4829
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5042
4830
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5043
|
-
const recipientDataArray = (0,
|
4831
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5044
4832
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5045
4833
|
);
|
5046
|
-
const amountDataArray = (0,
|
5047
|
-
"0x".concat((0,
|
4834
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4835
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5048
4836
|
);
|
5049
4837
|
const script = new Uint8Array([
|
5050
|
-
...(0,
|
4838
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5051
4839
|
...recipientDataArray,
|
5052
4840
|
...amountDataArray
|
5053
4841
|
]);
|
5054
|
-
const params = { script, ...txParams };
|
4842
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5055
4843
|
const request = new ScriptTransactionRequest(params);
|
5056
|
-
const
|
5057
|
-
const
|
5058
|
-
|
5059
|
-
|
5060
|
-
|
5061
|
-
|
5062
|
-
|
5063
|
-
|
5064
|
-
|
5065
|
-
|
5066
|
-
|
4844
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
|
4845
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4846
|
+
request,
|
4847
|
+
forwardingQuantities
|
4848
|
+
);
|
4849
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4850
|
+
this.validateGas({
|
4851
|
+
gasUsed,
|
4852
|
+
gasPrice: request.gasPrice,
|
4853
|
+
gasLimit: request.gasLimit,
|
4854
|
+
minGasPrice
|
4855
|
+
});
|
4856
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5067
4857
|
return this.sendTransaction(request);
|
5068
4858
|
}
|
5069
4859
|
async signMessage(message) {
|
@@ -5121,7 +4911,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5121
4911
|
}
|
5122
4912
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5123
4913
|
}
|
5124
|
-
validateGas({
|
4914
|
+
validateGas({
|
4915
|
+
gasUsed,
|
4916
|
+
gasPrice,
|
4917
|
+
gasLimit,
|
4918
|
+
minGasPrice
|
4919
|
+
}) {
|
4920
|
+
if (minGasPrice.gt(gasPrice)) {
|
4921
|
+
throw new import_errors16.FuelError(
|
4922
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4923
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4924
|
+
);
|
4925
|
+
}
|
5125
4926
|
if (gasUsed.gt(gasLimit)) {
|
5126
4927
|
throw new import_errors16.FuelError(
|
5127
4928
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5135,8 +4936,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5135
4936
|
var import_address5 = require("@fuel-ts/address");
|
5136
4937
|
var import_crypto = require("@fuel-ts/crypto");
|
5137
4938
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5138
|
-
var
|
5139
|
-
var
|
4939
|
+
var import_math19 = require("@fuel-ts/math");
|
4940
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5140
4941
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5141
4942
|
var Signer = class {
|
5142
4943
|
address;
|
@@ -5155,10 +4956,10 @@ var Signer = class {
|
|
5155
4956
|
privateKey = `0x${privateKey}`;
|
5156
4957
|
}
|
5157
4958
|
}
|
5158
|
-
const privateKeyBytes = (0,
|
5159
|
-
this.privateKey = (0,
|
5160
|
-
this.publicKey = (0,
|
5161
|
-
this.compressedPublicKey = (0,
|
4959
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4960
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4961
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4962
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5162
4963
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5163
4964
|
}
|
5164
4965
|
/**
|
@@ -5172,11 +4973,11 @@ var Signer = class {
|
|
5172
4973
|
* @returns hashed signature
|
5173
4974
|
*/
|
5174
4975
|
sign(data) {
|
5175
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5176
|
-
const r = (0,
|
5177
|
-
const s = (0,
|
4976
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4977
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4978
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5178
4979
|
s[0] |= (signature.recovery || 0) << 7;
|
5179
|
-
return (0,
|
4980
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5180
4981
|
}
|
5181
4982
|
/**
|
5182
4983
|
* Add point on the current elliptic curve
|
@@ -5185,8 +4986,8 @@ var Signer = class {
|
|
5185
4986
|
* @returns compressed point on the curve
|
5186
4987
|
*/
|
5187
4988
|
addPoint(point) {
|
5188
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5189
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4989
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4990
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5190
4991
|
const result = p0.add(p1);
|
5191
4992
|
return `0x${result.toHex(true)}`;
|
5192
4993
|
}
|
@@ -5198,16 +4999,16 @@ var Signer = class {
|
|
5198
4999
|
* @returns public key from signature from the
|
5199
5000
|
*/
|
5200
5001
|
static recoverPublicKey(data, signature) {
|
5201
|
-
const signedMessageBytes = (0,
|
5002
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5202
5003
|
const r = signedMessageBytes.slice(0, 32);
|
5203
5004
|
const s = signedMessageBytes.slice(32, 64);
|
5204
5005
|
const recoveryParam = (s[0] & 128) >> 7;
|
5205
5006
|
s[0] &= 127;
|
5206
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5007
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5207
5008
|
recoveryParam
|
5208
5009
|
);
|
5209
|
-
const publicKey = sig.recoverPublicKey((0,
|
5210
|
-
return (0,
|
5010
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5011
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5211
5012
|
}
|
5212
5013
|
/**
|
5213
5014
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5226,7 +5027,7 @@ var Signer = class {
|
|
5226
5027
|
* @returns random 32-byte hashed
|
5227
5028
|
*/
|
5228
5029
|
static generatePrivateKey(entropy) {
|
5229
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5030
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5230
5031
|
}
|
5231
5032
|
/**
|
5232
5033
|
* Extended publicKey from a compact publicKey
|
@@ -5235,8 +5036,8 @@ var Signer = class {
|
|
5235
5036
|
* @returns extended publicKey
|
5236
5037
|
*/
|
5237
5038
|
static extendPublicKey(publicKey) {
|
5238
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5239
|
-
return (0,
|
5039
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5040
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5240
5041
|
}
|
5241
5042
|
};
|
5242
5043
|
|
@@ -5244,7 +5045,7 @@ var Signer = class {
|
|
5244
5045
|
var import_address6 = require("@fuel-ts/address");
|
5245
5046
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5246
5047
|
var import_errors17 = require("@fuel-ts/errors");
|
5247
|
-
var
|
5048
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5248
5049
|
var import_uuid = require("uuid");
|
5249
5050
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5250
5051
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5327,7 +5128,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5327
5128
|
);
|
5328
5129
|
}
|
5329
5130
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5330
|
-
const privateKey = (0,
|
5131
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5331
5132
|
return privateKey;
|
5332
5133
|
}
|
5333
5134
|
|
@@ -5372,7 +5173,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5372
5173
|
*/
|
5373
5174
|
async signMessage(message) {
|
5374
5175
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5375
|
-
return (0,
|
5176
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5376
5177
|
}
|
5377
5178
|
/**
|
5378
5179
|
* Signs a transaction with the wallet's private key.
|
@@ -5385,7 +5186,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5385
5186
|
const chainId = this.provider.getChainId();
|
5386
5187
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5387
5188
|
const signature = await this.signer().sign(hashedTransaction);
|
5388
|
-
return (0,
|
5189
|
+
return (0, import_utils31.hexlify)(signature);
|
5389
5190
|
}
|
5390
5191
|
/**
|
5391
5192
|
* Populates a transaction with the witnesses signature.
|
@@ -5405,7 +5206,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5405
5206
|
* @param transactionRequestLike - The transaction request to send.
|
5406
5207
|
* @returns A promise that resolves to the TransactionResponse object.
|
5407
5208
|
*/
|
5408
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5209
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5409
5210
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5410
5211
|
if (estimateTxDependencies) {
|
5411
5212
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5446,16 +5247,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5446
5247
|
// src/hdwallet/hdwallet.ts
|
5447
5248
|
var import_errors20 = require("@fuel-ts/errors");
|
5448
5249
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5449
|
-
var
|
5450
|
-
var
|
5451
|
-
var
|
5250
|
+
var import_math20 = require("@fuel-ts/math");
|
5251
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5252
|
+
var import_ethers3 = require("ethers");
|
5452
5253
|
|
5453
5254
|
// src/mnemonic/mnemonic.ts
|
5454
5255
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5455
5256
|
var import_errors19 = require("@fuel-ts/errors");
|
5456
5257
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5457
|
-
var
|
5458
|
-
var
|
5258
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5259
|
+
var import_ethers2 = require("ethers");
|
5459
5260
|
|
5460
5261
|
// src/wordlists/words/english.ts
|
5461
5262
|
var english = [
|
@@ -7512,7 +7313,7 @@ var english = [
|
|
7512
7313
|
// src/mnemonic/utils.ts
|
7513
7314
|
var import_errors18 = require("@fuel-ts/errors");
|
7514
7315
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7515
|
-
var
|
7316
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7516
7317
|
function toUtf8Bytes(stri) {
|
7517
7318
|
const str = stri.normalize("NFKD");
|
7518
7319
|
const result = [];
|
@@ -7579,14 +7380,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7579
7380
|
}
|
7580
7381
|
}
|
7581
7382
|
const checksumBits = entropy.length / 4;
|
7582
|
-
const checksum = (0,
|
7383
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7583
7384
|
indices[indices.length - 1] <<= checksumBits;
|
7584
7385
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7585
7386
|
return indices;
|
7586
7387
|
}
|
7587
7388
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7588
7389
|
const size = Math.ceil(11 * words.length / 8);
|
7589
|
-
const entropy = (0,
|
7390
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7590
7391
|
let offset = 0;
|
7591
7392
|
for (let i = 0; i < words.length; i += 1) {
|
7592
7393
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7606,7 +7407,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7606
7407
|
const entropyBits = 32 * words.length / 3;
|
7607
7408
|
const checksumBits = words.length / 3;
|
7608
7409
|
const checksumMask = getUpperMask(checksumBits);
|
7609
|
-
const checksum = (0,
|
7410
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7610
7411
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7611
7412
|
throw new import_errors18.FuelError(
|
7612
7413
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7681,7 +7482,7 @@ var Mnemonic = class {
|
|
7681
7482
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7682
7483
|
const words = getWords(phrase);
|
7683
7484
|
assertMnemonic(words);
|
7684
|
-
return (0,
|
7485
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7685
7486
|
}
|
7686
7487
|
/**
|
7687
7488
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7689,7 +7490,7 @@ var Mnemonic = class {
|
|
7689
7490
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7690
7491
|
*/
|
7691
7492
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7692
|
-
const entropyBytes = (0,
|
7493
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7693
7494
|
assertWordList(wordlist);
|
7694
7495
|
assertEntropy(entropyBytes);
|
7695
7496
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7703,7 +7504,7 @@ var Mnemonic = class {
|
|
7703
7504
|
assertMnemonic(getWords(phrase));
|
7704
7505
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7705
7506
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7706
|
-
return (0,
|
7507
|
+
return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7707
7508
|
}
|
7708
7509
|
/**
|
7709
7510
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7758,14 +7559,14 @@ var Mnemonic = class {
|
|
7758
7559
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7759
7560
|
*/
|
7760
7561
|
static masterKeysFromSeed(seed) {
|
7761
|
-
const seedArray = (0,
|
7562
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7762
7563
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7763
7564
|
throw new import_errors19.FuelError(
|
7764
7565
|
import_errors19.ErrorCode.INVALID_SEED,
|
7765
7566
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7766
7567
|
);
|
7767
7568
|
}
|
7768
|
-
return (0,
|
7569
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7769
7570
|
}
|
7770
7571
|
/**
|
7771
7572
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7776,22 +7577,22 @@ var Mnemonic = class {
|
|
7776
7577
|
*/
|
7777
7578
|
static seedToExtendedKey(seed, testnet = false) {
|
7778
7579
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7779
|
-
const prefix = (0,
|
7580
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7780
7581
|
const depth = "0x00";
|
7781
7582
|
const fingerprint = "0x00000000";
|
7782
7583
|
const index = "0x00000000";
|
7783
7584
|
const chainCode = masterKey.slice(32);
|
7784
7585
|
const privateKey = masterKey.slice(0, 32);
|
7785
|
-
const extendedKey = (0,
|
7586
|
+
const extendedKey = (0, import_utils33.concat)([
|
7786
7587
|
prefix,
|
7787
7588
|
depth,
|
7788
7589
|
fingerprint,
|
7789
7590
|
index,
|
7790
7591
|
chainCode,
|
7791
|
-
(0,
|
7592
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7792
7593
|
]);
|
7793
|
-
const checksum = (0,
|
7794
|
-
return (0,
|
7594
|
+
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7595
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7795
7596
|
}
|
7796
7597
|
/**
|
7797
7598
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7806,7 +7607,7 @@ var Mnemonic = class {
|
|
7806
7607
|
* @returns A randomly generated mnemonic
|
7807
7608
|
*/
|
7808
7609
|
static generate(size = 32, extraEntropy = "") {
|
7809
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7610
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7810
7611
|
return Mnemonic.entropyToMnemonic(entropy);
|
7811
7612
|
}
|
7812
7613
|
};
|
@@ -7814,12 +7615,12 @@ var mnemonic_default = Mnemonic;
|
|
7814
7615
|
|
7815
7616
|
// src/hdwallet/hdwallet.ts
|
7816
7617
|
var HARDENED_INDEX = 2147483648;
|
7817
|
-
var MainnetPRV2 = (0,
|
7818
|
-
var MainnetPUB = (0,
|
7819
|
-
var TestnetPRV2 = (0,
|
7820
|
-
var TestnetPUB = (0,
|
7618
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7619
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7620
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7621
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7821
7622
|
function base58check(data) {
|
7822
|
-
return (0,
|
7623
|
+
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)]));
|
7823
7624
|
}
|
7824
7625
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7825
7626
|
if (isPublic) {
|
@@ -7828,11 +7629,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7828
7629
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7829
7630
|
}
|
7830
7631
|
function isPublicExtendedKey(extendedKey) {
|
7831
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7632
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7832
7633
|
}
|
7833
7634
|
function isValidExtendedKey(extendedKey) {
|
7834
7635
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7835
|
-
(0,
|
7636
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7836
7637
|
);
|
7837
7638
|
}
|
7838
7639
|
function parsePath(path2, depth = 0) {
|
@@ -7850,8 +7651,8 @@ function parsePath(path2, depth = 0) {
|
|
7850
7651
|
var HDWallet = class {
|
7851
7652
|
depth = 0;
|
7852
7653
|
index = 0;
|
7853
|
-
fingerprint = (0,
|
7854
|
-
parentFingerprint = (0,
|
7654
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7655
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7855
7656
|
privateKey;
|
7856
7657
|
publicKey;
|
7857
7658
|
chainCode;
|
@@ -7863,8 +7664,8 @@ var HDWallet = class {
|
|
7863
7664
|
constructor(config) {
|
7864
7665
|
if (config.privateKey) {
|
7865
7666
|
const signer = new Signer(config.privateKey);
|
7866
|
-
this.publicKey = (0,
|
7867
|
-
this.privateKey = (0,
|
7667
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7668
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7868
7669
|
} else {
|
7869
7670
|
if (!config.publicKey) {
|
7870
7671
|
throw new import_errors20.FuelError(
|
@@ -7872,10 +7673,10 @@ var HDWallet = class {
|
|
7872
7673
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7873
7674
|
);
|
7874
7675
|
}
|
7875
|
-
this.publicKey = (0,
|
7676
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7876
7677
|
}
|
7877
7678
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7878
|
-
this.fingerprint = (0,
|
7679
|
+
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
7879
7680
|
this.depth = config.depth || this.depth;
|
7880
7681
|
this.index = config.index || this.index;
|
7881
7682
|
this.chainCode = config.chainCode;
|
@@ -7891,9 +7692,9 @@ var HDWallet = class {
|
|
7891
7692
|
* @returns A new instance of HDWallet on the derived index
|
7892
7693
|
*/
|
7893
7694
|
deriveIndex(index) {
|
7894
|
-
const privateKey = this.privateKey && (0,
|
7895
|
-
const publicKey = (0,
|
7896
|
-
const chainCode = (0,
|
7695
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7696
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7697
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7897
7698
|
const data = new Uint8Array(37);
|
7898
7699
|
if (index & HARDENED_INDEX) {
|
7899
7700
|
if (!privateKey) {
|
@@ -7904,15 +7705,15 @@ var HDWallet = class {
|
|
7904
7705
|
}
|
7905
7706
|
data.set(privateKey, 1);
|
7906
7707
|
} else {
|
7907
|
-
data.set((0,
|
7708
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7908
7709
|
}
|
7909
|
-
data.set((0,
|
7910
|
-
const bytes = (0,
|
7710
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7711
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7911
7712
|
const IL = bytes.slice(0, 32);
|
7912
7713
|
const IR = bytes.slice(32);
|
7913
7714
|
if (privateKey) {
|
7914
7715
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7915
|
-
const ki = (0,
|
7716
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7916
7717
|
return new HDWallet({
|
7917
7718
|
privateKey: ki,
|
7918
7719
|
chainCode: IR,
|
@@ -7921,7 +7722,7 @@ var HDWallet = class {
|
|
7921
7722
|
parentFingerprint: this.fingerprint
|
7922
7723
|
});
|
7923
7724
|
}
|
7924
|
-
const signer = new Signer((0,
|
7725
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7925
7726
|
const Ki = signer.addPoint(publicKey);
|
7926
7727
|
return new HDWallet({
|
7927
7728
|
publicKey: Ki,
|
@@ -7956,12 +7757,12 @@ var HDWallet = class {
|
|
7956
7757
|
);
|
7957
7758
|
}
|
7958
7759
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7959
|
-
const depth = (0,
|
7760
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7960
7761
|
const parentFingerprint = this.parentFingerprint;
|
7961
|
-
const index = (0,
|
7762
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7962
7763
|
const chainCode = this.chainCode;
|
7963
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7964
|
-
const extendedKey = (0,
|
7764
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7765
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7965
7766
|
return base58check(extendedKey);
|
7966
7767
|
}
|
7967
7768
|
/**
|
@@ -7973,13 +7774,13 @@ var HDWallet = class {
|
|
7973
7774
|
static fromSeed(seed) {
|
7974
7775
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7975
7776
|
return new HDWallet({
|
7976
|
-
chainCode: (0,
|
7977
|
-
privateKey: (0,
|
7777
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7778
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7978
7779
|
});
|
7979
7780
|
}
|
7980
7781
|
static fromExtendedKey(extendedKey) {
|
7981
|
-
const decoded = (0,
|
7982
|
-
const bytes = (0,
|
7782
|
+
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7783
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7983
7784
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7984
7785
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7985
7786
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7988,9 +7789,9 @@ var HDWallet = class {
|
|
7988
7789
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7989
7790
|
}
|
7990
7791
|
const depth = bytes[4];
|
7991
|
-
const parentFingerprint = (0,
|
7992
|
-
const index = parseInt((0,
|
7993
|
-
const chainCode = (0,
|
7792
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7793
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7794
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7994
7795
|
const key = bytes.slice(45, 78);
|
7995
7796
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7996
7797
|
throw new import_errors20.FuelError(
|
@@ -8183,15 +7984,14 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8183
7984
|
process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
|
8184
7985
|
wallet.provider
|
8185
7986
|
);
|
8186
|
-
const
|
8187
|
-
|
8188
|
-
|
8189
|
-
|
7987
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7988
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7989
|
+
const request = new ScriptTransactionRequest({
|
7990
|
+
gasLimit: 1e4,
|
7991
|
+
gasPrice: minGasPrice
|
8190
7992
|
});
|
8191
|
-
|
8192
|
-
request.
|
8193
|
-
request.maxFee = txCost.maxFee;
|
8194
|
-
await genesisWallet.fund(request, txCost);
|
7993
|
+
request.addResources(resources);
|
7994
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8195
7995
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8196
7996
|
};
|
8197
7997
|
|
@@ -8205,12 +8005,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8205
8005
|
};
|
8206
8006
|
|
8207
8007
|
// src/test-utils/launchNode.ts
|
8208
|
-
var
|
8209
|
-
var
|
8008
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
8009
|
+
var import_math21 = require("@fuel-ts/math");
|
8010
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8210
8011
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8211
8012
|
var import_child_process = require("child_process");
|
8212
8013
|
var import_crypto5 = require("crypto");
|
8213
|
-
var import_ethers5 = require("ethers");
|
8214
8014
|
var import_fs = require("fs");
|
8215
8015
|
var import_os = __toESM(require("os"));
|
8216
8016
|
var import_path = __toESM(require("path"));
|
@@ -8259,13 +8059,13 @@ var launchNode = async ({
|
|
8259
8059
|
// eslint-disable-next-line no-async-promise-executor
|
8260
8060
|
new Promise(async (resolve, reject) => {
|
8261
8061
|
const remainingArgs = extractRemainingArgs(args, [
|
8262
|
-
"--
|
8062
|
+
"--chain",
|
8263
8063
|
"--consensus-key",
|
8264
8064
|
"--db-type",
|
8265
8065
|
"--poa-instant"
|
8266
8066
|
]);
|
8267
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8268
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8067
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8068
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8269
8069
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8270
8070
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8271
8071
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8283,54 +8083,36 @@ var launchNode = async ({
|
|
8283
8083
|
let chainConfigPathToUse;
|
8284
8084
|
const prefix = basePath || import_os.default.tmpdir();
|
8285
8085
|
const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
|
8286
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix
|
8086
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8287
8087
|
if (chainConfigPath) {
|
8288
8088
|
chainConfigPathToUse = chainConfigPath;
|
8289
8089
|
} else {
|
8290
8090
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8291
8091
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8292
8092
|
}
|
8293
|
-
|
8294
|
-
|
8295
|
-
stateConfigJson = {
|
8296
|
-
...stateConfigJson,
|
8297
|
-
coins: [
|
8298
|
-
...stateConfigJson.coins.map((coin) => ({
|
8299
|
-
...coin,
|
8300
|
-
amount: "18446744073709551615"
|
8301
|
-
}))
|
8302
|
-
],
|
8303
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8304
|
-
...message,
|
8305
|
-
amount: "18446744073709551615"
|
8306
|
-
}))
|
8307
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8308
|
-
};
|
8093
|
+
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8094
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8309
8095
|
if (!process.env.GENESIS_SECRET) {
|
8310
8096
|
const pk = Signer.generatePrivateKey();
|
8311
8097
|
const signer = new Signer(pk);
|
8312
|
-
process.env.GENESIS_SECRET = (0,
|
8313
|
-
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8318
|
-
|
8319
|
-
|
8320
|
-
|
8321
|
-
|
8322
|
-
|
8098
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8099
|
+
chainConfig = {
|
8100
|
+
...import_utils36.defaultChainConfig,
|
8101
|
+
initial_state: {
|
8102
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8103
|
+
coins: [
|
8104
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8105
|
+
{
|
8106
|
+
owner: signer.address.toHexString(),
|
8107
|
+
amount: (0, import_math21.toHex)(1e9),
|
8108
|
+
asset_id: import_utils36.defaultChainConfig?.consensus_parameters?.base_asset_id ?? import_configs11.ZeroBytes32
|
8109
|
+
}
|
8110
|
+
]
|
8111
|
+
}
|
8112
|
+
};
|
8323
8113
|
}
|
8324
|
-
|
8325
|
-
|
8326
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8327
|
-
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8328
|
-
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8329
|
-
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8330
|
-
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8331
|
-
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8332
|
-
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8333
|
-
chainConfigPathToUse = tempDirPath;
|
8114
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8115
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8334
8116
|
}
|
8335
8117
|
const child = (0, import_child_process.spawn)(
|
8336
8118
|
command,
|
@@ -8339,10 +8121,10 @@ var launchNode = async ({
|
|
8339
8121
|
["--ip", ipToUse],
|
8340
8122
|
["--port", portToUse],
|
8341
8123
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8342
|
-
["--min-gas-price", "
|
8124
|
+
["--min-gas-price", "0"],
|
8343
8125
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8344
8126
|
["--consensus-key", consensusKey],
|
8345
|
-
["--
|
8127
|
+
["--chain", chainConfigPathToUse],
|
8346
8128
|
"--vm-backtrace",
|
8347
8129
|
"--utxo-validation",
|
8348
8130
|
"--debug",
|
@@ -8389,9 +8171,10 @@ var launchNode = async ({
|
|
8389
8171
|
})
|
8390
8172
|
);
|
8391
8173
|
var generateWallets = async (count, provider) => {
|
8174
|
+
const baseAssetId = provider.getBaseAssetId();
|
8392
8175
|
const wallets = [];
|
8393
8176
|
for (let i = 0; i < count; i += 1) {
|
8394
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8177
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8395
8178
|
wallets.push(wallet);
|
8396
8179
|
}
|
8397
8180
|
return wallets;
|
@@ -8401,7 +8184,7 @@ var launchNodeAndGetWallets = async ({
|
|
8401
8184
|
walletCount = 10
|
8402
8185
|
} = {}) => {
|
8403
8186
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8404
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8187
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8405
8188
|
const wallets = await generateWallets(walletCount, provider);
|
8406
8189
|
const cleanup = () => {
|
8407
8190
|
closeNode();
|