@fuel-ts/account 0.0.0-rc-2037-20240423134048 → 0.0.0-rc-2021-20240423134551
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +829 -600
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +857 -637
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +680 -455
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +11 -18
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +822 -328
- 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 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +6 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -27
- 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/index.d.ts +0 -1
- package/dist/providers/transaction-request/index.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 +6 -7
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/index.d.ts +0 -1
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1545 -1076
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +837 -612
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +674 -446
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/providers/transaction-request/helpers.d.ts +0 -10
- package/dist/providers/transaction-request/helpers.d.ts.map +0 -1
- package/dist/test-utils/resources.d.ts +0 -4
- package/dist/test-utils/resources.d.ts.map +0 -1
- package/dist/test-utils/transactionRequest.d.ts +0 -5
- package/dist/test-utils/transactionRequest.d.ts.map +0 -1
package/dist/test-utils.js
CHANGED
@@ -48,9 +48,6 @@ var __privateMethod = (obj, member, method) => {
|
|
48
48
|
// src/test-utils/index.ts
|
49
49
|
var test_utils_exports = {};
|
50
50
|
__export(test_utils_exports, {
|
51
|
-
generateFakeRequestInputCoin: () => generateFakeRequestInputCoin,
|
52
|
-
generateFakeRequestInputContract: () => generateFakeRequestInputContract,
|
53
|
-
generateFakeRequestInputMessage: () => generateFakeRequestInputMessage,
|
54
51
|
generateTestWallet: () => generateTestWallet,
|
55
52
|
killNode: () => killNode,
|
56
53
|
launchNode: () => launchNode,
|
@@ -61,15 +58,16 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
61
58
|
|
62
59
|
// src/wallet/base-wallet-unlocked.ts
|
63
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
64
|
-
var
|
61
|
+
var import_utils30 = require("@fuel-ts/utils");
|
65
62
|
|
66
63
|
// src/account.ts
|
67
64
|
var import_address4 = require("@fuel-ts/address");
|
68
65
|
var import_configs12 = require("@fuel-ts/address/configs");
|
69
66
|
var import_errors16 = require("@fuel-ts/errors");
|
70
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
71
|
-
var
|
72
|
-
var
|
68
|
+
var import_math19 = require("@fuel-ts/math");
|
69
|
+
var import_utils27 = require("@fuel-ts/utils");
|
70
|
+
var import_ramda4 = require("ramda");
|
73
71
|
|
74
72
|
// src/providers/coin-quantity.ts
|
75
73
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -78,24 +76,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
78
76
|
var coinQuantityfy = (coinQuantityLike) => {
|
79
77
|
let assetId;
|
80
78
|
let amount;
|
81
|
-
let
|
79
|
+
let max;
|
82
80
|
if (Array.isArray(coinQuantityLike)) {
|
83
81
|
amount = coinQuantityLike[0];
|
84
82
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
85
|
-
|
83
|
+
max = coinQuantityLike[2] ?? void 0;
|
86
84
|
} else {
|
87
85
|
amount = coinQuantityLike.amount;
|
88
86
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
89
|
-
|
87
|
+
max = coinQuantityLike.max ?? void 0;
|
90
88
|
}
|
91
89
|
const bnAmount = (0, import_math.bn)(amount);
|
92
90
|
return {
|
93
91
|
assetId: (0, import_utils.hexlify)(assetId),
|
94
92
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
95
|
-
max:
|
93
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
96
94
|
};
|
97
95
|
};
|
98
|
-
var
|
96
|
+
var addAmountToCoinQuantities = (params) => {
|
99
97
|
const { amount, assetId } = params;
|
100
98
|
const coinQuantities = [...params.coinQuantities];
|
101
99
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -110,27 +108,51 @@ var addAmountToAsset = (params) => {
|
|
110
108
|
// src/providers/provider.ts
|
111
109
|
var import_address3 = require("@fuel-ts/address");
|
112
110
|
var import_errors14 = require("@fuel-ts/errors");
|
113
|
-
var
|
111
|
+
var import_math16 = require("@fuel-ts/math");
|
114
112
|
var import_transactions19 = require("@fuel-ts/transactions");
|
115
|
-
var
|
113
|
+
var import_utils22 = require("@fuel-ts/utils");
|
116
114
|
var import_versions = require("@fuel-ts/versions");
|
117
|
-
var
|
115
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
118
116
|
var import_ethers = require("ethers");
|
119
117
|
var import_graphql_request = require("graphql-request");
|
120
118
|
var import_ramda3 = require("ramda");
|
121
119
|
|
122
120
|
// src/providers/__generated__/operations.ts
|
123
121
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
122
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
|
123
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
124
|
+
type: __typename
|
125
|
+
... on SubmittedStatus {
|
126
|
+
time
|
127
|
+
}
|
128
|
+
... on SuccessStatus {
|
129
|
+
block {
|
130
|
+
id
|
131
|
+
}
|
132
|
+
time
|
133
|
+
programState {
|
134
|
+
returnType
|
135
|
+
data
|
136
|
+
}
|
137
|
+
}
|
138
|
+
... on FailureStatus {
|
139
|
+
block {
|
140
|
+
id
|
141
|
+
}
|
142
|
+
time
|
143
|
+
reason
|
144
|
+
}
|
145
|
+
... on SqueezedOutStatus {
|
146
|
+
reason
|
147
|
+
}
|
148
|
+
}
|
149
|
+
`;
|
124
150
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
125
151
|
fragment receiptFragment on Receipt {
|
126
|
-
|
127
|
-
id
|
128
|
-
}
|
152
|
+
id
|
129
153
|
pc
|
130
154
|
is
|
131
|
-
to
|
132
|
-
id
|
133
|
-
}
|
155
|
+
to
|
134
156
|
toAddress
|
135
157
|
amount
|
136
158
|
assetId
|
@@ -168,10 +190,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
168
190
|
id
|
169
191
|
}
|
170
192
|
time
|
193
|
+
receipts {
|
194
|
+
...receiptFragment
|
195
|
+
}
|
171
196
|
programState {
|
172
197
|
returnType
|
173
198
|
data
|
174
199
|
}
|
200
|
+
receipts {
|
201
|
+
...receiptFragment
|
202
|
+
}
|
175
203
|
}
|
176
204
|
... on FailureStatus {
|
177
205
|
block {
|
@@ -179,26 +207,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
179
207
|
}
|
180
208
|
time
|
181
209
|
reason
|
210
|
+
receipts {
|
211
|
+
...receiptFragment
|
212
|
+
}
|
182
213
|
}
|
183
214
|
... on SqueezedOutStatus {
|
184
215
|
reason
|
185
216
|
}
|
186
217
|
}
|
187
|
-
`;
|
218
|
+
${ReceiptFragmentFragmentDoc}`;
|
188
219
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
189
220
|
fragment transactionFragment on Transaction {
|
190
221
|
id
|
191
222
|
rawPayload
|
192
|
-
gasPrice
|
193
|
-
receipts {
|
194
|
-
...receiptFragment
|
195
|
-
}
|
196
223
|
status {
|
197
224
|
...transactionStatusFragment
|
198
225
|
}
|
199
226
|
}
|
200
|
-
${
|
201
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
227
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
202
228
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
203
229
|
fragment inputEstimatePredicatesFragment on Input {
|
204
230
|
... on InputCoin {
|
@@ -216,6 +242,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
216
242
|
}
|
217
243
|
}
|
218
244
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
245
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
247
|
+
reason
|
248
|
+
programState {
|
249
|
+
returnType
|
250
|
+
data
|
251
|
+
}
|
252
|
+
}
|
253
|
+
`;
|
254
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
255
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
256
|
+
programState {
|
257
|
+
returnType
|
258
|
+
data
|
259
|
+
}
|
260
|
+
}
|
261
|
+
`;
|
262
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
263
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
264
|
+
... on DryRunFailureStatus {
|
265
|
+
...dryRunFailureStatusFragment
|
266
|
+
}
|
267
|
+
... on DryRunSuccessStatus {
|
268
|
+
...dryRunSuccessStatusFragment
|
269
|
+
}
|
270
|
+
}
|
271
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
272
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
273
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
274
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
275
|
+
id
|
276
|
+
status {
|
277
|
+
...dryRunTransactionStatusFragment
|
278
|
+
}
|
279
|
+
receipts {
|
280
|
+
...receiptFragment
|
281
|
+
}
|
282
|
+
}
|
283
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
284
|
+
${ReceiptFragmentFragmentDoc}`;
|
219
285
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
220
286
|
fragment coinFragment on Coin {
|
221
287
|
__typename
|
@@ -223,7 +289,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
223
289
|
owner
|
224
290
|
amount
|
225
291
|
assetId
|
226
|
-
maturity
|
227
292
|
blockCreated
|
228
293
|
txCreatedIdx
|
229
294
|
}
|
@@ -262,26 +327,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
262
327
|
messageBlockHeader {
|
263
328
|
id
|
264
329
|
daHeight
|
330
|
+
consensusParametersVersion
|
331
|
+
stateTransitionBytecodeVersion
|
265
332
|
transactionsCount
|
333
|
+
messageReceiptCount
|
266
334
|
transactionsRoot
|
335
|
+
messageOutboxRoot
|
336
|
+
eventInboxRoot
|
267
337
|
height
|
268
338
|
prevRoot
|
269
339
|
time
|
270
340
|
applicationHash
|
271
|
-
messageReceiptRoot
|
272
|
-
messageReceiptCount
|
273
341
|
}
|
274
342
|
commitBlockHeader {
|
275
343
|
id
|
276
344
|
daHeight
|
345
|
+
consensusParametersVersion
|
346
|
+
stateTransitionBytecodeVersion
|
277
347
|
transactionsCount
|
348
|
+
messageReceiptCount
|
278
349
|
transactionsRoot
|
350
|
+
messageOutboxRoot
|
351
|
+
eventInboxRoot
|
279
352
|
height
|
280
353
|
prevRoot
|
281
354
|
time
|
282
355
|
applicationHash
|
283
|
-
messageReceiptRoot
|
284
|
-
messageReceiptCount
|
285
356
|
}
|
286
357
|
sender
|
287
358
|
recipient
|
@@ -300,8 +371,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
300
371
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
301
372
|
fragment blockFragment on Block {
|
302
373
|
id
|
374
|
+
height
|
303
375
|
header {
|
304
|
-
height
|
305
376
|
time
|
306
377
|
}
|
307
378
|
transactions {
|
@@ -359,6 +430,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
359
430
|
`;
|
360
431
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
361
432
|
fragment GasCostsFragment on GasCosts {
|
433
|
+
version {
|
434
|
+
... on Version {
|
435
|
+
value
|
436
|
+
}
|
437
|
+
}
|
362
438
|
add
|
363
439
|
addi
|
364
440
|
aloc
|
@@ -371,7 +447,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
371
447
|
cb
|
372
448
|
cfei
|
373
449
|
cfsi
|
374
|
-
croo
|
375
450
|
div
|
376
451
|
divi
|
377
452
|
ecr1
|
@@ -454,6 +529,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
454
529
|
ccp {
|
455
530
|
...DependentCostFragment
|
456
531
|
}
|
532
|
+
croo {
|
533
|
+
...DependentCostFragment
|
534
|
+
}
|
457
535
|
csiz {
|
458
536
|
...DependentCostFragment
|
459
537
|
}
|
@@ -513,6 +591,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
513
591
|
${DependentCostFragmentFragmentDoc}`;
|
514
592
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
515
593
|
fragment consensusParametersFragment on ConsensusParameters {
|
594
|
+
version {
|
595
|
+
... on Version {
|
596
|
+
value
|
597
|
+
}
|
598
|
+
}
|
516
599
|
txParams {
|
517
600
|
...TxParametersFragment
|
518
601
|
}
|
@@ -572,18 +655,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
572
655
|
fragment nodeInfoFragment on NodeInfo {
|
573
656
|
utxoValidation
|
574
657
|
vmBacktrace
|
575
|
-
minGasPrice
|
576
658
|
maxTx
|
577
659
|
maxDepth
|
578
660
|
nodeVersion
|
579
|
-
peers {
|
580
|
-
id
|
581
|
-
addresses
|
582
|
-
clientVersion
|
583
|
-
blockHeight
|
584
|
-
lastHeartbeatMs
|
585
|
-
appScore
|
586
|
-
}
|
587
661
|
}
|
588
662
|
`;
|
589
663
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -618,13 +692,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
618
692
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
619
693
|
transaction(id: $transactionId) {
|
620
694
|
...transactionFragment
|
621
|
-
receipts {
|
622
|
-
...receiptFragment
|
623
|
-
}
|
624
695
|
}
|
625
696
|
}
|
626
|
-
${TransactionFragmentFragmentDoc}
|
627
|
-
${ReceiptFragmentFragmentDoc}`;
|
697
|
+
${TransactionFragmentFragmentDoc}`;
|
628
698
|
var GetTransactionsDocument = import_graphql_tag.default`
|
629
699
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
630
700
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -752,6 +822,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
752
822
|
}
|
753
823
|
}
|
754
824
|
${BalanceFragmentFragmentDoc}`;
|
825
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
826
|
+
query getLatestGasPrice {
|
827
|
+
latestGasPrice {
|
828
|
+
gasPrice
|
829
|
+
}
|
830
|
+
}
|
831
|
+
`;
|
832
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
833
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
834
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
835
|
+
gasPrice
|
836
|
+
}
|
837
|
+
}
|
838
|
+
`;
|
755
839
|
var GetBalancesDocument = import_graphql_tag.default`
|
756
840
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
757
841
|
balances(
|
@@ -806,12 +890,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
806
890
|
}
|
807
891
|
`;
|
808
892
|
var DryRunDocument = import_graphql_tag.default`
|
809
|
-
mutation dryRun($
|
810
|
-
dryRun(
|
811
|
-
...
|
893
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
894
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
895
|
+
...dryRunTransactionExecutionStatusFragment
|
812
896
|
}
|
813
897
|
}
|
814
|
-
${
|
898
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
815
899
|
var SubmitDocument = import_graphql_tag.default`
|
816
900
|
mutation submit($encodedTransaction: HexString!) {
|
817
901
|
submit(tx: $encodedTransaction) {
|
@@ -830,17 +914,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
|
|
830
914
|
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
831
915
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
832
916
|
submitAndAwait(tx: $encodedTransaction) {
|
833
|
-
...
|
917
|
+
...transactionStatusSubscriptionFragment
|
834
918
|
}
|
835
919
|
}
|
836
|
-
${
|
920
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
837
921
|
var StatusChangeDocument = import_graphql_tag.default`
|
838
922
|
subscription statusChange($transactionId: TransactionId!) {
|
839
923
|
statusChange(id: $transactionId) {
|
840
|
-
...
|
924
|
+
...transactionStatusSubscriptionFragment
|
841
925
|
}
|
842
926
|
}
|
843
|
-
${
|
927
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
844
928
|
function getSdk(requester) {
|
845
929
|
return {
|
846
930
|
getVersion(variables, options) {
|
@@ -894,6 +978,12 @@ function getSdk(requester) {
|
|
894
978
|
getBalance(variables, options) {
|
895
979
|
return requester(GetBalanceDocument, variables, options);
|
896
980
|
},
|
981
|
+
getLatestGasPrice(variables, options) {
|
982
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
983
|
+
},
|
984
|
+
estimateGasPrice(variables, options) {
|
985
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
986
|
+
},
|
897
987
|
getBalances(variables, options) {
|
898
988
|
return requester(GetBalancesDocument, variables, options);
|
899
989
|
},
|
@@ -1087,10 +1177,9 @@ var inputify = (value) => {
|
|
1087
1177
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1088
1178
|
},
|
1089
1179
|
witnessIndex: value.witnessIndex,
|
1090
|
-
maturity: value.maturity ?? 0,
|
1091
1180
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1092
|
-
predicateLength: predicate.length,
|
1093
|
-
predicateDataLength: predicateData.length,
|
1181
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1182
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1094
1183
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1095
1184
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1096
1185
|
};
|
@@ -1121,8 +1210,8 @@ var inputify = (value) => {
|
|
1121
1210
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1122
1211
|
witnessIndex: value.witnessIndex,
|
1123
1212
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1124
|
-
predicateLength: predicate.length,
|
1125
|
-
predicateDataLength: predicateData.length,
|
1213
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1214
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1126
1215
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1127
1216
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1128
1217
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1201,7 +1290,7 @@ var import_address = require("@fuel-ts/address");
|
|
1201
1290
|
var import_configs7 = require("@fuel-ts/address/configs");
|
1202
1291
|
var import_crypto = require("@fuel-ts/crypto");
|
1203
1292
|
var import_math7 = require("@fuel-ts/math");
|
1204
|
-
var
|
1293
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1205
1294
|
var import_utils9 = require("@fuel-ts/utils");
|
1206
1295
|
|
1207
1296
|
// src/providers/resource.ts
|
@@ -1238,8 +1327,8 @@ function assembleReceiptByType(receipt) {
|
|
1238
1327
|
case "CALL" /* Call */: {
|
1239
1328
|
const callReceipt = {
|
1240
1329
|
type: import_transactions3.ReceiptType.Call,
|
1241
|
-
from: hexOrZero(receipt.
|
1242
|
-
to: hexOrZero(receipt?.to
|
1330
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1331
|
+
to: hexOrZero(receipt?.to),
|
1243
1332
|
amount: (0, import_math4.bn)(receipt.amount),
|
1244
1333
|
assetId: hexOrZero(receipt.assetId),
|
1245
1334
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1253,7 +1342,7 @@ function assembleReceiptByType(receipt) {
|
|
1253
1342
|
case "RETURN" /* Return */: {
|
1254
1343
|
const returnReceipt = {
|
1255
1344
|
type: import_transactions3.ReceiptType.Return,
|
1256
|
-
id: hexOrZero(receipt.
|
1345
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1257
1346
|
val: (0, import_math4.bn)(receipt.val),
|
1258
1347
|
pc: (0, import_math4.bn)(receipt.pc),
|
1259
1348
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1263,7 +1352,7 @@ function assembleReceiptByType(receipt) {
|
|
1263
1352
|
case "RETURN_DATA" /* ReturnData */: {
|
1264
1353
|
const returnDataReceipt = {
|
1265
1354
|
type: import_transactions3.ReceiptType.ReturnData,
|
1266
|
-
id: hexOrZero(receipt.
|
1355
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1267
1356
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1268
1357
|
len: (0, import_math4.bn)(receipt.len),
|
1269
1358
|
digest: hexOrZero(receipt.digest),
|
@@ -1275,7 +1364,7 @@ function assembleReceiptByType(receipt) {
|
|
1275
1364
|
case "PANIC" /* Panic */: {
|
1276
1365
|
const panicReceipt = {
|
1277
1366
|
type: import_transactions3.ReceiptType.Panic,
|
1278
|
-
id: hexOrZero(receipt.
|
1367
|
+
id: hexOrZero(receipt.id),
|
1279
1368
|
reason: (0, import_math4.bn)(receipt.reason),
|
1280
1369
|
pc: (0, import_math4.bn)(receipt.pc),
|
1281
1370
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1286,7 +1375,7 @@ function assembleReceiptByType(receipt) {
|
|
1286
1375
|
case "REVERT" /* Revert */: {
|
1287
1376
|
const revertReceipt = {
|
1288
1377
|
type: import_transactions3.ReceiptType.Revert,
|
1289
|
-
id: hexOrZero(receipt.
|
1378
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1290
1379
|
val: (0, import_math4.bn)(receipt.ra),
|
1291
1380
|
pc: (0, import_math4.bn)(receipt.pc),
|
1292
1381
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1296,7 +1385,7 @@ function assembleReceiptByType(receipt) {
|
|
1296
1385
|
case "LOG" /* Log */: {
|
1297
1386
|
const logReceipt = {
|
1298
1387
|
type: import_transactions3.ReceiptType.Log,
|
1299
|
-
id: hexOrZero(receipt.
|
1388
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1300
1389
|
val0: (0, import_math4.bn)(receipt.ra),
|
1301
1390
|
val1: (0, import_math4.bn)(receipt.rb),
|
1302
1391
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1309,7 +1398,7 @@ function assembleReceiptByType(receipt) {
|
|
1309
1398
|
case "LOG_DATA" /* LogData */: {
|
1310
1399
|
const logDataReceipt = {
|
1311
1400
|
type: import_transactions3.ReceiptType.LogData,
|
1312
|
-
id: hexOrZero(receipt.
|
1401
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1313
1402
|
val0: (0, import_math4.bn)(receipt.ra),
|
1314
1403
|
val1: (0, import_math4.bn)(receipt.rb),
|
1315
1404
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1323,8 +1412,8 @@ function assembleReceiptByType(receipt) {
|
|
1323
1412
|
case "TRANSFER" /* Transfer */: {
|
1324
1413
|
const transferReceipt = {
|
1325
1414
|
type: import_transactions3.ReceiptType.Transfer,
|
1326
|
-
from: hexOrZero(receipt.
|
1327
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1415
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1416
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1328
1417
|
amount: (0, import_math4.bn)(receipt.amount),
|
1329
1418
|
assetId: hexOrZero(receipt.assetId),
|
1330
1419
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1335,8 +1424,8 @@ function assembleReceiptByType(receipt) {
|
|
1335
1424
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1336
1425
|
const transferOutReceipt = {
|
1337
1426
|
type: import_transactions3.ReceiptType.TransferOut,
|
1338
|
-
from: hexOrZero(receipt.
|
1339
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1427
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1428
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1340
1429
|
amount: (0, import_math4.bn)(receipt.amount),
|
1341
1430
|
assetId: hexOrZero(receipt.assetId),
|
1342
1431
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1379,7 +1468,7 @@ function assembleReceiptByType(receipt) {
|
|
1379
1468
|
return receiptMessageOut;
|
1380
1469
|
}
|
1381
1470
|
case "MINT" /* Mint */: {
|
1382
|
-
const contractId = hexOrZero(receipt.
|
1471
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1383
1472
|
const subId = hexOrZero(receipt.subId);
|
1384
1473
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1385
1474
|
const mintReceipt = {
|
@@ -1394,7 +1483,7 @@ function assembleReceiptByType(receipt) {
|
|
1394
1483
|
return mintReceipt;
|
1395
1484
|
}
|
1396
1485
|
case "BURN" /* Burn */: {
|
1397
|
-
const contractId = hexOrZero(receipt.
|
1486
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1398
1487
|
const subId = hexOrZero(receipt.subId);
|
1399
1488
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1400
1489
|
const burnReceipt = {
|
@@ -1420,7 +1509,6 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1420
1509
|
var import_math5 = require("@fuel-ts/math");
|
1421
1510
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1422
1511
|
var import_utils6 = require("@fuel-ts/utils");
|
1423
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1424
1512
|
var getGasUsedFromReceipts = (receipts) => {
|
1425
1513
|
const scriptResult = receipts.filter(
|
1426
1514
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1441,18 +1529,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1441
1529
|
}
|
1442
1530
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1443
1531
|
const witnessCache = [];
|
1444
|
-
const
|
1532
|
+
const chargeableInputs = inputs.filter((input) => {
|
1533
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1534
|
+
if (isCoinOrMessage) {
|
1535
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1536
|
+
return true;
|
1537
|
+
}
|
1538
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1539
|
+
witnessCache.push(input.witnessIndex);
|
1540
|
+
return true;
|
1541
|
+
}
|
1542
|
+
}
|
1543
|
+
return false;
|
1544
|
+
});
|
1545
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1546
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1445
1547
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1446
1548
|
return total.add(
|
1447
|
-
|
1549
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1448
1550
|
);
|
1449
1551
|
}
|
1450
|
-
|
1451
|
-
|
1452
|
-
return total.add(gasCosts.ecr1);
|
1453
|
-
}
|
1454
|
-
return total;
|
1455
|
-
}, (0, import_math5.bn)());
|
1552
|
+
return total.add(gasCosts.ecr1);
|
1553
|
+
}, (0, import_math5.bn)(0));
|
1456
1554
|
return totalGas;
|
1457
1555
|
}
|
1458
1556
|
function getMinGas(params) {
|
@@ -1464,12 +1562,20 @@ function getMinGas(params) {
|
|
1464
1562
|
return minGas;
|
1465
1563
|
}
|
1466
1564
|
function getMaxGas(params) {
|
1467
|
-
const {
|
1565
|
+
const {
|
1566
|
+
gasPerByte,
|
1567
|
+
witnessesLength,
|
1568
|
+
witnessLimit,
|
1569
|
+
minGas,
|
1570
|
+
gasLimit = (0, import_math5.bn)(0),
|
1571
|
+
maxGasPerTx
|
1572
|
+
} = params;
|
1468
1573
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1469
1574
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1470
1575
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1471
1576
|
}
|
1472
|
-
|
1577
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1578
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1473
1579
|
}
|
1474
1580
|
function calculateMetadataGasForTxCreate({
|
1475
1581
|
gasCosts,
|
@@ -1491,6 +1597,10 @@ function calculateMetadataGasForTxScript({
|
|
1491
1597
|
}) {
|
1492
1598
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1493
1599
|
}
|
1600
|
+
var calculateGasFee = (params) => {
|
1601
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1602
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1603
|
+
};
|
1494
1604
|
|
1495
1605
|
// src/providers/utils/json.ts
|
1496
1606
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1614,12 +1724,6 @@ var NoWitnessAtIndexError = class extends Error {
|
|
1614
1724
|
name = "NoWitnessAtIndexError";
|
1615
1725
|
};
|
1616
1726
|
|
1617
|
-
// src/providers/transaction-request/helpers.ts
|
1618
|
-
var import_transactions6 = require("@fuel-ts/transactions");
|
1619
|
-
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
1620
|
-
var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
|
1621
|
-
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1622
|
-
|
1623
1727
|
// src/providers/transaction-request/witness.ts
|
1624
1728
|
var import_utils8 = require("@fuel-ts/utils");
|
1625
1729
|
var witnessify = (value) => {
|
@@ -1633,7 +1737,7 @@ var witnessify = (value) => {
|
|
1633
1737
|
// src/providers/transaction-request/transaction-request.ts
|
1634
1738
|
var BaseTransactionRequest = class {
|
1635
1739
|
/** Gas price for transaction */
|
1636
|
-
|
1740
|
+
tip;
|
1637
1741
|
/** Block until which tx cannot be included */
|
1638
1742
|
maturity;
|
1639
1743
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1652,7 +1756,7 @@ var BaseTransactionRequest = class {
|
|
1652
1756
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1653
1757
|
*/
|
1654
1758
|
constructor({
|
1655
|
-
|
1759
|
+
tip,
|
1656
1760
|
maturity,
|
1657
1761
|
maxFee,
|
1658
1762
|
witnessLimit,
|
@@ -1660,7 +1764,7 @@ var BaseTransactionRequest = class {
|
|
1660
1764
|
outputs,
|
1661
1765
|
witnesses
|
1662
1766
|
} = {}) {
|
1663
|
-
this.
|
1767
|
+
this.tip = (0, import_math7.bn)(tip);
|
1664
1768
|
this.maturity = maturity ?? 0;
|
1665
1769
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1666
1770
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1671,21 +1775,21 @@ var BaseTransactionRequest = class {
|
|
1671
1775
|
static getPolicyMeta(req) {
|
1672
1776
|
let policyTypes = 0;
|
1673
1777
|
const policies = [];
|
1674
|
-
if (req.
|
1675
|
-
policyTypes +=
|
1676
|
-
policies.push({ data: req.
|
1778
|
+
if (req.tip) {
|
1779
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1780
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1677
1781
|
}
|
1678
1782
|
if (req.witnessLimit) {
|
1679
|
-
policyTypes +=
|
1680
|
-
policies.push({ data: req.witnessLimit, type:
|
1783
|
+
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
1784
|
+
policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
|
1681
1785
|
}
|
1682
1786
|
if (req.maturity > 0) {
|
1683
|
-
policyTypes +=
|
1684
|
-
policies.push({ data: req.maturity, type:
|
1787
|
+
policyTypes += import_transactions6.PolicyType.Maturity;
|
1788
|
+
policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
|
1685
1789
|
}
|
1686
1790
|
if (req.maxFee) {
|
1687
|
-
policyTypes +=
|
1688
|
-
policies.push({ data: req.maxFee, type:
|
1791
|
+
policyTypes += import_transactions6.PolicyType.MaxFee;
|
1792
|
+
policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
|
1689
1793
|
}
|
1690
1794
|
return {
|
1691
1795
|
policyTypes,
|
@@ -1719,7 +1823,7 @@ var BaseTransactionRequest = class {
|
|
1719
1823
|
* @returns The transaction bytes.
|
1720
1824
|
*/
|
1721
1825
|
toTransactionBytes() {
|
1722
|
-
return new
|
1826
|
+
return new import_transactions6.TransactionCoder().encode(this.toTransaction());
|
1723
1827
|
}
|
1724
1828
|
/**
|
1725
1829
|
* @hidden
|
@@ -1810,7 +1914,7 @@ var BaseTransactionRequest = class {
|
|
1810
1914
|
*/
|
1811
1915
|
getCoinInputs() {
|
1812
1916
|
return this.inputs.filter(
|
1813
|
-
(input) => input.type ===
|
1917
|
+
(input) => input.type === import_transactions6.InputType.Coin
|
1814
1918
|
);
|
1815
1919
|
}
|
1816
1920
|
/**
|
@@ -1820,7 +1924,7 @@ var BaseTransactionRequest = class {
|
|
1820
1924
|
*/
|
1821
1925
|
getCoinOutputs() {
|
1822
1926
|
return this.outputs.filter(
|
1823
|
-
(output) => output.type ===
|
1927
|
+
(output) => output.type === import_transactions6.OutputType.Coin
|
1824
1928
|
);
|
1825
1929
|
}
|
1826
1930
|
/**
|
@@ -1830,7 +1934,7 @@ var BaseTransactionRequest = class {
|
|
1830
1934
|
*/
|
1831
1935
|
getChangeOutputs() {
|
1832
1936
|
return this.outputs.filter(
|
1833
|
-
(output) => output.type ===
|
1937
|
+
(output) => output.type === import_transactions6.OutputType.Change
|
1834
1938
|
);
|
1835
1939
|
}
|
1836
1940
|
/**
|
@@ -1842,9 +1946,9 @@ var BaseTransactionRequest = class {
|
|
1842
1946
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1843
1947
|
const found = this.inputs.find((input) => {
|
1844
1948
|
switch (input.type) {
|
1845
|
-
case
|
1949
|
+
case import_transactions6.InputType.Coin:
|
1846
1950
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1847
|
-
case
|
1951
|
+
case import_transactions6.InputType.Message:
|
1848
1952
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1849
1953
|
default:
|
1850
1954
|
return false;
|
@@ -1861,9 +1965,9 @@ var BaseTransactionRequest = class {
|
|
1861
1965
|
* @param predicateData - Predicate data bytes.
|
1862
1966
|
*/
|
1863
1967
|
addCoinInput(coin) {
|
1864
|
-
const { assetId, owner, amount
|
1968
|
+
const { assetId, owner, amount } = coin;
|
1865
1969
|
let witnessIndex;
|
1866
|
-
if (predicate) {
|
1970
|
+
if (coin.predicate) {
|
1867
1971
|
witnessIndex = 0;
|
1868
1972
|
} else {
|
1869
1973
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1872,14 +1976,13 @@ var BaseTransactionRequest = class {
|
|
1872
1976
|
}
|
1873
1977
|
}
|
1874
1978
|
const input = {
|
1875
|
-
|
1876
|
-
type:
|
1979
|
+
...coin,
|
1980
|
+
type: import_transactions6.InputType.Coin,
|
1877
1981
|
owner: owner.toB256(),
|
1878
1982
|
amount,
|
1879
1983
|
assetId,
|
1880
1984
|
txPointer: "0x00000000000000000000000000000000",
|
1881
|
-
witnessIndex
|
1882
|
-
predicate
|
1985
|
+
witnessIndex
|
1883
1986
|
};
|
1884
1987
|
this.pushInput(input);
|
1885
1988
|
this.addChangeOutput(owner, assetId);
|
@@ -1893,10 +1996,10 @@ var BaseTransactionRequest = class {
|
|
1893
1996
|
* @param predicateData - Predicate data bytes.
|
1894
1997
|
*/
|
1895
1998
|
addMessageInput(message) {
|
1896
|
-
const { recipient, sender, amount
|
1999
|
+
const { recipient, sender, amount } = message;
|
1897
2000
|
const assetId = import_configs7.BaseAssetId;
|
1898
2001
|
let witnessIndex;
|
1899
|
-
if (predicate) {
|
2002
|
+
if (message.predicate) {
|
1900
2003
|
witnessIndex = 0;
|
1901
2004
|
} else {
|
1902
2005
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1905,13 +2008,12 @@ var BaseTransactionRequest = class {
|
|
1905
2008
|
}
|
1906
2009
|
}
|
1907
2010
|
const input = {
|
1908
|
-
|
1909
|
-
type:
|
2011
|
+
...message,
|
2012
|
+
type: import_transactions6.InputType.Message,
|
1910
2013
|
sender: sender.toB256(),
|
1911
2014
|
recipient: recipient.toB256(),
|
1912
2015
|
amount,
|
1913
|
-
witnessIndex
|
1914
|
-
predicate
|
2016
|
+
witnessIndex
|
1915
2017
|
};
|
1916
2018
|
this.pushInput(input);
|
1917
2019
|
this.addChangeOutput(recipient, assetId);
|
@@ -1951,7 +2053,7 @@ var BaseTransactionRequest = class {
|
|
1951
2053
|
*/
|
1952
2054
|
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1953
2055
|
this.pushOutput({
|
1954
|
-
type:
|
2056
|
+
type: import_transactions6.OutputType.Coin,
|
1955
2057
|
to: (0, import_address.addressify)(to).toB256(),
|
1956
2058
|
amount,
|
1957
2059
|
assetId
|
@@ -1967,7 +2069,7 @@ var BaseTransactionRequest = class {
|
|
1967
2069
|
addCoinOutputs(to, quantities) {
|
1968
2070
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
1969
2071
|
this.pushOutput({
|
1970
|
-
type:
|
2072
|
+
type: import_transactions6.OutputType.Coin,
|
1971
2073
|
to: (0, import_address.addressify)(to).toB256(),
|
1972
2074
|
amount: quantity.amount,
|
1973
2075
|
assetId: quantity.assetId
|
@@ -1987,7 +2089,7 @@ var BaseTransactionRequest = class {
|
|
1987
2089
|
);
|
1988
2090
|
if (!changeOutput) {
|
1989
2091
|
this.pushOutput({
|
1990
|
-
type:
|
2092
|
+
type: import_transactions6.OutputType.Change,
|
1991
2093
|
to: (0, import_address.addressify)(to).toB256(),
|
1992
2094
|
assetId
|
1993
2095
|
});
|
@@ -2021,7 +2123,7 @@ var BaseTransactionRequest = class {
|
|
2021
2123
|
}
|
2022
2124
|
calculateMaxGas(chainInfo, minGas) {
|
2023
2125
|
const { consensusParameters } = chainInfo;
|
2024
|
-
const { gasPerByte } = consensusParameters;
|
2126
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2025
2127
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2026
2128
|
(acc, wit) => acc + wit.dataLength,
|
2027
2129
|
0
|
@@ -2030,7 +2132,8 @@ var BaseTransactionRequest = class {
|
|
2030
2132
|
gasPerByte,
|
2031
2133
|
minGas,
|
2032
2134
|
witnessesLength,
|
2033
|
-
witnessLimit: this.witnessLimit
|
2135
|
+
witnessLimit: this.witnessLimit,
|
2136
|
+
maxGasPerTx
|
2034
2137
|
});
|
2035
2138
|
}
|
2036
2139
|
/**
|
@@ -2048,17 +2151,20 @@ var BaseTransactionRequest = class {
|
|
2048
2151
|
});
|
2049
2152
|
const updateAssetInput = (assetId, quantity) => {
|
2050
2153
|
const assetInput = findAssetInput(assetId);
|
2154
|
+
let usedQuantity = quantity;
|
2155
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2156
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2157
|
+
}
|
2051
2158
|
if (assetInput && "assetId" in assetInput) {
|
2052
2159
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2053
|
-
assetInput.amount =
|
2160
|
+
assetInput.amount = usedQuantity;
|
2054
2161
|
} else {
|
2055
2162
|
this.addResources([
|
2056
2163
|
{
|
2057
2164
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2058
|
-
amount:
|
2165
|
+
amount: usedQuantity,
|
2059
2166
|
assetId,
|
2060
2167
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2061
|
-
maturity: 0,
|
2062
2168
|
blockCreated: (0, import_math7.bn)(1),
|
2063
2169
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2064
2170
|
}
|
@@ -2090,20 +2196,16 @@ var BaseTransactionRequest = class {
|
|
2090
2196
|
toJSON() {
|
2091
2197
|
return normalizeJSON(this);
|
2092
2198
|
}
|
2093
|
-
|
2094
|
-
this.witnesses.splice(index, 1);
|
2095
|
-
this.adjustWitnessIndexes(index);
|
2096
|
-
}
|
2097
|
-
updatePredicateInputs(inputs) {
|
2199
|
+
updatePredicateGasUsed(inputs) {
|
2098
2200
|
this.inputs.forEach((i) => {
|
2099
2201
|
let correspondingInput;
|
2100
2202
|
switch (i.type) {
|
2101
|
-
case
|
2102
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2203
|
+
case import_transactions6.InputType.Coin:
|
2204
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
|
2103
2205
|
break;
|
2104
|
-
case
|
2206
|
+
case import_transactions6.InputType.Message:
|
2105
2207
|
correspondingInput = inputs.find(
|
2106
|
-
(x) => x.type ===
|
2208
|
+
(x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
|
2107
2209
|
);
|
2108
2210
|
break;
|
2109
2211
|
default:
|
@@ -2116,10 +2218,12 @@ var BaseTransactionRequest = class {
|
|
2116
2218
|
}
|
2117
2219
|
});
|
2118
2220
|
}
|
2119
|
-
|
2120
|
-
this.inputs.
|
2121
|
-
if (input.
|
2122
|
-
input.
|
2221
|
+
shiftPredicateData() {
|
2222
|
+
this.inputs.forEach((input) => {
|
2223
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2224
|
+
input.predicateData = input.paddPredicateData(
|
2225
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2226
|
+
);
|
2123
2227
|
}
|
2124
2228
|
});
|
2125
2229
|
}
|
@@ -2128,25 +2232,25 @@ var BaseTransactionRequest = class {
|
|
2128
2232
|
// src/providers/transaction-request/create-transaction-request.ts
|
2129
2233
|
var import_configs9 = require("@fuel-ts/address/configs");
|
2130
2234
|
var import_math9 = require("@fuel-ts/math");
|
2131
|
-
var
|
2235
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2132
2236
|
var import_utils13 = require("@fuel-ts/utils");
|
2133
2237
|
|
2134
2238
|
// src/providers/transaction-request/hash-transaction.ts
|
2135
2239
|
var import_configs8 = require("@fuel-ts/address/configs");
|
2136
2240
|
var import_hasher = require("@fuel-ts/hasher");
|
2137
2241
|
var import_math8 = require("@fuel-ts/math");
|
2138
|
-
var
|
2242
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2139
2243
|
var import_utils11 = require("@fuel-ts/utils");
|
2140
2244
|
var import_ramda2 = require("ramda");
|
2141
2245
|
function hashTransaction(transactionRequest, chainId) {
|
2142
2246
|
const transaction = transactionRequest.toTransaction();
|
2143
|
-
if (transaction.type ===
|
2247
|
+
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2144
2248
|
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2145
2249
|
}
|
2146
2250
|
transaction.inputs = transaction.inputs.map((input) => {
|
2147
2251
|
const inputClone = (0, import_ramda2.clone)(input);
|
2148
2252
|
switch (inputClone.type) {
|
2149
|
-
case
|
2253
|
+
case import_transactions7.InputType.Coin: {
|
2150
2254
|
inputClone.txPointer = {
|
2151
2255
|
blockHeight: 0,
|
2152
2256
|
txIndex: 0
|
@@ -2154,11 +2258,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2154
2258
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2155
2259
|
return inputClone;
|
2156
2260
|
}
|
2157
|
-
case
|
2261
|
+
case import_transactions7.InputType.Message: {
|
2158
2262
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2159
2263
|
return inputClone;
|
2160
2264
|
}
|
2161
|
-
case
|
2265
|
+
case import_transactions7.InputType.Contract: {
|
2162
2266
|
inputClone.txPointer = {
|
2163
2267
|
blockHeight: 0,
|
2164
2268
|
txIndex: 0
|
@@ -2176,16 +2280,16 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2176
2280
|
transaction.outputs = transaction.outputs.map((output) => {
|
2177
2281
|
const outputClone = (0, import_ramda2.clone)(output);
|
2178
2282
|
switch (outputClone.type) {
|
2179
|
-
case
|
2283
|
+
case import_transactions7.OutputType.Contract: {
|
2180
2284
|
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2181
2285
|
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2182
2286
|
return outputClone;
|
2183
2287
|
}
|
2184
|
-
case
|
2288
|
+
case import_transactions7.OutputType.Change: {
|
2185
2289
|
outputClone.amount = (0, import_math8.bn)(0);
|
2186
2290
|
return outputClone;
|
2187
2291
|
}
|
2188
|
-
case
|
2292
|
+
case import_transactions7.OutputType.Variable: {
|
2189
2293
|
outputClone.to = import_configs8.ZeroBytes32;
|
2190
2294
|
outputClone.amount = (0, import_math8.bn)(0);
|
2191
2295
|
outputClone.assetId = import_configs8.ZeroBytes32;
|
@@ -2198,7 +2302,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2198
2302
|
transaction.witnessesCount = 0;
|
2199
2303
|
transaction.witnesses = [];
|
2200
2304
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2201
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2305
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
|
2202
2306
|
return (0, import_hasher.sha256)(concatenatedData);
|
2203
2307
|
}
|
2204
2308
|
|
@@ -2234,7 +2338,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2234
2338
|
return new this(obj);
|
2235
2339
|
}
|
2236
2340
|
/** Type of the transaction */
|
2237
|
-
type =
|
2341
|
+
type = import_transactions8.TransactionType.Create;
|
2238
2342
|
/** Witness index of contract bytecode to create */
|
2239
2343
|
bytecodeWitnessIndex;
|
2240
2344
|
/** Salt */
|
@@ -2267,11 +2371,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2267
2371
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2268
2372
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2269
2373
|
return {
|
2270
|
-
type:
|
2374
|
+
type: import_transactions8.TransactionType.Create,
|
2271
2375
|
...baseTransaction,
|
2272
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2273
2376
|
bytecodeWitnessIndex,
|
2274
|
-
storageSlotsCount: storageSlots.length,
|
2377
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2275
2378
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2276
2379
|
storageSlots
|
2277
2380
|
};
|
@@ -2283,7 +2386,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2283
2386
|
*/
|
2284
2387
|
getContractCreatedOutputs() {
|
2285
2388
|
return this.outputs.filter(
|
2286
|
-
(output) => output.type ===
|
2389
|
+
(output) => output.type === import_transactions8.OutputType.ContractCreated
|
2287
2390
|
);
|
2288
2391
|
}
|
2289
2392
|
/**
|
@@ -2304,7 +2407,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2304
2407
|
*/
|
2305
2408
|
addContractCreatedOutput(contractId, stateRoot) {
|
2306
2409
|
this.pushOutput({
|
2307
|
-
type:
|
2410
|
+
type: import_transactions8.OutputType.ContractCreated,
|
2308
2411
|
contractId,
|
2309
2412
|
stateRoot
|
2310
2413
|
});
|
@@ -2324,7 +2427,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
2324
2427
|
var import_address2 = require("@fuel-ts/address");
|
2325
2428
|
var import_configs10 = require("@fuel-ts/address/configs");
|
2326
2429
|
var import_math10 = require("@fuel-ts/math");
|
2327
|
-
var
|
2430
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2328
2431
|
var import_utils15 = require("@fuel-ts/utils");
|
2329
2432
|
|
2330
2433
|
// src/providers/transaction-request/scripts.ts
|
@@ -2362,7 +2465,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2362
2465
|
return new this(obj);
|
2363
2466
|
}
|
2364
2467
|
/** Type of the transaction */
|
2365
|
-
type =
|
2468
|
+
type = import_transactions9.TransactionType.Script;
|
2366
2469
|
/** Gas limit for transaction */
|
2367
2470
|
gasLimit;
|
2368
2471
|
/** Script to execute */
|
@@ -2391,11 +2494,11 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2494
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2392
2495
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2393
2496
|
return {
|
2394
|
-
type:
|
2497
|
+
type: import_transactions9.TransactionType.Script,
|
2395
2498
|
scriptGasLimit: this.gasLimit,
|
2396
2499
|
...super.getBaseTransaction(),
|
2397
|
-
scriptLength: script.length,
|
2398
|
-
scriptDataLength: scriptData.length,
|
2500
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2501
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2399
2502
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2400
2503
|
script: (0, import_utils15.hexlify)(script),
|
2401
2504
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2408,7 +2511,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2408
2511
|
*/
|
2409
2512
|
getContractInputs() {
|
2410
2513
|
return this.inputs.filter(
|
2411
|
-
(input) => input.type ===
|
2514
|
+
(input) => input.type === import_transactions9.InputType.Contract
|
2412
2515
|
);
|
2413
2516
|
}
|
2414
2517
|
/**
|
@@ -2418,7 +2521,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2418
2521
|
*/
|
2419
2522
|
getContractOutputs() {
|
2420
2523
|
return this.outputs.filter(
|
2421
|
-
(output) => output.type ===
|
2524
|
+
(output) => output.type === import_transactions9.OutputType.Contract
|
2422
2525
|
);
|
2423
2526
|
}
|
2424
2527
|
/**
|
@@ -2428,7 +2531,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2428
2531
|
*/
|
2429
2532
|
getVariableOutputs() {
|
2430
2533
|
return this.outputs.filter(
|
2431
|
-
(output) => output.type ===
|
2534
|
+
(output) => output.type === import_transactions9.OutputType.Variable
|
2432
2535
|
);
|
2433
2536
|
}
|
2434
2537
|
/**
|
@@ -2451,7 +2554,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2451
2554
|
let outputsNumber = numberOfVariables;
|
2452
2555
|
while (outputsNumber) {
|
2453
2556
|
this.pushOutput({
|
2454
|
-
type:
|
2557
|
+
type: import_transactions9.OutputType.Variable
|
2455
2558
|
});
|
2456
2559
|
outputsNumber -= 1;
|
2457
2560
|
}
|
@@ -2459,7 +2562,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2459
2562
|
}
|
2460
2563
|
calculateMaxGas(chainInfo, minGas) {
|
2461
2564
|
const { consensusParameters } = chainInfo;
|
2462
|
-
const { gasPerByte } = consensusParameters;
|
2565
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2463
2566
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2464
2567
|
(acc, wit) => acc + wit.dataLength,
|
2465
2568
|
0
|
@@ -2469,7 +2572,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2469
2572
|
minGas,
|
2470
2573
|
witnessesLength,
|
2471
2574
|
witnessLimit: this.witnessLimit,
|
2472
|
-
gasLimit: this.gasLimit
|
2575
|
+
gasLimit: this.gasLimit,
|
2576
|
+
maxGasPerTx
|
2473
2577
|
});
|
2474
2578
|
}
|
2475
2579
|
/**
|
@@ -2484,12 +2588,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2484
2588
|
return this;
|
2485
2589
|
}
|
2486
2590
|
const inputIndex = super.pushInput({
|
2487
|
-
type:
|
2591
|
+
type: import_transactions9.InputType.Contract,
|
2488
2592
|
contractId: contractAddress.toB256(),
|
2489
2593
|
txPointer: "0x00000000000000000000000000000000"
|
2490
2594
|
});
|
2491
2595
|
this.pushOutput({
|
2492
|
-
type:
|
2596
|
+
type: import_transactions9.OutputType.Contract,
|
2493
2597
|
inputIndex
|
2494
2598
|
});
|
2495
2599
|
return this;
|
@@ -2526,17 +2630,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2526
2630
|
|
2527
2631
|
// src/providers/transaction-request/utils.ts
|
2528
2632
|
var import_errors9 = require("@fuel-ts/errors");
|
2529
|
-
var
|
2633
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2530
2634
|
var transactionRequestify = (obj) => {
|
2531
2635
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2532
2636
|
return obj;
|
2533
2637
|
}
|
2534
2638
|
const { type } = obj;
|
2535
2639
|
switch (obj.type) {
|
2536
|
-
case
|
2640
|
+
case import_transactions10.TransactionType.Script: {
|
2537
2641
|
return ScriptTransactionRequest.from(obj);
|
2538
2642
|
}
|
2539
|
-
case
|
2643
|
+
case import_transactions10.TransactionType.Create: {
|
2540
2644
|
return CreateTransactionRequest.from(obj);
|
2541
2645
|
}
|
2542
2646
|
default: {
|
@@ -2544,42 +2648,59 @@ var transactionRequestify = (obj) => {
|
|
2544
2648
|
}
|
2545
2649
|
}
|
2546
2650
|
};
|
2651
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2652
|
+
(acc, input) => {
|
2653
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2654
|
+
acc.utxos.push(input.id);
|
2655
|
+
}
|
2656
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2657
|
+
acc.messages.push(input.nonce);
|
2658
|
+
}
|
2659
|
+
return acc;
|
2660
|
+
},
|
2661
|
+
{
|
2662
|
+
utxos: [],
|
2663
|
+
messages: []
|
2664
|
+
}
|
2665
|
+
);
|
2547
2666
|
|
2548
2667
|
// src/providers/transaction-response/transaction-response.ts
|
2549
2668
|
var import_errors13 = require("@fuel-ts/errors");
|
2550
|
-
var
|
2669
|
+
var import_math15 = require("@fuel-ts/math");
|
2551
2670
|
var import_transactions18 = require("@fuel-ts/transactions");
|
2552
|
-
var
|
2671
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2553
2672
|
|
2554
2673
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2555
|
-
var
|
2674
|
+
var import_math14 = require("@fuel-ts/math");
|
2675
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2676
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2556
2677
|
|
2557
2678
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2558
2679
|
var import_math11 = require("@fuel-ts/math");
|
2559
|
-
var
|
2680
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2560
2681
|
var import_utils16 = require("@fuel-ts/utils");
|
2561
2682
|
var calculateTransactionFee = (params) => {
|
2562
2683
|
const {
|
2563
|
-
|
2684
|
+
gasPrice,
|
2564
2685
|
rawPayload,
|
2565
|
-
|
2686
|
+
tip,
|
2687
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2566
2688
|
} = params;
|
2567
2689
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2568
2690
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2569
2691
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2570
|
-
const [transaction] = new
|
2571
|
-
if (transaction.type ===
|
2692
|
+
const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
|
2693
|
+
if (transaction.type === import_transactions11.TransactionType.Mint) {
|
2572
2694
|
return {
|
2573
2695
|
fee: (0, import_math11.bn)(0),
|
2574
2696
|
minFee: (0, import_math11.bn)(0),
|
2575
|
-
maxFee: (0, import_math11.bn)(0)
|
2576
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2697
|
+
maxFee: (0, import_math11.bn)(0)
|
2577
2698
|
};
|
2578
2699
|
}
|
2579
2700
|
const { type, witnesses, inputs, policies } = transaction;
|
2580
2701
|
let metadataGas = (0, import_math11.bn)(0);
|
2581
2702
|
let gasLimit = (0, import_math11.bn)(0);
|
2582
|
-
if (type ===
|
2703
|
+
if (type === import_transactions11.TransactionType.Create) {
|
2583
2704
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2584
2705
|
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2585
2706
|
metadataGas = calculateMetadataGasForTxCreate({
|
@@ -2605,25 +2726,32 @@ var calculateTransactionFee = (params) => {
|
|
2605
2726
|
metadataGas,
|
2606
2727
|
txBytesSize: transactionBytes.length
|
2607
2728
|
});
|
2608
|
-
const
|
2609
|
-
const witnessLimit = policies.find((policy) => policy.type === import_transactions12.PolicyType.WitnessLimit)?.data;
|
2729
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2610
2730
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2611
2731
|
const maxGas = getMaxGas({
|
2612
2732
|
gasPerByte,
|
2613
2733
|
minGas,
|
2614
2734
|
witnessesLength,
|
2615
2735
|
gasLimit,
|
2616
|
-
witnessLimit
|
2736
|
+
witnessLimit,
|
2737
|
+
maxGasPerTx
|
2738
|
+
});
|
2739
|
+
const minFee = calculateGasFee({
|
2740
|
+
gasPrice,
|
2741
|
+
gas: minGas,
|
2742
|
+
priceFactor: gasPriceFactor,
|
2743
|
+
tip
|
2744
|
+
});
|
2745
|
+
const maxFee = calculateGasFee({
|
2746
|
+
gasPrice,
|
2747
|
+
gas: maxGas,
|
2748
|
+
priceFactor: gasPriceFactor,
|
2749
|
+
tip
|
2617
2750
|
});
|
2618
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2619
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2620
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2621
|
-
const fee = minFee.add(feeFromGasUsed);
|
2622
2751
|
return {
|
2623
|
-
fee,
|
2624
2752
|
minFee,
|
2625
2753
|
maxFee,
|
2626
|
-
|
2754
|
+
fee: maxFee
|
2627
2755
|
};
|
2628
2756
|
};
|
2629
2757
|
|
@@ -2631,7 +2759,7 @@ var calculateTransactionFee = (params) => {
|
|
2631
2759
|
var import_configs11 = require("@fuel-ts/address/configs");
|
2632
2760
|
var import_errors11 = require("@fuel-ts/errors");
|
2633
2761
|
var import_math13 = require("@fuel-ts/math");
|
2634
|
-
var
|
2762
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2635
2763
|
|
2636
2764
|
// src/providers/transaction-summary/call.ts
|
2637
2765
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
@@ -2679,7 +2807,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2679
2807
|
|
2680
2808
|
// src/providers/transaction-summary/input.ts
|
2681
2809
|
var import_errors10 = require("@fuel-ts/errors");
|
2682
|
-
var
|
2810
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2683
2811
|
function getInputsByTypes(inputs, types) {
|
2684
2812
|
return inputs.filter((i) => types.includes(i.type));
|
2685
2813
|
}
|
@@ -2687,16 +2815,16 @@ function getInputsByType(inputs, type) {
|
|
2687
2815
|
return inputs.filter((i) => i.type === type);
|
2688
2816
|
}
|
2689
2817
|
function getInputsCoin(inputs) {
|
2690
|
-
return getInputsByType(inputs,
|
2818
|
+
return getInputsByType(inputs, import_transactions12.InputType.Coin);
|
2691
2819
|
}
|
2692
2820
|
function getInputsMessage(inputs) {
|
2693
|
-
return getInputsByType(inputs,
|
2821
|
+
return getInputsByType(inputs, import_transactions12.InputType.Message);
|
2694
2822
|
}
|
2695
2823
|
function getInputsCoinAndMessage(inputs) {
|
2696
|
-
return getInputsByTypes(inputs, [
|
2824
|
+
return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
|
2697
2825
|
}
|
2698
2826
|
function getInputsContract(inputs) {
|
2699
|
-
return getInputsByType(inputs,
|
2827
|
+
return getInputsByType(inputs, import_transactions12.InputType.Contract);
|
2700
2828
|
}
|
2701
2829
|
function getInputFromAssetId(inputs, assetId) {
|
2702
2830
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2715,7 +2843,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2715
2843
|
if (!contractInput) {
|
2716
2844
|
return void 0;
|
2717
2845
|
}
|
2718
|
-
if (contractInput.type !==
|
2846
|
+
if (contractInput.type !== import_transactions12.InputType.Contract) {
|
2719
2847
|
throw new import_errors10.FuelError(
|
2720
2848
|
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2721
2849
|
`Contract input should be of type 'contract'.`
|
@@ -2724,31 +2852,31 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2724
2852
|
return contractInput;
|
2725
2853
|
}
|
2726
2854
|
function getInputAccountAddress(input) {
|
2727
|
-
if (input.type ===
|
2855
|
+
if (input.type === import_transactions12.InputType.Coin) {
|
2728
2856
|
return input.owner.toString();
|
2729
2857
|
}
|
2730
|
-
if (input.type ===
|
2858
|
+
if (input.type === import_transactions12.InputType.Message) {
|
2731
2859
|
return input.recipient.toString();
|
2732
2860
|
}
|
2733
2861
|
return "";
|
2734
2862
|
}
|
2735
2863
|
|
2736
2864
|
// src/providers/transaction-summary/output.ts
|
2737
|
-
var
|
2865
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2738
2866
|
function getOutputsByType(outputs, type) {
|
2739
2867
|
return outputs.filter((o) => o.type === type);
|
2740
2868
|
}
|
2741
2869
|
function getOutputsContractCreated(outputs) {
|
2742
|
-
return getOutputsByType(outputs,
|
2870
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
|
2743
2871
|
}
|
2744
2872
|
function getOutputsCoin(outputs) {
|
2745
|
-
return getOutputsByType(outputs,
|
2873
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
|
2746
2874
|
}
|
2747
2875
|
function getOutputsChange(outputs) {
|
2748
|
-
return getOutputsByType(outputs,
|
2876
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Change);
|
2749
2877
|
}
|
2750
2878
|
function getOutputsContract(outputs) {
|
2751
|
-
return getOutputsByType(outputs,
|
2879
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
|
2752
2880
|
}
|
2753
2881
|
|
2754
2882
|
// src/providers/transaction-summary/operations.ts
|
@@ -2757,11 +2885,11 @@ function getReceiptsByType(receipts, type) {
|
|
2757
2885
|
}
|
2758
2886
|
function getTransactionTypeName(transactionType) {
|
2759
2887
|
switch (transactionType) {
|
2760
|
-
case
|
2888
|
+
case import_transactions14.TransactionType.Mint:
|
2761
2889
|
return "Mint" /* Mint */;
|
2762
|
-
case
|
2890
|
+
case import_transactions14.TransactionType.Create:
|
2763
2891
|
return "Create" /* Create */;
|
2764
|
-
case
|
2892
|
+
case import_transactions14.TransactionType.Script:
|
2765
2893
|
return "Script" /* Script */;
|
2766
2894
|
default:
|
2767
2895
|
throw new import_errors11.FuelError(
|
@@ -2784,10 +2912,10 @@ function isTypeScript(transactionType) {
|
|
2784
2912
|
return isType(transactionType, "Script" /* Script */);
|
2785
2913
|
}
|
2786
2914
|
function getReceiptsCall(receipts) {
|
2787
|
-
return getReceiptsByType(receipts,
|
2915
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
|
2788
2916
|
}
|
2789
2917
|
function getReceiptsMessageOut(receipts) {
|
2790
|
-
return getReceiptsByType(receipts,
|
2918
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
|
2791
2919
|
}
|
2792
2920
|
var mergeAssets = (op1, op2) => {
|
2793
2921
|
const assets1 = op1.assetsSent || [];
|
@@ -2983,11 +3111,11 @@ function getTransferOperations({
|
|
2983
3111
|
});
|
2984
3112
|
const transferReceipts = getReceiptsByType(
|
2985
3113
|
receipts,
|
2986
|
-
|
3114
|
+
import_transactions14.ReceiptType.Transfer
|
2987
3115
|
);
|
2988
3116
|
const transferOutReceipts = getReceiptsByType(
|
2989
3117
|
receipts,
|
2990
|
-
|
3118
|
+
import_transactions14.ReceiptType.TransferOut
|
2991
3119
|
);
|
2992
3120
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2993
3121
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3072,17 +3200,17 @@ function getOperations({
|
|
3072
3200
|
}
|
3073
3201
|
|
3074
3202
|
// src/providers/transaction-summary/receipt.ts
|
3075
|
-
var
|
3203
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3076
3204
|
var processGqlReceipt = (gqlReceipt) => {
|
3077
3205
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3078
3206
|
switch (receipt.type) {
|
3079
|
-
case
|
3207
|
+
case import_transactions15.ReceiptType.ReturnData: {
|
3080
3208
|
return {
|
3081
3209
|
...receipt,
|
3082
3210
|
data: gqlReceipt.data || "0x"
|
3083
3211
|
};
|
3084
3212
|
}
|
3085
|
-
case
|
3213
|
+
case import_transactions15.ReceiptType.LogData: {
|
3086
3214
|
return {
|
3087
3215
|
...receipt,
|
3088
3216
|
data: gqlReceipt.data || "0x"
|
@@ -3095,7 +3223,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3095
3223
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3096
3224
|
const mintedAssets = [];
|
3097
3225
|
receipts.forEach((receipt) => {
|
3098
|
-
if (receipt.type ===
|
3226
|
+
if (receipt.type === import_transactions15.ReceiptType.Mint) {
|
3099
3227
|
mintedAssets.push({
|
3100
3228
|
subId: receipt.subId,
|
3101
3229
|
contractId: receipt.contractId,
|
@@ -3109,7 +3237,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3109
3237
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3110
3238
|
const burnedAssets = [];
|
3111
3239
|
receipts.forEach((receipt) => {
|
3112
|
-
if (receipt.type ===
|
3240
|
+
if (receipt.type === import_transactions15.ReceiptType.Burn) {
|
3113
3241
|
burnedAssets.push({
|
3114
3242
|
subId: receipt.subId,
|
3115
3243
|
contractId: receipt.contractId,
|
@@ -3190,10 +3318,12 @@ function assembleTransactionSummary(params) {
|
|
3190
3318
|
gqlTransactionStatus,
|
3191
3319
|
abiMap = {},
|
3192
3320
|
maxInputs,
|
3193
|
-
gasCosts
|
3321
|
+
gasCosts,
|
3322
|
+
maxGasPerTx,
|
3323
|
+
gasPrice
|
3194
3324
|
} = params;
|
3195
3325
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3196
|
-
const rawPayload = (0,
|
3326
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3197
3327
|
const operations = getOperations({
|
3198
3328
|
transactionType: transaction.type,
|
3199
3329
|
inputs: transaction.inputs || [],
|
@@ -3204,11 +3334,14 @@ function assembleTransactionSummary(params) {
|
|
3204
3334
|
maxInputs
|
3205
3335
|
});
|
3206
3336
|
const typeName = getTransactionTypeName(transaction.type);
|
3337
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3207
3338
|
const { fee } = calculateTransactionFee({
|
3208
|
-
|
3339
|
+
gasPrice,
|
3209
3340
|
rawPayload,
|
3341
|
+
tip,
|
3210
3342
|
consensusParameters: {
|
3211
3343
|
gasCosts,
|
3344
|
+
maxGasPerTx,
|
3212
3345
|
feeParams: {
|
3213
3346
|
gasPerByte,
|
3214
3347
|
gasPriceFactor
|
@@ -3220,7 +3353,7 @@ function assembleTransactionSummary(params) {
|
|
3220
3353
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3221
3354
|
let date;
|
3222
3355
|
if (time) {
|
3223
|
-
date =
|
3356
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3224
3357
|
}
|
3225
3358
|
const transactionSummary = {
|
3226
3359
|
id,
|
@@ -3268,7 +3401,7 @@ var TransactionResponse = class {
|
|
3268
3401
|
/** Current provider */
|
3269
3402
|
provider;
|
3270
3403
|
/** Gas used on the transaction */
|
3271
|
-
gasUsed = (0,
|
3404
|
+
gasUsed = (0, import_math15.bn)(0);
|
3272
3405
|
/** The graphql Transaction with receipts object. */
|
3273
3406
|
gqlTransaction;
|
3274
3407
|
abis;
|
@@ -3327,7 +3460,7 @@ var TransactionResponse = class {
|
|
3327
3460
|
*/
|
3328
3461
|
decodeTransaction(transactionWithReceipts) {
|
3329
3462
|
return new import_transactions18.TransactionCoder().decode(
|
3330
|
-
(0,
|
3463
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3331
3464
|
0
|
3332
3465
|
)?.[0];
|
3333
3466
|
}
|
@@ -3346,20 +3479,27 @@ var TransactionResponse = class {
|
|
3346
3479
|
const decodedTransaction = this.decodeTransaction(
|
3347
3480
|
transaction
|
3348
3481
|
);
|
3349
|
-
|
3350
|
-
|
3482
|
+
let txReceipts = [];
|
3483
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3484
|
+
txReceipts = transaction.status.receipts;
|
3485
|
+
}
|
3486
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3487
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3488
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3351
3489
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3352
3490
|
const transactionSummary = assembleTransactionSummary({
|
3353
3491
|
id: this.id,
|
3354
3492
|
receipts,
|
3355
3493
|
transaction: decodedTransaction,
|
3356
|
-
transactionBytes: (0,
|
3494
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3357
3495
|
gqlTransactionStatus: transaction.status,
|
3358
3496
|
gasPerByte,
|
3359
3497
|
gasPriceFactor,
|
3360
3498
|
abiMap: contractsAbiMap,
|
3361
3499
|
maxInputs,
|
3362
|
-
gasCosts
|
3500
|
+
gasCosts,
|
3501
|
+
maxGasPerTx,
|
3502
|
+
gasPrice
|
3363
3503
|
});
|
3364
3504
|
return transactionSummary;
|
3365
3505
|
}
|
@@ -3486,29 +3626,29 @@ var processGqlChain = (chain) => {
|
|
3486
3626
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3487
3627
|
return {
|
3488
3628
|
name,
|
3489
|
-
baseChainHeight: (0,
|
3629
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3490
3630
|
consensusParameters: {
|
3491
|
-
contractMaxSize: (0,
|
3492
|
-
maxInputs: (0,
|
3493
|
-
maxOutputs: (0,
|
3494
|
-
maxWitnesses: (0,
|
3495
|
-
maxGasPerTx: (0,
|
3496
|
-
maxScriptLength: (0,
|
3497
|
-
maxScriptDataLength: (0,
|
3498
|
-
maxStorageSlots: (0,
|
3499
|
-
maxPredicateLength: (0,
|
3500
|
-
maxPredicateDataLength: (0,
|
3501
|
-
maxGasPerPredicate: (0,
|
3502
|
-
gasPriceFactor: (0,
|
3503
|
-
gasPerByte: (0,
|
3504
|
-
maxMessageDataLength: (0,
|
3505
|
-
chainId: (0,
|
3631
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3632
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3633
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3634
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3635
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3636
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3637
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3638
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3639
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3640
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3641
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3642
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3643
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3644
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3645
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3506
3646
|
gasCosts
|
3507
3647
|
},
|
3508
3648
|
gasCosts,
|
3509
3649
|
latestBlock: {
|
3510
3650
|
id: latestBlock.id,
|
3511
|
-
height: (0,
|
3651
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3512
3652
|
time: latestBlock.header.time,
|
3513
3653
|
transactions: latestBlock.transactions.map((i) => ({
|
3514
3654
|
id: i.id
|
@@ -3602,10 +3742,8 @@ var _Provider = class {
|
|
3602
3742
|
* Returns some helpful parameters related to gas fees.
|
3603
3743
|
*/
|
3604
3744
|
getGasConfig() {
|
3605
|
-
const { minGasPrice } = this.getNode();
|
3606
3745
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3607
3746
|
return {
|
3608
|
-
minGasPrice,
|
3609
3747
|
maxGasPerTx,
|
3610
3748
|
maxGasPerPredicate,
|
3611
3749
|
gasPriceFactor,
|
@@ -3703,7 +3841,7 @@ var _Provider = class {
|
|
3703
3841
|
*/
|
3704
3842
|
async getBlockNumber() {
|
3705
3843
|
const { chain } = await this.operations.getChain();
|
3706
|
-
return (0,
|
3844
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3707
3845
|
}
|
3708
3846
|
/**
|
3709
3847
|
* Returns the chain information.
|
@@ -3713,13 +3851,11 @@ var _Provider = class {
|
|
3713
3851
|
async fetchNode() {
|
3714
3852
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3715
3853
|
const processedNodeInfo = {
|
3716
|
-
maxDepth: (0,
|
3717
|
-
maxTx: (0,
|
3718
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3854
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
3855
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3719
3856
|
nodeVersion: nodeInfo.nodeVersion,
|
3720
3857
|
utxoValidation: nodeInfo.utxoValidation,
|
3721
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3722
|
-
peers: nodeInfo.peers
|
3858
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3723
3859
|
};
|
3724
3860
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3725
3861
|
return processedNodeInfo;
|
@@ -3761,7 +3897,7 @@ var _Provider = class {
|
|
3761
3897
|
if (estimateTxDependencies) {
|
3762
3898
|
await this.estimateTxDependencies(transactionRequest);
|
3763
3899
|
}
|
3764
|
-
const encodedTransaction = (0,
|
3900
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3765
3901
|
let abis;
|
3766
3902
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3767
3903
|
abis = transactionRequest.abis;
|
@@ -3804,15 +3940,14 @@ var _Provider = class {
|
|
3804
3940
|
if (estimateTxDependencies) {
|
3805
3941
|
return this.estimateTxDependencies(transactionRequest);
|
3806
3942
|
}
|
3807
|
-
const encodedTransaction = (0,
|
3808
|
-
const { dryRun:
|
3809
|
-
encodedTransaction,
|
3943
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3944
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3945
|
+
encodedTransactions: encodedTransaction,
|
3810
3946
|
utxoValidation: utxoValidation || false
|
3811
3947
|
});
|
3812
|
-
const receipts =
|
3813
|
-
|
3814
|
-
|
3815
|
-
};
|
3948
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3949
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3950
|
+
return { receipts, dryrunStatus: status };
|
3816
3951
|
}
|
3817
3952
|
/**
|
3818
3953
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3823,13 +3958,13 @@ var _Provider = class {
|
|
3823
3958
|
async estimatePredicates(transactionRequest) {
|
3824
3959
|
const shouldEstimatePredicates = Boolean(
|
3825
3960
|
transactionRequest.inputs.find(
|
3826
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3961
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
|
3827
3962
|
)
|
3828
3963
|
);
|
3829
3964
|
if (!shouldEstimatePredicates) {
|
3830
3965
|
return transactionRequest;
|
3831
3966
|
}
|
3832
|
-
const encodedTransaction = (0,
|
3967
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3833
3968
|
const response = await this.operations.estimatePredicates({
|
3834
3969
|
encodedTransaction
|
3835
3970
|
});
|
@@ -3838,7 +3973,7 @@ var _Provider = class {
|
|
3838
3973
|
} = response;
|
3839
3974
|
if (inputs) {
|
3840
3975
|
inputs.forEach((input, index) => {
|
3841
|
-
if ("predicateGasUsed" in input && (0,
|
3976
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
3842
3977
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3843
3978
|
}
|
3844
3979
|
});
|
@@ -3851,9 +3986,6 @@ var _Provider = class {
|
|
3851
3986
|
* If there are missing variable outputs,
|
3852
3987
|
* `addVariableOutputs` is called on the transaction.
|
3853
3988
|
*
|
3854
|
-
* @privateRemarks
|
3855
|
-
* TODO: Investigate support for missing contract IDs
|
3856
|
-
* TODO: Add support for missing output messages
|
3857
3989
|
*
|
3858
3990
|
* @param transactionRequest - The transaction request object.
|
3859
3991
|
* @returns A promise.
|
@@ -3866,16 +3998,19 @@ var _Provider = class {
|
|
3866
3998
|
missingContractIds: []
|
3867
3999
|
};
|
3868
4000
|
}
|
3869
|
-
await this.estimatePredicates(transactionRequest);
|
3870
4001
|
let receipts = [];
|
3871
4002
|
const missingContractIds = [];
|
3872
4003
|
let outputVariables = 0;
|
4004
|
+
let dryrunStatus;
|
3873
4005
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3874
|
-
const {
|
3875
|
-
|
4006
|
+
const {
|
4007
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4008
|
+
} = await this.operations.dryRun({
|
4009
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3876
4010
|
utxoValidation: false
|
3877
4011
|
});
|
3878
|
-
receipts =
|
4012
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4013
|
+
dryrunStatus = status;
|
3879
4014
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3880
4015
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3881
4016
|
if (hasMissingOutputs) {
|
@@ -3885,6 +4020,10 @@ var _Provider = class {
|
|
3885
4020
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3886
4021
|
missingContractIds.push(contractId);
|
3887
4022
|
});
|
4023
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4024
|
+
transactionRequest
|
4025
|
+
});
|
4026
|
+
transactionRequest.maxFee = maxFee;
|
3888
4027
|
} else {
|
3889
4028
|
break;
|
3890
4029
|
}
|
@@ -3892,37 +4031,139 @@ var _Provider = class {
|
|
3892
4031
|
return {
|
3893
4032
|
receipts,
|
3894
4033
|
outputVariables,
|
3895
|
-
missingContractIds
|
4034
|
+
missingContractIds,
|
4035
|
+
dryrunStatus
|
3896
4036
|
};
|
3897
4037
|
}
|
4038
|
+
/**
|
4039
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4040
|
+
*
|
4041
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4042
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4043
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4044
|
+
*
|
4045
|
+
* @param transactionRequests - Array of transaction request objects.
|
4046
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4047
|
+
*/
|
4048
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4049
|
+
const results = transactionRequests.map(() => ({
|
4050
|
+
receipts: [],
|
4051
|
+
outputVariables: 0,
|
4052
|
+
missingContractIds: [],
|
4053
|
+
dryrunStatus: void 0
|
4054
|
+
}));
|
4055
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4056
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4057
|
+
allRequests.forEach((req, index) => {
|
4058
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4059
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4060
|
+
}
|
4061
|
+
});
|
4062
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4063
|
+
let attempt = 0;
|
4064
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4065
|
+
const encodedTransactions = transactionsToProcess.map(
|
4066
|
+
(index) => serializedTransactionsMap.get(index)
|
4067
|
+
);
|
4068
|
+
const dryRunResults = await this.operations.dryRun({
|
4069
|
+
encodedTransactions,
|
4070
|
+
utxoValidation: false
|
4071
|
+
});
|
4072
|
+
const nextRoundTransactions = [];
|
4073
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4074
|
+
const currentResultIndex = transactionsToProcess[i];
|
4075
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4076
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4077
|
+
results[currentResultIndex].dryrunStatus = status;
|
4078
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4079
|
+
results[currentResultIndex].receipts
|
4080
|
+
);
|
4081
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4082
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4083
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4084
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4085
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4086
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4087
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4088
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4089
|
+
});
|
4090
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4091
|
+
transactionRequest: requestToProcess
|
4092
|
+
});
|
4093
|
+
requestToProcess.maxFee = maxFee;
|
4094
|
+
serializedTransactionsMap.set(
|
4095
|
+
currentResultIndex,
|
4096
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4097
|
+
);
|
4098
|
+
nextRoundTransactions.push(currentResultIndex);
|
4099
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4100
|
+
}
|
4101
|
+
}
|
4102
|
+
transactionsToProcess = nextRoundTransactions;
|
4103
|
+
attempt += 1;
|
4104
|
+
}
|
4105
|
+
return results;
|
4106
|
+
}
|
4107
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4108
|
+
if (estimateTxDependencies) {
|
4109
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4110
|
+
}
|
4111
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4112
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4113
|
+
encodedTransactions,
|
4114
|
+
utxoValidation: utxoValidation || false
|
4115
|
+
});
|
4116
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4117
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4118
|
+
return { receipts, dryrunStatus: status };
|
4119
|
+
});
|
4120
|
+
return results;
|
4121
|
+
}
|
3898
4122
|
/**
|
3899
4123
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3900
4124
|
* @param transactionRequest - The transaction request object.
|
3901
4125
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3902
4126
|
*/
|
3903
|
-
estimateTxGasAndFee(params) {
|
4127
|
+
async estimateTxGasAndFee(params) {
|
3904
4128
|
const { transactionRequest } = params;
|
3905
|
-
|
4129
|
+
let { gasPrice } = params;
|
3906
4130
|
const chainInfo = this.getChain();
|
3907
|
-
const
|
3908
|
-
transactionRequest.gasPrice = gasPrice;
|
4131
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3909
4132
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3910
|
-
|
4133
|
+
if (!gasPrice) {
|
4134
|
+
gasPrice = await this.estimateGasPrice(10);
|
4135
|
+
}
|
4136
|
+
const minFee = calculateGasFee({
|
4137
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4138
|
+
gas: minGas,
|
4139
|
+
priceFactor: gasPriceFactor,
|
4140
|
+
tip: transactionRequest.tip
|
4141
|
+
}).add(1);
|
4142
|
+
let gasLimit = (0, import_math16.bn)(0);
|
3911
4143
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4144
|
+
gasLimit = transactionRequest.gasLimit;
|
3912
4145
|
if (transactionRequest.gasLimit.eq(0)) {
|
3913
4146
|
transactionRequest.gasLimit = minGas;
|
3914
4147
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3915
4148
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3916
4149
|
);
|
4150
|
+
gasLimit = transactionRequest.gasLimit;
|
3917
4151
|
}
|
3918
4152
|
}
|
3919
4153
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3920
|
-
const maxFee =
|
4154
|
+
const maxFee = calculateGasFee({
|
4155
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4156
|
+
gas: maxGas,
|
4157
|
+
priceFactor: gasPriceFactor,
|
4158
|
+
tip: transactionRequest.tip
|
4159
|
+
}).add(1);
|
3921
4160
|
return {
|
3922
4161
|
minGas,
|
3923
4162
|
minFee,
|
3924
4163
|
maxGas,
|
3925
|
-
maxFee
|
4164
|
+
maxFee,
|
4165
|
+
gasPrice,
|
4166
|
+
gasLimit
|
3926
4167
|
};
|
3927
4168
|
}
|
3928
4169
|
/**
|
@@ -3940,15 +4181,17 @@ var _Provider = class {
|
|
3940
4181
|
if (estimateTxDependencies) {
|
3941
4182
|
return this.estimateTxDependencies(transactionRequest);
|
3942
4183
|
}
|
3943
|
-
const
|
3944
|
-
const { dryRun:
|
3945
|
-
|
4184
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4185
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4186
|
+
encodedTransactions,
|
3946
4187
|
utxoValidation: true
|
3947
4188
|
});
|
3948
|
-
const
|
3949
|
-
|
3950
|
-
receipts
|
3951
|
-
|
4189
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4190
|
+
const { id, receipts, status } = dryRunStatus;
|
4191
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4192
|
+
return { id, receipts: processedReceipts, status };
|
4193
|
+
});
|
4194
|
+
return { receipts: callResult[0].receipts };
|
3952
4195
|
}
|
3953
4196
|
/**
|
3954
4197
|
* Returns a transaction cost to enable user
|
@@ -3965,77 +4208,79 @@ var _Provider = class {
|
|
3965
4208
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3966
4209
|
* @returns A promise that resolves to the transaction cost object.
|
3967
4210
|
*/
|
3968
|
-
async getTransactionCost(transactionRequestLike,
|
3969
|
-
estimateTxDependencies = true,
|
3970
|
-
estimatePredicates = true,
|
3971
|
-
resourcesOwner,
|
3972
|
-
signatureCallback
|
3973
|
-
} = {}) {
|
4211
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3974
4212
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3975
|
-
const { minGasPrice } = this.getGasConfig();
|
3976
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3977
4213
|
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
3978
4214
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3979
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4215
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3980
4216
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4217
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
3981
4218
|
if (isScriptTransaction) {
|
3982
|
-
txRequestClone.gasLimit = (0,
|
4219
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
3983
4220
|
}
|
3984
|
-
if (
|
3985
|
-
|
3986
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3987
|
-
}
|
3988
|
-
await this.estimatePredicates(txRequestClone);
|
4221
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4222
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3989
4223
|
}
|
4224
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4225
|
+
let addedSignatures = 0;
|
3990
4226
|
if (signatureCallback && isScriptTransaction) {
|
3991
|
-
|
4227
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4228
|
+
await signatureCallback(signedRequest);
|
4229
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3992
4230
|
}
|
3993
|
-
|
3994
|
-
|
4231
|
+
await this.estimatePredicates(signedRequest);
|
4232
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4233
|
+
transactionRequest: signedRequest
|
3995
4234
|
});
|
3996
4235
|
let receipts = [];
|
3997
4236
|
let missingContractIds = [];
|
3998
4237
|
let outputVariables = 0;
|
3999
|
-
let gasUsed = (0,
|
4000
|
-
|
4001
|
-
|
4238
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4239
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4240
|
+
txRequestClone.maxFee = maxFee;
|
4241
|
+
if (isScriptTransaction) {
|
4242
|
+
txRequestClone.gasLimit = gasLimit;
|
4243
|
+
if (signatureCallback) {
|
4244
|
+
await signatureCallback(txRequestClone);
|
4245
|
+
}
|
4002
4246
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4003
4247
|
receipts = result.receipts;
|
4004
4248
|
outputVariables = result.outputVariables;
|
4005
4249
|
missingContractIds = result.missingContractIds;
|
4006
4250
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4007
4251
|
txRequestClone.gasLimit = gasUsed;
|
4008
|
-
|
4009
|
-
|
4010
|
-
|
4252
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4253
|
+
transactionRequest: txRequestClone,
|
4254
|
+
gasPrice
|
4011
4255
|
}));
|
4012
4256
|
}
|
4013
4257
|
return {
|
4014
4258
|
requiredQuantities: allQuantities,
|
4015
4259
|
receipts,
|
4016
4260
|
gasUsed,
|
4017
|
-
|
4018
|
-
gasPrice: setGasPrice,
|
4261
|
+
gasPrice,
|
4019
4262
|
minGas,
|
4020
4263
|
maxGas,
|
4021
4264
|
minFee,
|
4022
4265
|
maxFee,
|
4023
|
-
estimatedInputs: txRequestClone.inputs,
|
4024
4266
|
outputVariables,
|
4025
|
-
missingContractIds
|
4267
|
+
missingContractIds,
|
4268
|
+
addedSignatures,
|
4269
|
+
estimatedPredicates: txRequestClone.inputs
|
4026
4270
|
};
|
4027
4271
|
}
|
4028
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4272
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4029
4273
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4030
4274
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4031
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4275
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4276
|
+
quantitiesToContract
|
4277
|
+
});
|
4032
4278
|
transactionRequest.addResources(
|
4033
4279
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4034
4280
|
);
|
4035
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4036
|
-
|
4037
|
-
|
4038
|
-
);
|
4281
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4282
|
+
quantitiesToContract
|
4283
|
+
});
|
4039
4284
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4040
4285
|
return {
|
4041
4286
|
resources,
|
@@ -4051,17 +4296,16 @@ var _Provider = class {
|
|
4051
4296
|
const result = await this.operations.getCoins({
|
4052
4297
|
first: 10,
|
4053
4298
|
...paginationArgs,
|
4054
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4299
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4055
4300
|
});
|
4056
4301
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4057
4302
|
return coins.map((coin) => ({
|
4058
4303
|
id: coin.utxoId,
|
4059
4304
|
assetId: coin.assetId,
|
4060
|
-
amount: (0,
|
4305
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4061
4306
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4062
|
-
|
4063
|
-
|
4064
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4307
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4308
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4065
4309
|
}));
|
4066
4310
|
}
|
4067
4311
|
/**
|
@@ -4075,19 +4319,19 @@ var _Provider = class {
|
|
4075
4319
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4076
4320
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4077
4321
|
const excludeInput = {
|
4078
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4079
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4322
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4323
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4080
4324
|
};
|
4081
4325
|
if (this.cache) {
|
4082
4326
|
const uniqueUtxos = new Set(
|
4083
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4327
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4084
4328
|
);
|
4085
4329
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4086
4330
|
}
|
4087
4331
|
const coinsQuery = {
|
4088
4332
|
owner: ownerAddress.toB256(),
|
4089
4333
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4090
|
-
assetId: (0,
|
4334
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4091
4335
|
amount: amount.toString(10),
|
4092
4336
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4093
4337
|
})),
|
@@ -4098,9 +4342,9 @@ var _Provider = class {
|
|
4098
4342
|
switch (coin.__typename) {
|
4099
4343
|
case "MessageCoin":
|
4100
4344
|
return {
|
4101
|
-
amount: (0,
|
4345
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4102
4346
|
assetId: coin.assetId,
|
4103
|
-
daHeight: (0,
|
4347
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4104
4348
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4105
4349
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4106
4350
|
nonce: coin.nonce
|
@@ -4108,12 +4352,11 @@ var _Provider = class {
|
|
4108
4352
|
case "Coin":
|
4109
4353
|
return {
|
4110
4354
|
id: coin.utxoId,
|
4111
|
-
amount: (0,
|
4355
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4112
4356
|
assetId: coin.assetId,
|
4113
4357
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4114
|
-
|
4115
|
-
|
4116
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4358
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4359
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4117
4360
|
};
|
4118
4361
|
default:
|
4119
4362
|
return null;
|
@@ -4130,13 +4373,13 @@ var _Provider = class {
|
|
4130
4373
|
async getBlock(idOrHeight) {
|
4131
4374
|
let variables;
|
4132
4375
|
if (typeof idOrHeight === "number") {
|
4133
|
-
variables = { height: (0,
|
4376
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4134
4377
|
} else if (idOrHeight === "latest") {
|
4135
4378
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4136
4379
|
} else if (idOrHeight.length === 66) {
|
4137
4380
|
variables = { blockId: idOrHeight };
|
4138
4381
|
} else {
|
4139
|
-
variables = { blockId: (0,
|
4382
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4140
4383
|
}
|
4141
4384
|
const { block } = await this.operations.getBlock(variables);
|
4142
4385
|
if (!block) {
|
@@ -4144,7 +4387,7 @@ var _Provider = class {
|
|
4144
4387
|
}
|
4145
4388
|
return {
|
4146
4389
|
id: block.id,
|
4147
|
-
height: (0,
|
4390
|
+
height: (0, import_math16.bn)(block.height),
|
4148
4391
|
time: block.header.time,
|
4149
4392
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4150
4393
|
};
|
@@ -4159,7 +4402,7 @@ var _Provider = class {
|
|
4159
4402
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4160
4403
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4161
4404
|
id: block.id,
|
4162
|
-
height: (0,
|
4405
|
+
height: (0, import_math16.bn)(block.height),
|
4163
4406
|
time: block.header.time,
|
4164
4407
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4165
4408
|
}));
|
@@ -4174,7 +4417,7 @@ var _Provider = class {
|
|
4174
4417
|
async getBlockWithTransactions(idOrHeight) {
|
4175
4418
|
let variables;
|
4176
4419
|
if (typeof idOrHeight === "number") {
|
4177
|
-
variables = { blockHeight: (0,
|
4420
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4178
4421
|
} else if (idOrHeight === "latest") {
|
4179
4422
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4180
4423
|
} else {
|
@@ -4186,11 +4429,11 @@ var _Provider = class {
|
|
4186
4429
|
}
|
4187
4430
|
return {
|
4188
4431
|
id: block.id,
|
4189
|
-
height: (0,
|
4432
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4190
4433
|
time: block.header.time,
|
4191
4434
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4192
4435
|
transactions: block.transactions.map(
|
4193
|
-
(tx) => new import_transactions19.TransactionCoder().decode((0,
|
4436
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4194
4437
|
)
|
4195
4438
|
};
|
4196
4439
|
}
|
@@ -4206,7 +4449,7 @@ var _Provider = class {
|
|
4206
4449
|
return null;
|
4207
4450
|
}
|
4208
4451
|
return new import_transactions19.TransactionCoder().decode(
|
4209
|
-
(0,
|
4452
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4210
4453
|
0
|
4211
4454
|
)?.[0];
|
4212
4455
|
}
|
@@ -4233,9 +4476,9 @@ var _Provider = class {
|
|
4233
4476
|
async getContractBalance(contractId, assetId) {
|
4234
4477
|
const { contractBalance } = await this.operations.getContractBalance({
|
4235
4478
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4236
|
-
asset: (0,
|
4479
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4237
4480
|
});
|
4238
|
-
return (0,
|
4481
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4239
4482
|
}
|
4240
4483
|
/**
|
4241
4484
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4247,9 +4490,9 @@ var _Provider = class {
|
|
4247
4490
|
async getBalance(owner, assetId) {
|
4248
4491
|
const { balance } = await this.operations.getBalance({
|
4249
4492
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4250
|
-
assetId: (0,
|
4493
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4251
4494
|
});
|
4252
|
-
return (0,
|
4495
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4253
4496
|
}
|
4254
4497
|
/**
|
4255
4498
|
* Returns balances for the given owner.
|
@@ -4267,7 +4510,7 @@ var _Provider = class {
|
|
4267
4510
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4268
4511
|
return balances.map((balance) => ({
|
4269
4512
|
assetId: balance.assetId,
|
4270
|
-
amount: (0,
|
4513
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4271
4514
|
}));
|
4272
4515
|
}
|
4273
4516
|
/**
|
@@ -4289,15 +4532,15 @@ var _Provider = class {
|
|
4289
4532
|
sender: message.sender,
|
4290
4533
|
recipient: message.recipient,
|
4291
4534
|
nonce: message.nonce,
|
4292
|
-
amount: (0,
|
4535
|
+
amount: (0, import_math16.bn)(message.amount),
|
4293
4536
|
data: message.data
|
4294
4537
|
}),
|
4295
4538
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4296
4539
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4297
4540
|
nonce: message.nonce,
|
4298
|
-
amount: (0,
|
4541
|
+
amount: (0, import_math16.bn)(message.amount),
|
4299
4542
|
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4300
|
-
daHeight: (0,
|
4543
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4301
4544
|
}));
|
4302
4545
|
}
|
4303
4546
|
/**
|
@@ -4350,44 +4593,60 @@ var _Provider = class {
|
|
4350
4593
|
} = result.messageProof;
|
4351
4594
|
return {
|
4352
4595
|
messageProof: {
|
4353
|
-
proofIndex: (0,
|
4596
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4354
4597
|
proofSet: messageProof.proofSet
|
4355
4598
|
},
|
4356
4599
|
blockProof: {
|
4357
|
-
proofIndex: (0,
|
4600
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4358
4601
|
proofSet: blockProof.proofSet
|
4359
4602
|
},
|
4360
4603
|
messageBlockHeader: {
|
4361
4604
|
id: messageBlockHeader.id,
|
4362
|
-
daHeight: (0,
|
4363
|
-
transactionsCount: (0,
|
4605
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4606
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4364
4607
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4365
|
-
height: (0,
|
4608
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4366
4609
|
prevRoot: messageBlockHeader.prevRoot,
|
4367
4610
|
time: messageBlockHeader.time,
|
4368
4611
|
applicationHash: messageBlockHeader.applicationHash,
|
4369
|
-
|
4370
|
-
|
4612
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4613
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4614
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4615
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4616
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4371
4617
|
},
|
4372
4618
|
commitBlockHeader: {
|
4373
4619
|
id: commitBlockHeader.id,
|
4374
|
-
daHeight: (0,
|
4375
|
-
transactionsCount: (0,
|
4620
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4621
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4376
4622
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4377
|
-
height: (0,
|
4623
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4378
4624
|
prevRoot: commitBlockHeader.prevRoot,
|
4379
4625
|
time: commitBlockHeader.time,
|
4380
4626
|
applicationHash: commitBlockHeader.applicationHash,
|
4381
|
-
|
4382
|
-
|
4627
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4628
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4629
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4630
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4631
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4383
4632
|
},
|
4384
4633
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4385
4634
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4386
4635
|
nonce,
|
4387
|
-
amount: (0,
|
4636
|
+
amount: (0, import_math16.bn)(amount),
|
4388
4637
|
data
|
4389
4638
|
};
|
4390
4639
|
}
|
4640
|
+
async getLatestGasPrice() {
|
4641
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4642
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4643
|
+
}
|
4644
|
+
async estimateGasPrice(blockHorizon) {
|
4645
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4646
|
+
blockHorizon: String(blockHorizon)
|
4647
|
+
});
|
4648
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4649
|
+
}
|
4391
4650
|
/**
|
4392
4651
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4393
4652
|
*
|
@@ -4407,10 +4666,10 @@ var _Provider = class {
|
|
4407
4666
|
*/
|
4408
4667
|
async produceBlocks(amount, startTime) {
|
4409
4668
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4410
|
-
blocksToProduce: (0,
|
4411
|
-
startTimestamp: startTime ?
|
4669
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4670
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4412
4671
|
});
|
4413
|
-
return (0,
|
4672
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4414
4673
|
}
|
4415
4674
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4416
4675
|
async getTransactionResponse(transactionId) {
|
@@ -4434,9 +4693,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4434
4693
|
|
4435
4694
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4436
4695
|
var import_errors15 = require("@fuel-ts/errors");
|
4437
|
-
var
|
4696
|
+
var import_math17 = require("@fuel-ts/math");
|
4438
4697
|
var import_transactions20 = require("@fuel-ts/transactions");
|
4439
|
-
var
|
4698
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4440
4699
|
|
4441
4700
|
// src/providers/chains.ts
|
4442
4701
|
var CHAIN_IDS = {
|
@@ -4485,17 +4744,17 @@ var assets = [
|
|
4485
4744
|
|
4486
4745
|
// src/utils/formatTransferToContractScriptData.ts
|
4487
4746
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4488
|
-
var
|
4489
|
-
var
|
4747
|
+
var import_math18 = require("@fuel-ts/math");
|
4748
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4490
4749
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4491
4750
|
var formatTransferToContractScriptData = (params) => {
|
4492
4751
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4493
4752
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4494
|
-
const encoded = numberCoder.encode(new
|
4753
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4495
4754
|
const scriptData = Uint8Array.from([
|
4496
|
-
...(0,
|
4755
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4497
4756
|
...encoded,
|
4498
|
-
...(0,
|
4757
|
+
...(0, import_utils26.arrayify)(assetId)
|
4499
4758
|
]);
|
4500
4759
|
return scriptData;
|
4501
4760
|
};
|
@@ -4680,36 +4939,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4680
4939
|
* @param fee - The estimated transaction fee.
|
4681
4940
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4682
4941
|
*/
|
4683
|
-
async fund(request,
|
4684
|
-
const
|
4685
|
-
|
4942
|
+
async fund(request, params) {
|
4943
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4944
|
+
const txRequest = request;
|
4945
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4946
|
+
amount: (0, import_math19.bn)(fee),
|
4686
4947
|
assetId: import_configs12.BaseAssetId,
|
4687
|
-
coinQuantities
|
4948
|
+
coinQuantities: requiredQuantities
|
4688
4949
|
});
|
4689
4950
|
const quantitiesDict = {};
|
4690
|
-
|
4951
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4691
4952
|
quantitiesDict[assetId] = {
|
4692
4953
|
required: amount,
|
4693
|
-
owned: (0,
|
4954
|
+
owned: (0, import_math19.bn)(0)
|
4694
4955
|
};
|
4695
4956
|
});
|
4696
|
-
|
4697
|
-
const cachedMessages = [];
|
4698
|
-
const owner = this.address.toB256();
|
4699
|
-
request.inputs.forEach((input) => {
|
4957
|
+
txRequest.inputs.forEach((input) => {
|
4700
4958
|
const isResource = "amount" in input;
|
4701
4959
|
if (isResource) {
|
4702
4960
|
const isCoin2 = "owner" in input;
|
4703
4961
|
if (isCoin2) {
|
4704
4962
|
const assetId = String(input.assetId);
|
4705
|
-
if (
|
4706
|
-
const amount = (0,
|
4963
|
+
if (quantitiesDict[assetId]) {
|
4964
|
+
const amount = (0, import_math19.bn)(input.amount);
|
4707
4965
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4708
|
-
cachedUtxos.push(input.id);
|
4709
4966
|
}
|
4710
|
-
} else if (input.
|
4967
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4711
4968
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4712
|
-
cachedMessages.push(input.nonce);
|
4713
4969
|
}
|
4714
4970
|
}
|
4715
4971
|
});
|
@@ -4724,12 +4980,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4724
4980
|
});
|
4725
4981
|
const needsToBeFunded = missingQuantities.length;
|
4726
4982
|
if (needsToBeFunded) {
|
4727
|
-
const
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4983
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4984
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4985
|
+
txRequest.addResources(resources);
|
4986
|
+
}
|
4987
|
+
txRequest.shiftPredicateData();
|
4988
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4989
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4990
|
+
if (addedSignatures) {
|
4991
|
+
Array.from({ length: addedSignatures }).forEach(
|
4992
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4993
|
+
);
|
4732
4994
|
}
|
4995
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4996
|
+
transactionRequest: requestToBeReEstimate
|
4997
|
+
});
|
4998
|
+
txRequest.maxFee = maxFee;
|
4999
|
+
return txRequest;
|
4733
5000
|
}
|
4734
5001
|
/**
|
4735
5002
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4737,28 +5004,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4737
5004
|
* @param destination - The address of the destination.
|
4738
5005
|
* @param amount - The amount of coins to transfer.
|
4739
5006
|
* @param assetId - The asset ID of the coins to transfer.
|
4740
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5007
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4741
5008
|
* @returns A promise that resolves to the prepared transaction request.
|
4742
5009
|
*/
|
4743
5010
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4744
|
-
const
|
4745
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4746
|
-
const request = new ScriptTransactionRequest(params);
|
5011
|
+
const request = new ScriptTransactionRequest(txParams);
|
4747
5012
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4748
|
-
const
|
5013
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4749
5014
|
estimateTxDependencies: true,
|
4750
5015
|
resourcesOwner: this
|
4751
5016
|
});
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
await this.fund(request,
|
4761
|
-
request.updatePredicateInputs(estimatedInputs);
|
5017
|
+
if ("gasLimit" in txParams) {
|
5018
|
+
this.validateGas({
|
5019
|
+
gasUsed: txCost.gasUsed,
|
5020
|
+
gasLimit: request.gasLimit
|
5021
|
+
});
|
5022
|
+
}
|
5023
|
+
request.gasLimit = txCost.gasUsed;
|
5024
|
+
request.maxFee = txCost.maxFee;
|
5025
|
+
await this.fund(request, txCost);
|
4762
5026
|
return request;
|
4763
5027
|
}
|
4764
5028
|
/**
|
@@ -4771,7 +5035,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4771
5035
|
* @returns A promise that resolves to the transaction response.
|
4772
5036
|
*/
|
4773
5037
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4774
|
-
if ((0,
|
5038
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4775
5039
|
throw new import_errors16.FuelError(
|
4776
5040
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4777
5041
|
"Transfer amount must be a positive number."
|
@@ -4790,38 +5054,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4790
5054
|
* @returns A promise that resolves to the transaction response.
|
4791
5055
|
*/
|
4792
5056
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4793
|
-
if ((0,
|
5057
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4794
5058
|
throw new import_errors16.FuelError(
|
4795
5059
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4796
5060
|
"Transfer amount must be a positive number."
|
4797
5061
|
);
|
4798
5062
|
}
|
4799
5063
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4800
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4801
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4802
5064
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4803
5065
|
hexlifiedContractId: contractAddress.toB256(),
|
4804
|
-
amountToTransfer: (0,
|
5066
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
4805
5067
|
assetId
|
4806
5068
|
});
|
4807
5069
|
const request = new ScriptTransactionRequest({
|
4808
|
-
...
|
5070
|
+
...txParams,
|
4809
5071
|
script,
|
4810
5072
|
scriptData
|
4811
5073
|
});
|
4812
5074
|
request.addContractInputAndOutput(contractAddress);
|
4813
|
-
const
|
4814
|
-
|
4815
|
-
[{ amount: (0,
|
4816
|
-
);
|
4817
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4818
|
-
this.validateGas({
|
4819
|
-
gasUsed,
|
4820
|
-
gasPrice: request.gasPrice,
|
4821
|
-
gasLimit: request.gasLimit,
|
4822
|
-
minGasPrice
|
5075
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5076
|
+
resourcesOwner: this,
|
5077
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
4823
5078
|
});
|
4824
|
-
|
5079
|
+
if (txParams.gasLimit) {
|
5080
|
+
this.validateGas({
|
5081
|
+
gasUsed: txCost.gasUsed,
|
5082
|
+
gasLimit: request.gasLimit
|
5083
|
+
});
|
5084
|
+
}
|
5085
|
+
request.gasLimit = txCost.gasUsed;
|
5086
|
+
request.maxFee = txCost.maxFee;
|
5087
|
+
await this.fund(request, txCost);
|
4825
5088
|
return this.sendTransaction(request);
|
4826
5089
|
}
|
4827
5090
|
/**
|
@@ -4833,34 +5096,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4833
5096
|
* @returns A promise that resolves to the transaction response.
|
4834
5097
|
*/
|
4835
5098
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4836
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4837
5099
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4838
|
-
const recipientDataArray = (0,
|
5100
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
4839
5101
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4840
5102
|
);
|
4841
|
-
const amountDataArray = (0,
|
4842
|
-
"0x".concat((0,
|
5103
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5104
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4843
5105
|
);
|
4844
5106
|
const script = new Uint8Array([
|
4845
|
-
...(0,
|
5107
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4846
5108
|
...recipientDataArray,
|
4847
5109
|
...amountDataArray
|
4848
5110
|
]);
|
4849
|
-
const params = { script,
|
5111
|
+
const params = { script, ...txParams };
|
4850
5112
|
const request = new ScriptTransactionRequest(params);
|
4851
|
-
const
|
4852
|
-
const
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4858
|
-
|
4859
|
-
|
4860
|
-
|
4861
|
-
|
4862
|
-
});
|
4863
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5113
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5114
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5115
|
+
if (txParams.gasLimit) {
|
5116
|
+
this.validateGas({
|
5117
|
+
gasUsed: txCost.gasUsed,
|
5118
|
+
gasLimit: request.gasLimit
|
5119
|
+
});
|
5120
|
+
}
|
5121
|
+
request.maxFee = txCost.maxFee;
|
5122
|
+
request.gasLimit = txCost.gasUsed;
|
5123
|
+
await this.fund(request, txCost);
|
4864
5124
|
return this.sendTransaction(request);
|
4865
5125
|
}
|
4866
5126
|
async signMessage(message) {
|
@@ -4918,18 +5178,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4918
5178
|
}
|
4919
5179
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4920
5180
|
}
|
4921
|
-
validateGas({
|
4922
|
-
gasUsed,
|
4923
|
-
gasPrice,
|
4924
|
-
gasLimit,
|
4925
|
-
minGasPrice
|
4926
|
-
}) {
|
4927
|
-
if (minGasPrice.gt(gasPrice)) {
|
4928
|
-
throw new import_errors16.FuelError(
|
4929
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4930
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4931
|
-
);
|
4932
|
-
}
|
5181
|
+
validateGas({ gasUsed, gasLimit }) {
|
4933
5182
|
if (gasUsed.gt(gasLimit)) {
|
4934
5183
|
throw new import_errors16.FuelError(
|
4935
5184
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -4943,8 +5192,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4943
5192
|
var import_address5 = require("@fuel-ts/address");
|
4944
5193
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4945
5194
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4946
|
-
var
|
4947
|
-
var
|
5195
|
+
var import_math20 = require("@fuel-ts/math");
|
5196
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4948
5197
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4949
5198
|
var Signer = class {
|
4950
5199
|
address;
|
@@ -4963,10 +5212,10 @@ var Signer = class {
|
|
4963
5212
|
privateKey = `0x${privateKey}`;
|
4964
5213
|
}
|
4965
5214
|
}
|
4966
|
-
const privateKeyBytes = (0,
|
4967
|
-
this.privateKey = (0,
|
4968
|
-
this.publicKey = (0,
|
4969
|
-
this.compressedPublicKey = (0,
|
5215
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5216
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5217
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5218
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4970
5219
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4971
5220
|
}
|
4972
5221
|
/**
|
@@ -4980,11 +5229,11 @@ var Signer = class {
|
|
4980
5229
|
* @returns hashed signature
|
4981
5230
|
*/
|
4982
5231
|
sign(data) {
|
4983
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4984
|
-
const r = (0,
|
4985
|
-
const s = (0,
|
5232
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5233
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5234
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4986
5235
|
s[0] |= (signature.recovery || 0) << 7;
|
4987
|
-
return (0,
|
5236
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4988
5237
|
}
|
4989
5238
|
/**
|
4990
5239
|
* Add point on the current elliptic curve
|
@@ -4993,8 +5242,8 @@ var Signer = class {
|
|
4993
5242
|
* @returns compressed point on the curve
|
4994
5243
|
*/
|
4995
5244
|
addPoint(point) {
|
4996
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4997
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5245
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5246
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
4998
5247
|
const result = p0.add(p1);
|
4999
5248
|
return `0x${result.toHex(true)}`;
|
5000
5249
|
}
|
@@ -5006,16 +5255,16 @@ var Signer = class {
|
|
5006
5255
|
* @returns public key from signature from the
|
5007
5256
|
*/
|
5008
5257
|
static recoverPublicKey(data, signature) {
|
5009
|
-
const signedMessageBytes = (0,
|
5258
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5010
5259
|
const r = signedMessageBytes.slice(0, 32);
|
5011
5260
|
const s = signedMessageBytes.slice(32, 64);
|
5012
5261
|
const recoveryParam = (s[0] & 128) >> 7;
|
5013
5262
|
s[0] &= 127;
|
5014
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5263
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5015
5264
|
recoveryParam
|
5016
5265
|
);
|
5017
|
-
const publicKey = sig.recoverPublicKey((0,
|
5018
|
-
return (0,
|
5266
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5267
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5019
5268
|
}
|
5020
5269
|
/**
|
5021
5270
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5034,7 +5283,7 @@ var Signer = class {
|
|
5034
5283
|
* @returns random 32-byte hashed
|
5035
5284
|
*/
|
5036
5285
|
static generatePrivateKey(entropy) {
|
5037
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5286
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5038
5287
|
}
|
5039
5288
|
/**
|
5040
5289
|
* Extended publicKey from a compact publicKey
|
@@ -5043,8 +5292,8 @@ var Signer = class {
|
|
5043
5292
|
* @returns extended publicKey
|
5044
5293
|
*/
|
5045
5294
|
static extendPublicKey(publicKey) {
|
5046
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5047
|
-
return (0,
|
5295
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5296
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5048
5297
|
}
|
5049
5298
|
};
|
5050
5299
|
|
@@ -5052,7 +5301,7 @@ var Signer = class {
|
|
5052
5301
|
var import_address6 = require("@fuel-ts/address");
|
5053
5302
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5054
5303
|
var import_errors17 = require("@fuel-ts/errors");
|
5055
|
-
var
|
5304
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5056
5305
|
var import_uuid = require("uuid");
|
5057
5306
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5058
5307
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5135,7 +5384,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5135
5384
|
);
|
5136
5385
|
}
|
5137
5386
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5138
|
-
const privateKey = (0,
|
5387
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5139
5388
|
return privateKey;
|
5140
5389
|
}
|
5141
5390
|
|
@@ -5180,7 +5429,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5180
5429
|
*/
|
5181
5430
|
async signMessage(message) {
|
5182
5431
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5183
|
-
return (0,
|
5432
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5184
5433
|
}
|
5185
5434
|
/**
|
5186
5435
|
* Signs a transaction with the wallet's private key.
|
@@ -5193,7 +5442,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5193
5442
|
const chainId = this.provider.getChainId();
|
5194
5443
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5195
5444
|
const signature = await this.signer().sign(hashedTransaction);
|
5196
|
-
return (0,
|
5445
|
+
return (0, import_utils30.hexlify)(signature);
|
5197
5446
|
}
|
5198
5447
|
/**
|
5199
5448
|
* Populates a transaction with the witnesses signature.
|
@@ -5213,7 +5462,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5213
5462
|
* @param transactionRequestLike - The transaction request to send.
|
5214
5463
|
* @returns A promise that resolves to the TransactionResponse object.
|
5215
5464
|
*/
|
5216
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5465
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5217
5466
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5218
5467
|
if (estimateTxDependencies) {
|
5219
5468
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5254,15 +5503,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5254
5503
|
// src/hdwallet/hdwallet.ts
|
5255
5504
|
var import_errors20 = require("@fuel-ts/errors");
|
5256
5505
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5257
|
-
var
|
5258
|
-
var
|
5506
|
+
var import_math21 = require("@fuel-ts/math");
|
5507
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5259
5508
|
var import_ethers3 = require("ethers");
|
5260
5509
|
|
5261
5510
|
// src/mnemonic/mnemonic.ts
|
5262
5511
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5263
5512
|
var import_errors19 = require("@fuel-ts/errors");
|
5264
5513
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5265
|
-
var
|
5514
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5266
5515
|
var import_ethers2 = require("ethers");
|
5267
5516
|
|
5268
5517
|
// src/wordlists/words/english.ts
|
@@ -7320,7 +7569,7 @@ var english = [
|
|
7320
7569
|
// src/mnemonic/utils.ts
|
7321
7570
|
var import_errors18 = require("@fuel-ts/errors");
|
7322
7571
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7323
|
-
var
|
7572
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7324
7573
|
function toUtf8Bytes(stri) {
|
7325
7574
|
const str = stri.normalize("NFKD");
|
7326
7575
|
const result = [];
|
@@ -7387,14 +7636,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7387
7636
|
}
|
7388
7637
|
}
|
7389
7638
|
const checksumBits = entropy.length / 4;
|
7390
|
-
const checksum = (0,
|
7639
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7391
7640
|
indices[indices.length - 1] <<= checksumBits;
|
7392
7641
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7393
7642
|
return indices;
|
7394
7643
|
}
|
7395
7644
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7396
7645
|
const size = Math.ceil(11 * words.length / 8);
|
7397
|
-
const entropy = (0,
|
7646
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7398
7647
|
let offset = 0;
|
7399
7648
|
for (let i = 0; i < words.length; i += 1) {
|
7400
7649
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7414,7 +7663,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7414
7663
|
const entropyBits = 32 * words.length / 3;
|
7415
7664
|
const checksumBits = words.length / 3;
|
7416
7665
|
const checksumMask = getUpperMask(checksumBits);
|
7417
|
-
const checksum = (0,
|
7666
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7418
7667
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7419
7668
|
throw new import_errors18.FuelError(
|
7420
7669
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7489,7 +7738,7 @@ var Mnemonic = class {
|
|
7489
7738
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7490
7739
|
const words = getWords(phrase);
|
7491
7740
|
assertMnemonic(words);
|
7492
|
-
return (0,
|
7741
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7493
7742
|
}
|
7494
7743
|
/**
|
7495
7744
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7497,7 +7746,7 @@ var Mnemonic = class {
|
|
7497
7746
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7498
7747
|
*/
|
7499
7748
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7500
|
-
const entropyBytes = (0,
|
7749
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7501
7750
|
assertWordList(wordlist);
|
7502
7751
|
assertEntropy(entropyBytes);
|
7503
7752
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7566,14 +7815,14 @@ var Mnemonic = class {
|
|
7566
7815
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7567
7816
|
*/
|
7568
7817
|
static masterKeysFromSeed(seed) {
|
7569
|
-
const seedArray = (0,
|
7818
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7570
7819
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7571
7820
|
throw new import_errors19.FuelError(
|
7572
7821
|
import_errors19.ErrorCode.INVALID_SEED,
|
7573
7822
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7574
7823
|
);
|
7575
7824
|
}
|
7576
|
-
return (0,
|
7825
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7577
7826
|
}
|
7578
7827
|
/**
|
7579
7828
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7584,22 +7833,22 @@ var Mnemonic = class {
|
|
7584
7833
|
*/
|
7585
7834
|
static seedToExtendedKey(seed, testnet = false) {
|
7586
7835
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7587
|
-
const prefix = (0,
|
7836
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7588
7837
|
const depth = "0x00";
|
7589
7838
|
const fingerprint = "0x00000000";
|
7590
7839
|
const index = "0x00000000";
|
7591
7840
|
const chainCode = masterKey.slice(32);
|
7592
7841
|
const privateKey = masterKey.slice(0, 32);
|
7593
|
-
const extendedKey = (0,
|
7842
|
+
const extendedKey = (0, import_utils32.concat)([
|
7594
7843
|
prefix,
|
7595
7844
|
depth,
|
7596
7845
|
fingerprint,
|
7597
7846
|
index,
|
7598
7847
|
chainCode,
|
7599
|
-
(0,
|
7848
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7600
7849
|
]);
|
7601
7850
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7602
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7851
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7603
7852
|
}
|
7604
7853
|
/**
|
7605
7854
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7614,7 +7863,7 @@ var Mnemonic = class {
|
|
7614
7863
|
* @returns A randomly generated mnemonic
|
7615
7864
|
*/
|
7616
7865
|
static generate(size = 32, extraEntropy = "") {
|
7617
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7866
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7618
7867
|
return Mnemonic.entropyToMnemonic(entropy);
|
7619
7868
|
}
|
7620
7869
|
};
|
@@ -7622,12 +7871,12 @@ var mnemonic_default = Mnemonic;
|
|
7622
7871
|
|
7623
7872
|
// src/hdwallet/hdwallet.ts
|
7624
7873
|
var HARDENED_INDEX = 2147483648;
|
7625
|
-
var MainnetPRV2 = (0,
|
7626
|
-
var MainnetPUB = (0,
|
7627
|
-
var TestnetPRV2 = (0,
|
7628
|
-
var TestnetPUB = (0,
|
7874
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7875
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7876
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7877
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7629
7878
|
function base58check(data) {
|
7630
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7879
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7631
7880
|
}
|
7632
7881
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7633
7882
|
if (isPublic) {
|
@@ -7636,11 +7885,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7636
7885
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7637
7886
|
}
|
7638
7887
|
function isPublicExtendedKey(extendedKey) {
|
7639
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7888
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
7640
7889
|
}
|
7641
7890
|
function isValidExtendedKey(extendedKey) {
|
7642
7891
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7643
|
-
(0,
|
7892
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
7644
7893
|
);
|
7645
7894
|
}
|
7646
7895
|
function parsePath(path2, depth = 0) {
|
@@ -7658,8 +7907,8 @@ function parsePath(path2, depth = 0) {
|
|
7658
7907
|
var HDWallet = class {
|
7659
7908
|
depth = 0;
|
7660
7909
|
index = 0;
|
7661
|
-
fingerprint = (0,
|
7662
|
-
parentFingerprint = (0,
|
7910
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7911
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7663
7912
|
privateKey;
|
7664
7913
|
publicKey;
|
7665
7914
|
chainCode;
|
@@ -7671,8 +7920,8 @@ var HDWallet = class {
|
|
7671
7920
|
constructor(config) {
|
7672
7921
|
if (config.privateKey) {
|
7673
7922
|
const signer = new Signer(config.privateKey);
|
7674
|
-
this.publicKey = (0,
|
7675
|
-
this.privateKey = (0,
|
7923
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7924
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7676
7925
|
} else {
|
7677
7926
|
if (!config.publicKey) {
|
7678
7927
|
throw new import_errors20.FuelError(
|
@@ -7680,7 +7929,7 @@ var HDWallet = class {
|
|
7680
7929
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7681
7930
|
);
|
7682
7931
|
}
|
7683
|
-
this.publicKey = (0,
|
7932
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7684
7933
|
}
|
7685
7934
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7686
7935
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7699,9 +7948,9 @@ var HDWallet = class {
|
|
7699
7948
|
* @returns A new instance of HDWallet on the derived index
|
7700
7949
|
*/
|
7701
7950
|
deriveIndex(index) {
|
7702
|
-
const privateKey = this.privateKey && (0,
|
7703
|
-
const publicKey = (0,
|
7704
|
-
const chainCode = (0,
|
7951
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
7952
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
7953
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
7705
7954
|
const data = new Uint8Array(37);
|
7706
7955
|
if (index & HARDENED_INDEX) {
|
7707
7956
|
if (!privateKey) {
|
@@ -7712,15 +7961,15 @@ var HDWallet = class {
|
|
7712
7961
|
}
|
7713
7962
|
data.set(privateKey, 1);
|
7714
7963
|
} else {
|
7715
|
-
data.set((0,
|
7964
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7716
7965
|
}
|
7717
|
-
data.set((0,
|
7718
|
-
const bytes = (0,
|
7966
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
7967
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7719
7968
|
const IL = bytes.slice(0, 32);
|
7720
7969
|
const IR = bytes.slice(32);
|
7721
7970
|
if (privateKey) {
|
7722
7971
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7723
|
-
const ki = (0,
|
7972
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7724
7973
|
return new HDWallet({
|
7725
7974
|
privateKey: ki,
|
7726
7975
|
chainCode: IR,
|
@@ -7729,7 +7978,7 @@ var HDWallet = class {
|
|
7729
7978
|
parentFingerprint: this.fingerprint
|
7730
7979
|
});
|
7731
7980
|
}
|
7732
|
-
const signer = new Signer((0,
|
7981
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
7733
7982
|
const Ki = signer.addPoint(publicKey);
|
7734
7983
|
return new HDWallet({
|
7735
7984
|
publicKey: Ki,
|
@@ -7764,12 +8013,12 @@ var HDWallet = class {
|
|
7764
8013
|
);
|
7765
8014
|
}
|
7766
8015
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7767
|
-
const depth = (0,
|
8016
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7768
8017
|
const parentFingerprint = this.parentFingerprint;
|
7769
|
-
const index = (0,
|
8018
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
7770
8019
|
const chainCode = this.chainCode;
|
7771
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7772
|
-
const extendedKey = (0,
|
8020
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8021
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7773
8022
|
return base58check(extendedKey);
|
7774
8023
|
}
|
7775
8024
|
/**
|
@@ -7781,13 +8030,13 @@ var HDWallet = class {
|
|
7781
8030
|
static fromSeed(seed) {
|
7782
8031
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7783
8032
|
return new HDWallet({
|
7784
|
-
chainCode: (0,
|
7785
|
-
privateKey: (0,
|
8033
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8034
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
7786
8035
|
});
|
7787
8036
|
}
|
7788
8037
|
static fromExtendedKey(extendedKey) {
|
7789
8038
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7790
|
-
const bytes = (0,
|
8039
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
7791
8040
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7792
8041
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7793
8042
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7796,9 +8045,9 @@ var HDWallet = class {
|
|
7796
8045
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7797
8046
|
}
|
7798
8047
|
const depth = bytes[4];
|
7799
|
-
const parentFingerprint = (0,
|
7800
|
-
const index = parseInt((0,
|
7801
|
-
const chainCode = (0,
|
8048
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8049
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8050
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7802
8051
|
const key = bytes.slice(45, 78);
|
7803
8052
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7804
8053
|
throw new import_errors20.FuelError(
|
@@ -7986,26 +8235,20 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
7986
8235
|
|
7987
8236
|
// src/test-utils/seedTestWallet.ts
|
7988
8237
|
var import_crypto5 = require("@fuel-ts/crypto");
|
7989
|
-
var seedTestWallet = async (wallet, quantities
|
7990
|
-
const toFundAccounts = Array.isArray(wallet) ? wallet : [wallet];
|
8238
|
+
var seedTestWallet = async (wallet, quantities) => {
|
7991
8239
|
const genesisWallet = new WalletUnlocked(
|
7992
8240
|
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7993
|
-
|
8241
|
+
wallet.provider
|
7994
8242
|
);
|
7995
|
-
const
|
7996
|
-
|
7997
|
-
|
7998
|
-
|
7999
|
-
gasPrice: minGasPrice
|
8243
|
+
const request = new ScriptTransactionRequest();
|
8244
|
+
quantities.forEach((quantity) => {
|
8245
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8246
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
8000
8247
|
});
|
8001
|
-
|
8002
|
-
|
8003
|
-
|
8004
|
-
|
8005
|
-
request.addCoinOutput(address, amount.div(utxosAmount), assetId);
|
8006
|
-
}
|
8007
|
-
})
|
8008
|
-
);
|
8248
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8249
|
+
request.gasLimit = txCost.gasUsed;
|
8250
|
+
request.maxFee = txCost.maxFee;
|
8251
|
+
await genesisWallet.fund(request, txCost);
|
8009
8252
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8010
8253
|
};
|
8011
8254
|
|
@@ -8020,8 +8263,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8020
8263
|
|
8021
8264
|
// src/test-utils/launchNode.ts
|
8022
8265
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8023
|
-
var
|
8024
|
-
var import_utils36 = require("@fuel-ts/utils");
|
8266
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8025
8267
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8026
8268
|
var import_child_process = require("child_process");
|
8027
8269
|
var import_crypto6 = require("crypto");
|
@@ -8030,6 +8272,8 @@ var import_os = __toESM(require("os"));
|
|
8030
8272
|
var import_path = __toESM(require("path"));
|
8031
8273
|
var import_portfinder = require("portfinder");
|
8032
8274
|
var import_tree_kill = __toESM(require("tree-kill"));
|
8275
|
+
var import_crypto7 = require("@fuel-ts/crypto");
|
8276
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8033
8277
|
var getFlagValueFromArgs = (args, flag) => {
|
8034
8278
|
const flagIndex = args.indexOf(flag);
|
8035
8279
|
if (flagIndex === -1) {
|
@@ -8073,13 +8317,13 @@ var launchNode = async ({
|
|
8073
8317
|
// eslint-disable-next-line no-async-promise-executor
|
8074
8318
|
new Promise(async (resolve, reject) => {
|
8075
8319
|
const remainingArgs = extractRemainingArgs(args, [
|
8076
|
-
"--
|
8320
|
+
"--snapshot",
|
8077
8321
|
"--consensus-key",
|
8078
8322
|
"--db-type",
|
8079
8323
|
"--poa-instant"
|
8080
8324
|
]);
|
8081
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8082
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8325
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8326
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
|
8083
8327
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8084
8328
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8085
8329
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8097,36 +8341,54 @@ var launchNode = async ({
|
|
8097
8341
|
let chainConfigPathToUse;
|
8098
8342
|
const prefix = basePath || import_os.default.tmpdir();
|
8099
8343
|
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8100
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8344
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "chainConfigs");
|
8101
8345
|
if (chainConfigPath) {
|
8102
8346
|
chainConfigPathToUse = chainConfigPath;
|
8103
8347
|
} else {
|
8104
8348
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8105
8349
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8106
8350
|
}
|
8107
|
-
|
8108
|
-
|
8351
|
+
let { stateConfigJson } = import_utils35.defaultChainConfigs;
|
8352
|
+
const { chainConfigJson, metadataJson } = import_utils35.defaultChainConfigs;
|
8353
|
+
stateConfigJson = {
|
8354
|
+
...stateConfigJson,
|
8355
|
+
coins: [
|
8356
|
+
...stateConfigJson.coins.map((coin) => ({
|
8357
|
+
...coin,
|
8358
|
+
amount: "18446744073709551615"
|
8359
|
+
}))
|
8360
|
+
],
|
8361
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8362
|
+
...message,
|
8363
|
+
amount: "18446744073709551615"
|
8364
|
+
}))
|
8365
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8366
|
+
};
|
8109
8367
|
if (!process.env.GENESIS_SECRET) {
|
8110
8368
|
const pk = Signer.generatePrivateKey();
|
8111
8369
|
const signer = new Signer(pk);
|
8112
|
-
process.env.GENESIS_SECRET = (0,
|
8113
|
-
|
8114
|
-
|
8115
|
-
|
8116
|
-
|
8117
|
-
|
8118
|
-
|
8119
|
-
|
8120
|
-
|
8121
|
-
|
8122
|
-
|
8123
|
-
}
|
8124
|
-
]
|
8125
|
-
}
|
8126
|
-
};
|
8370
|
+
process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
|
8371
|
+
stateConfigJson.coins.push({
|
8372
|
+
tx_id: (0, import_utils35.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8373
|
+
owner: signer.address.toHexString(),
|
8374
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8375
|
+
amount: "18446744073709551615",
|
8376
|
+
asset_id: import_configs13.BaseAssetId,
|
8377
|
+
output_index: 0,
|
8378
|
+
tx_pointer_block_height: 0,
|
8379
|
+
tx_pointer_tx_idx: 0
|
8380
|
+
});
|
8127
8381
|
}
|
8128
|
-
|
8129
|
-
|
8382
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8383
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8384
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8385
|
+
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8386
|
+
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8387
|
+
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8388
|
+
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8389
|
+
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8390
|
+
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8391
|
+
chainConfigPathToUse = tempDirPath;
|
8130
8392
|
}
|
8131
8393
|
const child = (0, import_child_process.spawn)(
|
8132
8394
|
command,
|
@@ -8135,10 +8397,10 @@ var launchNode = async ({
|
|
8135
8397
|
["--ip", ipToUse],
|
8136
8398
|
["--port", portToUse],
|
8137
8399
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8138
|
-
["--min-gas-price", "
|
8400
|
+
["--min-gas-price", "1"],
|
8139
8401
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8140
8402
|
["--consensus-key", consensusKey],
|
8141
|
-
["--
|
8403
|
+
["--snapshot", chainConfigPathToUse],
|
8142
8404
|
"--vm-backtrace",
|
8143
8405
|
"--utxo-validation",
|
8144
8406
|
"--debug",
|
@@ -8197,52 +8459,15 @@ var launchNodeAndGetWallets = async ({
|
|
8197
8459
|
walletCount = 10
|
8198
8460
|
} = {}) => {
|
8199
8461
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8200
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8462
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8201
8463
|
const wallets = await generateWallets(walletCount, provider);
|
8202
8464
|
const cleanup = () => {
|
8203
8465
|
closeNode();
|
8204
8466
|
};
|
8205
8467
|
return { wallets, stop: cleanup, provider };
|
8206
8468
|
};
|
8207
|
-
|
8208
|
-
// src/test-utils/transactionRequest.ts
|
8209
|
-
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8210
|
-
var import_address7 = require("@fuel-ts/address");
|
8211
|
-
var import_configs14 = require("@fuel-ts/address/configs");
|
8212
|
-
var import_crypto7 = require("@fuel-ts/crypto");
|
8213
|
-
var import_math22 = require("@fuel-ts/math");
|
8214
|
-
var import_transactions21 = require("@fuel-ts/transactions");
|
8215
|
-
var import_utils37 = require("@fuel-ts/utils");
|
8216
|
-
var generateFakeRequestInputCoin = (partial = {}) => ({
|
8217
|
-
id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8218
|
-
type: import_transactions21.InputType.Coin,
|
8219
|
-
owner: (0, import_address7.getRandomB256)(),
|
8220
|
-
amount: (0, import_math22.bn)(100),
|
8221
|
-
assetId: import_configs14.ZeroBytes32,
|
8222
|
-
txPointer: "0x00000000000000000000000000000000",
|
8223
|
-
witnessIndex: 0,
|
8224
|
-
...partial
|
8225
|
-
});
|
8226
|
-
var generateFakeRequestInputMessage = (partial = {}) => ({
|
8227
|
-
nonce: (0, import_address7.getRandomB256)(),
|
8228
|
-
type: import_transactions21.InputType.Message,
|
8229
|
-
sender: (0, import_address7.getRandomB256)(),
|
8230
|
-
recipient: (0, import_address7.getRandomB256)(),
|
8231
|
-
amount: (0, import_math22.bn)(100),
|
8232
|
-
witnessIndex: 0,
|
8233
|
-
...partial
|
8234
|
-
});
|
8235
|
-
var generateFakeRequestInputContract = (partial = {}) => ({
|
8236
|
-
contractId: (0, import_address7.getRandomB256)(),
|
8237
|
-
type: import_transactions21.InputType.Contract,
|
8238
|
-
txPointer: "0x00000000000000000000000000000000",
|
8239
|
-
...partial
|
8240
|
-
});
|
8241
8469
|
// Annotate the CommonJS export names for ESM import in node:
|
8242
8470
|
0 && (module.exports = {
|
8243
|
-
generateFakeRequestInputCoin,
|
8244
|
-
generateFakeRequestInputContract,
|
8245
|
-
generateFakeRequestInputMessage,
|
8246
8471
|
generateTestWallet,
|
8247
8472
|
killNode,
|
8248
8473
|
launchNode,
|