@fuel-ts/account 0.0.0-rc-2021-20240409151049 → 0.0.0-rc-2034-20240410011904
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +623 -868
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +525 -759
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +406 -639
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +328 -894
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +31 -36
- 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 +25 -8
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1122 -1582
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +521 -735
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +415 -629
- 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,16 +58,15 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
58
|
|
59
59
|
// src/wallet/base-wallet-unlocked.ts
|
60
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
61
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
65
|
var import_configs12 = require("@fuel-ts/address/configs");
|
66
66
|
var import_errors16 = require("@fuel-ts/errors");
|
67
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
|
-
var
|
69
|
-
var
|
70
|
-
var import_ramda4 = require("ramda");
|
68
|
+
var import_math18 = require("@fuel-ts/math");
|
69
|
+
var import_utils28 = require("@fuel-ts/utils");
|
71
70
|
|
72
71
|
// src/providers/coin-quantity.ts
|
73
72
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -76,24 +75,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
76
75
|
var coinQuantityfy = (coinQuantityLike) => {
|
77
76
|
let assetId;
|
78
77
|
let amount;
|
79
|
-
let
|
78
|
+
let max2;
|
80
79
|
if (Array.isArray(coinQuantityLike)) {
|
81
80
|
amount = coinQuantityLike[0];
|
82
81
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
83
|
-
|
82
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
84
83
|
} else {
|
85
84
|
amount = coinQuantityLike.amount;
|
86
85
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
87
|
-
|
86
|
+
max2 = coinQuantityLike.max ?? void 0;
|
88
87
|
}
|
89
88
|
const bnAmount = (0, import_math.bn)(amount);
|
90
89
|
return {
|
91
90
|
assetId: (0, import_utils.hexlify)(assetId),
|
92
91
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
93
|
-
max:
|
92
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
94
93
|
};
|
95
94
|
};
|
96
|
-
var
|
95
|
+
var addAmountToAsset = (params) => {
|
97
96
|
const { amount, assetId } = params;
|
98
97
|
const coinQuantities = [...params.coinQuantities];
|
99
98
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -108,11 +107,11 @@ var addAmountToCoinQuantities = (params) => {
|
|
108
107
|
// src/providers/provider.ts
|
109
108
|
var import_address3 = require("@fuel-ts/address");
|
110
109
|
var import_errors14 = require("@fuel-ts/errors");
|
111
|
-
var
|
112
|
-
var
|
113
|
-
var
|
110
|
+
var import_math15 = require("@fuel-ts/math");
|
111
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
112
|
+
var import_utils23 = require("@fuel-ts/utils");
|
114
113
|
var import_versions = require("@fuel-ts/versions");
|
115
|
-
var
|
114
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
116
115
|
var import_ethers2 = require("ethers");
|
117
116
|
var import_graphql_request = require("graphql-request");
|
118
117
|
var import_ramda3 = require("ramda");
|
@@ -121,10 +120,14 @@ var import_ramda3 = require("ramda");
|
|
121
120
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
122
121
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
123
122
|
fragment receiptFragment on Receipt {
|
124
|
-
|
123
|
+
contract {
|
124
|
+
id
|
125
|
+
}
|
125
126
|
pc
|
126
127
|
is
|
127
|
-
to
|
128
|
+
to {
|
129
|
+
id
|
130
|
+
}
|
128
131
|
toAddress
|
129
132
|
amount
|
130
133
|
assetId
|
@@ -162,16 +165,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
162
165
|
id
|
163
166
|
}
|
164
167
|
time
|
165
|
-
receipts {
|
166
|
-
...receiptFragment
|
167
|
-
}
|
168
168
|
programState {
|
169
169
|
returnType
|
170
170
|
data
|
171
171
|
}
|
172
|
-
receipts {
|
173
|
-
...receiptFragment
|
174
|
-
}
|
175
172
|
}
|
176
173
|
... on FailureStatus {
|
177
174
|
block {
|
@@ -179,24 +176,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
179
176
|
}
|
180
177
|
time
|
181
178
|
reason
|
182
|
-
receipts {
|
183
|
-
...receiptFragment
|
184
|
-
}
|
185
179
|
}
|
186
180
|
... on SqueezedOutStatus {
|
187
181
|
reason
|
188
182
|
}
|
189
183
|
}
|
190
|
-
|
184
|
+
`;
|
191
185
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
192
186
|
fragment transactionFragment on Transaction {
|
193
187
|
id
|
194
188
|
rawPayload
|
189
|
+
gasPrice
|
190
|
+
receipts {
|
191
|
+
...receiptFragment
|
192
|
+
}
|
195
193
|
status {
|
196
194
|
...transactionStatusFragment
|
197
195
|
}
|
198
196
|
}
|
199
|
-
${
|
197
|
+
${ReceiptFragmentFragmentDoc}
|
198
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
200
199
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
201
200
|
fragment inputEstimatePredicatesFragment on Input {
|
202
201
|
... on InputCoin {
|
@@ -214,46 +213,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
214
213
|
}
|
215
214
|
}
|
216
215
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
217
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
218
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
219
|
-
reason
|
220
|
-
programState {
|
221
|
-
returnType
|
222
|
-
data
|
223
|
-
}
|
224
|
-
}
|
225
|
-
`;
|
226
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
227
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
228
|
-
programState {
|
229
|
-
returnType
|
230
|
-
data
|
231
|
-
}
|
232
|
-
}
|
233
|
-
`;
|
234
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
235
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
236
|
-
... on DryRunFailureStatus {
|
237
|
-
...dryRunFailureStatusFragment
|
238
|
-
}
|
239
|
-
... on DryRunSuccessStatus {
|
240
|
-
...dryRunSuccessStatusFragment
|
241
|
-
}
|
242
|
-
}
|
243
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
244
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
245
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
247
|
-
id
|
248
|
-
status {
|
249
|
-
...dryRunTransactionStatusFragment
|
250
|
-
}
|
251
|
-
receipts {
|
252
|
-
...receiptFragment
|
253
|
-
}
|
254
|
-
}
|
255
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
256
|
-
${ReceiptFragmentFragmentDoc}`;
|
257
216
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
258
217
|
fragment coinFragment on Coin {
|
259
218
|
__typename
|
@@ -261,6 +220,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
261
220
|
owner
|
262
221
|
amount
|
263
222
|
assetId
|
223
|
+
maturity
|
264
224
|
blockCreated
|
265
225
|
txCreatedIdx
|
266
226
|
}
|
@@ -305,6 +265,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
305
265
|
prevRoot
|
306
266
|
time
|
307
267
|
applicationHash
|
268
|
+
messageReceiptRoot
|
308
269
|
messageReceiptCount
|
309
270
|
}
|
310
271
|
commitBlockHeader {
|
@@ -316,6 +277,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
316
277
|
prevRoot
|
317
278
|
time
|
318
279
|
applicationHash
|
280
|
+
messageReceiptRoot
|
319
281
|
messageReceiptCount
|
320
282
|
}
|
321
283
|
sender
|
@@ -335,8 +297,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
335
297
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
336
298
|
fragment blockFragment on Block {
|
337
299
|
id
|
338
|
-
height
|
339
300
|
header {
|
301
|
+
height
|
340
302
|
time
|
341
303
|
}
|
342
304
|
transactions {
|
@@ -394,11 +356,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
394
356
|
`;
|
395
357
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
396
358
|
fragment GasCostsFragment on GasCosts {
|
397
|
-
version {
|
398
|
-
... on Version {
|
399
|
-
value
|
400
|
-
}
|
401
|
-
}
|
402
359
|
add
|
403
360
|
addi
|
404
361
|
aloc
|
@@ -411,6 +368,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
411
368
|
cb
|
412
369
|
cfei
|
413
370
|
cfsi
|
371
|
+
croo
|
414
372
|
div
|
415
373
|
divi
|
416
374
|
ecr1
|
@@ -493,9 +451,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
493
451
|
ccp {
|
494
452
|
...DependentCostFragment
|
495
453
|
}
|
496
|
-
croo {
|
497
|
-
...DependentCostFragment
|
498
|
-
}
|
499
454
|
csiz {
|
500
455
|
...DependentCostFragment
|
501
456
|
}
|
@@ -555,11 +510,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
555
510
|
${DependentCostFragmentFragmentDoc}`;
|
556
511
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
557
512
|
fragment consensusParametersFragment on ConsensusParameters {
|
558
|
-
version {
|
559
|
-
... on Version {
|
560
|
-
value
|
561
|
-
}
|
562
|
-
}
|
563
513
|
txParams {
|
564
514
|
...TxParametersFragment
|
565
515
|
}
|
@@ -619,9 +569,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
619
569
|
fragment nodeInfoFragment on NodeInfo {
|
620
570
|
utxoValidation
|
621
571
|
vmBacktrace
|
572
|
+
minGasPrice
|
622
573
|
maxTx
|
623
574
|
maxDepth
|
624
575
|
nodeVersion
|
576
|
+
peers {
|
577
|
+
id
|
578
|
+
addresses
|
579
|
+
clientVersion
|
580
|
+
blockHeight
|
581
|
+
lastHeartbeatMs
|
582
|
+
appScore
|
583
|
+
}
|
625
584
|
}
|
626
585
|
`;
|
627
586
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -656,9 +615,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
656
615
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
657
616
|
transaction(id: $transactionId) {
|
658
617
|
...transactionFragment
|
618
|
+
receipts {
|
619
|
+
...receiptFragment
|
620
|
+
}
|
659
621
|
}
|
660
622
|
}
|
661
|
-
${TransactionFragmentFragmentDoc}
|
623
|
+
${TransactionFragmentFragmentDoc}
|
624
|
+
${ReceiptFragmentFragmentDoc}`;
|
662
625
|
var GetTransactionsDocument = import_graphql_tag.default`
|
663
626
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
664
627
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -786,20 +749,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
786
749
|
}
|
787
750
|
}
|
788
751
|
${BalanceFragmentFragmentDoc}`;
|
789
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
790
|
-
query getLatestGasPrice {
|
791
|
-
latestGasPrice {
|
792
|
-
gasPrice
|
793
|
-
}
|
794
|
-
}
|
795
|
-
`;
|
796
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
797
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
798
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
799
|
-
gasPrice
|
800
|
-
}
|
801
|
-
}
|
802
|
-
`;
|
803
752
|
var GetBalancesDocument = import_graphql_tag.default`
|
804
753
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
805
754
|
balances(
|
@@ -854,12 +803,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
854
803
|
}
|
855
804
|
`;
|
856
805
|
var DryRunDocument = import_graphql_tag.default`
|
857
|
-
mutation dryRun($
|
858
|
-
dryRun(
|
859
|
-
...
|
806
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
807
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
808
|
+
...receiptFragment
|
860
809
|
}
|
861
810
|
}
|
862
|
-
${
|
811
|
+
${ReceiptFragmentFragmentDoc}`;
|
863
812
|
var SubmitDocument = import_graphql_tag.default`
|
864
813
|
mutation submit($encodedTransaction: HexString!) {
|
865
814
|
submit(tx: $encodedTransaction) {
|
@@ -942,12 +891,6 @@ function getSdk(requester) {
|
|
942
891
|
getBalance(variables, options) {
|
943
892
|
return requester(GetBalanceDocument, variables, options);
|
944
893
|
},
|
945
|
-
getLatestGasPrice(variables, options) {
|
946
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
947
|
-
},
|
948
|
-
estimateGasPrice(variables, options) {
|
949
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
950
|
-
},
|
951
894
|
getBalances(variables, options) {
|
952
895
|
return requester(GetBalancesDocument, variables, options);
|
953
896
|
},
|
@@ -1017,14 +960,11 @@ var _FuelGraphqlSubscriber = class {
|
|
1017
960
|
let data;
|
1018
961
|
let errors;
|
1019
962
|
try {
|
1020
|
-
|
1021
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
963
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
1022
964
|
} catch (e) {
|
1023
965
|
throw new import_errors.FuelError(
|
1024
966
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
1025
|
-
`Error while parsing stream data response: ${text}
|
1026
|
-
|
1027
|
-
Thrown error: ${e}`
|
967
|
+
`Error while parsing stream data response: ${text}`
|
1028
968
|
);
|
1029
969
|
}
|
1030
970
|
if (Array.isArray(errors)) {
|
@@ -1125,7 +1065,7 @@ var inputify = (value) => {
|
|
1125
1065
|
return {
|
1126
1066
|
type: import_transactions.InputType.Coin,
|
1127
1067
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1128
|
-
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32,
|
1068
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 33)),
|
1129
1069
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1130
1070
|
amount: (0, import_math2.bn)(value.amount),
|
1131
1071
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1134,9 +1074,10 @@ var inputify = (value) => {
|
|
1134
1074
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1135
1075
|
},
|
1136
1076
|
witnessIndex: value.witnessIndex,
|
1077
|
+
maturity: value.maturity ?? 0,
|
1137
1078
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1138
|
-
predicateLength:
|
1139
|
-
predicateDataLength:
|
1079
|
+
predicateLength: predicate.length,
|
1080
|
+
predicateDataLength: predicateData.length,
|
1140
1081
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1141
1082
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1142
1083
|
};
|
@@ -1167,8 +1108,8 @@ var inputify = (value) => {
|
|
1167
1108
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1168
1109
|
witnessIndex: value.witnessIndex,
|
1169
1110
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1170
|
-
predicateLength:
|
1171
|
-
predicateDataLength:
|
1111
|
+
predicateLength: predicate.length,
|
1112
|
+
predicateDataLength: predicateData.length,
|
1172
1113
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1173
1114
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1174
1115
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1283,8 +1224,8 @@ function assembleReceiptByType(receipt) {
|
|
1283
1224
|
case "CALL" /* Call */: {
|
1284
1225
|
const callReceipt = {
|
1285
1226
|
type: import_transactions3.ReceiptType.Call,
|
1286
|
-
from: hexOrZero(receipt.id
|
1287
|
-
to: hexOrZero(receipt?.to),
|
1227
|
+
from: hexOrZero(receipt.contract?.id),
|
1228
|
+
to: hexOrZero(receipt?.to?.id),
|
1288
1229
|
amount: (0, import_math4.bn)(receipt.amount),
|
1289
1230
|
assetId: hexOrZero(receipt.assetId),
|
1290
1231
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1298,7 +1239,7 @@ function assembleReceiptByType(receipt) {
|
|
1298
1239
|
case "RETURN" /* Return */: {
|
1299
1240
|
const returnReceipt = {
|
1300
1241
|
type: import_transactions3.ReceiptType.Return,
|
1301
|
-
id: hexOrZero(receipt.id
|
1242
|
+
id: hexOrZero(receipt.contract?.id),
|
1302
1243
|
val: (0, import_math4.bn)(receipt.val),
|
1303
1244
|
pc: (0, import_math4.bn)(receipt.pc),
|
1304
1245
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1308,7 +1249,7 @@ function assembleReceiptByType(receipt) {
|
|
1308
1249
|
case "RETURN_DATA" /* ReturnData */: {
|
1309
1250
|
const returnDataReceipt = {
|
1310
1251
|
type: import_transactions3.ReceiptType.ReturnData,
|
1311
|
-
id: hexOrZero(receipt.id
|
1252
|
+
id: hexOrZero(receipt.contract?.id),
|
1312
1253
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1313
1254
|
len: (0, import_math4.bn)(receipt.len),
|
1314
1255
|
digest: hexOrZero(receipt.digest),
|
@@ -1320,7 +1261,7 @@ function assembleReceiptByType(receipt) {
|
|
1320
1261
|
case "PANIC" /* Panic */: {
|
1321
1262
|
const panicReceipt = {
|
1322
1263
|
type: import_transactions3.ReceiptType.Panic,
|
1323
|
-
id: hexOrZero(receipt.id),
|
1264
|
+
id: hexOrZero(receipt.contract?.id),
|
1324
1265
|
reason: (0, import_math4.bn)(receipt.reason),
|
1325
1266
|
pc: (0, import_math4.bn)(receipt.pc),
|
1326
1267
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1331,7 +1272,7 @@ function assembleReceiptByType(receipt) {
|
|
1331
1272
|
case "REVERT" /* Revert */: {
|
1332
1273
|
const revertReceipt = {
|
1333
1274
|
type: import_transactions3.ReceiptType.Revert,
|
1334
|
-
id: hexOrZero(receipt.id
|
1275
|
+
id: hexOrZero(receipt.contract?.id),
|
1335
1276
|
val: (0, import_math4.bn)(receipt.ra),
|
1336
1277
|
pc: (0, import_math4.bn)(receipt.pc),
|
1337
1278
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1341,7 +1282,7 @@ function assembleReceiptByType(receipt) {
|
|
1341
1282
|
case "LOG" /* Log */: {
|
1342
1283
|
const logReceipt = {
|
1343
1284
|
type: import_transactions3.ReceiptType.Log,
|
1344
|
-
id: hexOrZero(receipt.id
|
1285
|
+
id: hexOrZero(receipt.contract?.id),
|
1345
1286
|
val0: (0, import_math4.bn)(receipt.ra),
|
1346
1287
|
val1: (0, import_math4.bn)(receipt.rb),
|
1347
1288
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1354,7 +1295,7 @@ function assembleReceiptByType(receipt) {
|
|
1354
1295
|
case "LOG_DATA" /* LogData */: {
|
1355
1296
|
const logDataReceipt = {
|
1356
1297
|
type: import_transactions3.ReceiptType.LogData,
|
1357
|
-
id: hexOrZero(receipt.id
|
1298
|
+
id: hexOrZero(receipt.contract?.id),
|
1358
1299
|
val0: (0, import_math4.bn)(receipt.ra),
|
1359
1300
|
val1: (0, import_math4.bn)(receipt.rb),
|
1360
1301
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1368,8 +1309,8 @@ function assembleReceiptByType(receipt) {
|
|
1368
1309
|
case "TRANSFER" /* Transfer */: {
|
1369
1310
|
const transferReceipt = {
|
1370
1311
|
type: import_transactions3.ReceiptType.Transfer,
|
1371
|
-
from: hexOrZero(receipt.id
|
1372
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1312
|
+
from: hexOrZero(receipt.contract?.id),
|
1313
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1373
1314
|
amount: (0, import_math4.bn)(receipt.amount),
|
1374
1315
|
assetId: hexOrZero(receipt.assetId),
|
1375
1316
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1380,8 +1321,8 @@ function assembleReceiptByType(receipt) {
|
|
1380
1321
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1381
1322
|
const transferOutReceipt = {
|
1382
1323
|
type: import_transactions3.ReceiptType.TransferOut,
|
1383
|
-
from: hexOrZero(receipt.id
|
1384
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1324
|
+
from: hexOrZero(receipt.contract?.id),
|
1325
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1385
1326
|
amount: (0, import_math4.bn)(receipt.amount),
|
1386
1327
|
assetId: hexOrZero(receipt.assetId),
|
1387
1328
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1424,7 +1365,7 @@ function assembleReceiptByType(receipt) {
|
|
1424
1365
|
return receiptMessageOut;
|
1425
1366
|
}
|
1426
1367
|
case "MINT" /* Mint */: {
|
1427
|
-
const contractId = hexOrZero(receipt.id
|
1368
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1428
1369
|
const subId = hexOrZero(receipt.subId);
|
1429
1370
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1430
1371
|
const mintReceipt = {
|
@@ -1439,7 +1380,7 @@ function assembleReceiptByType(receipt) {
|
|
1439
1380
|
return mintReceipt;
|
1440
1381
|
}
|
1441
1382
|
case "BURN" /* Burn */: {
|
1442
|
-
const contractId = hexOrZero(receipt.id
|
1383
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1443
1384
|
const subId = hexOrZero(receipt.subId);
|
1444
1385
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1445
1386
|
const burnReceipt = {
|
@@ -1465,6 +1406,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1465
1406
|
var import_math5 = require("@fuel-ts/math");
|
1466
1407
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1467
1408
|
var import_utils6 = require("@fuel-ts/utils");
|
1409
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1468
1410
|
var getGasUsedFromReceipts = (receipts) => {
|
1469
1411
|
const scriptResult = receipts.filter(
|
1470
1412
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1485,28 +1427,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1485
1427
|
}
|
1486
1428
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1487
1429
|
const witnessCache = [];
|
1488
|
-
const
|
1489
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1490
|
-
if (isCoinOrMessage) {
|
1491
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1492
|
-
return true;
|
1493
|
-
}
|
1494
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1495
|
-
witnessCache.push(input.witnessIndex);
|
1496
|
-
return true;
|
1497
|
-
}
|
1498
|
-
}
|
1499
|
-
return false;
|
1500
|
-
});
|
1501
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1502
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1430
|
+
const totalGas = inputs.reduce((total, input) => {
|
1503
1431
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1504
1432
|
return total.add(
|
1505
|
-
|
1433
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1506
1434
|
);
|
1507
1435
|
}
|
1508
|
-
|
1509
|
-
|
1436
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1437
|
+
witnessCache.push(input.witnessIndex);
|
1438
|
+
return total.add(gasCosts.ecr1);
|
1439
|
+
}
|
1440
|
+
return total;
|
1441
|
+
}, (0, import_math5.bn)());
|
1510
1442
|
return totalGas;
|
1511
1443
|
}
|
1512
1444
|
function getMinGas(params) {
|
@@ -1518,20 +1450,12 @@ function getMinGas(params) {
|
|
1518
1450
|
return minGas;
|
1519
1451
|
}
|
1520
1452
|
function getMaxGas(params) {
|
1521
|
-
const {
|
1522
|
-
gasPerByte,
|
1523
|
-
witnessesLength,
|
1524
|
-
witnessLimit,
|
1525
|
-
minGas,
|
1526
|
-
gasLimit = (0, import_math5.bn)(0),
|
1527
|
-
maxGasPerTx
|
1528
|
-
} = params;
|
1453
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1529
1454
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1530
1455
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1531
1456
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1532
1457
|
}
|
1533
|
-
|
1534
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1458
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1535
1459
|
}
|
1536
1460
|
function calculateMetadataGasForTxCreate({
|
1537
1461
|
gasCosts,
|
@@ -1553,10 +1477,6 @@ function calculateMetadataGasForTxScript({
|
|
1553
1477
|
}) {
|
1554
1478
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1555
1479
|
}
|
1556
|
-
var calculateGasFee = (params) => {
|
1557
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1558
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1559
|
-
};
|
1560
1480
|
|
1561
1481
|
// src/providers/utils/json.ts
|
1562
1482
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1693,7 +1613,7 @@ var witnessify = (value) => {
|
|
1693
1613
|
// src/providers/transaction-request/transaction-request.ts
|
1694
1614
|
var BaseTransactionRequest = class {
|
1695
1615
|
/** Gas price for transaction */
|
1696
|
-
|
1616
|
+
gasPrice;
|
1697
1617
|
/** Block until which tx cannot be included */
|
1698
1618
|
maturity;
|
1699
1619
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1712,7 +1632,7 @@ var BaseTransactionRequest = class {
|
|
1712
1632
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1713
1633
|
*/
|
1714
1634
|
constructor({
|
1715
|
-
|
1635
|
+
gasPrice,
|
1716
1636
|
maturity,
|
1717
1637
|
maxFee,
|
1718
1638
|
witnessLimit,
|
@@ -1720,7 +1640,7 @@ var BaseTransactionRequest = class {
|
|
1720
1640
|
outputs,
|
1721
1641
|
witnesses
|
1722
1642
|
} = {}) {
|
1723
|
-
this.
|
1643
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1724
1644
|
this.maturity = maturity ?? 0;
|
1725
1645
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1726
1646
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1731,9 +1651,9 @@ var BaseTransactionRequest = class {
|
|
1731
1651
|
static getPolicyMeta(req) {
|
1732
1652
|
let policyTypes = 0;
|
1733
1653
|
const policies = [];
|
1734
|
-
if (req.
|
1735
|
-
policyTypes += import_transactions6.PolicyType.
|
1736
|
-
policies.push({ data: req.
|
1654
|
+
if (req.gasPrice) {
|
1655
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1656
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1737
1657
|
}
|
1738
1658
|
if (req.witnessLimit) {
|
1739
1659
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1920,10 +1840,10 @@ var BaseTransactionRequest = class {
|
|
1920
1840
|
* @param predicate - Predicate bytes.
|
1921
1841
|
* @param predicateData - Predicate data bytes.
|
1922
1842
|
*/
|
1923
|
-
addCoinInput(coin) {
|
1843
|
+
addCoinInput(coin, predicate) {
|
1924
1844
|
const { assetId, owner, amount } = coin;
|
1925
1845
|
let witnessIndex;
|
1926
|
-
if (
|
1846
|
+
if (predicate) {
|
1927
1847
|
witnessIndex = 0;
|
1928
1848
|
} else {
|
1929
1849
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1938,7 +1858,9 @@ var BaseTransactionRequest = class {
|
|
1938
1858
|
amount,
|
1939
1859
|
assetId,
|
1940
1860
|
txPointer: "0x00000000000000000000000000000000",
|
1941
|
-
witnessIndex
|
1861
|
+
witnessIndex,
|
1862
|
+
predicate: predicate?.bytes,
|
1863
|
+
predicateData: predicate?.predicateDataBytes
|
1942
1864
|
};
|
1943
1865
|
this.pushInput(input);
|
1944
1866
|
this.addChangeOutput(owner, assetId);
|
@@ -1951,11 +1873,11 @@ var BaseTransactionRequest = class {
|
|
1951
1873
|
* @param predicate - Predicate bytes.
|
1952
1874
|
* @param predicateData - Predicate data bytes.
|
1953
1875
|
*/
|
1954
|
-
addMessageInput(message) {
|
1876
|
+
addMessageInput(message, predicate) {
|
1955
1877
|
const { recipient, sender, amount } = message;
|
1956
1878
|
const assetId = import_configs7.BaseAssetId;
|
1957
1879
|
let witnessIndex;
|
1958
|
-
if (
|
1880
|
+
if (predicate) {
|
1959
1881
|
witnessIndex = 0;
|
1960
1882
|
} else {
|
1961
1883
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1969,7 +1891,9 @@ var BaseTransactionRequest = class {
|
|
1969
1891
|
sender: sender.toB256(),
|
1970
1892
|
recipient: recipient.toB256(),
|
1971
1893
|
amount,
|
1972
|
-
witnessIndex
|
1894
|
+
witnessIndex,
|
1895
|
+
predicate: predicate?.bytes,
|
1896
|
+
predicateData: predicate?.predicateDataBytes
|
1973
1897
|
};
|
1974
1898
|
this.pushInput(input);
|
1975
1899
|
this.addChangeOutput(recipient, assetId);
|
@@ -2000,6 +1924,32 @@ var BaseTransactionRequest = class {
|
|
2000
1924
|
resources.forEach((resource) => this.addResource(resource));
|
2001
1925
|
return this;
|
2002
1926
|
}
|
1927
|
+
/**
|
1928
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1929
|
+
* outputs from the related assetIds.
|
1930
|
+
*
|
1931
|
+
* @param resources - The resources to add.
|
1932
|
+
* @returns This transaction.
|
1933
|
+
*/
|
1934
|
+
addPredicateResource(resource, predicate) {
|
1935
|
+
if (isCoin(resource)) {
|
1936
|
+
this.addCoinInput(resource, predicate);
|
1937
|
+
} else {
|
1938
|
+
this.addMessageInput(resource, predicate);
|
1939
|
+
}
|
1940
|
+
return this;
|
1941
|
+
}
|
1942
|
+
/**
|
1943
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1944
|
+
* from the related assetIds.
|
1945
|
+
*
|
1946
|
+
* @param resources - The resources to add.
|
1947
|
+
* @returns This transaction.
|
1948
|
+
*/
|
1949
|
+
addPredicateResources(resources, predicate) {
|
1950
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1951
|
+
return this;
|
1952
|
+
}
|
2003
1953
|
/**
|
2004
1954
|
* Adds a coin output to the transaction.
|
2005
1955
|
*
|
@@ -2079,7 +2029,7 @@ var BaseTransactionRequest = class {
|
|
2079
2029
|
}
|
2080
2030
|
calculateMaxGas(chainInfo, minGas) {
|
2081
2031
|
const { consensusParameters } = chainInfo;
|
2082
|
-
const { gasPerByte
|
2032
|
+
const { gasPerByte } = consensusParameters;
|
2083
2033
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2084
2034
|
(acc, wit) => acc + wit.dataLength,
|
2085
2035
|
0
|
@@ -2088,8 +2038,7 @@ var BaseTransactionRequest = class {
|
|
2088
2038
|
gasPerByte,
|
2089
2039
|
minGas,
|
2090
2040
|
witnessesLength,
|
2091
|
-
witnessLimit: this.witnessLimit
|
2092
|
-
maxGasPerTx
|
2041
|
+
witnessLimit: this.witnessLimit
|
2093
2042
|
});
|
2094
2043
|
}
|
2095
2044
|
/**
|
@@ -2107,20 +2056,17 @@ var BaseTransactionRequest = class {
|
|
2107
2056
|
});
|
2108
2057
|
const updateAssetInput = (assetId, quantity) => {
|
2109
2058
|
const assetInput = findAssetInput(assetId);
|
2110
|
-
let usedQuantity = quantity;
|
2111
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2112
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2113
|
-
}
|
2114
2059
|
if (assetInput && "assetId" in assetInput) {
|
2115
|
-
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(
|
2116
|
-
assetInput.amount =
|
2060
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33));
|
2061
|
+
assetInput.amount = quantity;
|
2117
2062
|
} else {
|
2118
2063
|
this.addResources([
|
2119
2064
|
{
|
2120
|
-
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(
|
2121
|
-
amount:
|
2065
|
+
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33)),
|
2066
|
+
amount: quantity,
|
2122
2067
|
assetId,
|
2123
2068
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2069
|
+
maturity: 0,
|
2124
2070
|
blockCreated: (0, import_math7.bn)(1),
|
2125
2071
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2126
2072
|
}
|
@@ -2152,7 +2098,7 @@ var BaseTransactionRequest = class {
|
|
2152
2098
|
toJSON() {
|
2153
2099
|
return normalizeJSON(this);
|
2154
2100
|
}
|
2155
|
-
|
2101
|
+
updatePredicateInputs(inputs) {
|
2156
2102
|
this.inputs.forEach((i) => {
|
2157
2103
|
let correspondingInput;
|
2158
2104
|
switch (i.type) {
|
@@ -2174,15 +2120,6 @@ var BaseTransactionRequest = class {
|
|
2174
2120
|
}
|
2175
2121
|
});
|
2176
2122
|
}
|
2177
|
-
shiftPredicateData() {
|
2178
|
-
this.inputs.forEach((input) => {
|
2179
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2180
|
-
input.predicateData = input.paddPredicateData(
|
2181
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2182
|
-
);
|
2183
|
-
}
|
2184
|
-
});
|
2185
|
-
}
|
2186
2123
|
};
|
2187
2124
|
|
2188
2125
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2329,8 +2266,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2329
2266
|
return {
|
2330
2267
|
type: import_transactions8.TransactionType.Create,
|
2331
2268
|
...baseTransaction,
|
2269
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2332
2270
|
bytecodeWitnessIndex,
|
2333
|
-
storageSlotsCount:
|
2271
|
+
storageSlotsCount: storageSlots.length,
|
2334
2272
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2335
2273
|
storageSlots
|
2336
2274
|
};
|
@@ -2453,8 +2391,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2453
2391
|
type: import_transactions9.TransactionType.Script,
|
2454
2392
|
scriptGasLimit: this.gasLimit,
|
2455
2393
|
...super.getBaseTransaction(),
|
2456
|
-
scriptLength:
|
2457
|
-
scriptDataLength:
|
2394
|
+
scriptLength: script.length,
|
2395
|
+
scriptDataLength: scriptData.length,
|
2458
2396
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2459
2397
|
script: (0, import_utils15.hexlify)(script),
|
2460
2398
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2518,7 +2456,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2518
2456
|
}
|
2519
2457
|
calculateMaxGas(chainInfo, minGas) {
|
2520
2458
|
const { consensusParameters } = chainInfo;
|
2521
|
-
const { gasPerByte
|
2459
|
+
const { gasPerByte } = consensusParameters;
|
2522
2460
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2523
2461
|
(acc, wit) => acc + wit.dataLength,
|
2524
2462
|
0
|
@@ -2528,8 +2466,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2528
2466
|
minGas,
|
2529
2467
|
witnessesLength,
|
2530
2468
|
witnessLimit: this.witnessLimit,
|
2531
|
-
gasLimit: this.gasLimit
|
2532
|
-
maxGasPerTx
|
2469
|
+
gasLimit: this.gasLimit
|
2533
2470
|
});
|
2534
2471
|
}
|
2535
2472
|
/**
|
@@ -2604,32 +2541,15 @@ var transactionRequestify = (obj) => {
|
|
2604
2541
|
}
|
2605
2542
|
}
|
2606
2543
|
};
|
2607
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2608
|
-
(acc, input) => {
|
2609
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2610
|
-
acc.utxos.push(input.id);
|
2611
|
-
}
|
2612
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2613
|
-
acc.messages.push(input.nonce);
|
2614
|
-
}
|
2615
|
-
return acc;
|
2616
|
-
},
|
2617
|
-
{
|
2618
|
-
utxos: [],
|
2619
|
-
messages: []
|
2620
|
-
}
|
2621
|
-
);
|
2622
2544
|
|
2623
2545
|
// src/providers/transaction-response/transaction-response.ts
|
2624
2546
|
var import_errors13 = require("@fuel-ts/errors");
|
2625
|
-
var
|
2626
|
-
var
|
2627
|
-
var
|
2547
|
+
var import_math14 = require("@fuel-ts/math");
|
2548
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2549
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2628
2550
|
|
2629
2551
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2630
|
-
var
|
2631
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2632
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2552
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2633
2553
|
|
2634
2554
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2635
2555
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2637,10 +2557,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2637
2557
|
var import_utils16 = require("@fuel-ts/utils");
|
2638
2558
|
var calculateTransactionFee = (params) => {
|
2639
2559
|
const {
|
2640
|
-
|
2560
|
+
gasUsed,
|
2641
2561
|
rawPayload,
|
2642
|
-
|
2643
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2562
|
+
consensusParameters: { gasCosts, feeParams }
|
2644
2563
|
} = params;
|
2645
2564
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2646
2565
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2650,7 +2569,8 @@ var calculateTransactionFee = (params) => {
|
|
2650
2569
|
return {
|
2651
2570
|
fee: (0, import_math11.bn)(0),
|
2652
2571
|
minFee: (0, import_math11.bn)(0),
|
2653
|
-
maxFee: (0, import_math11.bn)(0)
|
2572
|
+
maxFee: (0, import_math11.bn)(0),
|
2573
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2654
2574
|
};
|
2655
2575
|
}
|
2656
2576
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2682,6 +2602,7 @@ var calculateTransactionFee = (params) => {
|
|
2682
2602
|
metadataGas,
|
2683
2603
|
txBytesSize: transactionBytes.length
|
2684
2604
|
});
|
2605
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2685
2606
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2686
2607
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2687
2608
|
const maxGas = getMaxGas({
|
@@ -2689,25 +2610,17 @@ var calculateTransactionFee = (params) => {
|
|
2689
2610
|
minGas,
|
2690
2611
|
witnessesLength,
|
2691
2612
|
gasLimit,
|
2692
|
-
witnessLimit
|
2693
|
-
maxGasPerTx
|
2694
|
-
});
|
2695
|
-
const minFee = calculateGasFee({
|
2696
|
-
gasPrice,
|
2697
|
-
gas: minGas,
|
2698
|
-
priceFactor: gasPriceFactor,
|
2699
|
-
tip
|
2700
|
-
});
|
2701
|
-
const maxFee = calculateGasFee({
|
2702
|
-
gasPrice,
|
2703
|
-
gas: maxGas,
|
2704
|
-
priceFactor: gasPriceFactor,
|
2705
|
-
tip
|
2613
|
+
witnessLimit
|
2706
2614
|
});
|
2615
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2616
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2617
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2618
|
+
const fee = minFee.add(feeFromGasUsed);
|
2707
2619
|
return {
|
2620
|
+
fee,
|
2708
2621
|
minFee,
|
2709
2622
|
maxFee,
|
2710
|
-
|
2623
|
+
feeFromGasUsed
|
2711
2624
|
};
|
2712
2625
|
};
|
2713
2626
|
|
@@ -3274,12 +3187,10 @@ function assembleTransactionSummary(params) {
|
|
3274
3187
|
gqlTransactionStatus,
|
3275
3188
|
abiMap = {},
|
3276
3189
|
maxInputs,
|
3277
|
-
gasCosts
|
3278
|
-
maxGasPerTx,
|
3279
|
-
gasPrice
|
3190
|
+
gasCosts
|
3280
3191
|
} = params;
|
3281
3192
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3282
|
-
const rawPayload = (0,
|
3193
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3283
3194
|
const operations = getOperations({
|
3284
3195
|
transactionType: transaction.type,
|
3285
3196
|
inputs: transaction.inputs || [],
|
@@ -3290,14 +3201,11 @@ function assembleTransactionSummary(params) {
|
|
3290
3201
|
maxInputs
|
3291
3202
|
});
|
3292
3203
|
const typeName = getTransactionTypeName(transaction.type);
|
3293
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3294
3204
|
const { fee } = calculateTransactionFee({
|
3295
|
-
|
3205
|
+
gasUsed,
|
3296
3206
|
rawPayload,
|
3297
|
-
tip,
|
3298
3207
|
consensusParameters: {
|
3299
3208
|
gasCosts,
|
3300
|
-
maxGasPerTx,
|
3301
3209
|
feeParams: {
|
3302
3210
|
gasPerByte,
|
3303
3211
|
gasPriceFactor
|
@@ -3309,7 +3217,7 @@ function assembleTransactionSummary(params) {
|
|
3309
3217
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3310
3218
|
let date;
|
3311
3219
|
if (time) {
|
3312
|
-
date =
|
3220
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3313
3221
|
}
|
3314
3222
|
const transactionSummary = {
|
3315
3223
|
id,
|
@@ -3337,12 +3245,12 @@ function assembleTransactionSummary(params) {
|
|
3337
3245
|
|
3338
3246
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3339
3247
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3340
|
-
var
|
3248
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3341
3249
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3342
3250
|
return receipts.reduce((logs, receipt) => {
|
3343
|
-
if (receipt.type ===
|
3251
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3344
3252
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3345
|
-
const data = receipt.type ===
|
3253
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3346
3254
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3347
3255
|
logs.push(decodedLog);
|
3348
3256
|
}
|
@@ -3357,7 +3265,7 @@ var TransactionResponse = class {
|
|
3357
3265
|
/** Current provider */
|
3358
3266
|
provider;
|
3359
3267
|
/** Gas used on the transaction */
|
3360
|
-
gasUsed = (0,
|
3268
|
+
gasUsed = (0, import_math14.bn)(0);
|
3361
3269
|
/** The graphql Transaction with receipts object. */
|
3362
3270
|
gqlTransaction;
|
3363
3271
|
abis;
|
@@ -3415,8 +3323,8 @@ var TransactionResponse = class {
|
|
3415
3323
|
* @returns The decoded transaction.
|
3416
3324
|
*/
|
3417
3325
|
decodeTransaction(transactionWithReceipts) {
|
3418
|
-
return new
|
3419
|
-
(0,
|
3326
|
+
return new import_transactions17.TransactionCoder().decode(
|
3327
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3420
3328
|
0
|
3421
3329
|
)?.[0];
|
3422
3330
|
}
|
@@ -3435,27 +3343,20 @@ var TransactionResponse = class {
|
|
3435
3343
|
const decodedTransaction = this.decodeTransaction(
|
3436
3344
|
transaction
|
3437
3345
|
);
|
3438
|
-
|
3439
|
-
|
3440
|
-
txReceipts = transaction.status.receipts;
|
3441
|
-
}
|
3442
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3443
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3444
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3346
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3347
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3445
3348
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3446
3349
|
const transactionSummary = assembleTransactionSummary({
|
3447
3350
|
id: this.id,
|
3448
3351
|
receipts,
|
3449
3352
|
transaction: decodedTransaction,
|
3450
|
-
transactionBytes: (0,
|
3353
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3451
3354
|
gqlTransactionStatus: transaction.status,
|
3452
3355
|
gasPerByte,
|
3453
3356
|
gasPriceFactor,
|
3454
3357
|
abiMap: contractsAbiMap,
|
3455
3358
|
maxInputs,
|
3456
|
-
gasCosts
|
3457
|
-
maxGasPerTx,
|
3458
|
-
gasPrice
|
3359
|
+
gasCosts
|
3459
3360
|
});
|
3460
3361
|
return transactionSummary;
|
3461
3362
|
}
|
@@ -3582,29 +3483,29 @@ var processGqlChain = (chain) => {
|
|
3582
3483
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3583
3484
|
return {
|
3584
3485
|
name,
|
3585
|
-
baseChainHeight: (0,
|
3486
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3586
3487
|
consensusParameters: {
|
3587
|
-
contractMaxSize: (0,
|
3588
|
-
maxInputs: (0,
|
3589
|
-
maxOutputs: (0,
|
3590
|
-
maxWitnesses: (0,
|
3591
|
-
maxGasPerTx: (0,
|
3592
|
-
maxScriptLength: (0,
|
3593
|
-
maxScriptDataLength: (0,
|
3594
|
-
maxStorageSlots: (0,
|
3595
|
-
maxPredicateLength: (0,
|
3596
|
-
maxPredicateDataLength: (0,
|
3597
|
-
maxGasPerPredicate: (0,
|
3598
|
-
gasPriceFactor: (0,
|
3599
|
-
gasPerByte: (0,
|
3600
|
-
maxMessageDataLength: (0,
|
3601
|
-
chainId: (0,
|
3488
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3489
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3490
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3491
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3492
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3493
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3494
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3495
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3496
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3497
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3498
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3499
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3500
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3501
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3502
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3602
3503
|
gasCosts
|
3603
3504
|
},
|
3604
3505
|
gasCosts,
|
3605
3506
|
latestBlock: {
|
3606
3507
|
id: latestBlock.id,
|
3607
|
-
height: (0,
|
3508
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3608
3509
|
time: latestBlock.header.time,
|
3609
3510
|
transactions: latestBlock.transactions.map((i) => ({
|
3610
3511
|
id: i.id
|
@@ -3698,8 +3599,10 @@ var _Provider = class {
|
|
3698
3599
|
* Returns some helpful parameters related to gas fees.
|
3699
3600
|
*/
|
3700
3601
|
getGasConfig() {
|
3602
|
+
const { minGasPrice } = this.getNode();
|
3701
3603
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3702
3604
|
return {
|
3605
|
+
minGasPrice,
|
3703
3606
|
maxGasPerTx,
|
3704
3607
|
maxGasPerPredicate,
|
3705
3608
|
gasPriceFactor,
|
@@ -3797,7 +3700,7 @@ var _Provider = class {
|
|
3797
3700
|
*/
|
3798
3701
|
async getBlockNumber() {
|
3799
3702
|
const { chain } = await this.operations.getChain();
|
3800
|
-
return (0,
|
3703
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3801
3704
|
}
|
3802
3705
|
/**
|
3803
3706
|
* Returns the chain information.
|
@@ -3807,11 +3710,13 @@ var _Provider = class {
|
|
3807
3710
|
async fetchNode() {
|
3808
3711
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3809
3712
|
const processedNodeInfo = {
|
3810
|
-
maxDepth: (0,
|
3811
|
-
maxTx: (0,
|
3713
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3714
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3715
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3812
3716
|
nodeVersion: nodeInfo.nodeVersion,
|
3813
3717
|
utxoValidation: nodeInfo.utxoValidation,
|
3814
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3718
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3719
|
+
peers: nodeInfo.peers
|
3815
3720
|
};
|
3816
3721
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3817
3722
|
return processedNodeInfo;
|
@@ -3853,9 +3758,9 @@ var _Provider = class {
|
|
3853
3758
|
if (estimateTxDependencies) {
|
3854
3759
|
await this.estimateTxDependencies(transactionRequest);
|
3855
3760
|
}
|
3856
|
-
const encodedTransaction = (0,
|
3761
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3857
3762
|
let abis;
|
3858
|
-
if (transactionRequest.type ===
|
3763
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3859
3764
|
abis = transactionRequest.abis;
|
3860
3765
|
}
|
3861
3766
|
if (awaitExecution) {
|
@@ -3896,14 +3801,15 @@ var _Provider = class {
|
|
3896
3801
|
if (estimateTxDependencies) {
|
3897
3802
|
return this.estimateTxDependencies(transactionRequest);
|
3898
3803
|
}
|
3899
|
-
const encodedTransaction = (0,
|
3900
|
-
const { dryRun:
|
3901
|
-
|
3804
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3805
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3806
|
+
encodedTransaction,
|
3902
3807
|
utxoValidation: utxoValidation || false
|
3903
3808
|
});
|
3904
|
-
const
|
3905
|
-
|
3906
|
-
|
3809
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3810
|
+
return {
|
3811
|
+
receipts
|
3812
|
+
};
|
3907
3813
|
}
|
3908
3814
|
/**
|
3909
3815
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3914,13 +3820,13 @@ var _Provider = class {
|
|
3914
3820
|
async estimatePredicates(transactionRequest) {
|
3915
3821
|
const shouldEstimatePredicates = Boolean(
|
3916
3822
|
transactionRequest.inputs.find(
|
3917
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3823
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
|
3918
3824
|
)
|
3919
3825
|
);
|
3920
3826
|
if (!shouldEstimatePredicates) {
|
3921
3827
|
return transactionRequest;
|
3922
3828
|
}
|
3923
|
-
const encodedTransaction = (0,
|
3829
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3924
3830
|
const response = await this.operations.estimatePredicates({
|
3925
3831
|
encodedTransaction
|
3926
3832
|
});
|
@@ -3929,7 +3835,7 @@ var _Provider = class {
|
|
3929
3835
|
} = response;
|
3930
3836
|
if (inputs) {
|
3931
3837
|
inputs.forEach((input, index) => {
|
3932
|
-
if ("predicateGasUsed" in input && (0,
|
3838
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3933
3839
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3934
3840
|
}
|
3935
3841
|
});
|
@@ -3942,31 +3848,31 @@ var _Provider = class {
|
|
3942
3848
|
* If there are missing variable outputs,
|
3943
3849
|
* `addVariableOutputs` is called on the transaction.
|
3944
3850
|
*
|
3851
|
+
* @privateRemarks
|
3852
|
+
* TODO: Investigate support for missing contract IDs
|
3853
|
+
* TODO: Add support for missing output messages
|
3945
3854
|
*
|
3946
3855
|
* @param transactionRequest - The transaction request object.
|
3947
3856
|
* @returns A promise.
|
3948
3857
|
*/
|
3949
3858
|
async estimateTxDependencies(transactionRequest) {
|
3950
|
-
if (transactionRequest.type ===
|
3859
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3951
3860
|
return {
|
3952
3861
|
receipts: [],
|
3953
3862
|
outputVariables: 0,
|
3954
3863
|
missingContractIds: []
|
3955
3864
|
};
|
3956
3865
|
}
|
3866
|
+
await this.estimatePredicates(transactionRequest);
|
3957
3867
|
let receipts = [];
|
3958
3868
|
const missingContractIds = [];
|
3959
3869
|
let outputVariables = 0;
|
3960
|
-
let dryrunStatus;
|
3961
3870
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3962
|
-
const {
|
3963
|
-
|
3964
|
-
} = await this.operations.dryRun({
|
3965
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3871
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3872
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3966
3873
|
utxoValidation: false
|
3967
3874
|
});
|
3968
|
-
receipts =
|
3969
|
-
dryrunStatus = status;
|
3875
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3970
3876
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3971
3877
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3972
3878
|
if (hasMissingOutputs) {
|
@@ -3976,11 +3882,6 @@ var _Provider = class {
|
|
3976
3882
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3977
3883
|
missingContractIds.push(contractId);
|
3978
3884
|
});
|
3979
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3980
|
-
transactionRequest,
|
3981
|
-
optimizeGas: false
|
3982
|
-
});
|
3983
|
-
transactionRequest.maxFee = maxFee;
|
3984
3885
|
} else {
|
3985
3886
|
break;
|
3986
3887
|
}
|
@@ -3988,133 +3889,38 @@ var _Provider = class {
|
|
3988
3889
|
return {
|
3989
3890
|
receipts,
|
3990
3891
|
outputVariables,
|
3991
|
-
missingContractIds
|
3992
|
-
dryrunStatus
|
3892
|
+
missingContractIds
|
3993
3893
|
};
|
3994
3894
|
}
|
3995
3895
|
/**
|
3996
|
-
*
|
3997
|
-
*
|
3998
|
-
*
|
3999
|
-
*
|
4000
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4001
|
-
*
|
4002
|
-
* @param transactionRequests - Array of transaction request objects.
|
4003
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
3896
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3897
|
+
* @param transactionRequest - The transaction request object.
|
3898
|
+
* @param optimizeGas - Optional. Specifies whether to optimize the gas. Default is false.
|
3899
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4004
3900
|
*/
|
4005
|
-
|
4006
|
-
const
|
4007
|
-
|
4008
|
-
outputVariables: 0,
|
4009
|
-
missingContractIds: [],
|
4010
|
-
dryrunStatus: void 0
|
4011
|
-
}));
|
4012
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4013
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4014
|
-
allRequests.forEach((req, index) => {
|
4015
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4016
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4017
|
-
}
|
4018
|
-
});
|
4019
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4020
|
-
let attempt = 0;
|
4021
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4022
|
-
const encodedTransactions = transactionsToProcess.map(
|
4023
|
-
(index) => serializedTransactionsMap.get(index)
|
4024
|
-
);
|
4025
|
-
const dryRunResults = await this.operations.dryRun({
|
4026
|
-
encodedTransactions,
|
4027
|
-
utxoValidation: false
|
4028
|
-
});
|
4029
|
-
const nextRoundTransactions = [];
|
4030
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4031
|
-
const currentResultIndex = transactionsToProcess[i];
|
4032
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4033
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4034
|
-
results[currentResultIndex].dryrunStatus = status;
|
4035
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4036
|
-
results[currentResultIndex].receipts
|
4037
|
-
);
|
4038
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4039
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4040
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4041
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4042
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4043
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4044
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4045
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4046
|
-
});
|
4047
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4048
|
-
transactionRequest: requestToProcess,
|
4049
|
-
optimizeGas: false
|
4050
|
-
});
|
4051
|
-
requestToProcess.maxFee = maxFee;
|
4052
|
-
serializedTransactionsMap.set(
|
4053
|
-
currentResultIndex,
|
4054
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4055
|
-
);
|
4056
|
-
nextRoundTransactions.push(currentResultIndex);
|
4057
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4058
|
-
}
|
4059
|
-
}
|
4060
|
-
transactionsToProcess = nextRoundTransactions;
|
4061
|
-
attempt += 1;
|
4062
|
-
}
|
4063
|
-
return results;
|
4064
|
-
}
|
4065
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4066
|
-
if (estimateTxDependencies) {
|
4067
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4068
|
-
}
|
4069
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4070
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4071
|
-
encodedTransactions,
|
4072
|
-
utxoValidation: utxoValidation || false
|
4073
|
-
});
|
4074
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4075
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4076
|
-
return { receipts, dryrunStatus: status };
|
4077
|
-
});
|
4078
|
-
return results;
|
4079
|
-
}
|
4080
|
-
async estimateTxGasAndFee(params) {
|
4081
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4082
|
-
let { gasPrice } = params;
|
3901
|
+
estimateTxGasAndFee(params) {
|
3902
|
+
const { transactionRequest } = params;
|
3903
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4083
3904
|
const chainInfo = this.getChain();
|
4084
|
-
const
|
3905
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3906
|
+
transactionRequest.gasPrice = gasPrice;
|
4085
3907
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4086
|
-
|
4087
|
-
|
4088
|
-
|
4089
|
-
const minFee = calculateGasFee({
|
4090
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4091
|
-
gas: minGas,
|
4092
|
-
priceFactor: gasPriceFactor,
|
4093
|
-
tip: transactionRequest.tip
|
4094
|
-
}).add(1);
|
4095
|
-
let gasLimit = (0, import_math16.bn)(0);
|
4096
|
-
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4097
|
-
gasLimit = transactionRequest.gasLimit;
|
4098
|
-
if (!optimizeGas) {
|
3908
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3909
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3910
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4099
3911
|
transactionRequest.gasLimit = minGas;
|
4100
|
-
gasLimit =
|
4101
|
-
|
3912
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3913
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3914
|
+
);
|
4102
3915
|
}
|
4103
3916
|
}
|
4104
3917
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4105
|
-
const maxFee =
|
4106
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4107
|
-
gas: maxGas,
|
4108
|
-
priceFactor: gasPriceFactor,
|
4109
|
-
tip: transactionRequest.tip
|
4110
|
-
}).add(1);
|
3918
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4111
3919
|
return {
|
4112
3920
|
minGas,
|
4113
3921
|
minFee,
|
4114
3922
|
maxGas,
|
4115
|
-
maxFee
|
4116
|
-
gasPrice,
|
4117
|
-
gasLimit
|
3923
|
+
maxFee
|
4118
3924
|
};
|
4119
3925
|
}
|
4120
3926
|
/**
|
@@ -4132,17 +3938,15 @@ var _Provider = class {
|
|
4132
3938
|
if (estimateTxDependencies) {
|
4133
3939
|
return this.estimateTxDependencies(transactionRequest);
|
4134
3940
|
}
|
4135
|
-
const
|
4136
|
-
const { dryRun:
|
4137
|
-
|
3941
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3942
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3943
|
+
encodedTransaction,
|
4138
3944
|
utxoValidation: true
|
4139
3945
|
});
|
4140
|
-
const
|
4141
|
-
|
4142
|
-
|
4143
|
-
|
4144
|
-
});
|
4145
|
-
return { receipts: callResult[0].receipts };
|
3946
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3947
|
+
return {
|
3948
|
+
receipts
|
3949
|
+
};
|
4146
3950
|
}
|
4147
3951
|
/**
|
4148
3952
|
* Returns a transaction cost to enable user
|
@@ -4159,80 +3963,77 @@ var _Provider = class {
|
|
4159
3963
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4160
3964
|
* @returns A promise that resolves to the transaction cost object.
|
4161
3965
|
*/
|
4162
|
-
async getTransactionCost(transactionRequestLike,
|
3966
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3967
|
+
estimateTxDependencies = true,
|
3968
|
+
estimatePredicates = true,
|
3969
|
+
resourcesOwner,
|
3970
|
+
signatureCallback
|
3971
|
+
} = {}) {
|
4163
3972
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4164
|
-
const
|
3973
|
+
const { minGasPrice } = this.getGasConfig();
|
3974
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3975
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4165
3976
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4166
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3977
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4167
3978
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4168
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4169
3979
|
if (isScriptTransaction) {
|
4170
|
-
txRequestClone.gasLimit = (0,
|
3980
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4171
3981
|
}
|
4172
|
-
if (
|
4173
|
-
resourcesOwner
|
3982
|
+
if (estimatePredicates) {
|
3983
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3984
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3985
|
+
}
|
3986
|
+
await this.estimatePredicates(txRequestClone);
|
4174
3987
|
}
|
4175
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4176
|
-
let addedSignatures = 0;
|
4177
3988
|
if (signatureCallback && isScriptTransaction) {
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4182
|
-
await this.estimatePredicates(signedRequest);
|
4183
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4184
|
-
transactionRequest: signedRequest,
|
4185
|
-
optimizeGas: false
|
3989
|
+
await signatureCallback(txRequestClone);
|
3990
|
+
}
|
3991
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3992
|
+
transactionRequest: txRequestClone
|
4186
3993
|
});
|
4187
|
-
txRequestClone.maxFee = maxFee;
|
4188
3994
|
let receipts = [];
|
4189
3995
|
let missingContractIds = [];
|
4190
3996
|
let outputVariables = 0;
|
4191
|
-
let gasUsed = (0,
|
4192
|
-
|
4193
|
-
|
4194
|
-
if (signatureCallback) {
|
4195
|
-
await signatureCallback(txRequestClone);
|
4196
|
-
}
|
4197
|
-
txRequestClone.gasLimit = gasLimit;
|
3997
|
+
let gasUsed = (0, import_math15.bn)(0);
|
3998
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3999
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4198
4000
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4199
4001
|
receipts = result.receipts;
|
4200
4002
|
outputVariables = result.outputVariables;
|
4201
4003
|
missingContractIds = result.missingContractIds;
|
4202
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4004
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4203
4005
|
txRequestClone.gasLimit = gasUsed;
|
4204
|
-
|
4205
|
-
|
4206
|
-
|
4006
|
+
txRequestClone.gasPrice = setGasPrice;
|
4007
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4008
|
+
transactionRequest: txRequestClone
|
4207
4009
|
}));
|
4208
4010
|
}
|
4209
4011
|
return {
|
4210
4012
|
requiredQuantities: allQuantities,
|
4211
4013
|
receipts,
|
4212
4014
|
gasUsed,
|
4213
|
-
|
4015
|
+
minGasPrice,
|
4016
|
+
gasPrice: setGasPrice,
|
4214
4017
|
minGas,
|
4215
4018
|
maxGas,
|
4216
4019
|
minFee,
|
4217
4020
|
maxFee,
|
4021
|
+
estimatedInputs: txRequestClone.inputs,
|
4218
4022
|
outputVariables,
|
4219
|
-
missingContractIds
|
4220
|
-
addedSignatures,
|
4221
|
-
estimatedPredicates: txRequestClone.inputs
|
4023
|
+
missingContractIds
|
4222
4024
|
};
|
4223
4025
|
}
|
4224
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4026
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4225
4027
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4226
4028
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4227
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4228
|
-
quantitiesToContract
|
4229
|
-
});
|
4029
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4230
4030
|
transactionRequest.addResources(
|
4231
4031
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4232
4032
|
);
|
4233
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4234
|
-
|
4235
|
-
|
4033
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4034
|
+
transactionRequest,
|
4035
|
+
forwardingQuantities
|
4036
|
+
);
|
4236
4037
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4237
4038
|
return {
|
4238
4039
|
resources,
|
@@ -4248,16 +4049,17 @@ var _Provider = class {
|
|
4248
4049
|
const result = await this.operations.getCoins({
|
4249
4050
|
first: 10,
|
4250
4051
|
...paginationArgs,
|
4251
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4052
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4252
4053
|
});
|
4253
4054
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4254
4055
|
return coins.map((coin) => ({
|
4255
4056
|
id: coin.utxoId,
|
4256
4057
|
assetId: coin.assetId,
|
4257
|
-
amount: (0,
|
4058
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4258
4059
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4259
|
-
|
4260
|
-
|
4060
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4061
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4062
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4261
4063
|
}));
|
4262
4064
|
}
|
4263
4065
|
/**
|
@@ -4271,19 +4073,19 @@ var _Provider = class {
|
|
4271
4073
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4272
4074
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4273
4075
|
const excludeInput = {
|
4274
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4275
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4076
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4077
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4276
4078
|
};
|
4277
4079
|
if (this.cache) {
|
4278
4080
|
const uniqueUtxos = new Set(
|
4279
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4081
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4280
4082
|
);
|
4281
4083
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4282
4084
|
}
|
4283
4085
|
const coinsQuery = {
|
4284
4086
|
owner: ownerAddress.toB256(),
|
4285
4087
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4286
|
-
assetId: (0,
|
4088
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4287
4089
|
amount: amount.toString(10),
|
4288
4090
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4289
4091
|
})),
|
@@ -4294,9 +4096,9 @@ var _Provider = class {
|
|
4294
4096
|
switch (coin.__typename) {
|
4295
4097
|
case "MessageCoin":
|
4296
4098
|
return {
|
4297
|
-
amount: (0,
|
4099
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4298
4100
|
assetId: coin.assetId,
|
4299
|
-
daHeight: (0,
|
4101
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4300
4102
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4301
4103
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4302
4104
|
nonce: coin.nonce
|
@@ -4304,11 +4106,12 @@ var _Provider = class {
|
|
4304
4106
|
case "Coin":
|
4305
4107
|
return {
|
4306
4108
|
id: coin.utxoId,
|
4307
|
-
amount: (0,
|
4109
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4308
4110
|
assetId: coin.assetId,
|
4309
4111
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4310
|
-
|
4311
|
-
|
4112
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4113
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4114
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4312
4115
|
};
|
4313
4116
|
default:
|
4314
4117
|
return null;
|
@@ -4325,13 +4128,13 @@ var _Provider = class {
|
|
4325
4128
|
async getBlock(idOrHeight) {
|
4326
4129
|
let variables;
|
4327
4130
|
if (typeof idOrHeight === "number") {
|
4328
|
-
variables = { height: (0,
|
4131
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4329
4132
|
} else if (idOrHeight === "latest") {
|
4330
4133
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4331
4134
|
} else if (idOrHeight.length === 66) {
|
4332
4135
|
variables = { blockId: idOrHeight };
|
4333
4136
|
} else {
|
4334
|
-
variables = { blockId: (0,
|
4137
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4335
4138
|
}
|
4336
4139
|
const { block } = await this.operations.getBlock(variables);
|
4337
4140
|
if (!block) {
|
@@ -4339,7 +4142,7 @@ var _Provider = class {
|
|
4339
4142
|
}
|
4340
4143
|
return {
|
4341
4144
|
id: block.id,
|
4342
|
-
height: (0,
|
4145
|
+
height: (0, import_math15.bn)(block.header.height),
|
4343
4146
|
time: block.header.time,
|
4344
4147
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4345
4148
|
};
|
@@ -4354,7 +4157,7 @@ var _Provider = class {
|
|
4354
4157
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4355
4158
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4356
4159
|
id: block.id,
|
4357
|
-
height: (0,
|
4160
|
+
height: (0, import_math15.bn)(block.header.height),
|
4358
4161
|
time: block.header.time,
|
4359
4162
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4360
4163
|
}));
|
@@ -4369,7 +4172,7 @@ var _Provider = class {
|
|
4369
4172
|
async getBlockWithTransactions(idOrHeight) {
|
4370
4173
|
let variables;
|
4371
4174
|
if (typeof idOrHeight === "number") {
|
4372
|
-
variables = { blockHeight: (0,
|
4175
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4373
4176
|
} else if (idOrHeight === "latest") {
|
4374
4177
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4375
4178
|
} else {
|
@@ -4381,11 +4184,11 @@ var _Provider = class {
|
|
4381
4184
|
}
|
4382
4185
|
return {
|
4383
4186
|
id: block.id,
|
4384
|
-
height: (0,
|
4187
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4385
4188
|
time: block.header.time,
|
4386
4189
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4387
4190
|
transactions: block.transactions.map(
|
4388
|
-
(tx) => new
|
4191
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4389
4192
|
)
|
4390
4193
|
};
|
4391
4194
|
}
|
@@ -4400,8 +4203,8 @@ var _Provider = class {
|
|
4400
4203
|
if (!transaction) {
|
4401
4204
|
return null;
|
4402
4205
|
}
|
4403
|
-
return new
|
4404
|
-
(0,
|
4206
|
+
return new import_transactions18.TransactionCoder().decode(
|
4207
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4405
4208
|
0
|
4406
4209
|
)?.[0];
|
4407
4210
|
}
|
@@ -4428,9 +4231,9 @@ var _Provider = class {
|
|
4428
4231
|
async getContractBalance(contractId, assetId) {
|
4429
4232
|
const { contractBalance } = await this.operations.getContractBalance({
|
4430
4233
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4431
|
-
asset: (0,
|
4234
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4432
4235
|
});
|
4433
|
-
return (0,
|
4236
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4434
4237
|
}
|
4435
4238
|
/**
|
4436
4239
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4442,9 +4245,9 @@ var _Provider = class {
|
|
4442
4245
|
async getBalance(owner, assetId) {
|
4443
4246
|
const { balance } = await this.operations.getBalance({
|
4444
4247
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4445
|
-
assetId: (0,
|
4248
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4446
4249
|
});
|
4447
|
-
return (0,
|
4250
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4448
4251
|
}
|
4449
4252
|
/**
|
4450
4253
|
* Returns balances for the given owner.
|
@@ -4462,7 +4265,7 @@ var _Provider = class {
|
|
4462
4265
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4463
4266
|
return balances.map((balance) => ({
|
4464
4267
|
assetId: balance.assetId,
|
4465
|
-
amount: (0,
|
4268
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4466
4269
|
}));
|
4467
4270
|
}
|
4468
4271
|
/**
|
@@ -4480,19 +4283,19 @@ var _Provider = class {
|
|
4480
4283
|
});
|
4481
4284
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4482
4285
|
return messages.map((message) => ({
|
4483
|
-
messageId:
|
4286
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4484
4287
|
sender: message.sender,
|
4485
4288
|
recipient: message.recipient,
|
4486
4289
|
nonce: message.nonce,
|
4487
|
-
amount: (0,
|
4290
|
+
amount: (0, import_math15.bn)(message.amount),
|
4488
4291
|
data: message.data
|
4489
4292
|
}),
|
4490
4293
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4491
4294
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4492
4295
|
nonce: message.nonce,
|
4493
|
-
amount: (0,
|
4494
|
-
data:
|
4495
|
-
daHeight: (0,
|
4296
|
+
amount: (0, import_math15.bn)(message.amount),
|
4297
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4298
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4496
4299
|
}));
|
4497
4300
|
}
|
4498
4301
|
/**
|
@@ -4545,52 +4348,44 @@ var _Provider = class {
|
|
4545
4348
|
} = result.messageProof;
|
4546
4349
|
return {
|
4547
4350
|
messageProof: {
|
4548
|
-
proofIndex: (0,
|
4351
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4549
4352
|
proofSet: messageProof.proofSet
|
4550
4353
|
},
|
4551
4354
|
blockProof: {
|
4552
|
-
proofIndex: (0,
|
4355
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4553
4356
|
proofSet: blockProof.proofSet
|
4554
4357
|
},
|
4555
4358
|
messageBlockHeader: {
|
4556
4359
|
id: messageBlockHeader.id,
|
4557
|
-
daHeight: (0,
|
4558
|
-
transactionsCount: (0,
|
4360
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4361
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4559
4362
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4560
|
-
height: (0,
|
4363
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4561
4364
|
prevRoot: messageBlockHeader.prevRoot,
|
4562
4365
|
time: messageBlockHeader.time,
|
4563
4366
|
applicationHash: messageBlockHeader.applicationHash,
|
4564
|
-
|
4367
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4368
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4565
4369
|
},
|
4566
4370
|
commitBlockHeader: {
|
4567
4371
|
id: commitBlockHeader.id,
|
4568
|
-
daHeight: (0,
|
4569
|
-
transactionsCount: (0,
|
4372
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4373
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4570
4374
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4571
|
-
height: (0,
|
4375
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4572
4376
|
prevRoot: commitBlockHeader.prevRoot,
|
4573
4377
|
time: commitBlockHeader.time,
|
4574
4378
|
applicationHash: commitBlockHeader.applicationHash,
|
4575
|
-
|
4379
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4380
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4576
4381
|
},
|
4577
4382
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4578
4383
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4579
4384
|
nonce,
|
4580
|
-
amount: (0,
|
4385
|
+
amount: (0, import_math15.bn)(amount),
|
4581
4386
|
data
|
4582
4387
|
};
|
4583
4388
|
}
|
4584
|
-
async getLatestGasPrice() {
|
4585
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4586
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4587
|
-
}
|
4588
|
-
async estimateGasPrice(blockHorizon) {
|
4589
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4590
|
-
blockHorizon: String(blockHorizon)
|
4591
|
-
});
|
4592
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4593
|
-
}
|
4594
4389
|
/**
|
4595
4390
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4596
4391
|
*
|
@@ -4610,10 +4405,10 @@ var _Provider = class {
|
|
4610
4405
|
*/
|
4611
4406
|
async produceBlocks(amount, startTime) {
|
4612
4407
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4613
|
-
blocksToProduce: (0,
|
4614
|
-
startTimestamp: startTime ?
|
4408
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4409
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4615
4410
|
});
|
4616
|
-
return (0,
|
4411
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4617
4412
|
}
|
4618
4413
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4619
4414
|
async getTransactionResponse(transactionId) {
|
@@ -4627,7 +4422,7 @@ cacheInputs_fn = function(inputs) {
|
|
4627
4422
|
return;
|
4628
4423
|
}
|
4629
4424
|
inputs.forEach((input) => {
|
4630
|
-
if (input.type ===
|
4425
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4631
4426
|
this.cache?.set(input.id);
|
4632
4427
|
}
|
4633
4428
|
});
|
@@ -4637,9 +4432,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4637
4432
|
|
4638
4433
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4639
4434
|
var import_errors15 = require("@fuel-ts/errors");
|
4640
|
-
var
|
4641
|
-
var
|
4642
|
-
var
|
4435
|
+
var import_math16 = require("@fuel-ts/math");
|
4436
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4437
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4643
4438
|
|
4644
4439
|
// src/providers/chains.ts
|
4645
4440
|
var CHAIN_IDS = {
|
@@ -4688,17 +4483,17 @@ var assets = [
|
|
4688
4483
|
|
4689
4484
|
// src/utils/formatTransferToContractScriptData.ts
|
4690
4485
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4691
|
-
var
|
4692
|
-
var
|
4486
|
+
var import_math17 = require("@fuel-ts/math");
|
4487
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4693
4488
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4694
4489
|
var formatTransferToContractScriptData = (params) => {
|
4695
4490
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4696
4491
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4697
|
-
const encoded = numberCoder.encode(new
|
4492
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4698
4493
|
const scriptData = Uint8Array.from([
|
4699
|
-
...(0,
|
4494
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4700
4495
|
...encoded,
|
4701
|
-
...(0,
|
4496
|
+
...(0, import_utils27.arrayify)(assetId)
|
4702
4497
|
]);
|
4703
4498
|
return scriptData;
|
4704
4499
|
};
|
@@ -4883,33 +4678,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4883
4678
|
* @param fee - The estimated transaction fee.
|
4884
4679
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4885
4680
|
*/
|
4886
|
-
async fund(request,
|
4887
|
-
const
|
4888
|
-
|
4889
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4890
|
-
amount: (0, import_math19.bn)(fee),
|
4681
|
+
async fund(request, coinQuantities, fee) {
|
4682
|
+
const updatedQuantities = addAmountToAsset({
|
4683
|
+
amount: (0, import_math18.bn)(fee),
|
4891
4684
|
assetId: import_configs12.BaseAssetId,
|
4892
|
-
coinQuantities
|
4685
|
+
coinQuantities
|
4893
4686
|
});
|
4894
4687
|
const quantitiesDict = {};
|
4895
|
-
|
4688
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4896
4689
|
quantitiesDict[assetId] = {
|
4897
4690
|
required: amount,
|
4898
|
-
owned: (0,
|
4691
|
+
owned: (0, import_math18.bn)(0)
|
4899
4692
|
};
|
4900
4693
|
});
|
4901
|
-
|
4694
|
+
const cachedUtxos = [];
|
4695
|
+
const cachedMessages = [];
|
4696
|
+
const owner = this.address.toB256();
|
4697
|
+
request.inputs.forEach((input) => {
|
4902
4698
|
const isResource = "amount" in input;
|
4903
4699
|
if (isResource) {
|
4904
4700
|
const isCoin2 = "owner" in input;
|
4905
4701
|
if (isCoin2) {
|
4906
4702
|
const assetId = String(input.assetId);
|
4907
|
-
if (quantitiesDict[assetId]) {
|
4908
|
-
const amount = (0,
|
4703
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4704
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4909
4705
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4706
|
+
cachedUtxos.push(input.id);
|
4910
4707
|
}
|
4911
|
-
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4708
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4912
4709
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4710
|
+
cachedMessages.push(input.nonce);
|
4913
4711
|
}
|
4914
4712
|
}
|
4915
4713
|
});
|
@@ -4924,23 +4722,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4924
4722
|
});
|
4925
4723
|
const needsToBeFunded = missingQuantities.length;
|
4926
4724
|
if (needsToBeFunded) {
|
4927
|
-
const
|
4928
|
-
|
4929
|
-
|
4930
|
-
|
4931
|
-
|
4932
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4933
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4934
|
-
if (addedSignatures) {
|
4935
|
-
Array.from({ length: addedSignatures }).forEach(
|
4936
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4937
|
-
);
|
4725
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4726
|
+
messages: cachedMessages,
|
4727
|
+
utxos: cachedUtxos
|
4728
|
+
});
|
4729
|
+
request.addResources(resources);
|
4938
4730
|
}
|
4939
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4940
|
-
transactionRequest: requestToBeReEstimate
|
4941
|
-
});
|
4942
|
-
txRequest.maxFee = maxFee;
|
4943
|
-
return txRequest;
|
4944
4731
|
}
|
4945
4732
|
/**
|
4946
4733
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4948,25 +4735,28 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4948
4735
|
* @param destination - The address of the destination.
|
4949
4736
|
* @param amount - The amount of coins to transfer.
|
4950
4737
|
* @param assetId - The asset ID of the coins to transfer.
|
4951
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4738
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4952
4739
|
* @returns A promise that resolves to the prepared transaction request.
|
4953
4740
|
*/
|
4954
4741
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4955
|
-
const
|
4742
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4743
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4744
|
+
const request = new ScriptTransactionRequest(params);
|
4956
4745
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4957
|
-
const
|
4746
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4958
4747
|
estimateTxDependencies: true,
|
4959
4748
|
resourcesOwner: this
|
4960
4749
|
});
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
4966
|
-
|
4967
|
-
|
4968
|
-
|
4969
|
-
await this.fund(request,
|
4750
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4751
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4752
|
+
this.validateGas({
|
4753
|
+
gasUsed,
|
4754
|
+
gasPrice: request.gasPrice,
|
4755
|
+
gasLimit: request.gasLimit,
|
4756
|
+
minGasPrice
|
4757
|
+
});
|
4758
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4759
|
+
request.updatePredicateInputs(estimatedInputs);
|
4970
4760
|
return request;
|
4971
4761
|
}
|
4972
4762
|
/**
|
@@ -4979,7 +4769,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4979
4769
|
* @returns A promise that resolves to the transaction response.
|
4980
4770
|
*/
|
4981
4771
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4982
|
-
if ((0,
|
4772
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4983
4773
|
throw new import_errors16.FuelError(
|
4984
4774
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4985
4775
|
"Transfer amount must be a positive number."
|
@@ -4998,37 +4788,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4998
4788
|
* @returns A promise that resolves to the transaction response.
|
4999
4789
|
*/
|
5000
4790
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5001
|
-
if ((0,
|
4791
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5002
4792
|
throw new import_errors16.FuelError(
|
5003
4793
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5004
4794
|
"Transfer amount must be a positive number."
|
5005
4795
|
);
|
5006
4796
|
}
|
5007
4797
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4798
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4799
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5008
4800
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5009
4801
|
hexlifiedContractId: contractAddress.toB256(),
|
5010
|
-
amountToTransfer: (0,
|
4802
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5011
4803
|
assetId
|
5012
4804
|
});
|
5013
4805
|
const request = new ScriptTransactionRequest({
|
5014
|
-
...
|
4806
|
+
...params,
|
5015
4807
|
script,
|
5016
4808
|
scriptData
|
5017
4809
|
});
|
5018
4810
|
request.addContractInputAndOutput(contractAddress);
|
5019
|
-
const
|
5020
|
-
|
5021
|
-
|
4811
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4812
|
+
request,
|
4813
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4814
|
+
);
|
4815
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4816
|
+
this.validateGas({
|
4817
|
+
gasUsed,
|
4818
|
+
gasPrice: request.gasPrice,
|
4819
|
+
gasLimit: request.gasLimit,
|
4820
|
+
minGasPrice
|
5022
4821
|
});
|
5023
|
-
|
5024
|
-
this.validateGas({
|
5025
|
-
gasUsed: txCost.gasUsed,
|
5026
|
-
gasLimit: request.gasLimit
|
5027
|
-
});
|
5028
|
-
}
|
5029
|
-
request.gasLimit = txCost.gasUsed;
|
5030
|
-
request.maxFee = txCost.maxFee;
|
5031
|
-
await this.fund(request, txCost);
|
4822
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5032
4823
|
return this.sendTransaction(request);
|
5033
4824
|
}
|
5034
4825
|
/**
|
@@ -5040,31 +4831,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5040
4831
|
* @returns A promise that resolves to the transaction response.
|
5041
4832
|
*/
|
5042
4833
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4834
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5043
4835
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5044
|
-
const recipientDataArray = (0,
|
4836
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5045
4837
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5046
4838
|
);
|
5047
|
-
const amountDataArray = (0,
|
5048
|
-
"0x".concat((0,
|
4839
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4840
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5049
4841
|
);
|
5050
4842
|
const script = new Uint8Array([
|
5051
|
-
...(0,
|
4843
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5052
4844
|
...recipientDataArray,
|
5053
4845
|
...amountDataArray
|
5054
4846
|
]);
|
5055
|
-
const params = { script, ...txParams };
|
4847
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5056
4848
|
const request = new ScriptTransactionRequest(params);
|
5057
|
-
const
|
5058
|
-
const
|
5059
|
-
|
5060
|
-
|
5061
|
-
|
5062
|
-
|
5063
|
-
|
5064
|
-
|
5065
|
-
|
5066
|
-
|
5067
|
-
|
4849
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4850
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4851
|
+
request,
|
4852
|
+
forwardingQuantities
|
4853
|
+
);
|
4854
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4855
|
+
this.validateGas({
|
4856
|
+
gasUsed,
|
4857
|
+
gasPrice: request.gasPrice,
|
4858
|
+
gasLimit: request.gasLimit,
|
4859
|
+
minGasPrice
|
4860
|
+
});
|
4861
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5068
4862
|
return this.sendTransaction(request);
|
5069
4863
|
}
|
5070
4864
|
async signMessage(message) {
|
@@ -5122,7 +4916,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5122
4916
|
}
|
5123
4917
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5124
4918
|
}
|
5125
|
-
validateGas({
|
4919
|
+
validateGas({
|
4920
|
+
gasUsed,
|
4921
|
+
gasPrice,
|
4922
|
+
gasLimit,
|
4923
|
+
minGasPrice
|
4924
|
+
}) {
|
4925
|
+
if (minGasPrice.gt(gasPrice)) {
|
4926
|
+
throw new import_errors16.FuelError(
|
4927
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4928
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4929
|
+
);
|
4930
|
+
}
|
5126
4931
|
if (gasUsed.gt(gasLimit)) {
|
5127
4932
|
throw new import_errors16.FuelError(
|
5128
4933
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5136,8 +4941,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5136
4941
|
var import_address5 = require("@fuel-ts/address");
|
5137
4942
|
var import_crypto = require("@fuel-ts/crypto");
|
5138
4943
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5139
|
-
var
|
5140
|
-
var
|
4944
|
+
var import_math19 = require("@fuel-ts/math");
|
4945
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5141
4946
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5142
4947
|
var Signer = class {
|
5143
4948
|
address;
|
@@ -5156,10 +4961,10 @@ var Signer = class {
|
|
5156
4961
|
privateKey = `0x${privateKey}`;
|
5157
4962
|
}
|
5158
4963
|
}
|
5159
|
-
const privateKeyBytes = (0,
|
5160
|
-
this.privateKey = (0,
|
5161
|
-
this.publicKey = (0,
|
5162
|
-
this.compressedPublicKey = (0,
|
4964
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4965
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4966
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4967
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5163
4968
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5164
4969
|
}
|
5165
4970
|
/**
|
@@ -5173,11 +4978,11 @@ var Signer = class {
|
|
5173
4978
|
* @returns hashed signature
|
5174
4979
|
*/
|
5175
4980
|
sign(data) {
|
5176
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5177
|
-
const r = (0,
|
5178
|
-
const s = (0,
|
4981
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4982
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4983
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5179
4984
|
s[0] |= (signature.recovery || 0) << 7;
|
5180
|
-
return (0,
|
4985
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5181
4986
|
}
|
5182
4987
|
/**
|
5183
4988
|
* Add point on the current elliptic curve
|
@@ -5186,8 +4991,8 @@ var Signer = class {
|
|
5186
4991
|
* @returns compressed point on the curve
|
5187
4992
|
*/
|
5188
4993
|
addPoint(point) {
|
5189
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5190
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4994
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4995
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5191
4996
|
const result = p0.add(p1);
|
5192
4997
|
return `0x${result.toHex(true)}`;
|
5193
4998
|
}
|
@@ -5199,16 +5004,16 @@ var Signer = class {
|
|
5199
5004
|
* @returns public key from signature from the
|
5200
5005
|
*/
|
5201
5006
|
static recoverPublicKey(data, signature) {
|
5202
|
-
const signedMessageBytes = (0,
|
5007
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5203
5008
|
const r = signedMessageBytes.slice(0, 32);
|
5204
5009
|
const s = signedMessageBytes.slice(32, 64);
|
5205
5010
|
const recoveryParam = (s[0] & 128) >> 7;
|
5206
5011
|
s[0] &= 127;
|
5207
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5012
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5208
5013
|
recoveryParam
|
5209
5014
|
);
|
5210
|
-
const publicKey = sig.recoverPublicKey((0,
|
5211
|
-
return (0,
|
5015
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5016
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5212
5017
|
}
|
5213
5018
|
/**
|
5214
5019
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5227,7 +5032,7 @@ var Signer = class {
|
|
5227
5032
|
* @returns random 32-byte hashed
|
5228
5033
|
*/
|
5229
5034
|
static generatePrivateKey(entropy) {
|
5230
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5035
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5231
5036
|
}
|
5232
5037
|
/**
|
5233
5038
|
* Extended publicKey from a compact publicKey
|
@@ -5236,8 +5041,8 @@ var Signer = class {
|
|
5236
5041
|
* @returns extended publicKey
|
5237
5042
|
*/
|
5238
5043
|
static extendPublicKey(publicKey) {
|
5239
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5240
|
-
return (0,
|
5044
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5045
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5241
5046
|
}
|
5242
5047
|
};
|
5243
5048
|
|
@@ -5245,7 +5050,7 @@ var Signer = class {
|
|
5245
5050
|
var import_address6 = require("@fuel-ts/address");
|
5246
5051
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5247
5052
|
var import_errors17 = require("@fuel-ts/errors");
|
5248
|
-
var
|
5053
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5249
5054
|
var import_uuid = require("uuid");
|
5250
5055
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5251
5056
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5328,7 +5133,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5328
5133
|
);
|
5329
5134
|
}
|
5330
5135
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5331
|
-
const privateKey = (0,
|
5136
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5332
5137
|
return privateKey;
|
5333
5138
|
}
|
5334
5139
|
|
@@ -5373,7 +5178,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5373
5178
|
*/
|
5374
5179
|
async signMessage(message) {
|
5375
5180
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5376
|
-
return (0,
|
5181
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5377
5182
|
}
|
5378
5183
|
/**
|
5379
5184
|
* Signs a transaction with the wallet's private key.
|
@@ -5386,7 +5191,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5386
5191
|
const chainId = this.provider.getChainId();
|
5387
5192
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5388
5193
|
const signature = await this.signer().sign(hashedTransaction);
|
5389
|
-
return (0,
|
5194
|
+
return (0, import_utils31.hexlify)(signature);
|
5390
5195
|
}
|
5391
5196
|
/**
|
5392
5197
|
* Populates a transaction with the witnesses signature.
|
@@ -5406,7 +5211,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5406
5211
|
* @param transactionRequestLike - The transaction request to send.
|
5407
5212
|
* @returns A promise that resolves to the TransactionResponse object.
|
5408
5213
|
*/
|
5409
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5214
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5410
5215
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5411
5216
|
if (estimateTxDependencies) {
|
5412
5217
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5447,15 +5252,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5447
5252
|
// src/hdwallet/hdwallet.ts
|
5448
5253
|
var import_errors20 = require("@fuel-ts/errors");
|
5449
5254
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5450
|
-
var
|
5451
|
-
var
|
5255
|
+
var import_math20 = require("@fuel-ts/math");
|
5256
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5452
5257
|
var import_ethers4 = require("ethers");
|
5453
5258
|
|
5454
5259
|
// src/mnemonic/mnemonic.ts
|
5455
5260
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5456
5261
|
var import_errors19 = require("@fuel-ts/errors");
|
5457
5262
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5458
|
-
var
|
5263
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5459
5264
|
var import_ethers3 = require("ethers");
|
5460
5265
|
|
5461
5266
|
// src/wordlists/words/english.ts
|
@@ -7513,7 +7318,7 @@ var english = [
|
|
7513
7318
|
// src/mnemonic/utils.ts
|
7514
7319
|
var import_errors18 = require("@fuel-ts/errors");
|
7515
7320
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7516
|
-
var
|
7321
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7517
7322
|
function toUtf8Bytes(stri) {
|
7518
7323
|
const str = stri.normalize("NFKD");
|
7519
7324
|
const result = [];
|
@@ -7580,14 +7385,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7580
7385
|
}
|
7581
7386
|
}
|
7582
7387
|
const checksumBits = entropy.length / 4;
|
7583
|
-
const checksum = (0,
|
7388
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7584
7389
|
indices[indices.length - 1] <<= checksumBits;
|
7585
7390
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7586
7391
|
return indices;
|
7587
7392
|
}
|
7588
7393
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7589
7394
|
const size = Math.ceil(11 * words.length / 8);
|
7590
|
-
const entropy = (0,
|
7395
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7591
7396
|
let offset = 0;
|
7592
7397
|
for (let i = 0; i < words.length; i += 1) {
|
7593
7398
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7607,7 +7412,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7607
7412
|
const entropyBits = 32 * words.length / 3;
|
7608
7413
|
const checksumBits = words.length / 3;
|
7609
7414
|
const checksumMask = getUpperMask(checksumBits);
|
7610
|
-
const checksum = (0,
|
7415
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7611
7416
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7612
7417
|
throw new import_errors18.FuelError(
|
7613
7418
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7682,7 +7487,7 @@ var Mnemonic = class {
|
|
7682
7487
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7683
7488
|
const words = getWords(phrase);
|
7684
7489
|
assertMnemonic(words);
|
7685
|
-
return (0,
|
7490
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7686
7491
|
}
|
7687
7492
|
/**
|
7688
7493
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7690,7 +7495,7 @@ var Mnemonic = class {
|
|
7690
7495
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7691
7496
|
*/
|
7692
7497
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7693
|
-
const entropyBytes = (0,
|
7498
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7694
7499
|
assertWordList(wordlist);
|
7695
7500
|
assertEntropy(entropyBytes);
|
7696
7501
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7759,14 +7564,14 @@ var Mnemonic = class {
|
|
7759
7564
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7760
7565
|
*/
|
7761
7566
|
static masterKeysFromSeed(seed) {
|
7762
|
-
const seedArray = (0,
|
7567
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7763
7568
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7764
7569
|
throw new import_errors19.FuelError(
|
7765
7570
|
import_errors19.ErrorCode.INVALID_SEED,
|
7766
7571
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7767
7572
|
);
|
7768
7573
|
}
|
7769
|
-
return (0,
|
7574
|
+
return (0, import_utils33.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
|
7770
7575
|
}
|
7771
7576
|
/**
|
7772
7577
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7777,22 +7582,22 @@ var Mnemonic = class {
|
|
7777
7582
|
*/
|
7778
7583
|
static seedToExtendedKey(seed, testnet = false) {
|
7779
7584
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7780
|
-
const prefix = (0,
|
7585
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7781
7586
|
const depth = "0x00";
|
7782
7587
|
const fingerprint = "0x00000000";
|
7783
7588
|
const index = "0x00000000";
|
7784
7589
|
const chainCode = masterKey.slice(32);
|
7785
7590
|
const privateKey = masterKey.slice(0, 32);
|
7786
|
-
const extendedKey = (0,
|
7591
|
+
const extendedKey = (0, import_utils33.concat)([
|
7787
7592
|
prefix,
|
7788
7593
|
depth,
|
7789
7594
|
fingerprint,
|
7790
7595
|
index,
|
7791
7596
|
chainCode,
|
7792
|
-
(0,
|
7597
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7793
7598
|
]);
|
7794
7599
|
const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7795
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7600
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7796
7601
|
}
|
7797
7602
|
/**
|
7798
7603
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7807,7 +7612,7 @@ var Mnemonic = class {
|
|
7807
7612
|
* @returns A randomly generated mnemonic
|
7808
7613
|
*/
|
7809
7614
|
static generate(size = 32, extraEntropy = "") {
|
7810
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7615
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7811
7616
|
return Mnemonic.entropyToMnemonic(entropy);
|
7812
7617
|
}
|
7813
7618
|
};
|
@@ -7815,12 +7620,12 @@ var mnemonic_default = Mnemonic;
|
|
7815
7620
|
|
7816
7621
|
// src/hdwallet/hdwallet.ts
|
7817
7622
|
var HARDENED_INDEX = 2147483648;
|
7818
|
-
var MainnetPRV2 = (0,
|
7819
|
-
var MainnetPUB = (0,
|
7820
|
-
var TestnetPRV2 = (0,
|
7821
|
-
var TestnetPUB = (0,
|
7623
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7624
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7625
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7626
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7822
7627
|
function base58check(data) {
|
7823
|
-
return (0, import_ethers4.encodeBase58)((0,
|
7628
|
+
return (0, import_ethers4.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7824
7629
|
}
|
7825
7630
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7826
7631
|
if (isPublic) {
|
@@ -7829,11 +7634,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7829
7634
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7830
7635
|
}
|
7831
7636
|
function isPublicExtendedKey(extendedKey) {
|
7832
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7637
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7833
7638
|
}
|
7834
7639
|
function isValidExtendedKey(extendedKey) {
|
7835
7640
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7836
|
-
(0,
|
7641
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7837
7642
|
);
|
7838
7643
|
}
|
7839
7644
|
function parsePath(path2, depth = 0) {
|
@@ -7851,8 +7656,8 @@ function parsePath(path2, depth = 0) {
|
|
7851
7656
|
var HDWallet = class {
|
7852
7657
|
depth = 0;
|
7853
7658
|
index = 0;
|
7854
|
-
fingerprint = (0,
|
7855
|
-
parentFingerprint = (0,
|
7659
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7660
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7856
7661
|
privateKey;
|
7857
7662
|
publicKey;
|
7858
7663
|
chainCode;
|
@@ -7864,8 +7669,8 @@ var HDWallet = class {
|
|
7864
7669
|
constructor(config) {
|
7865
7670
|
if (config.privateKey) {
|
7866
7671
|
const signer = new Signer(config.privateKey);
|
7867
|
-
this.publicKey = (0,
|
7868
|
-
this.privateKey = (0,
|
7672
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7673
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7869
7674
|
} else {
|
7870
7675
|
if (!config.publicKey) {
|
7871
7676
|
throw new import_errors20.FuelError(
|
@@ -7873,7 +7678,7 @@ var HDWallet = class {
|
|
7873
7678
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7874
7679
|
);
|
7875
7680
|
}
|
7876
|
-
this.publicKey = (0,
|
7681
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7877
7682
|
}
|
7878
7683
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7879
7684
|
this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7892,9 +7697,9 @@ var HDWallet = class {
|
|
7892
7697
|
* @returns A new instance of HDWallet on the derived index
|
7893
7698
|
*/
|
7894
7699
|
deriveIndex(index) {
|
7895
|
-
const privateKey = this.privateKey && (0,
|
7896
|
-
const publicKey = (0,
|
7897
|
-
const chainCode = (0,
|
7700
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7701
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7702
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7898
7703
|
const data = new Uint8Array(37);
|
7899
7704
|
if (index & HARDENED_INDEX) {
|
7900
7705
|
if (!privateKey) {
|
@@ -7905,15 +7710,15 @@ var HDWallet = class {
|
|
7905
7710
|
}
|
7906
7711
|
data.set(privateKey, 1);
|
7907
7712
|
} else {
|
7908
|
-
data.set((0,
|
7713
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7909
7714
|
}
|
7910
|
-
data.set((0,
|
7911
|
-
const bytes = (0,
|
7715
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7716
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
|
7912
7717
|
const IL = bytes.slice(0, 32);
|
7913
7718
|
const IR = bytes.slice(32);
|
7914
7719
|
if (privateKey) {
|
7915
7720
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7916
|
-
const ki = (0,
|
7721
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7917
7722
|
return new HDWallet({
|
7918
7723
|
privateKey: ki,
|
7919
7724
|
chainCode: IR,
|
@@ -7922,7 +7727,7 @@ var HDWallet = class {
|
|
7922
7727
|
parentFingerprint: this.fingerprint
|
7923
7728
|
});
|
7924
7729
|
}
|
7925
|
-
const signer = new Signer((0,
|
7730
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7926
7731
|
const Ki = signer.addPoint(publicKey);
|
7927
7732
|
return new HDWallet({
|
7928
7733
|
publicKey: Ki,
|
@@ -7957,12 +7762,12 @@ var HDWallet = class {
|
|
7957
7762
|
);
|
7958
7763
|
}
|
7959
7764
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7960
|
-
const depth = (0,
|
7765
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7961
7766
|
const parentFingerprint = this.parentFingerprint;
|
7962
|
-
const index = (0,
|
7767
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7963
7768
|
const chainCode = this.chainCode;
|
7964
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7965
|
-
const extendedKey = (0,
|
7769
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7770
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7966
7771
|
return base58check(extendedKey);
|
7967
7772
|
}
|
7968
7773
|
/**
|
@@ -7974,13 +7779,13 @@ var HDWallet = class {
|
|
7974
7779
|
static fromSeed(seed) {
|
7975
7780
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7976
7781
|
return new HDWallet({
|
7977
|
-
chainCode: (0,
|
7978
|
-
privateKey: (0,
|
7782
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7783
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7979
7784
|
});
|
7980
7785
|
}
|
7981
7786
|
static fromExtendedKey(extendedKey) {
|
7982
7787
|
const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
|
7983
|
-
const bytes = (0,
|
7788
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7984
7789
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7985
7790
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7986
7791
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7989,9 +7794,9 @@ var HDWallet = class {
|
|
7989
7794
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7990
7795
|
}
|
7991
7796
|
const depth = bytes[4];
|
7992
|
-
const parentFingerprint = (0,
|
7993
|
-
const index = parseInt((0,
|
7994
|
-
const chainCode = (0,
|
7797
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7798
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7799
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7995
7800
|
const key = bytes.slice(45, 78);
|
7996
7801
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7997
7802
|
throw new import_errors20.FuelError(
|
@@ -8184,15 +7989,14 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8184
7989
|
process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
|
8185
7990
|
wallet.provider
|
8186
7991
|
);
|
8187
|
-
const
|
8188
|
-
|
8189
|
-
|
8190
|
-
|
7992
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7993
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7994
|
+
const request = new ScriptTransactionRequest({
|
7995
|
+
gasLimit: 1e4,
|
7996
|
+
gasPrice: minGasPrice
|
8191
7997
|
});
|
8192
|
-
|
8193
|
-
request.
|
8194
|
-
request.maxFee = txCost.maxFee;
|
8195
|
-
await genesisWallet.fund(request, txCost);
|
7998
|
+
request.addResources(resources);
|
7999
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8196
8000
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8197
8001
|
};
|
8198
8002
|
|
@@ -8207,11 +8011,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8207
8011
|
|
8208
8012
|
// src/test-utils/launchNode.ts
|
8209
8013
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8210
|
-
var
|
8014
|
+
var import_math21 = require("@fuel-ts/math");
|
8015
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8211
8016
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8212
8017
|
var import_child_process = require("child_process");
|
8213
8018
|
var import_crypto5 = require("crypto");
|
8214
|
-
var import_ethers5 = require("ethers");
|
8215
8019
|
var import_fs = require("fs");
|
8216
8020
|
var import_os = __toESM(require("os"));
|
8217
8021
|
var import_path = __toESM(require("path"));
|
@@ -8260,13 +8064,13 @@ var launchNode = async ({
|
|
8260
8064
|
// eslint-disable-next-line no-async-promise-executor
|
8261
8065
|
new Promise(async (resolve, reject) => {
|
8262
8066
|
const remainingArgs = extractRemainingArgs(args, [
|
8263
|
-
"--
|
8067
|
+
"--chain",
|
8264
8068
|
"--consensus-key",
|
8265
8069
|
"--db-type",
|
8266
8070
|
"--poa-instant"
|
8267
8071
|
]);
|
8268
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8269
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8072
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8073
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8270
8074
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8271
8075
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8272
8076
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8284,54 +8088,36 @@ var launchNode = async ({
|
|
8284
8088
|
let chainConfigPathToUse;
|
8285
8089
|
const prefix = basePath || import_os.default.tmpdir();
|
8286
8090
|
const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
|
8287
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix
|
8091
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8288
8092
|
if (chainConfigPath) {
|
8289
8093
|
chainConfigPathToUse = chainConfigPath;
|
8290
8094
|
} else {
|
8291
8095
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8292
8096
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8293
8097
|
}
|
8294
|
-
|
8295
|
-
|
8296
|
-
stateConfigJson = {
|
8297
|
-
...stateConfigJson,
|
8298
|
-
coins: [
|
8299
|
-
...stateConfigJson.coins.map((coin) => ({
|
8300
|
-
...coin,
|
8301
|
-
amount: "18446744073709551615"
|
8302
|
-
}))
|
8303
|
-
],
|
8304
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8305
|
-
...message,
|
8306
|
-
amount: "18446744073709551615"
|
8307
|
-
}))
|
8308
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8309
|
-
};
|
8098
|
+
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8099
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8310
8100
|
if (!process.env.GENESIS_SECRET) {
|
8311
8101
|
const pk = Signer.generatePrivateKey();
|
8312
8102
|
const signer = new Signer(pk);
|
8313
|
-
process.env.GENESIS_SECRET = (0,
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8318
|
-
|
8319
|
-
|
8320
|
-
|
8321
|
-
|
8322
|
-
|
8323
|
-
|
8103
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8104
|
+
chainConfig = {
|
8105
|
+
...import_utils36.defaultChainConfig,
|
8106
|
+
initial_state: {
|
8107
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8108
|
+
coins: [
|
8109
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8110
|
+
{
|
8111
|
+
owner: signer.address.toHexString(),
|
8112
|
+
amount: (0, import_math21.toHex)(1e9),
|
8113
|
+
asset_id: import_configs13.BaseAssetId
|
8114
|
+
}
|
8115
|
+
]
|
8116
|
+
}
|
8117
|
+
};
|
8324
8118
|
}
|
8325
|
-
|
8326
|
-
|
8327
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8328
|
-
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8329
|
-
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8330
|
-
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8331
|
-
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8332
|
-
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8333
|
-
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8334
|
-
chainConfigPathToUse = tempDirPath;
|
8119
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8120
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8335
8121
|
}
|
8336
8122
|
const child = (0, import_child_process.spawn)(
|
8337
8123
|
command,
|
@@ -8340,10 +8126,10 @@ var launchNode = async ({
|
|
8340
8126
|
["--ip", ipToUse],
|
8341
8127
|
["--port", portToUse],
|
8342
8128
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8343
|
-
["--min-gas-price", "
|
8129
|
+
["--min-gas-price", "0"],
|
8344
8130
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8345
8131
|
["--consensus-key", consensusKey],
|
8346
|
-
["--
|
8132
|
+
["--chain", chainConfigPathToUse],
|
8347
8133
|
"--vm-backtrace",
|
8348
8134
|
"--utxo-validation",
|
8349
8135
|
"--debug",
|
@@ -8402,7 +8188,7 @@ var launchNodeAndGetWallets = async ({
|
|
8402
8188
|
walletCount = 10
|
8403
8189
|
} = {}) => {
|
8404
8190
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8405
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8191
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8406
8192
|
const wallets = await generateWallets(walletCount, provider);
|
8407
8193
|
const cleanup = () => {
|
8408
8194
|
closeNode();
|