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