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