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