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