@fuel-ts/account 0.81.0 → 0.83.0
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 +3 -3
- package/dist/account.d.ts +7 -6
- 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 +890 -619
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +853 -604
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +696 -448
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +12 -24
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +810 -359
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +44 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +13 -33
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/providers/utils/merge-quantities.d.ts +1 -1
- package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1615 -1114
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +841 -596
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +696 -451
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -24,37 +24,36 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
31
|
-
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
29
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
30
|
+
import { arrayify as arrayify14, isDefined } from "@fuel-ts/utils";
|
31
|
+
import { clone as clone4 } from "ramda";
|
32
32
|
|
33
33
|
// src/providers/coin-quantity.ts
|
34
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
35
34
|
import { bn } from "@fuel-ts/math";
|
36
35
|
import { hexlify } from "@fuel-ts/utils";
|
37
36
|
var coinQuantityfy = (coinQuantityLike) => {
|
38
37
|
let assetId;
|
39
38
|
let amount;
|
40
|
-
let
|
39
|
+
let max;
|
41
40
|
if (Array.isArray(coinQuantityLike)) {
|
42
41
|
amount = coinQuantityLike[0];
|
43
|
-
assetId = coinQuantityLike[1]
|
44
|
-
|
42
|
+
assetId = coinQuantityLike[1];
|
43
|
+
max = coinQuantityLike[2] ?? void 0;
|
45
44
|
} else {
|
46
45
|
amount = coinQuantityLike.amount;
|
47
|
-
assetId = coinQuantityLike.assetId
|
48
|
-
|
46
|
+
assetId = coinQuantityLike.assetId;
|
47
|
+
max = coinQuantityLike.max ?? void 0;
|
49
48
|
}
|
50
49
|
const bnAmount = bn(amount);
|
51
50
|
return {
|
52
51
|
assetId: hexlify(assetId),
|
53
52
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
54
|
-
max:
|
53
|
+
max: max ? bn(max) : void 0
|
55
54
|
};
|
56
55
|
};
|
57
|
-
var
|
56
|
+
var addAmountToCoinQuantities = (params) => {
|
58
57
|
const { amount, assetId } = params;
|
59
58
|
const coinQuantities = [...params.coinQuantities];
|
60
59
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -69,9 +68,9 @@ var addAmountToAsset = (params) => {
|
|
69
68
|
// src/providers/provider.ts
|
70
69
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
70
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
|
-
import { BN, bn as
|
71
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
73
72
|
import {
|
74
|
-
InputType as
|
73
|
+
InputType as InputType7,
|
75
74
|
TransactionType as TransactionType8,
|
76
75
|
InputMessageCoder,
|
77
76
|
TransactionCoder as TransactionCoder5
|
@@ -85,16 +84,20 @@ import { clone as clone3 } from "ramda";
|
|
85
84
|
|
86
85
|
// src/providers/__generated__/operations.ts
|
87
86
|
import gql from "graphql-tag";
|
87
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
88
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
89
|
+
type: __typename
|
90
|
+
... on SqueezedOutStatus {
|
91
|
+
reason
|
92
|
+
}
|
93
|
+
}
|
94
|
+
`;
|
88
95
|
var ReceiptFragmentFragmentDoc = gql`
|
89
96
|
fragment receiptFragment on Receipt {
|
90
|
-
|
91
|
-
id
|
92
|
-
}
|
97
|
+
id
|
93
98
|
pc
|
94
99
|
is
|
95
|
-
to
|
96
|
-
id
|
97
|
-
}
|
100
|
+
to
|
98
101
|
toAddress
|
99
102
|
amount
|
100
103
|
assetId
|
@@ -132,10 +135,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
132
135
|
id
|
133
136
|
}
|
134
137
|
time
|
138
|
+
receipts {
|
139
|
+
...receiptFragment
|
140
|
+
}
|
135
141
|
programState {
|
136
142
|
returnType
|
137
143
|
data
|
138
144
|
}
|
145
|
+
receipts {
|
146
|
+
...receiptFragment
|
147
|
+
}
|
139
148
|
}
|
140
149
|
... on FailureStatus {
|
141
150
|
block {
|
@@ -143,26 +152,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
143
152
|
}
|
144
153
|
time
|
145
154
|
reason
|
155
|
+
receipts {
|
156
|
+
...receiptFragment
|
157
|
+
}
|
146
158
|
}
|
147
159
|
... on SqueezedOutStatus {
|
148
160
|
reason
|
149
161
|
}
|
150
162
|
}
|
151
|
-
`;
|
163
|
+
${ReceiptFragmentFragmentDoc}`;
|
152
164
|
var TransactionFragmentFragmentDoc = gql`
|
153
165
|
fragment transactionFragment on Transaction {
|
154
166
|
id
|
155
167
|
rawPayload
|
156
|
-
gasPrice
|
157
|
-
receipts {
|
158
|
-
...receiptFragment
|
159
|
-
}
|
160
168
|
status {
|
161
169
|
...transactionStatusFragment
|
162
170
|
}
|
163
171
|
}
|
164
|
-
${
|
165
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
172
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
166
173
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
167
174
|
fragment inputEstimatePredicatesFragment on Input {
|
168
175
|
... on InputCoin {
|
@@ -180,6 +187,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
180
187
|
}
|
181
188
|
}
|
182
189
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
190
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
191
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
192
|
+
reason
|
193
|
+
programState {
|
194
|
+
returnType
|
195
|
+
data
|
196
|
+
}
|
197
|
+
}
|
198
|
+
`;
|
199
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
200
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
201
|
+
programState {
|
202
|
+
returnType
|
203
|
+
data
|
204
|
+
}
|
205
|
+
}
|
206
|
+
`;
|
207
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
208
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
209
|
+
... on DryRunFailureStatus {
|
210
|
+
...dryRunFailureStatusFragment
|
211
|
+
}
|
212
|
+
... on DryRunSuccessStatus {
|
213
|
+
...dryRunSuccessStatusFragment
|
214
|
+
}
|
215
|
+
}
|
216
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
217
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
218
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
219
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
220
|
+
id
|
221
|
+
status {
|
222
|
+
...dryRunTransactionStatusFragment
|
223
|
+
}
|
224
|
+
receipts {
|
225
|
+
...receiptFragment
|
226
|
+
}
|
227
|
+
}
|
228
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
229
|
+
${ReceiptFragmentFragmentDoc}`;
|
183
230
|
var CoinFragmentFragmentDoc = gql`
|
184
231
|
fragment coinFragment on Coin {
|
185
232
|
__typename
|
@@ -187,7 +234,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
187
234
|
owner
|
188
235
|
amount
|
189
236
|
assetId
|
190
|
-
maturity
|
191
237
|
blockCreated
|
192
238
|
txCreatedIdx
|
193
239
|
}
|
@@ -226,26 +272,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
226
272
|
messageBlockHeader {
|
227
273
|
id
|
228
274
|
daHeight
|
275
|
+
consensusParametersVersion
|
276
|
+
stateTransitionBytecodeVersion
|
229
277
|
transactionsCount
|
278
|
+
messageReceiptCount
|
230
279
|
transactionsRoot
|
280
|
+
messageOutboxRoot
|
281
|
+
eventInboxRoot
|
231
282
|
height
|
232
283
|
prevRoot
|
233
284
|
time
|
234
285
|
applicationHash
|
235
|
-
messageReceiptRoot
|
236
|
-
messageReceiptCount
|
237
286
|
}
|
238
287
|
commitBlockHeader {
|
239
288
|
id
|
240
289
|
daHeight
|
290
|
+
consensusParametersVersion
|
291
|
+
stateTransitionBytecodeVersion
|
241
292
|
transactionsCount
|
293
|
+
messageReceiptCount
|
242
294
|
transactionsRoot
|
295
|
+
messageOutboxRoot
|
296
|
+
eventInboxRoot
|
243
297
|
height
|
244
298
|
prevRoot
|
245
299
|
time
|
246
300
|
applicationHash
|
247
|
-
messageReceiptRoot
|
248
|
-
messageReceiptCount
|
249
301
|
}
|
250
302
|
sender
|
251
303
|
recipient
|
@@ -264,8 +316,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
264
316
|
var BlockFragmentFragmentDoc = gql`
|
265
317
|
fragment blockFragment on Block {
|
266
318
|
id
|
319
|
+
height
|
267
320
|
header {
|
268
|
-
height
|
269
321
|
time
|
270
322
|
}
|
271
323
|
transactions {
|
@@ -275,6 +327,7 @@ var BlockFragmentFragmentDoc = gql`
|
|
275
327
|
`;
|
276
328
|
var TxParametersFragmentFragmentDoc = gql`
|
277
329
|
fragment TxParametersFragment on TxParameters {
|
330
|
+
version
|
278
331
|
maxInputs
|
279
332
|
maxOutputs
|
280
333
|
maxWitnesses
|
@@ -284,6 +337,7 @@ var TxParametersFragmentFragmentDoc = gql`
|
|
284
337
|
`;
|
285
338
|
var PredicateParametersFragmentFragmentDoc = gql`
|
286
339
|
fragment PredicateParametersFragment on PredicateParameters {
|
340
|
+
version
|
287
341
|
maxPredicateLength
|
288
342
|
maxPredicateDataLength
|
289
343
|
maxGasPerPredicate
|
@@ -292,18 +346,21 @@ var PredicateParametersFragmentFragmentDoc = gql`
|
|
292
346
|
`;
|
293
347
|
var ScriptParametersFragmentFragmentDoc = gql`
|
294
348
|
fragment ScriptParametersFragment on ScriptParameters {
|
349
|
+
version
|
295
350
|
maxScriptLength
|
296
351
|
maxScriptDataLength
|
297
352
|
}
|
298
353
|
`;
|
299
354
|
var ContractParametersFragmentFragmentDoc = gql`
|
300
355
|
fragment ContractParametersFragment on ContractParameters {
|
356
|
+
version
|
301
357
|
contractMaxSize
|
302
358
|
maxStorageSlots
|
303
359
|
}
|
304
360
|
`;
|
305
361
|
var FeeParametersFragmentFragmentDoc = gql`
|
306
362
|
fragment FeeParametersFragment on FeeParameters {
|
363
|
+
version
|
307
364
|
gasPriceFactor
|
308
365
|
gasPerByte
|
309
366
|
}
|
@@ -323,6 +380,7 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
323
380
|
`;
|
324
381
|
var GasCostsFragmentFragmentDoc = gql`
|
325
382
|
fragment GasCostsFragment on GasCosts {
|
383
|
+
version
|
326
384
|
add
|
327
385
|
addi
|
328
386
|
aloc
|
@@ -335,7 +393,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
335
393
|
cb
|
336
394
|
cfei
|
337
395
|
cfsi
|
338
|
-
croo
|
339
396
|
div
|
340
397
|
divi
|
341
398
|
ecr1
|
@@ -418,6 +475,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
418
475
|
ccp {
|
419
476
|
...DependentCostFragment
|
420
477
|
}
|
478
|
+
croo {
|
479
|
+
...DependentCostFragment
|
480
|
+
}
|
421
481
|
csiz {
|
422
482
|
...DependentCostFragment
|
423
483
|
}
|
@@ -477,6 +537,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
477
537
|
${DependentCostFragmentFragmentDoc}`;
|
478
538
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
479
539
|
fragment consensusParametersFragment on ConsensusParameters {
|
540
|
+
version
|
480
541
|
txParams {
|
481
542
|
...TxParametersFragment
|
482
543
|
}
|
@@ -536,18 +597,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
536
597
|
fragment nodeInfoFragment on NodeInfo {
|
537
598
|
utxoValidation
|
538
599
|
vmBacktrace
|
539
|
-
minGasPrice
|
540
600
|
maxTx
|
541
601
|
maxDepth
|
542
602
|
nodeVersion
|
543
|
-
peers {
|
544
|
-
id
|
545
|
-
addresses
|
546
|
-
clientVersion
|
547
|
-
blockHeight
|
548
|
-
lastHeartbeatMs
|
549
|
-
appScore
|
550
|
-
}
|
551
603
|
}
|
552
604
|
`;
|
553
605
|
var GetVersionDocument = gql`
|
@@ -582,13 +634,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
582
634
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
583
635
|
transaction(id: $transactionId) {
|
584
636
|
...transactionFragment
|
585
|
-
receipts {
|
586
|
-
...receiptFragment
|
587
|
-
}
|
588
637
|
}
|
589
638
|
}
|
590
|
-
${TransactionFragmentFragmentDoc}
|
591
|
-
${ReceiptFragmentFragmentDoc}`;
|
639
|
+
${TransactionFragmentFragmentDoc}`;
|
592
640
|
var GetTransactionsDocument = gql`
|
593
641
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
594
642
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -716,6 +764,20 @@ var GetBalanceDocument = gql`
|
|
716
764
|
}
|
717
765
|
}
|
718
766
|
${BalanceFragmentFragmentDoc}`;
|
767
|
+
var GetLatestGasPriceDocument = gql`
|
768
|
+
query getLatestGasPrice {
|
769
|
+
latestGasPrice {
|
770
|
+
gasPrice
|
771
|
+
}
|
772
|
+
}
|
773
|
+
`;
|
774
|
+
var EstimateGasPriceDocument = gql`
|
775
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
776
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
777
|
+
gasPrice
|
778
|
+
}
|
779
|
+
}
|
780
|
+
`;
|
719
781
|
var GetBalancesDocument = gql`
|
720
782
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
721
783
|
balances(
|
@@ -770,12 +832,12 @@ var GetMessageStatusDocument = gql`
|
|
770
832
|
}
|
771
833
|
`;
|
772
834
|
var DryRunDocument = gql`
|
773
|
-
mutation dryRun($
|
774
|
-
dryRun(
|
775
|
-
...
|
835
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
836
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
837
|
+
...dryRunTransactionExecutionStatusFragment
|
776
838
|
}
|
777
839
|
}
|
778
|
-
${
|
840
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
779
841
|
var SubmitDocument = gql`
|
780
842
|
mutation submit($encodedTransaction: HexString!) {
|
781
843
|
submit(tx: $encodedTransaction) {
|
@@ -794,17 +856,17 @@ var ProduceBlocksDocument = gql`
|
|
794
856
|
var SubmitAndAwaitDocument = gql`
|
795
857
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
796
858
|
submitAndAwait(tx: $encodedTransaction) {
|
797
|
-
...
|
859
|
+
...transactionStatusSubscriptionFragment
|
798
860
|
}
|
799
861
|
}
|
800
|
-
${
|
862
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
801
863
|
var StatusChangeDocument = gql`
|
802
864
|
subscription statusChange($transactionId: TransactionId!) {
|
803
865
|
statusChange(id: $transactionId) {
|
804
|
-
...
|
866
|
+
...transactionStatusSubscriptionFragment
|
805
867
|
}
|
806
868
|
}
|
807
|
-
${
|
869
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
808
870
|
function getSdk(requester) {
|
809
871
|
return {
|
810
872
|
getVersion(variables, options) {
|
@@ -858,6 +920,12 @@ function getSdk(requester) {
|
|
858
920
|
getBalance(variables, options) {
|
859
921
|
return requester(GetBalanceDocument, variables, options);
|
860
922
|
},
|
923
|
+
getLatestGasPrice(variables, options) {
|
924
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
925
|
+
},
|
926
|
+
estimateGasPrice(variables, options) {
|
927
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
928
|
+
},
|
861
929
|
getBalances(variables, options) {
|
862
930
|
return requester(GetBalancesDocument, variables, options);
|
863
931
|
},
|
@@ -1051,10 +1119,9 @@ var inputify = (value) => {
|
|
1051
1119
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1052
1120
|
},
|
1053
1121
|
witnessIndex: value.witnessIndex,
|
1054
|
-
maturity: value.maturity ?? 0,
|
1055
1122
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1056
|
-
predicateLength: predicate.length,
|
1057
|
-
predicateDataLength: predicateData.length,
|
1123
|
+
predicateLength: bn2(predicate.length),
|
1124
|
+
predicateDataLength: bn2(predicateData.length),
|
1058
1125
|
predicate: hexlify3(predicate),
|
1059
1126
|
predicateData: hexlify3(predicateData)
|
1060
1127
|
};
|
@@ -1085,8 +1152,8 @@ var inputify = (value) => {
|
|
1085
1152
|
nonce: hexlify3(value.nonce),
|
1086
1153
|
witnessIndex: value.witnessIndex,
|
1087
1154
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1088
|
-
predicateLength: predicate.length,
|
1089
|
-
predicateDataLength: predicateData.length,
|
1155
|
+
predicateLength: bn2(predicate.length),
|
1156
|
+
predicateDataLength: bn2(predicateData.length),
|
1090
1157
|
predicate: hexlify3(predicate),
|
1091
1158
|
predicateData: hexlify3(predicateData),
|
1092
1159
|
data: hexlify3(data),
|
@@ -1162,7 +1229,7 @@ var outputify = (value) => {
|
|
1162
1229
|
// src/providers/transaction-request/transaction-request.ts
|
1163
1230
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1164
1231
|
import { Address, addressify } from "@fuel-ts/address";
|
1165
|
-
import {
|
1232
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1166
1233
|
import { randomBytes } from "@fuel-ts/crypto";
|
1167
1234
|
import { bn as bn7 } from "@fuel-ts/math";
|
1168
1235
|
import {
|
@@ -1213,8 +1280,8 @@ function assembleReceiptByType(receipt) {
|
|
1213
1280
|
case "CALL" /* Call */: {
|
1214
1281
|
const callReceipt = {
|
1215
1282
|
type: ReceiptType.Call,
|
1216
|
-
from: hexOrZero(receipt.
|
1217
|
-
to: hexOrZero(receipt?.to
|
1283
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1284
|
+
to: hexOrZero(receipt?.to),
|
1218
1285
|
amount: bn4(receipt.amount),
|
1219
1286
|
assetId: hexOrZero(receipt.assetId),
|
1220
1287
|
gas: bn4(receipt.gas),
|
@@ -1228,7 +1295,7 @@ function assembleReceiptByType(receipt) {
|
|
1228
1295
|
case "RETURN" /* Return */: {
|
1229
1296
|
const returnReceipt = {
|
1230
1297
|
type: ReceiptType.Return,
|
1231
|
-
id: hexOrZero(receipt.
|
1298
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1232
1299
|
val: bn4(receipt.val),
|
1233
1300
|
pc: bn4(receipt.pc),
|
1234
1301
|
is: bn4(receipt.is)
|
@@ -1238,7 +1305,7 @@ function assembleReceiptByType(receipt) {
|
|
1238
1305
|
case "RETURN_DATA" /* ReturnData */: {
|
1239
1306
|
const returnDataReceipt = {
|
1240
1307
|
type: ReceiptType.ReturnData,
|
1241
|
-
id: hexOrZero(receipt.
|
1308
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1242
1309
|
ptr: bn4(receipt.ptr),
|
1243
1310
|
len: bn4(receipt.len),
|
1244
1311
|
digest: hexOrZero(receipt.digest),
|
@@ -1250,7 +1317,7 @@ function assembleReceiptByType(receipt) {
|
|
1250
1317
|
case "PANIC" /* Panic */: {
|
1251
1318
|
const panicReceipt = {
|
1252
1319
|
type: ReceiptType.Panic,
|
1253
|
-
id: hexOrZero(receipt.
|
1320
|
+
id: hexOrZero(receipt.id),
|
1254
1321
|
reason: bn4(receipt.reason),
|
1255
1322
|
pc: bn4(receipt.pc),
|
1256
1323
|
is: bn4(receipt.is),
|
@@ -1261,7 +1328,7 @@ function assembleReceiptByType(receipt) {
|
|
1261
1328
|
case "REVERT" /* Revert */: {
|
1262
1329
|
const revertReceipt = {
|
1263
1330
|
type: ReceiptType.Revert,
|
1264
|
-
id: hexOrZero(receipt.
|
1331
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1265
1332
|
val: bn4(receipt.ra),
|
1266
1333
|
pc: bn4(receipt.pc),
|
1267
1334
|
is: bn4(receipt.is)
|
@@ -1271,7 +1338,7 @@ function assembleReceiptByType(receipt) {
|
|
1271
1338
|
case "LOG" /* Log */: {
|
1272
1339
|
const logReceipt = {
|
1273
1340
|
type: ReceiptType.Log,
|
1274
|
-
id: hexOrZero(receipt.
|
1341
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1275
1342
|
val0: bn4(receipt.ra),
|
1276
1343
|
val1: bn4(receipt.rb),
|
1277
1344
|
val2: bn4(receipt.rc),
|
@@ -1284,7 +1351,7 @@ function assembleReceiptByType(receipt) {
|
|
1284
1351
|
case "LOG_DATA" /* LogData */: {
|
1285
1352
|
const logDataReceipt = {
|
1286
1353
|
type: ReceiptType.LogData,
|
1287
|
-
id: hexOrZero(receipt.
|
1354
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1288
1355
|
val0: bn4(receipt.ra),
|
1289
1356
|
val1: bn4(receipt.rb),
|
1290
1357
|
ptr: bn4(receipt.ptr),
|
@@ -1298,8 +1365,8 @@ function assembleReceiptByType(receipt) {
|
|
1298
1365
|
case "TRANSFER" /* Transfer */: {
|
1299
1366
|
const transferReceipt = {
|
1300
1367
|
type: ReceiptType.Transfer,
|
1301
|
-
from: hexOrZero(receipt.
|
1302
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1368
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1369
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1303
1370
|
amount: bn4(receipt.amount),
|
1304
1371
|
assetId: hexOrZero(receipt.assetId),
|
1305
1372
|
pc: bn4(receipt.pc),
|
@@ -1310,8 +1377,8 @@ function assembleReceiptByType(receipt) {
|
|
1310
1377
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1311
1378
|
const transferOutReceipt = {
|
1312
1379
|
type: ReceiptType.TransferOut,
|
1313
|
-
from: hexOrZero(receipt.
|
1314
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1380
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1381
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1315
1382
|
amount: bn4(receipt.amount),
|
1316
1383
|
assetId: hexOrZero(receipt.assetId),
|
1317
1384
|
pc: bn4(receipt.pc),
|
@@ -1354,7 +1421,7 @@ function assembleReceiptByType(receipt) {
|
|
1354
1421
|
return receiptMessageOut;
|
1355
1422
|
}
|
1356
1423
|
case "MINT" /* Mint */: {
|
1357
|
-
const contractId = hexOrZero(receipt.
|
1424
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1358
1425
|
const subId = hexOrZero(receipt.subId);
|
1359
1426
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1360
1427
|
const mintReceipt = {
|
@@ -1369,7 +1436,7 @@ function assembleReceiptByType(receipt) {
|
|
1369
1436
|
return mintReceipt;
|
1370
1437
|
}
|
1371
1438
|
case "BURN" /* Burn */: {
|
1372
|
-
const contractId = hexOrZero(receipt.
|
1439
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1373
1440
|
const subId = hexOrZero(receipt.subId);
|
1374
1441
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1375
1442
|
const burnReceipt = {
|
@@ -1395,7 +1462,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1395
1462
|
import { bn as bn5 } from "@fuel-ts/math";
|
1396
1463
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1397
1464
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1398
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1399
1465
|
var getGasUsedFromReceipts = (receipts) => {
|
1400
1466
|
const scriptResult = receipts.filter(
|
1401
1467
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1416,18 +1482,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1416
1482
|
}
|
1417
1483
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1418
1484
|
const witnessCache = [];
|
1419
|
-
const
|
1485
|
+
const chargeableInputs = inputs.filter((input) => {
|
1486
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1487
|
+
if (isCoinOrMessage) {
|
1488
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1489
|
+
return true;
|
1490
|
+
}
|
1491
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1492
|
+
witnessCache.push(input.witnessIndex);
|
1493
|
+
return true;
|
1494
|
+
}
|
1495
|
+
}
|
1496
|
+
return false;
|
1497
|
+
});
|
1498
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1499
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1420
1500
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1421
1501
|
return total.add(
|
1422
|
-
|
1502
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1423
1503
|
);
|
1424
1504
|
}
|
1425
|
-
|
1426
|
-
|
1427
|
-
return total.add(gasCosts.ecr1);
|
1428
|
-
}
|
1429
|
-
return total;
|
1430
|
-
}, bn5());
|
1505
|
+
return total.add(gasCosts.ecr1);
|
1506
|
+
}, bn5(0));
|
1431
1507
|
return totalGas;
|
1432
1508
|
}
|
1433
1509
|
function getMinGas(params) {
|
@@ -1439,12 +1515,20 @@ function getMinGas(params) {
|
|
1439
1515
|
return minGas;
|
1440
1516
|
}
|
1441
1517
|
function getMaxGas(params) {
|
1442
|
-
const {
|
1518
|
+
const {
|
1519
|
+
gasPerByte,
|
1520
|
+
witnessesLength,
|
1521
|
+
witnessLimit,
|
1522
|
+
minGas,
|
1523
|
+
gasLimit = bn5(0),
|
1524
|
+
maxGasPerTx
|
1525
|
+
} = params;
|
1443
1526
|
let remainingAllowedWitnessGas = bn5(0);
|
1444
1527
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1445
1528
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1446
1529
|
}
|
1447
|
-
|
1530
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1531
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1448
1532
|
}
|
1449
1533
|
function calculateMetadataGasForTxCreate({
|
1450
1534
|
gasCosts,
|
@@ -1466,6 +1550,10 @@ function calculateMetadataGasForTxScript({
|
|
1466
1550
|
}) {
|
1467
1551
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1468
1552
|
}
|
1553
|
+
var calculateGasFee = (params) => {
|
1554
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1555
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1556
|
+
};
|
1469
1557
|
|
1470
1558
|
// src/providers/utils/json.ts
|
1471
1559
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1610,7 +1698,7 @@ var witnessify = (value) => {
|
|
1610
1698
|
// src/providers/transaction-request/transaction-request.ts
|
1611
1699
|
var BaseTransactionRequest = class {
|
1612
1700
|
/** Gas price for transaction */
|
1613
|
-
|
1701
|
+
tip;
|
1614
1702
|
/** Block until which tx cannot be included */
|
1615
1703
|
maturity;
|
1616
1704
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1629,7 +1717,7 @@ var BaseTransactionRequest = class {
|
|
1629
1717
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1630
1718
|
*/
|
1631
1719
|
constructor({
|
1632
|
-
|
1720
|
+
tip,
|
1633
1721
|
maturity,
|
1634
1722
|
maxFee,
|
1635
1723
|
witnessLimit,
|
@@ -1637,7 +1725,7 @@ var BaseTransactionRequest = class {
|
|
1637
1725
|
outputs,
|
1638
1726
|
witnesses
|
1639
1727
|
} = {}) {
|
1640
|
-
this.
|
1728
|
+
this.tip = bn7(tip);
|
1641
1729
|
this.maturity = maturity ?? 0;
|
1642
1730
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1643
1731
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1648,9 +1736,9 @@ var BaseTransactionRequest = class {
|
|
1648
1736
|
static getPolicyMeta(req) {
|
1649
1737
|
let policyTypes = 0;
|
1650
1738
|
const policies = [];
|
1651
|
-
if (req.
|
1652
|
-
policyTypes += PolicyType.
|
1653
|
-
policies.push({ data: req.
|
1739
|
+
if (req.tip) {
|
1740
|
+
policyTypes += PolicyType.Tip;
|
1741
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1654
1742
|
}
|
1655
1743
|
if (req.witnessLimit) {
|
1656
1744
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1834,13 +1922,11 @@ var BaseTransactionRequest = class {
|
|
1834
1922
|
* assetId, if one it was not added yet.
|
1835
1923
|
*
|
1836
1924
|
* @param coin - Coin resource.
|
1837
|
-
* @param predicate - Predicate bytes.
|
1838
|
-
* @param predicateData - Predicate data bytes.
|
1839
1925
|
*/
|
1840
|
-
addCoinInput(coin
|
1926
|
+
addCoinInput(coin) {
|
1841
1927
|
const { assetId, owner, amount } = coin;
|
1842
1928
|
let witnessIndex;
|
1843
|
-
if (predicate) {
|
1929
|
+
if (coin.predicate) {
|
1844
1930
|
witnessIndex = 0;
|
1845
1931
|
} else {
|
1846
1932
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1855,25 +1941,21 @@ var BaseTransactionRequest = class {
|
|
1855
1941
|
amount,
|
1856
1942
|
assetId,
|
1857
1943
|
txPointer: "0x00000000000000000000000000000000",
|
1858
|
-
witnessIndex
|
1859
|
-
predicate: predicate?.bytes
|
1944
|
+
witnessIndex
|
1860
1945
|
};
|
1861
1946
|
this.pushInput(input);
|
1862
1947
|
this.addChangeOutput(owner, assetId);
|
1863
1948
|
}
|
1864
1949
|
/**
|
1865
1950
|
* Adds a single message input to the transaction and a change output for the
|
1866
|
-
*
|
1951
|
+
* asset against the message
|
1867
1952
|
*
|
1868
1953
|
* @param message - Message resource.
|
1869
|
-
* @param predicate - Predicate bytes.
|
1870
|
-
* @param predicateData - Predicate data bytes.
|
1871
1954
|
*/
|
1872
|
-
addMessageInput(message
|
1873
|
-
const { recipient, sender, amount } = message;
|
1874
|
-
const assetId = BaseAssetId2;
|
1955
|
+
addMessageInput(message) {
|
1956
|
+
const { recipient, sender, amount, assetId } = message;
|
1875
1957
|
let witnessIndex;
|
1876
|
-
if (predicate) {
|
1958
|
+
if (message.predicate) {
|
1877
1959
|
witnessIndex = 0;
|
1878
1960
|
} else {
|
1879
1961
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1887,8 +1969,7 @@ var BaseTransactionRequest = class {
|
|
1887
1969
|
sender: sender.toB256(),
|
1888
1970
|
recipient: recipient.toB256(),
|
1889
1971
|
amount,
|
1890
|
-
witnessIndex
|
1891
|
-
predicate: predicate?.bytes
|
1972
|
+
witnessIndex
|
1892
1973
|
};
|
1893
1974
|
this.pushInput(input);
|
1894
1975
|
this.addChangeOutput(recipient, assetId);
|
@@ -1919,32 +2000,6 @@ var BaseTransactionRequest = class {
|
|
1919
2000
|
resources.forEach((resource) => this.addResource(resource));
|
1920
2001
|
return this;
|
1921
2002
|
}
|
1922
|
-
/**
|
1923
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1924
|
-
* outputs from the related assetIds.
|
1925
|
-
*
|
1926
|
-
* @param resources - The resources to add.
|
1927
|
-
* @returns This transaction.
|
1928
|
-
*/
|
1929
|
-
addPredicateResource(resource, predicate) {
|
1930
|
-
if (isCoin(resource)) {
|
1931
|
-
this.addCoinInput(resource, predicate);
|
1932
|
-
} else {
|
1933
|
-
this.addMessageInput(resource, predicate);
|
1934
|
-
}
|
1935
|
-
return this;
|
1936
|
-
}
|
1937
|
-
/**
|
1938
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1939
|
-
* from the related assetIds.
|
1940
|
-
*
|
1941
|
-
* @param resources - The resources to add.
|
1942
|
-
* @returns This transaction.
|
1943
|
-
*/
|
1944
|
-
addPredicateResources(resources, predicate) {
|
1945
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1946
|
-
return this;
|
1947
|
-
}
|
1948
2003
|
/**
|
1949
2004
|
* Adds a coin output to the transaction.
|
1950
2005
|
*
|
@@ -1952,7 +2007,7 @@ var BaseTransactionRequest = class {
|
|
1952
2007
|
* @param amount - Amount of coin.
|
1953
2008
|
* @param assetId - Asset ID of coin.
|
1954
2009
|
*/
|
1955
|
-
addCoinOutput(to, amount, assetId
|
2010
|
+
addCoinOutput(to, amount, assetId) {
|
1956
2011
|
this.pushOutput({
|
1957
2012
|
type: OutputType2.Coin,
|
1958
2013
|
to: addressify(to).toB256(),
|
@@ -1984,7 +2039,7 @@ var BaseTransactionRequest = class {
|
|
1984
2039
|
* @param to - Address of the owner.
|
1985
2040
|
* @param assetId - Asset ID of coin.
|
1986
2041
|
*/
|
1987
|
-
addChangeOutput(to, assetId
|
2042
|
+
addChangeOutput(to, assetId) {
|
1988
2043
|
const changeOutput = this.getChangeOutputs().find(
|
1989
2044
|
(output) => hexlify7(output.assetId) === assetId
|
1990
2045
|
);
|
@@ -2024,7 +2079,7 @@ var BaseTransactionRequest = class {
|
|
2024
2079
|
}
|
2025
2080
|
calculateMaxGas(chainInfo, minGas) {
|
2026
2081
|
const { consensusParameters } = chainInfo;
|
2027
|
-
const { gasPerByte } = consensusParameters;
|
2082
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2028
2083
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2029
2084
|
(acc, wit) => acc + wit.dataLength,
|
2030
2085
|
0
|
@@ -2033,7 +2088,8 @@ var BaseTransactionRequest = class {
|
|
2033
2088
|
gasPerByte,
|
2034
2089
|
minGas,
|
2035
2090
|
witnessesLength,
|
2036
|
-
witnessLimit: this.witnessLimit
|
2091
|
+
witnessLimit: this.witnessLimit,
|
2092
|
+
maxGasPerTx
|
2037
2093
|
});
|
2038
2094
|
}
|
2039
2095
|
/**
|
@@ -2041,8 +2097,9 @@ var BaseTransactionRequest = class {
|
|
2041
2097
|
* quantities array.
|
2042
2098
|
*
|
2043
2099
|
* @param quantities - CoinQuantity Array.
|
2100
|
+
* @param baseAssetId - The base asset to fund the transaction.
|
2044
2101
|
*/
|
2045
|
-
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2102
|
+
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2046
2103
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2047
2104
|
if ("assetId" in input) {
|
2048
2105
|
return input.assetId === assetId;
|
@@ -2051,24 +2108,27 @@ var BaseTransactionRequest = class {
|
|
2051
2108
|
});
|
2052
2109
|
const updateAssetInput = (assetId, quantity) => {
|
2053
2110
|
const assetInput = findAssetInput(assetId);
|
2111
|
+
let usedQuantity = quantity;
|
2112
|
+
if (assetId === baseAssetId) {
|
2113
|
+
usedQuantity = bn7("1000000000000000000");
|
2114
|
+
}
|
2054
2115
|
if (assetInput && "assetId" in assetInput) {
|
2055
2116
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2056
|
-
assetInput.amount =
|
2117
|
+
assetInput.amount = usedQuantity;
|
2057
2118
|
} else {
|
2058
2119
|
this.addResources([
|
2059
2120
|
{
|
2060
2121
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2061
|
-
amount:
|
2122
|
+
amount: usedQuantity,
|
2062
2123
|
assetId,
|
2063
2124
|
owner: resourcesOwner || Address.fromRandom(),
|
2064
|
-
maturity: 0,
|
2065
2125
|
blockCreated: bn7(1),
|
2066
2126
|
txCreatedIdx: bn7(1)
|
2067
2127
|
}
|
2068
2128
|
]);
|
2069
2129
|
}
|
2070
2130
|
};
|
2071
|
-
updateAssetInput(
|
2131
|
+
updateAssetInput(baseAssetId, bn7(1e11));
|
2072
2132
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2073
2133
|
}
|
2074
2134
|
/**
|
@@ -2093,7 +2153,7 @@ var BaseTransactionRequest = class {
|
|
2093
2153
|
toJSON() {
|
2094
2154
|
return normalizeJSON(this);
|
2095
2155
|
}
|
2096
|
-
|
2156
|
+
updatePredicateGasUsed(inputs) {
|
2097
2157
|
this.inputs.forEach((i) => {
|
2098
2158
|
let correspondingInput;
|
2099
2159
|
switch (i.type) {
|
@@ -2115,6 +2175,15 @@ var BaseTransactionRequest = class {
|
|
2115
2175
|
}
|
2116
2176
|
});
|
2117
2177
|
}
|
2178
|
+
shiftPredicateData() {
|
2179
|
+
this.inputs.forEach((input) => {
|
2180
|
+
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2181
|
+
input.predicateData = input.padPredicateData(
|
2182
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2183
|
+
);
|
2184
|
+
}
|
2185
|
+
});
|
2186
|
+
}
|
2118
2187
|
};
|
2119
2188
|
|
2120
2189
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2238,12 +2307,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2238
2307
|
*
|
2239
2308
|
* @param createTransactionRequestLike - The initial values for the instance
|
2240
2309
|
*/
|
2241
|
-
constructor({
|
2242
|
-
bytecodeWitnessIndex,
|
2243
|
-
salt,
|
2244
|
-
storageSlots,
|
2245
|
-
...rest
|
2246
|
-
} = {}) {
|
2310
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2247
2311
|
super(rest);
|
2248
2312
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2249
2313
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2261,9 +2325,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2261
2325
|
return {
|
2262
2326
|
type: TransactionType3.Create,
|
2263
2327
|
...baseTransaction,
|
2264
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2265
2328
|
bytecodeWitnessIndex,
|
2266
|
-
storageSlotsCount: storageSlots.length,
|
2329
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2267
2330
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2268
2331
|
storageSlots
|
2269
2332
|
};
|
@@ -2386,8 +2449,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2386
2449
|
type: TransactionType4.Script,
|
2387
2450
|
scriptGasLimit: this.gasLimit,
|
2388
2451
|
...super.getBaseTransaction(),
|
2389
|
-
scriptLength: script.length,
|
2390
|
-
scriptDataLength: scriptData.length,
|
2452
|
+
scriptLength: bn10(script.length),
|
2453
|
+
scriptDataLength: bn10(scriptData.length),
|
2391
2454
|
receiptsRoot: ZeroBytes327,
|
2392
2455
|
script: hexlify10(script),
|
2393
2456
|
scriptData: hexlify10(scriptData)
|
@@ -2451,7 +2514,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2451
2514
|
}
|
2452
2515
|
calculateMaxGas(chainInfo, minGas) {
|
2453
2516
|
const { consensusParameters } = chainInfo;
|
2454
|
-
const { gasPerByte } = consensusParameters;
|
2517
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2455
2518
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2456
2519
|
(acc, wit) => acc + wit.dataLength,
|
2457
2520
|
0
|
@@ -2461,7 +2524,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2461
2524
|
minGas,
|
2462
2525
|
witnessesLength,
|
2463
2526
|
witnessLimit: this.witnessLimit,
|
2464
|
-
gasLimit: this.gasLimit
|
2527
|
+
gasLimit: this.gasLimit,
|
2528
|
+
maxGasPerTx
|
2465
2529
|
});
|
2466
2530
|
}
|
2467
2531
|
/**
|
@@ -2518,7 +2582,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2518
2582
|
|
2519
2583
|
// src/providers/transaction-request/utils.ts
|
2520
2584
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2521
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2585
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2522
2586
|
var transactionRequestify = (obj) => {
|
2523
2587
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2524
2588
|
return obj;
|
@@ -2536,14 +2600,31 @@ var transactionRequestify = (obj) => {
|
|
2536
2600
|
}
|
2537
2601
|
}
|
2538
2602
|
};
|
2603
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2604
|
+
(acc, input) => {
|
2605
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2606
|
+
acc.utxos.push(input.id);
|
2607
|
+
}
|
2608
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2609
|
+
acc.messages.push(input.nonce);
|
2610
|
+
}
|
2611
|
+
return acc;
|
2612
|
+
},
|
2613
|
+
{
|
2614
|
+
utxos: [],
|
2615
|
+
messages: []
|
2616
|
+
}
|
2617
|
+
);
|
2539
2618
|
|
2540
2619
|
// src/providers/transaction-response/transaction-response.ts
|
2541
2620
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2542
|
-
import { bn as
|
2621
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2543
2622
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2544
2623
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2545
2624
|
|
2546
2625
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2626
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2627
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2547
2628
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2548
2629
|
|
2549
2630
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2552,9 +2633,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2552
2633
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2553
2634
|
var calculateTransactionFee = (params) => {
|
2554
2635
|
const {
|
2555
|
-
|
2636
|
+
gasPrice,
|
2556
2637
|
rawPayload,
|
2557
|
-
|
2638
|
+
tip,
|
2639
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2558
2640
|
} = params;
|
2559
2641
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2560
2642
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2564,8 +2646,7 @@ var calculateTransactionFee = (params) => {
|
|
2564
2646
|
return {
|
2565
2647
|
fee: bn11(0),
|
2566
2648
|
minFee: bn11(0),
|
2567
|
-
maxFee: bn11(0)
|
2568
|
-
feeFromGasUsed: bn11(0)
|
2649
|
+
maxFee: bn11(0)
|
2569
2650
|
};
|
2570
2651
|
}
|
2571
2652
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2597,7 +2678,6 @@ var calculateTransactionFee = (params) => {
|
|
2597
2678
|
metadataGas,
|
2598
2679
|
txBytesSize: transactionBytes.length
|
2599
2680
|
});
|
2600
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2601
2681
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2602
2682
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2603
2683
|
const maxGas = getMaxGas({
|
@@ -2605,17 +2685,25 @@ var calculateTransactionFee = (params) => {
|
|
2605
2685
|
minGas,
|
2606
2686
|
witnessesLength,
|
2607
2687
|
gasLimit,
|
2608
|
-
witnessLimit
|
2688
|
+
witnessLimit,
|
2689
|
+
maxGasPerTx
|
2690
|
+
});
|
2691
|
+
const minFee = calculateGasFee({
|
2692
|
+
gasPrice,
|
2693
|
+
gas: minGas,
|
2694
|
+
priceFactor: gasPriceFactor,
|
2695
|
+
tip
|
2696
|
+
});
|
2697
|
+
const maxFee = calculateGasFee({
|
2698
|
+
gasPrice,
|
2699
|
+
gas: maxGas,
|
2700
|
+
priceFactor: gasPriceFactor,
|
2701
|
+
tip
|
2609
2702
|
});
|
2610
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2611
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2612
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2613
|
-
const fee = minFee.add(feeFromGasUsed);
|
2614
2703
|
return {
|
2615
|
-
fee,
|
2616
2704
|
minFee,
|
2617
2705
|
maxFee,
|
2618
|
-
|
2706
|
+
fee: maxFee
|
2619
2707
|
};
|
2620
2708
|
};
|
2621
2709
|
|
@@ -2671,7 +2759,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2671
2759
|
|
2672
2760
|
// src/providers/transaction-summary/input.ts
|
2673
2761
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2674
|
-
import { InputType as
|
2762
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2675
2763
|
function getInputsByTypes(inputs, types) {
|
2676
2764
|
return inputs.filter((i) => types.includes(i.type));
|
2677
2765
|
}
|
@@ -2679,16 +2767,16 @@ function getInputsByType(inputs, type) {
|
|
2679
2767
|
return inputs.filter((i) => i.type === type);
|
2680
2768
|
}
|
2681
2769
|
function getInputsCoin(inputs) {
|
2682
|
-
return getInputsByType(inputs,
|
2770
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2683
2771
|
}
|
2684
2772
|
function getInputsMessage(inputs) {
|
2685
|
-
return getInputsByType(inputs,
|
2773
|
+
return getInputsByType(inputs, InputType6.Message);
|
2686
2774
|
}
|
2687
2775
|
function getInputsCoinAndMessage(inputs) {
|
2688
|
-
return getInputsByTypes(inputs, [
|
2776
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2689
2777
|
}
|
2690
2778
|
function getInputsContract(inputs) {
|
2691
|
-
return getInputsByType(inputs,
|
2779
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2692
2780
|
}
|
2693
2781
|
function getInputFromAssetId(inputs, assetId) {
|
2694
2782
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2707,7 +2795,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2707
2795
|
if (!contractInput) {
|
2708
2796
|
return void 0;
|
2709
2797
|
}
|
2710
|
-
if (contractInput.type !==
|
2798
|
+
if (contractInput.type !== InputType6.Contract) {
|
2711
2799
|
throw new FuelError9(
|
2712
2800
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2713
2801
|
`Contract input should be of type 'contract'.`
|
@@ -2716,10 +2804,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2716
2804
|
return contractInput;
|
2717
2805
|
}
|
2718
2806
|
function getInputAccountAddress(input) {
|
2719
|
-
if (input.type ===
|
2807
|
+
if (input.type === InputType6.Coin) {
|
2720
2808
|
return input.owner.toString();
|
2721
2809
|
}
|
2722
|
-
if (input.type ===
|
2810
|
+
if (input.type === InputType6.Message) {
|
2723
2811
|
return input.recipient.toString();
|
2724
2812
|
}
|
2725
2813
|
return "";
|
@@ -3182,7 +3270,9 @@ function assembleTransactionSummary(params) {
|
|
3182
3270
|
gqlTransactionStatus,
|
3183
3271
|
abiMap = {},
|
3184
3272
|
maxInputs,
|
3185
|
-
gasCosts
|
3273
|
+
gasCosts,
|
3274
|
+
maxGasPerTx,
|
3275
|
+
gasPrice
|
3186
3276
|
} = params;
|
3187
3277
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3188
3278
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3196,11 +3286,14 @@ function assembleTransactionSummary(params) {
|
|
3196
3286
|
maxInputs
|
3197
3287
|
});
|
3198
3288
|
const typeName = getTransactionTypeName(transaction.type);
|
3289
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3199
3290
|
const { fee } = calculateTransactionFee({
|
3200
|
-
|
3291
|
+
gasPrice,
|
3201
3292
|
rawPayload,
|
3293
|
+
tip,
|
3202
3294
|
consensusParameters: {
|
3203
3295
|
gasCosts,
|
3296
|
+
maxGasPerTx,
|
3204
3297
|
feeParams: {
|
3205
3298
|
gasPerByte,
|
3206
3299
|
gasPriceFactor
|
@@ -3260,7 +3353,7 @@ var TransactionResponse = class {
|
|
3260
3353
|
/** Current provider */
|
3261
3354
|
provider;
|
3262
3355
|
/** Gas used on the transaction */
|
3263
|
-
gasUsed =
|
3356
|
+
gasUsed = bn15(0);
|
3264
3357
|
/** The graphql Transaction with receipts object. */
|
3265
3358
|
gqlTransaction;
|
3266
3359
|
abis;
|
@@ -3338,8 +3431,13 @@ var TransactionResponse = class {
|
|
3338
3431
|
const decodedTransaction = this.decodeTransaction(
|
3339
3432
|
transaction
|
3340
3433
|
);
|
3341
|
-
|
3342
|
-
|
3434
|
+
let txReceipts = [];
|
3435
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3436
|
+
txReceipts = transaction.status.receipts;
|
3437
|
+
}
|
3438
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3439
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3440
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3343
3441
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3344
3442
|
const transactionSummary = assembleTransactionSummary({
|
3345
3443
|
id: this.id,
|
@@ -3351,7 +3449,9 @@ var TransactionResponse = class {
|
|
3351
3449
|
gasPriceFactor,
|
3352
3450
|
abiMap: contractsAbiMap,
|
3353
3451
|
maxInputs,
|
3354
|
-
gasCosts
|
3452
|
+
gasCosts,
|
3453
|
+
maxGasPerTx,
|
3454
|
+
gasPrice
|
3355
3455
|
});
|
3356
3456
|
return transactionSummary;
|
3357
3457
|
}
|
@@ -3457,7 +3557,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3457
3557
|
}
|
3458
3558
|
|
3459
3559
|
// src/providers/utils/merge-quantities.ts
|
3460
|
-
var mergeQuantities = (
|
3560
|
+
var mergeQuantities = (...coinQuantities) => {
|
3461
3561
|
const resultMap = {};
|
3462
3562
|
function addToMap({ amount, assetId }) {
|
3463
3563
|
if (resultMap[assetId]) {
|
@@ -3466,8 +3566,7 @@ var mergeQuantities = (arr1, arr2) => {
|
|
3466
3566
|
resultMap[assetId] = amount;
|
3467
3567
|
}
|
3468
3568
|
}
|
3469
|
-
|
3470
|
-
arr2.forEach(addToMap);
|
3569
|
+
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
3471
3570
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
3472
3571
|
};
|
3473
3572
|
|
@@ -3478,29 +3577,30 @@ var processGqlChain = (chain) => {
|
|
3478
3577
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3479
3578
|
return {
|
3480
3579
|
name,
|
3481
|
-
baseChainHeight:
|
3580
|
+
baseChainHeight: bn16(daHeight),
|
3482
3581
|
consensusParameters: {
|
3483
|
-
contractMaxSize:
|
3484
|
-
maxInputs:
|
3485
|
-
maxOutputs:
|
3486
|
-
maxWitnesses:
|
3487
|
-
maxGasPerTx:
|
3488
|
-
maxScriptLength:
|
3489
|
-
maxScriptDataLength:
|
3490
|
-
maxStorageSlots:
|
3491
|
-
maxPredicateLength:
|
3492
|
-
maxPredicateDataLength:
|
3493
|
-
maxGasPerPredicate:
|
3494
|
-
gasPriceFactor:
|
3495
|
-
gasPerByte:
|
3496
|
-
maxMessageDataLength:
|
3497
|
-
chainId:
|
3582
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3583
|
+
maxInputs: bn16(txParams.maxInputs),
|
3584
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3585
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3586
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3587
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3588
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3589
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3590
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3591
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3592
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3593
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3594
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3595
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3596
|
+
chainId: bn16(consensusParameters.chainId),
|
3597
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3498
3598
|
gasCosts
|
3499
3599
|
},
|
3500
3600
|
gasCosts,
|
3501
3601
|
latestBlock: {
|
3502
3602
|
id: latestBlock.id,
|
3503
|
-
height:
|
3603
|
+
height: bn16(latestBlock.height),
|
3504
3604
|
time: latestBlock.header.time,
|
3505
3605
|
transactions: latestBlock.transactions.map((i) => ({
|
3506
3606
|
id: i.id
|
@@ -3594,10 +3694,8 @@ var _Provider = class {
|
|
3594
3694
|
* Returns some helpful parameters related to gas fees.
|
3595
3695
|
*/
|
3596
3696
|
getGasConfig() {
|
3597
|
-
const { minGasPrice } = this.getNode();
|
3598
3697
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3599
3698
|
return {
|
3600
|
-
minGasPrice,
|
3601
3699
|
maxGasPerTx,
|
3602
3700
|
maxGasPerPredicate,
|
3603
3701
|
gasPriceFactor,
|
@@ -3695,7 +3793,7 @@ var _Provider = class {
|
|
3695
3793
|
*/
|
3696
3794
|
async getBlockNumber() {
|
3697
3795
|
const { chain } = await this.operations.getChain();
|
3698
|
-
return
|
3796
|
+
return bn16(chain.latestBlock.height, 10);
|
3699
3797
|
}
|
3700
3798
|
/**
|
3701
3799
|
* Returns the chain information.
|
@@ -3705,13 +3803,11 @@ var _Provider = class {
|
|
3705
3803
|
async fetchNode() {
|
3706
3804
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3707
3805
|
const processedNodeInfo = {
|
3708
|
-
maxDepth:
|
3709
|
-
maxTx:
|
3710
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3806
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3807
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3711
3808
|
nodeVersion: nodeInfo.nodeVersion,
|
3712
3809
|
utxoValidation: nodeInfo.utxoValidation,
|
3713
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3714
|
-
peers: nodeInfo.peers
|
3810
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3715
3811
|
};
|
3716
3812
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3717
3813
|
return processedNodeInfo;
|
@@ -3737,6 +3833,17 @@ var _Provider = class {
|
|
3737
3833
|
} = this.getChain();
|
3738
3834
|
return chainId.toNumber();
|
3739
3835
|
}
|
3836
|
+
/**
|
3837
|
+
* Returns the base asset ID for the current provider network
|
3838
|
+
*
|
3839
|
+
* @returns the base asset ID
|
3840
|
+
*/
|
3841
|
+
getBaseAssetId() {
|
3842
|
+
const {
|
3843
|
+
consensusParameters: { baseAssetId }
|
3844
|
+
} = this.getChain();
|
3845
|
+
return baseAssetId;
|
3846
|
+
}
|
3740
3847
|
/**
|
3741
3848
|
* Submits a transaction to the chain to be executed.
|
3742
3849
|
*
|
@@ -3797,14 +3904,13 @@ var _Provider = class {
|
|
3797
3904
|
return this.estimateTxDependencies(transactionRequest);
|
3798
3905
|
}
|
3799
3906
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3800
|
-
const { dryRun:
|
3801
|
-
encodedTransaction,
|
3907
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3908
|
+
encodedTransactions: encodedTransaction,
|
3802
3909
|
utxoValidation: utxoValidation || false
|
3803
3910
|
});
|
3804
|
-
const receipts =
|
3805
|
-
|
3806
|
-
|
3807
|
-
};
|
3911
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3912
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3913
|
+
return { receipts, dryrunStatus: status };
|
3808
3914
|
}
|
3809
3915
|
/**
|
3810
3916
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3830,7 +3936,7 @@ var _Provider = class {
|
|
3830
3936
|
} = response;
|
3831
3937
|
if (inputs) {
|
3832
3938
|
inputs.forEach((input, index) => {
|
3833
|
-
if ("predicateGasUsed" in input &&
|
3939
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3834
3940
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3835
3941
|
}
|
3836
3942
|
});
|
@@ -3843,9 +3949,6 @@ var _Provider = class {
|
|
3843
3949
|
* If there are missing variable outputs,
|
3844
3950
|
* `addVariableOutputs` is called on the transaction.
|
3845
3951
|
*
|
3846
|
-
* @privateRemarks
|
3847
|
-
* TODO: Investigate support for missing contract IDs
|
3848
|
-
* TODO: Add support for missing output messages
|
3849
3952
|
*
|
3850
3953
|
* @param transactionRequest - The transaction request object.
|
3851
3954
|
* @returns A promise.
|
@@ -3858,16 +3961,19 @@ var _Provider = class {
|
|
3858
3961
|
missingContractIds: []
|
3859
3962
|
};
|
3860
3963
|
}
|
3861
|
-
await this.estimatePredicates(transactionRequest);
|
3862
3964
|
let receipts = [];
|
3863
3965
|
const missingContractIds = [];
|
3864
3966
|
let outputVariables = 0;
|
3967
|
+
let dryrunStatus;
|
3865
3968
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3866
|
-
const {
|
3867
|
-
|
3969
|
+
const {
|
3970
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3971
|
+
} = await this.operations.dryRun({
|
3972
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3868
3973
|
utxoValidation: false
|
3869
3974
|
});
|
3870
|
-
receipts =
|
3975
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3976
|
+
dryrunStatus = status;
|
3871
3977
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3872
3978
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3873
3979
|
if (hasMissingOutputs) {
|
@@ -3877,6 +3983,10 @@ var _Provider = class {
|
|
3877
3983
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3878
3984
|
missingContractIds.push(contractId);
|
3879
3985
|
});
|
3986
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3987
|
+
transactionRequest
|
3988
|
+
});
|
3989
|
+
transactionRequest.maxFee = maxFee;
|
3880
3990
|
} else {
|
3881
3991
|
break;
|
3882
3992
|
}
|
@@ -3884,37 +3994,136 @@ var _Provider = class {
|
|
3884
3994
|
return {
|
3885
3995
|
receipts,
|
3886
3996
|
outputVariables,
|
3887
|
-
missingContractIds
|
3997
|
+
missingContractIds,
|
3998
|
+
dryrunStatus
|
3888
3999
|
};
|
3889
4000
|
}
|
4001
|
+
/**
|
4002
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4003
|
+
*
|
4004
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4005
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4006
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4007
|
+
*
|
4008
|
+
* @param transactionRequests - Array of transaction request objects.
|
4009
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4010
|
+
*/
|
4011
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4012
|
+
const results = transactionRequests.map(() => ({
|
4013
|
+
receipts: [],
|
4014
|
+
outputVariables: 0,
|
4015
|
+
missingContractIds: [],
|
4016
|
+
dryrunStatus: void 0
|
4017
|
+
}));
|
4018
|
+
const allRequests = clone3(transactionRequests);
|
4019
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4020
|
+
allRequests.forEach((req, index) => {
|
4021
|
+
if (req.type === TransactionType8.Script) {
|
4022
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4023
|
+
}
|
4024
|
+
});
|
4025
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4026
|
+
let attempt = 0;
|
4027
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4028
|
+
const encodedTransactions = transactionsToProcess.map(
|
4029
|
+
(index) => serializedTransactionsMap.get(index)
|
4030
|
+
);
|
4031
|
+
const dryRunResults = await this.operations.dryRun({
|
4032
|
+
encodedTransactions,
|
4033
|
+
utxoValidation: false
|
4034
|
+
});
|
4035
|
+
const nextRoundTransactions = [];
|
4036
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4037
|
+
const requestIdx = transactionsToProcess[i];
|
4038
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4039
|
+
const result = results[requestIdx];
|
4040
|
+
result.receipts = rawReceipts.map(processGqlReceipt);
|
4041
|
+
result.dryrunStatus = status;
|
4042
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4043
|
+
result.receipts
|
4044
|
+
);
|
4045
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4046
|
+
const request = allRequests[requestIdx];
|
4047
|
+
if (hasMissingOutputs && request?.type === TransactionType8.Script) {
|
4048
|
+
result.outputVariables += missingOutputVariables.length;
|
4049
|
+
request.addVariableOutputs(missingOutputVariables.length);
|
4050
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4051
|
+
request.addContractInputAndOutput(Address2.fromString(contractId));
|
4052
|
+
result.missingContractIds.push(contractId);
|
4053
|
+
});
|
4054
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4055
|
+
transactionRequest: request
|
4056
|
+
});
|
4057
|
+
request.maxFee = maxFee;
|
4058
|
+
serializedTransactionsMap.set(requestIdx, hexlify12(request.toTransactionBytes()));
|
4059
|
+
nextRoundTransactions.push(requestIdx);
|
4060
|
+
}
|
4061
|
+
}
|
4062
|
+
transactionsToProcess = nextRoundTransactions;
|
4063
|
+
attempt += 1;
|
4064
|
+
}
|
4065
|
+
return results;
|
4066
|
+
}
|
4067
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4068
|
+
if (estimateTxDependencies) {
|
4069
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4070
|
+
}
|
4071
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4072
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4073
|
+
encodedTransactions,
|
4074
|
+
utxoValidation: utxoValidation || false
|
4075
|
+
});
|
4076
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4077
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4078
|
+
return { receipts, dryrunStatus: status };
|
4079
|
+
});
|
4080
|
+
return results;
|
4081
|
+
}
|
3890
4082
|
/**
|
3891
4083
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3892
4084
|
* @param transactionRequest - The transaction request object.
|
3893
4085
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3894
4086
|
*/
|
3895
|
-
estimateTxGasAndFee(params) {
|
4087
|
+
async estimateTxGasAndFee(params) {
|
3896
4088
|
const { transactionRequest } = params;
|
3897
|
-
|
4089
|
+
let { gasPrice } = params;
|
3898
4090
|
const chainInfo = this.getChain();
|
3899
|
-
const
|
3900
|
-
transactionRequest.gasPrice = gasPrice;
|
4091
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3901
4092
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3902
|
-
|
4093
|
+
if (!gasPrice) {
|
4094
|
+
gasPrice = await this.estimateGasPrice(10);
|
4095
|
+
}
|
4096
|
+
const minFee = calculateGasFee({
|
4097
|
+
gasPrice: bn16(gasPrice),
|
4098
|
+
gas: minGas,
|
4099
|
+
priceFactor: gasPriceFactor,
|
4100
|
+
tip: transactionRequest.tip
|
4101
|
+
}).add(1);
|
4102
|
+
let gasLimit = bn16(0);
|
3903
4103
|
if (transactionRequest.type === TransactionType8.Script) {
|
4104
|
+
gasLimit = transactionRequest.gasLimit;
|
3904
4105
|
if (transactionRequest.gasLimit.eq(0)) {
|
3905
4106
|
transactionRequest.gasLimit = minGas;
|
3906
4107
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3907
4108
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3908
4109
|
);
|
4110
|
+
gasLimit = transactionRequest.gasLimit;
|
3909
4111
|
}
|
3910
4112
|
}
|
3911
4113
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3912
|
-
const maxFee =
|
4114
|
+
const maxFee = calculateGasFee({
|
4115
|
+
gasPrice: bn16(gasPrice),
|
4116
|
+
gas: maxGas,
|
4117
|
+
priceFactor: gasPriceFactor,
|
4118
|
+
tip: transactionRequest.tip
|
4119
|
+
}).add(1);
|
3913
4120
|
return {
|
3914
4121
|
minGas,
|
3915
4122
|
minFee,
|
3916
4123
|
maxGas,
|
3917
|
-
maxFee
|
4124
|
+
maxFee,
|
4125
|
+
gasPrice,
|
4126
|
+
gasLimit
|
3918
4127
|
};
|
3919
4128
|
}
|
3920
4129
|
/**
|
@@ -3932,15 +4141,17 @@ var _Provider = class {
|
|
3932
4141
|
if (estimateTxDependencies) {
|
3933
4142
|
return this.estimateTxDependencies(transactionRequest);
|
3934
4143
|
}
|
3935
|
-
const
|
3936
|
-
const { dryRun:
|
3937
|
-
|
4144
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4145
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4146
|
+
encodedTransactions,
|
3938
4147
|
utxoValidation: true
|
3939
4148
|
});
|
3940
|
-
const
|
3941
|
-
|
3942
|
-
receipts
|
3943
|
-
|
4149
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4150
|
+
const { id, receipts, status } = dryRunStatus;
|
4151
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4152
|
+
return { id, receipts: processedReceipts, status };
|
4153
|
+
});
|
4154
|
+
return { receipts: callResult[0].receipts };
|
3944
4155
|
}
|
3945
4156
|
/**
|
3946
4157
|
* Returns a transaction cost to enable user
|
@@ -3957,77 +4168,80 @@ var _Provider = class {
|
|
3957
4168
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3958
4169
|
* @returns A promise that resolves to the transaction cost object.
|
3959
4170
|
*/
|
3960
|
-
async getTransactionCost(transactionRequestLike,
|
3961
|
-
estimateTxDependencies = true,
|
3962
|
-
estimatePredicates = true,
|
3963
|
-
resourcesOwner,
|
3964
|
-
signatureCallback
|
3965
|
-
} = {}) {
|
4171
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3966
4172
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3967
|
-
const { minGasPrice } = this.getGasConfig();
|
3968
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3969
4173
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4174
|
+
const baseAssetId = this.getBaseAssetId();
|
3970
4175
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3971
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3972
|
-
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4176
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4177
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4178
|
+
txRequestClone.maxFee = bn16(0);
|
3973
4179
|
if (isScriptTransaction) {
|
3974
|
-
txRequestClone.gasLimit =
|
4180
|
+
txRequestClone.gasLimit = bn16(0);
|
3975
4181
|
}
|
3976
|
-
if (
|
3977
|
-
|
3978
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3979
|
-
}
|
3980
|
-
await this.estimatePredicates(txRequestClone);
|
4182
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4183
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3981
4184
|
}
|
4185
|
+
const signedRequest = clone3(txRequestClone);
|
4186
|
+
let addedSignatures = 0;
|
3982
4187
|
if (signatureCallback && isScriptTransaction) {
|
3983
|
-
|
4188
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4189
|
+
await signatureCallback(signedRequest);
|
4190
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3984
4191
|
}
|
3985
|
-
|
3986
|
-
|
4192
|
+
await this.estimatePredicates(signedRequest);
|
4193
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4194
|
+
transactionRequest: signedRequest
|
3987
4195
|
});
|
3988
4196
|
let receipts = [];
|
3989
4197
|
let missingContractIds = [];
|
3990
4198
|
let outputVariables = 0;
|
3991
|
-
let gasUsed =
|
3992
|
-
|
3993
|
-
|
4199
|
+
let gasUsed = bn16(0);
|
4200
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4201
|
+
txRequestClone.maxFee = maxFee;
|
4202
|
+
if (isScriptTransaction) {
|
4203
|
+
txRequestClone.gasLimit = gasLimit;
|
4204
|
+
if (signatureCallback) {
|
4205
|
+
await signatureCallback(txRequestClone);
|
4206
|
+
}
|
3994
4207
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3995
4208
|
receipts = result.receipts;
|
3996
4209
|
outputVariables = result.outputVariables;
|
3997
4210
|
missingContractIds = result.missingContractIds;
|
3998
4211
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3999
4212
|
txRequestClone.gasLimit = gasUsed;
|
4000
|
-
|
4001
|
-
|
4002
|
-
|
4213
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4214
|
+
transactionRequest: txRequestClone,
|
4215
|
+
gasPrice
|
4003
4216
|
}));
|
4004
4217
|
}
|
4005
4218
|
return {
|
4006
4219
|
requiredQuantities: allQuantities,
|
4007
4220
|
receipts,
|
4008
4221
|
gasUsed,
|
4009
|
-
|
4010
|
-
gasPrice: setGasPrice,
|
4222
|
+
gasPrice,
|
4011
4223
|
minGas,
|
4012
4224
|
maxGas,
|
4013
4225
|
minFee,
|
4014
4226
|
maxFee,
|
4015
|
-
estimatedInputs: txRequestClone.inputs,
|
4016
4227
|
outputVariables,
|
4017
|
-
missingContractIds
|
4228
|
+
missingContractIds,
|
4229
|
+
addedSignatures,
|
4230
|
+
estimatedPredicates: txRequestClone.inputs
|
4018
4231
|
};
|
4019
4232
|
}
|
4020
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4233
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4021
4234
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4022
4235
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4023
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4236
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4237
|
+
quantitiesToContract
|
4238
|
+
});
|
4024
4239
|
transactionRequest.addResources(
|
4025
4240
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4026
4241
|
);
|
4027
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4028
|
-
|
4029
|
-
|
4030
|
-
);
|
4242
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4243
|
+
quantitiesToContract
|
4244
|
+
});
|
4031
4245
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4032
4246
|
return {
|
4033
4247
|
resources,
|
@@ -4049,11 +4263,10 @@ var _Provider = class {
|
|
4049
4263
|
return coins.map((coin) => ({
|
4050
4264
|
id: coin.utxoId,
|
4051
4265
|
assetId: coin.assetId,
|
4052
|
-
amount:
|
4266
|
+
amount: bn16(coin.amount),
|
4053
4267
|
owner: Address2.fromAddressOrString(coin.owner),
|
4054
|
-
|
4055
|
-
|
4056
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4268
|
+
blockCreated: bn16(coin.blockCreated),
|
4269
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4057
4270
|
}));
|
4058
4271
|
}
|
4059
4272
|
/**
|
@@ -4090,9 +4303,9 @@ var _Provider = class {
|
|
4090
4303
|
switch (coin.__typename) {
|
4091
4304
|
case "MessageCoin":
|
4092
4305
|
return {
|
4093
|
-
amount:
|
4306
|
+
amount: bn16(coin.amount),
|
4094
4307
|
assetId: coin.assetId,
|
4095
|
-
daHeight:
|
4308
|
+
daHeight: bn16(coin.daHeight),
|
4096
4309
|
sender: Address2.fromAddressOrString(coin.sender),
|
4097
4310
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4098
4311
|
nonce: coin.nonce
|
@@ -4100,12 +4313,11 @@ var _Provider = class {
|
|
4100
4313
|
case "Coin":
|
4101
4314
|
return {
|
4102
4315
|
id: coin.utxoId,
|
4103
|
-
amount:
|
4316
|
+
amount: bn16(coin.amount),
|
4104
4317
|
assetId: coin.assetId,
|
4105
4318
|
owner: Address2.fromAddressOrString(coin.owner),
|
4106
|
-
|
4107
|
-
|
4108
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4319
|
+
blockCreated: bn16(coin.blockCreated),
|
4320
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4109
4321
|
};
|
4110
4322
|
default:
|
4111
4323
|
return null;
|
@@ -4122,13 +4334,13 @@ var _Provider = class {
|
|
4122
4334
|
async getBlock(idOrHeight) {
|
4123
4335
|
let variables;
|
4124
4336
|
if (typeof idOrHeight === "number") {
|
4125
|
-
variables = { height:
|
4337
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4126
4338
|
} else if (idOrHeight === "latest") {
|
4127
4339
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4128
4340
|
} else if (idOrHeight.length === 66) {
|
4129
4341
|
variables = { blockId: idOrHeight };
|
4130
4342
|
} else {
|
4131
|
-
variables = { blockId:
|
4343
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4132
4344
|
}
|
4133
4345
|
const { block } = await this.operations.getBlock(variables);
|
4134
4346
|
if (!block) {
|
@@ -4136,7 +4348,7 @@ var _Provider = class {
|
|
4136
4348
|
}
|
4137
4349
|
return {
|
4138
4350
|
id: block.id,
|
4139
|
-
height:
|
4351
|
+
height: bn16(block.height),
|
4140
4352
|
time: block.header.time,
|
4141
4353
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4142
4354
|
};
|
@@ -4151,7 +4363,7 @@ var _Provider = class {
|
|
4151
4363
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4152
4364
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4153
4365
|
id: block.id,
|
4154
|
-
height:
|
4366
|
+
height: bn16(block.height),
|
4155
4367
|
time: block.header.time,
|
4156
4368
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4157
4369
|
}));
|
@@ -4166,7 +4378,7 @@ var _Provider = class {
|
|
4166
4378
|
async getBlockWithTransactions(idOrHeight) {
|
4167
4379
|
let variables;
|
4168
4380
|
if (typeof idOrHeight === "number") {
|
4169
|
-
variables = { blockHeight:
|
4381
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4170
4382
|
} else if (idOrHeight === "latest") {
|
4171
4383
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4172
4384
|
} else {
|
@@ -4178,7 +4390,7 @@ var _Provider = class {
|
|
4178
4390
|
}
|
4179
4391
|
return {
|
4180
4392
|
id: block.id,
|
4181
|
-
height:
|
4393
|
+
height: bn16(block.height, 10),
|
4182
4394
|
time: block.header.time,
|
4183
4395
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4184
4396
|
transactions: block.transactions.map(
|
@@ -4227,7 +4439,7 @@ var _Provider = class {
|
|
4227
4439
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4228
4440
|
asset: hexlify12(assetId)
|
4229
4441
|
});
|
4230
|
-
return
|
4442
|
+
return bn16(contractBalance.amount, 10);
|
4231
4443
|
}
|
4232
4444
|
/**
|
4233
4445
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4241,7 +4453,7 @@ var _Provider = class {
|
|
4241
4453
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4242
4454
|
assetId: hexlify12(assetId)
|
4243
4455
|
});
|
4244
|
-
return
|
4456
|
+
return bn16(balance.amount, 10);
|
4245
4457
|
}
|
4246
4458
|
/**
|
4247
4459
|
* Returns balances for the given owner.
|
@@ -4259,7 +4471,7 @@ var _Provider = class {
|
|
4259
4471
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4260
4472
|
return balances.map((balance) => ({
|
4261
4473
|
assetId: balance.assetId,
|
4262
|
-
amount:
|
4474
|
+
amount: bn16(balance.amount)
|
4263
4475
|
}));
|
4264
4476
|
}
|
4265
4477
|
/**
|
@@ -4281,15 +4493,15 @@ var _Provider = class {
|
|
4281
4493
|
sender: message.sender,
|
4282
4494
|
recipient: message.recipient,
|
4283
4495
|
nonce: message.nonce,
|
4284
|
-
amount:
|
4496
|
+
amount: bn16(message.amount),
|
4285
4497
|
data: message.data
|
4286
4498
|
}),
|
4287
4499
|
sender: Address2.fromAddressOrString(message.sender),
|
4288
4500
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4289
4501
|
nonce: message.nonce,
|
4290
|
-
amount:
|
4502
|
+
amount: bn16(message.amount),
|
4291
4503
|
data: InputMessageCoder.decodeData(message.data),
|
4292
|
-
daHeight:
|
4504
|
+
daHeight: bn16(message.daHeight)
|
4293
4505
|
}));
|
4294
4506
|
}
|
4295
4507
|
/**
|
@@ -4342,44 +4554,60 @@ var _Provider = class {
|
|
4342
4554
|
} = result.messageProof;
|
4343
4555
|
return {
|
4344
4556
|
messageProof: {
|
4345
|
-
proofIndex:
|
4557
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4346
4558
|
proofSet: messageProof.proofSet
|
4347
4559
|
},
|
4348
4560
|
blockProof: {
|
4349
|
-
proofIndex:
|
4561
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4350
4562
|
proofSet: blockProof.proofSet
|
4351
4563
|
},
|
4352
4564
|
messageBlockHeader: {
|
4353
4565
|
id: messageBlockHeader.id,
|
4354
|
-
daHeight:
|
4355
|
-
transactionsCount:
|
4566
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4567
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4356
4568
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4357
|
-
height:
|
4569
|
+
height: bn16(messageBlockHeader.height),
|
4358
4570
|
prevRoot: messageBlockHeader.prevRoot,
|
4359
4571
|
time: messageBlockHeader.time,
|
4360
4572
|
applicationHash: messageBlockHeader.applicationHash,
|
4361
|
-
|
4362
|
-
|
4573
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4574
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4575
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4576
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4577
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4363
4578
|
},
|
4364
4579
|
commitBlockHeader: {
|
4365
4580
|
id: commitBlockHeader.id,
|
4366
|
-
daHeight:
|
4367
|
-
transactionsCount:
|
4581
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4582
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4368
4583
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4369
|
-
height:
|
4584
|
+
height: bn16(commitBlockHeader.height),
|
4370
4585
|
prevRoot: commitBlockHeader.prevRoot,
|
4371
4586
|
time: commitBlockHeader.time,
|
4372
4587
|
applicationHash: commitBlockHeader.applicationHash,
|
4373
|
-
|
4374
|
-
|
4588
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4589
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4590
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4591
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4592
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4375
4593
|
},
|
4376
4594
|
sender: Address2.fromAddressOrString(sender),
|
4377
4595
|
recipient: Address2.fromAddressOrString(recipient),
|
4378
4596
|
nonce,
|
4379
|
-
amount:
|
4597
|
+
amount: bn16(amount),
|
4380
4598
|
data
|
4381
4599
|
};
|
4382
4600
|
}
|
4601
|
+
async getLatestGasPrice() {
|
4602
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4603
|
+
return bn16(latestGasPrice.gasPrice);
|
4604
|
+
}
|
4605
|
+
async estimateGasPrice(blockHorizon) {
|
4606
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4607
|
+
blockHorizon: String(blockHorizon)
|
4608
|
+
});
|
4609
|
+
return bn16(estimateGasPrice.gasPrice);
|
4610
|
+
}
|
4383
4611
|
/**
|
4384
4612
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4385
4613
|
*
|
@@ -4399,10 +4627,10 @@ var _Provider = class {
|
|
4399
4627
|
*/
|
4400
4628
|
async produceBlocks(amount, startTime) {
|
4401
4629
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4402
|
-
blocksToProduce:
|
4630
|
+
blocksToProduce: bn16(amount).toString(10),
|
4403
4631
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4404
4632
|
});
|
4405
|
-
return
|
4633
|
+
return bn16(latestBlockHeight);
|
4406
4634
|
}
|
4407
4635
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4408
4636
|
async getTransactionResponse(transactionId) {
|
@@ -4416,7 +4644,7 @@ cacheInputs_fn = function(inputs) {
|
|
4416
4644
|
return;
|
4417
4645
|
}
|
4418
4646
|
inputs.forEach((input) => {
|
4419
|
-
if (input.type ===
|
4647
|
+
if (input.type === InputType7.Coin) {
|
4420
4648
|
this.cache?.set(input.id);
|
4421
4649
|
}
|
4422
4650
|
});
|
@@ -4426,7 +4654,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4426
4654
|
|
4427
4655
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4428
4656
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4429
|
-
import { bn as
|
4657
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4430
4658
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4431
4659
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4432
4660
|
|
@@ -4634,8 +4862,9 @@ var Account = class extends AbstractAccount {
|
|
4634
4862
|
* @param assetId - The asset ID to check the balance for.
|
4635
4863
|
* @returns A promise that resolves to the balance amount.
|
4636
4864
|
*/
|
4637
|
-
async getBalance(assetId
|
4638
|
-
const
|
4865
|
+
async getBalance(assetId) {
|
4866
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4867
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4639
4868
|
return amount;
|
4640
4869
|
}
|
4641
4870
|
/**
|
@@ -4672,37 +4901,31 @@ var Account = class extends AbstractAccount {
|
|
4672
4901
|
* @param fee - The estimated transaction fee.
|
4673
4902
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4674
4903
|
*/
|
4675
|
-
async fund(request,
|
4676
|
-
const
|
4677
|
-
|
4678
|
-
|
4679
|
-
|
4904
|
+
async fund(request, params) {
|
4905
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4906
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4907
|
+
const txRequest = request;
|
4908
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4909
|
+
amount: bn18(fee),
|
4910
|
+
assetId: baseAssetId,
|
4911
|
+
coinQuantities: requiredQuantities
|
4680
4912
|
});
|
4681
4913
|
const quantitiesDict = {};
|
4682
|
-
|
4914
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4683
4915
|
quantitiesDict[assetId] = {
|
4684
4916
|
required: amount,
|
4685
|
-
owned:
|
4917
|
+
owned: bn18(0)
|
4686
4918
|
};
|
4687
4919
|
});
|
4688
|
-
|
4689
|
-
const cachedMessages = [];
|
4690
|
-
const owner = this.address.toB256();
|
4691
|
-
request.inputs.forEach((input) => {
|
4920
|
+
txRequest.inputs.forEach((input) => {
|
4692
4921
|
const isResource = "amount" in input;
|
4693
|
-
if (isResource) {
|
4694
|
-
|
4695
|
-
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
cachedUtxos.push(input.id);
|
4701
|
-
}
|
4702
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4703
|
-
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4704
|
-
cachedMessages.push(input.nonce);
|
4705
|
-
}
|
4922
|
+
if (!isResource) {
|
4923
|
+
return;
|
4924
|
+
}
|
4925
|
+
const isCoin2 = "owner" in input;
|
4926
|
+
const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
|
4927
|
+
if (quantitiesDict[assetId]) {
|
4928
|
+
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
|
4706
4929
|
}
|
4707
4930
|
});
|
4708
4931
|
const missingQuantities = [];
|
@@ -4716,12 +4939,21 @@ var Account = class extends AbstractAccount {
|
|
4716
4939
|
});
|
4717
4940
|
const needsToBeFunded = missingQuantities.length;
|
4718
4941
|
if (needsToBeFunded) {
|
4719
|
-
const
|
4720
|
-
|
4721
|
-
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
4942
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4943
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4944
|
+
txRequest.addResources(resources);
|
4945
|
+
}
|
4946
|
+
txRequest.shiftPredicateData();
|
4947
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4948
|
+
const requestToReestimate = clone4(txRequest);
|
4949
|
+
if (addedSignatures) {
|
4950
|
+
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
4951
|
+
}
|
4952
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4953
|
+
transactionRequest: requestToReestimate
|
4954
|
+
});
|
4955
|
+
txRequest.maxFee = maxFee;
|
4956
|
+
return txRequest;
|
4725
4957
|
}
|
4726
4958
|
/**
|
4727
4959
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4729,28 +4961,25 @@ var Account = class extends AbstractAccount {
|
|
4729
4961
|
* @param destination - The address of the destination.
|
4730
4962
|
* @param amount - The amount of coins to transfer.
|
4731
4963
|
* @param assetId - The asset ID of the coins to transfer.
|
4732
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4964
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4733
4965
|
* @returns A promise that resolves to the prepared transaction request.
|
4734
4966
|
*/
|
4735
|
-
async createTransfer(destination, amount, assetId
|
4736
|
-
const
|
4737
|
-
const
|
4738
|
-
|
4739
|
-
|
4740
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4967
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4968
|
+
const request = new ScriptTransactionRequest(txParams);
|
4969
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4970
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4971
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4741
4972
|
estimateTxDependencies: true,
|
4742
4973
|
resourcesOwner: this
|
4743
4974
|
});
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
gasPrice: request.gasPrice,
|
4749
|
-
gasLimit: request.gasLimit,
|
4750
|
-
minGasPrice
|
4975
|
+
this.validateGasLimitAndMaxFee({
|
4976
|
+
gasUsed: txCost.gasUsed,
|
4977
|
+
maxFee: txCost.maxFee,
|
4978
|
+
txParams
|
4751
4979
|
});
|
4752
|
-
|
4753
|
-
request.
|
4980
|
+
request.gasLimit = txCost.gasUsed;
|
4981
|
+
request.maxFee = txCost.maxFee;
|
4982
|
+
await this.fund(request, txCost);
|
4754
4983
|
return request;
|
4755
4984
|
}
|
4756
4985
|
/**
|
@@ -4759,17 +4988,18 @@ var Account = class extends AbstractAccount {
|
|
4759
4988
|
* @param destination - The address of the destination.
|
4760
4989
|
* @param amount - The amount of coins to transfer.
|
4761
4990
|
* @param assetId - The asset ID of the coins to transfer.
|
4762
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4991
|
+
* @param txParams - The transaction parameters (gasLimit, maturity).
|
4763
4992
|
* @returns A promise that resolves to the transaction response.
|
4764
4993
|
*/
|
4765
|
-
async transfer(destination, amount, assetId
|
4766
|
-
if (
|
4994
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4995
|
+
if (bn18(amount).lte(0)) {
|
4767
4996
|
throw new FuelError15(
|
4768
4997
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4769
4998
|
"Transfer amount must be a positive number."
|
4770
4999
|
);
|
4771
5000
|
}
|
4772
|
-
const
|
5001
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5002
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4773
5003
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4774
5004
|
}
|
4775
5005
|
/**
|
@@ -4781,39 +5011,38 @@ var Account = class extends AbstractAccount {
|
|
4781
5011
|
* @param txParams - The optional transaction parameters.
|
4782
5012
|
* @returns A promise that resolves to the transaction response.
|
4783
5013
|
*/
|
4784
|
-
async transferToContract(contractId, amount, assetId
|
4785
|
-
if (
|
5014
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5015
|
+
if (bn18(amount).lte(0)) {
|
4786
5016
|
throw new FuelError15(
|
4787
5017
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4788
5018
|
"Transfer amount must be a positive number."
|
4789
5019
|
);
|
4790
5020
|
}
|
4791
5021
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4792
|
-
const
|
4793
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5022
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4794
5023
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4795
5024
|
hexlifiedContractId: contractAddress.toB256(),
|
4796
|
-
amountToTransfer:
|
4797
|
-
assetId
|
5025
|
+
amountToTransfer: bn18(amount),
|
5026
|
+
assetId: assetIdToTransfer
|
4798
5027
|
});
|
4799
5028
|
const request = new ScriptTransactionRequest({
|
4800
|
-
...
|
5029
|
+
...txParams,
|
4801
5030
|
script,
|
4802
5031
|
scriptData
|
4803
5032
|
});
|
4804
5033
|
request.addContractInputAndOutput(contractAddress);
|
4805
|
-
const
|
4806
|
-
|
4807
|
-
[{ amount:
|
4808
|
-
);
|
4809
|
-
|
4810
|
-
|
4811
|
-
|
4812
|
-
|
4813
|
-
gasLimit: request.gasLimit,
|
4814
|
-
minGasPrice
|
5034
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5035
|
+
resourcesOwner: this,
|
5036
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetIdToTransfer) }]
|
5037
|
+
});
|
5038
|
+
this.validateGasLimitAndMaxFee({
|
5039
|
+
gasUsed: txCost.gasUsed,
|
5040
|
+
maxFee: txCost.maxFee,
|
5041
|
+
txParams
|
4815
5042
|
});
|
4816
|
-
|
5043
|
+
request.gasLimit = txCost.gasUsed;
|
5044
|
+
request.maxFee = txCost.maxFee;
|
5045
|
+
await this.fund(request, txCost);
|
4817
5046
|
return this.sendTransaction(request);
|
4818
5047
|
}
|
4819
5048
|
/**
|
@@ -4825,34 +5054,31 @@ var Account = class extends AbstractAccount {
|
|
4825
5054
|
* @returns A promise that resolves to the transaction response.
|
4826
5055
|
*/
|
4827
5056
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4828
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4829
5057
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4830
5058
|
const recipientDataArray = arrayify14(
|
4831
5059
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4832
5060
|
);
|
4833
5061
|
const amountDataArray = arrayify14(
|
4834
|
-
"0x".concat(
|
5062
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4835
5063
|
);
|
4836
5064
|
const script = new Uint8Array([
|
4837
5065
|
...arrayify14(withdrawScript.bytes),
|
4838
5066
|
...recipientDataArray,
|
4839
5067
|
...amountDataArray
|
4840
5068
|
]);
|
4841
|
-
const params = { script,
|
5069
|
+
const params = { script, ...txParams };
|
5070
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4842
5071
|
const request = new ScriptTransactionRequest(params);
|
4843
|
-
const
|
4844
|
-
const
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
this.validateGas({
|
4850
|
-
gasUsed,
|
4851
|
-
gasPrice: request.gasPrice,
|
4852
|
-
gasLimit: request.gasLimit,
|
4853
|
-
minGasPrice
|
5072
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: baseAssetId }];
|
5073
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5074
|
+
this.validateGasLimitAndMaxFee({
|
5075
|
+
gasUsed: txCost.gasUsed,
|
5076
|
+
maxFee: txCost.maxFee,
|
5077
|
+
txParams
|
4854
5078
|
});
|
4855
|
-
|
5079
|
+
request.maxFee = txCost.maxFee;
|
5080
|
+
request.gasLimit = txCost.gasUsed;
|
5081
|
+
await this.fund(request, txCost);
|
4856
5082
|
return this.sendTransaction(request);
|
4857
5083
|
}
|
4858
5084
|
async signMessage(message) {
|
@@ -4910,22 +5136,21 @@ var Account = class extends AbstractAccount {
|
|
4910
5136
|
}
|
4911
5137
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4912
5138
|
}
|
4913
|
-
|
5139
|
+
validateGasLimitAndMaxFee({
|
5140
|
+
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
4914
5141
|
gasUsed,
|
4915
|
-
|
4916
|
-
gasLimit,
|
4917
|
-
minGasPrice
|
5142
|
+
maxFee
|
4918
5143
|
}) {
|
4919
|
-
if (
|
5144
|
+
if (isDefined(setGasLimit) && gasUsed.gt(setGasLimit)) {
|
4920
5145
|
throw new FuelError15(
|
4921
|
-
ErrorCode15.
|
4922
|
-
`Gas
|
5146
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5147
|
+
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
4923
5148
|
);
|
4924
5149
|
}
|
4925
|
-
if (
|
5150
|
+
if (isDefined(setMaxFee) && maxFee.gt(setMaxFee)) {
|
4926
5151
|
throw new FuelError15(
|
4927
|
-
ErrorCode15.
|
4928
|
-
`
|
5152
|
+
ErrorCode15.MAX_FEE_TOO_LOW,
|
5153
|
+
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
4929
5154
|
);
|
4930
5155
|
}
|
4931
5156
|
}
|
@@ -5213,7 +5438,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5213
5438
|
* @param transactionRequestLike - The transaction request to send.
|
5214
5439
|
* @returns A promise that resolves to the TransactionResponse object.
|
5215
5440
|
*/
|
5216
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5441
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5217
5442
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5218
5443
|
if (estimateTxDependencies) {
|
5219
5444
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5254,7 +5479,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5254
5479
|
// src/hdwallet/hdwallet.ts
|
5255
5480
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5256
5481
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5257
|
-
import { bn as
|
5482
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5258
5483
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5259
5484
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5260
5485
|
|
@@ -7720,7 +7945,7 @@ var HDWallet = class {
|
|
7720
7945
|
const IR = bytes.slice(32);
|
7721
7946
|
if (privateKey) {
|
7722
7947
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7723
|
-
const ki =
|
7948
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7724
7949
|
return new HDWallet({
|
7725
7950
|
privateKey: ki,
|
7726
7951
|
chainCode: IR,
|
@@ -7991,14 +8216,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7991
8216
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
7992
8217
|
wallet.provider
|
7993
8218
|
);
|
7994
|
-
const
|
7995
|
-
|
7996
|
-
|
7997
|
-
|
7998
|
-
gasPrice: minGasPrice
|
8219
|
+
const request = new ScriptTransactionRequest();
|
8220
|
+
quantities.forEach((quantity) => {
|
8221
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8222
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7999
8223
|
});
|
8000
|
-
|
8001
|
-
|
8224
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8225
|
+
request.gasLimit = txCost.gasUsed;
|
8226
|
+
request.maxFee = txCost.maxFee;
|
8227
|
+
await genesisWallet.fund(request, txCost);
|
8002
8228
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8003
8229
|
};
|
8004
8230
|
|
@@ -8012,9 +8238,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8012
8238
|
};
|
8013
8239
|
|
8014
8240
|
// src/test-utils/launchNode.ts
|
8015
|
-
import {
|
8016
|
-
import {
|
8017
|
-
import {
|
8241
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8242
|
+
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8243
|
+
import { defaultSnapshotConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8018
8244
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8019
8245
|
import { spawn } from "child_process";
|
8020
8246
|
import { randomUUID } from "crypto";
|
@@ -8066,12 +8292,12 @@ var launchNode = async ({
|
|
8066
8292
|
// eslint-disable-next-line no-async-promise-executor
|
8067
8293
|
new Promise(async (resolve, reject) => {
|
8068
8294
|
const remainingArgs = extractRemainingArgs(args, [
|
8069
|
-
"--
|
8295
|
+
"--snapshot",
|
8070
8296
|
"--consensus-key",
|
8071
8297
|
"--db-type",
|
8072
8298
|
"--poa-instant"
|
8073
8299
|
]);
|
8074
|
-
const
|
8300
|
+
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
8075
8301
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8076
8302
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8077
8303
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8087,39 +8313,57 @@ var launchNode = async ({
|
|
8087
8313
|
stopPort: 5e3
|
8088
8314
|
// don't try ports above 5000
|
8089
8315
|
})).toString();
|
8090
|
-
let
|
8316
|
+
let snapshotDirToUse;
|
8091
8317
|
const prefix = basePath || os.tmpdir();
|
8092
8318
|
const suffix = basePath ? "" : randomUUID();
|
8093
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8094
|
-
if (
|
8095
|
-
|
8319
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8320
|
+
if (snapshotDir) {
|
8321
|
+
snapshotDirToUse = snapshotDir;
|
8096
8322
|
} else {
|
8097
8323
|
if (!existsSync(tempDirPath)) {
|
8098
8324
|
mkdirSync(tempDirPath, { recursive: true });
|
8099
8325
|
}
|
8100
|
-
|
8101
|
-
|
8326
|
+
let { stateConfigJson } = defaultSnapshotConfigs;
|
8327
|
+
const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
|
8328
|
+
stateConfigJson = {
|
8329
|
+
...stateConfigJson,
|
8330
|
+
coins: [
|
8331
|
+
...stateConfigJson.coins.map((coin) => ({
|
8332
|
+
...coin,
|
8333
|
+
amount: "18446744073709551615"
|
8334
|
+
}))
|
8335
|
+
],
|
8336
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8337
|
+
...message,
|
8338
|
+
amount: "18446744073709551615"
|
8339
|
+
}))
|
8340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8341
|
+
};
|
8102
8342
|
if (!process.env.GENESIS_SECRET) {
|
8103
8343
|
const pk = Signer.generatePrivateKey();
|
8104
8344
|
const signer = new Signer(pk);
|
8105
8345
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8106
|
-
|
8107
|
-
|
8108
|
-
|
8109
|
-
|
8110
|
-
|
8111
|
-
|
8112
|
-
|
8113
|
-
|
8114
|
-
|
8115
|
-
|
8116
|
-
}
|
8117
|
-
]
|
8118
|
-
}
|
8119
|
-
};
|
8346
|
+
stateConfigJson.coins.push({
|
8347
|
+
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8348
|
+
owner: signer.address.toHexString(),
|
8349
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8350
|
+
amount: "18446744073709551615",
|
8351
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8352
|
+
output_index: 0,
|
8353
|
+
tx_pointer_block_height: 0,
|
8354
|
+
tx_pointer_tx_idx: 0
|
8355
|
+
});
|
8120
8356
|
}
|
8121
|
-
|
8122
|
-
|
8357
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8358
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8359
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8360
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8361
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8362
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8363
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8364
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8365
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8366
|
+
snapshotDirToUse = tempDirPath;
|
8123
8367
|
}
|
8124
8368
|
const child = spawn(
|
8125
8369
|
command,
|
@@ -8128,10 +8372,10 @@ var launchNode = async ({
|
|
8128
8372
|
["--ip", ipToUse],
|
8129
8373
|
["--port", portToUse],
|
8130
8374
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8131
|
-
["--min-gas-price", "
|
8375
|
+
["--min-gas-price", "1"],
|
8132
8376
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8133
8377
|
["--consensus-key", consensusKey],
|
8134
|
-
["--
|
8378
|
+
["--snapshot", snapshotDirToUse],
|
8135
8379
|
"--vm-backtrace",
|
8136
8380
|
"--utxo-validation",
|
8137
8381
|
"--debug",
|
@@ -8161,7 +8405,7 @@ var launchNode = async ({
|
|
8161
8405
|
cleanup: () => killNode(cleanupConfig),
|
8162
8406
|
ip: ipToUse,
|
8163
8407
|
port: portToUse,
|
8164
|
-
|
8408
|
+
snapshotDir: snapshotDirToUse
|
8165
8409
|
});
|
8166
8410
|
}
|
8167
8411
|
if (/error/i.test(chunk)) {
|
@@ -8178,9 +8422,10 @@ var launchNode = async ({
|
|
8178
8422
|
})
|
8179
8423
|
);
|
8180
8424
|
var generateWallets = async (count, provider) => {
|
8425
|
+
const baseAssetId = provider.getBaseAssetId();
|
8181
8426
|
const wallets = [];
|
8182
8427
|
for (let i = 0; i < count; i += 1) {
|
8183
|
-
const wallet = await generateTestWallet(provider, [[
|
8428
|
+
const wallet = await generateTestWallet(provider, [[1e5, baseAssetId]]);
|
8184
8429
|
wallets.push(wallet);
|
8185
8430
|
}
|
8186
8431
|
return wallets;
|
@@ -8190,7 +8435,7 @@ var launchNodeAndGetWallets = async ({
|
|
8190
8435
|
walletCount = 10
|
8191
8436
|
} = {}) => {
|
8192
8437
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8193
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8438
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8194
8439
|
const wallets = await generateWallets(walletCount, provider);
|
8195
8440
|
const cleanup = () => {
|
8196
8441
|
closeNode();
|