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