@fuel-ts/account 0.0.0-rc-1976-20240424110729 → 0.0.0-rc-2021-20240424121206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +861 -611
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +864 -608
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +706 -451
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +822 -328
- 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 +37 -34
- 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 +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +8 -32
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1578 -1114
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +845 -609
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +699 -463
- 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,35 +24,38 @@ 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";
|
27
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
30
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
30
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
+
import { clone as clone4 } from "ramda";
|
31
33
|
|
32
34
|
// src/providers/coin-quantity.ts
|
35
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
33
36
|
import { bn } from "@fuel-ts/math";
|
34
37
|
import { hexlify } from "@fuel-ts/utils";
|
35
38
|
var coinQuantityfy = (coinQuantityLike) => {
|
36
39
|
let assetId;
|
37
40
|
let amount;
|
38
|
-
let
|
41
|
+
let max;
|
39
42
|
if (Array.isArray(coinQuantityLike)) {
|
40
43
|
amount = coinQuantityLike[0];
|
41
|
-
assetId = coinQuantityLike[1];
|
42
|
-
|
44
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
45
|
+
max = coinQuantityLike[2] ?? void 0;
|
43
46
|
} else {
|
44
47
|
amount = coinQuantityLike.amount;
|
45
|
-
assetId = coinQuantityLike.assetId;
|
46
|
-
|
48
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
49
|
+
max = coinQuantityLike.max ?? void 0;
|
47
50
|
}
|
48
51
|
const bnAmount = bn(amount);
|
49
52
|
return {
|
50
53
|
assetId: hexlify(assetId),
|
51
54
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
52
|
-
max:
|
55
|
+
max: max ? bn(max) : void 0
|
53
56
|
};
|
54
57
|
};
|
55
|
-
var
|
58
|
+
var addAmountToCoinQuantities = (params) => {
|
56
59
|
const { amount, assetId } = params;
|
57
60
|
const coinQuantities = [...params.coinQuantities];
|
58
61
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -67,9 +70,9 @@ var addAmountToAsset = (params) => {
|
|
67
70
|
// src/providers/provider.ts
|
68
71
|
import { Address as Address2 } from "@fuel-ts/address";
|
69
72
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
70
|
-
import { BN, bn as
|
73
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
71
74
|
import {
|
72
|
-
InputType as
|
75
|
+
InputType as InputType7,
|
73
76
|
TransactionType as TransactionType8,
|
74
77
|
InputMessageCoder,
|
75
78
|
TransactionCoder as TransactionCoder5
|
@@ -83,16 +86,40 @@ import { clone as clone3 } from "ramda";
|
|
83
86
|
|
84
87
|
// src/providers/__generated__/operations.ts
|
85
88
|
import gql from "graphql-tag";
|
89
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
90
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
91
|
+
type: __typename
|
92
|
+
... on SubmittedStatus {
|
93
|
+
time
|
94
|
+
}
|
95
|
+
... on SuccessStatus {
|
96
|
+
block {
|
97
|
+
id
|
98
|
+
}
|
99
|
+
time
|
100
|
+
programState {
|
101
|
+
returnType
|
102
|
+
data
|
103
|
+
}
|
104
|
+
}
|
105
|
+
... on FailureStatus {
|
106
|
+
block {
|
107
|
+
id
|
108
|
+
}
|
109
|
+
time
|
110
|
+
reason
|
111
|
+
}
|
112
|
+
... on SqueezedOutStatus {
|
113
|
+
reason
|
114
|
+
}
|
115
|
+
}
|
116
|
+
`;
|
86
117
|
var ReceiptFragmentFragmentDoc = gql`
|
87
118
|
fragment receiptFragment on Receipt {
|
88
|
-
|
89
|
-
id
|
90
|
-
}
|
119
|
+
id
|
91
120
|
pc
|
92
121
|
is
|
93
|
-
to
|
94
|
-
id
|
95
|
-
}
|
122
|
+
to
|
96
123
|
toAddress
|
97
124
|
amount
|
98
125
|
assetId
|
@@ -130,10 +157,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
130
157
|
id
|
131
158
|
}
|
132
159
|
time
|
160
|
+
receipts {
|
161
|
+
...receiptFragment
|
162
|
+
}
|
133
163
|
programState {
|
134
164
|
returnType
|
135
165
|
data
|
136
166
|
}
|
167
|
+
receipts {
|
168
|
+
...receiptFragment
|
169
|
+
}
|
137
170
|
}
|
138
171
|
... on FailureStatus {
|
139
172
|
block {
|
@@ -141,26 +174,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
141
174
|
}
|
142
175
|
time
|
143
176
|
reason
|
177
|
+
receipts {
|
178
|
+
...receiptFragment
|
179
|
+
}
|
144
180
|
}
|
145
181
|
... on SqueezedOutStatus {
|
146
182
|
reason
|
147
183
|
}
|
148
184
|
}
|
149
|
-
`;
|
185
|
+
${ReceiptFragmentFragmentDoc}`;
|
150
186
|
var TransactionFragmentFragmentDoc = gql`
|
151
187
|
fragment transactionFragment on Transaction {
|
152
188
|
id
|
153
189
|
rawPayload
|
154
|
-
gasPrice
|
155
|
-
receipts {
|
156
|
-
...receiptFragment
|
157
|
-
}
|
158
190
|
status {
|
159
191
|
...transactionStatusFragment
|
160
192
|
}
|
161
193
|
}
|
162
|
-
${
|
163
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
194
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
164
195
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
165
196
|
fragment inputEstimatePredicatesFragment on Input {
|
166
197
|
... on InputCoin {
|
@@ -178,6 +209,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
178
209
|
}
|
179
210
|
}
|
180
211
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
212
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
213
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
214
|
+
reason
|
215
|
+
programState {
|
216
|
+
returnType
|
217
|
+
data
|
218
|
+
}
|
219
|
+
}
|
220
|
+
`;
|
221
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
222
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
223
|
+
programState {
|
224
|
+
returnType
|
225
|
+
data
|
226
|
+
}
|
227
|
+
}
|
228
|
+
`;
|
229
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
230
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
231
|
+
... on DryRunFailureStatus {
|
232
|
+
...dryRunFailureStatusFragment
|
233
|
+
}
|
234
|
+
... on DryRunSuccessStatus {
|
235
|
+
...dryRunSuccessStatusFragment
|
236
|
+
}
|
237
|
+
}
|
238
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
239
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
240
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
241
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
242
|
+
id
|
243
|
+
status {
|
244
|
+
...dryRunTransactionStatusFragment
|
245
|
+
}
|
246
|
+
receipts {
|
247
|
+
...receiptFragment
|
248
|
+
}
|
249
|
+
}
|
250
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
251
|
+
${ReceiptFragmentFragmentDoc}`;
|
181
252
|
var CoinFragmentFragmentDoc = gql`
|
182
253
|
fragment coinFragment on Coin {
|
183
254
|
__typename
|
@@ -185,7 +256,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
185
256
|
owner
|
186
257
|
amount
|
187
258
|
assetId
|
188
|
-
maturity
|
189
259
|
blockCreated
|
190
260
|
txCreatedIdx
|
191
261
|
}
|
@@ -224,26 +294,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
224
294
|
messageBlockHeader {
|
225
295
|
id
|
226
296
|
daHeight
|
297
|
+
consensusParametersVersion
|
298
|
+
stateTransitionBytecodeVersion
|
227
299
|
transactionsCount
|
300
|
+
messageReceiptCount
|
228
301
|
transactionsRoot
|
302
|
+
messageOutboxRoot
|
303
|
+
eventInboxRoot
|
229
304
|
height
|
230
305
|
prevRoot
|
231
306
|
time
|
232
307
|
applicationHash
|
233
|
-
messageReceiptRoot
|
234
|
-
messageReceiptCount
|
235
308
|
}
|
236
309
|
commitBlockHeader {
|
237
310
|
id
|
238
311
|
daHeight
|
312
|
+
consensusParametersVersion
|
313
|
+
stateTransitionBytecodeVersion
|
239
314
|
transactionsCount
|
315
|
+
messageReceiptCount
|
240
316
|
transactionsRoot
|
317
|
+
messageOutboxRoot
|
318
|
+
eventInboxRoot
|
241
319
|
height
|
242
320
|
prevRoot
|
243
321
|
time
|
244
322
|
applicationHash
|
245
|
-
messageReceiptRoot
|
246
|
-
messageReceiptCount
|
247
323
|
}
|
248
324
|
sender
|
249
325
|
recipient
|
@@ -262,8 +338,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
262
338
|
var BlockFragmentFragmentDoc = gql`
|
263
339
|
fragment blockFragment on Block {
|
264
340
|
id
|
341
|
+
height
|
265
342
|
header {
|
266
|
-
height
|
267
343
|
time
|
268
344
|
}
|
269
345
|
transactions {
|
@@ -321,6 +397,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
321
397
|
`;
|
322
398
|
var GasCostsFragmentFragmentDoc = gql`
|
323
399
|
fragment GasCostsFragment on GasCosts {
|
400
|
+
version {
|
401
|
+
... on Version {
|
402
|
+
value
|
403
|
+
}
|
404
|
+
}
|
324
405
|
add
|
325
406
|
addi
|
326
407
|
aloc
|
@@ -333,7 +414,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
333
414
|
cb
|
334
415
|
cfei
|
335
416
|
cfsi
|
336
|
-
croo
|
337
417
|
div
|
338
418
|
divi
|
339
419
|
ecr1
|
@@ -416,6 +496,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
416
496
|
ccp {
|
417
497
|
...DependentCostFragment
|
418
498
|
}
|
499
|
+
croo {
|
500
|
+
...DependentCostFragment
|
501
|
+
}
|
419
502
|
csiz {
|
420
503
|
...DependentCostFragment
|
421
504
|
}
|
@@ -475,6 +558,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
475
558
|
${DependentCostFragmentFragmentDoc}`;
|
476
559
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
477
560
|
fragment consensusParametersFragment on ConsensusParameters {
|
561
|
+
version {
|
562
|
+
... on Version {
|
563
|
+
value
|
564
|
+
}
|
565
|
+
}
|
478
566
|
txParams {
|
479
567
|
...TxParametersFragment
|
480
568
|
}
|
@@ -534,18 +622,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
534
622
|
fragment nodeInfoFragment on NodeInfo {
|
535
623
|
utxoValidation
|
536
624
|
vmBacktrace
|
537
|
-
minGasPrice
|
538
625
|
maxTx
|
539
626
|
maxDepth
|
540
627
|
nodeVersion
|
541
|
-
peers {
|
542
|
-
id
|
543
|
-
addresses
|
544
|
-
clientVersion
|
545
|
-
blockHeight
|
546
|
-
lastHeartbeatMs
|
547
|
-
appScore
|
548
|
-
}
|
549
628
|
}
|
550
629
|
`;
|
551
630
|
var GetVersionDocument = gql`
|
@@ -580,13 +659,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
580
659
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
581
660
|
transaction(id: $transactionId) {
|
582
661
|
...transactionFragment
|
583
|
-
receipts {
|
584
|
-
...receiptFragment
|
585
|
-
}
|
586
662
|
}
|
587
663
|
}
|
588
|
-
${TransactionFragmentFragmentDoc}
|
589
|
-
${ReceiptFragmentFragmentDoc}`;
|
664
|
+
${TransactionFragmentFragmentDoc}`;
|
590
665
|
var GetTransactionsDocument = gql`
|
591
666
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
592
667
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -714,6 +789,20 @@ var GetBalanceDocument = gql`
|
|
714
789
|
}
|
715
790
|
}
|
716
791
|
${BalanceFragmentFragmentDoc}`;
|
792
|
+
var GetLatestGasPriceDocument = gql`
|
793
|
+
query getLatestGasPrice {
|
794
|
+
latestGasPrice {
|
795
|
+
gasPrice
|
796
|
+
}
|
797
|
+
}
|
798
|
+
`;
|
799
|
+
var EstimateGasPriceDocument = gql`
|
800
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
801
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
802
|
+
gasPrice
|
803
|
+
}
|
804
|
+
}
|
805
|
+
`;
|
717
806
|
var GetBalancesDocument = gql`
|
718
807
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
719
808
|
balances(
|
@@ -768,12 +857,12 @@ var GetMessageStatusDocument = gql`
|
|
768
857
|
}
|
769
858
|
`;
|
770
859
|
var DryRunDocument = gql`
|
771
|
-
mutation dryRun($
|
772
|
-
dryRun(
|
773
|
-
...
|
860
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
861
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
862
|
+
...dryRunTransactionExecutionStatusFragment
|
774
863
|
}
|
775
864
|
}
|
776
|
-
${
|
865
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
777
866
|
var SubmitDocument = gql`
|
778
867
|
mutation submit($encodedTransaction: HexString!) {
|
779
868
|
submit(tx: $encodedTransaction) {
|
@@ -792,17 +881,17 @@ var ProduceBlocksDocument = gql`
|
|
792
881
|
var SubmitAndAwaitDocument = gql`
|
793
882
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
794
883
|
submitAndAwait(tx: $encodedTransaction) {
|
795
|
-
...
|
884
|
+
...transactionStatusSubscriptionFragment
|
796
885
|
}
|
797
886
|
}
|
798
|
-
${
|
887
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
799
888
|
var StatusChangeDocument = gql`
|
800
889
|
subscription statusChange($transactionId: TransactionId!) {
|
801
890
|
statusChange(id: $transactionId) {
|
802
|
-
...
|
891
|
+
...transactionStatusSubscriptionFragment
|
803
892
|
}
|
804
893
|
}
|
805
|
-
${
|
894
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
806
895
|
function getSdk(requester) {
|
807
896
|
return {
|
808
897
|
getVersion(variables, options) {
|
@@ -856,6 +945,12 @@ function getSdk(requester) {
|
|
856
945
|
getBalance(variables, options) {
|
857
946
|
return requester(GetBalanceDocument, variables, options);
|
858
947
|
},
|
948
|
+
getLatestGasPrice(variables, options) {
|
949
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
950
|
+
},
|
951
|
+
estimateGasPrice(variables, options) {
|
952
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
953
|
+
},
|
859
954
|
getBalances(variables, options) {
|
860
955
|
return requester(GetBalancesDocument, variables, options);
|
861
956
|
},
|
@@ -1049,10 +1144,9 @@ var inputify = (value) => {
|
|
1049
1144
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1050
1145
|
},
|
1051
1146
|
witnessIndex: value.witnessIndex,
|
1052
|
-
maturity: value.maturity ?? 0,
|
1053
1147
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1054
|
-
predicateLength: predicate.length,
|
1055
|
-
predicateDataLength: predicateData.length,
|
1148
|
+
predicateLength: bn2(predicate.length),
|
1149
|
+
predicateDataLength: bn2(predicateData.length),
|
1056
1150
|
predicate: hexlify3(predicate),
|
1057
1151
|
predicateData: hexlify3(predicateData)
|
1058
1152
|
};
|
@@ -1083,8 +1177,8 @@ var inputify = (value) => {
|
|
1083
1177
|
nonce: hexlify3(value.nonce),
|
1084
1178
|
witnessIndex: value.witnessIndex,
|
1085
1179
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1086
|
-
predicateLength: predicate.length,
|
1087
|
-
predicateDataLength: predicateData.length,
|
1180
|
+
predicateLength: bn2(predicate.length),
|
1181
|
+
predicateDataLength: bn2(predicateData.length),
|
1088
1182
|
predicate: hexlify3(predicate),
|
1089
1183
|
predicateData: hexlify3(predicateData),
|
1090
1184
|
data: hexlify3(data),
|
@@ -1160,7 +1254,7 @@ var outputify = (value) => {
|
|
1160
1254
|
// src/providers/transaction-request/transaction-request.ts
|
1161
1255
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1162
1256
|
import { Address, addressify } from "@fuel-ts/address";
|
1163
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1257
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1164
1258
|
import { randomBytes } from "@fuel-ts/crypto";
|
1165
1259
|
import { bn as bn7 } from "@fuel-ts/math";
|
1166
1260
|
import {
|
@@ -1211,8 +1305,8 @@ function assembleReceiptByType(receipt) {
|
|
1211
1305
|
case "CALL" /* Call */: {
|
1212
1306
|
const callReceipt = {
|
1213
1307
|
type: ReceiptType.Call,
|
1214
|
-
from: hexOrZero(receipt.
|
1215
|
-
to: hexOrZero(receipt?.to
|
1308
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1309
|
+
to: hexOrZero(receipt?.to),
|
1216
1310
|
amount: bn4(receipt.amount),
|
1217
1311
|
assetId: hexOrZero(receipt.assetId),
|
1218
1312
|
gas: bn4(receipt.gas),
|
@@ -1226,7 +1320,7 @@ function assembleReceiptByType(receipt) {
|
|
1226
1320
|
case "RETURN" /* Return */: {
|
1227
1321
|
const returnReceipt = {
|
1228
1322
|
type: ReceiptType.Return,
|
1229
|
-
id: hexOrZero(receipt.
|
1323
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1230
1324
|
val: bn4(receipt.val),
|
1231
1325
|
pc: bn4(receipt.pc),
|
1232
1326
|
is: bn4(receipt.is)
|
@@ -1236,7 +1330,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1330
|
case "RETURN_DATA" /* ReturnData */: {
|
1237
1331
|
const returnDataReceipt = {
|
1238
1332
|
type: ReceiptType.ReturnData,
|
1239
|
-
id: hexOrZero(receipt.
|
1333
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1240
1334
|
ptr: bn4(receipt.ptr),
|
1241
1335
|
len: bn4(receipt.len),
|
1242
1336
|
digest: hexOrZero(receipt.digest),
|
@@ -1248,7 +1342,7 @@ function assembleReceiptByType(receipt) {
|
|
1248
1342
|
case "PANIC" /* Panic */: {
|
1249
1343
|
const panicReceipt = {
|
1250
1344
|
type: ReceiptType.Panic,
|
1251
|
-
id: hexOrZero(receipt.
|
1345
|
+
id: hexOrZero(receipt.id),
|
1252
1346
|
reason: bn4(receipt.reason),
|
1253
1347
|
pc: bn4(receipt.pc),
|
1254
1348
|
is: bn4(receipt.is),
|
@@ -1259,7 +1353,7 @@ function assembleReceiptByType(receipt) {
|
|
1259
1353
|
case "REVERT" /* Revert */: {
|
1260
1354
|
const revertReceipt = {
|
1261
1355
|
type: ReceiptType.Revert,
|
1262
|
-
id: hexOrZero(receipt.
|
1356
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1263
1357
|
val: bn4(receipt.ra),
|
1264
1358
|
pc: bn4(receipt.pc),
|
1265
1359
|
is: bn4(receipt.is)
|
@@ -1269,7 +1363,7 @@ function assembleReceiptByType(receipt) {
|
|
1269
1363
|
case "LOG" /* Log */: {
|
1270
1364
|
const logReceipt = {
|
1271
1365
|
type: ReceiptType.Log,
|
1272
|
-
id: hexOrZero(receipt.
|
1366
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1273
1367
|
val0: bn4(receipt.ra),
|
1274
1368
|
val1: bn4(receipt.rb),
|
1275
1369
|
val2: bn4(receipt.rc),
|
@@ -1282,7 +1376,7 @@ function assembleReceiptByType(receipt) {
|
|
1282
1376
|
case "LOG_DATA" /* LogData */: {
|
1283
1377
|
const logDataReceipt = {
|
1284
1378
|
type: ReceiptType.LogData,
|
1285
|
-
id: hexOrZero(receipt.
|
1379
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1286
1380
|
val0: bn4(receipt.ra),
|
1287
1381
|
val1: bn4(receipt.rb),
|
1288
1382
|
ptr: bn4(receipt.ptr),
|
@@ -1296,8 +1390,8 @@ function assembleReceiptByType(receipt) {
|
|
1296
1390
|
case "TRANSFER" /* Transfer */: {
|
1297
1391
|
const transferReceipt = {
|
1298
1392
|
type: ReceiptType.Transfer,
|
1299
|
-
from: hexOrZero(receipt.
|
1300
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1393
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1394
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1301
1395
|
amount: bn4(receipt.amount),
|
1302
1396
|
assetId: hexOrZero(receipt.assetId),
|
1303
1397
|
pc: bn4(receipt.pc),
|
@@ -1308,8 +1402,8 @@ function assembleReceiptByType(receipt) {
|
|
1308
1402
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1309
1403
|
const transferOutReceipt = {
|
1310
1404
|
type: ReceiptType.TransferOut,
|
1311
|
-
from: hexOrZero(receipt.
|
1312
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1405
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1406
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1313
1407
|
amount: bn4(receipt.amount),
|
1314
1408
|
assetId: hexOrZero(receipt.assetId),
|
1315
1409
|
pc: bn4(receipt.pc),
|
@@ -1352,7 +1446,7 @@ function assembleReceiptByType(receipt) {
|
|
1352
1446
|
return receiptMessageOut;
|
1353
1447
|
}
|
1354
1448
|
case "MINT" /* Mint */: {
|
1355
|
-
const contractId = hexOrZero(receipt.
|
1449
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1356
1450
|
const subId = hexOrZero(receipt.subId);
|
1357
1451
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1358
1452
|
const mintReceipt = {
|
@@ -1367,7 +1461,7 @@ function assembleReceiptByType(receipt) {
|
|
1367
1461
|
return mintReceipt;
|
1368
1462
|
}
|
1369
1463
|
case "BURN" /* Burn */: {
|
1370
|
-
const contractId = hexOrZero(receipt.
|
1464
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1371
1465
|
const subId = hexOrZero(receipt.subId);
|
1372
1466
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1373
1467
|
const burnReceipt = {
|
@@ -1393,7 +1487,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1393
1487
|
import { bn as bn5 } from "@fuel-ts/math";
|
1394
1488
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1395
1489
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1396
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1397
1490
|
var getGasUsedFromReceipts = (receipts) => {
|
1398
1491
|
const scriptResult = receipts.filter(
|
1399
1492
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1414,18 +1507,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1414
1507
|
}
|
1415
1508
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1416
1509
|
const witnessCache = [];
|
1417
|
-
const
|
1510
|
+
const chargeableInputs = inputs.filter((input) => {
|
1511
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1512
|
+
if (isCoinOrMessage) {
|
1513
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1514
|
+
return true;
|
1515
|
+
}
|
1516
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1517
|
+
witnessCache.push(input.witnessIndex);
|
1518
|
+
return true;
|
1519
|
+
}
|
1520
|
+
}
|
1521
|
+
return false;
|
1522
|
+
});
|
1523
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1524
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1418
1525
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1419
1526
|
return total.add(
|
1420
|
-
|
1527
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1421
1528
|
);
|
1422
1529
|
}
|
1423
|
-
|
1424
|
-
|
1425
|
-
return total.add(gasCosts.ecr1);
|
1426
|
-
}
|
1427
|
-
return total;
|
1428
|
-
}, bn5());
|
1530
|
+
return total.add(gasCosts.ecr1);
|
1531
|
+
}, bn5(0));
|
1429
1532
|
return totalGas;
|
1430
1533
|
}
|
1431
1534
|
function getMinGas(params) {
|
@@ -1437,12 +1540,20 @@ function getMinGas(params) {
|
|
1437
1540
|
return minGas;
|
1438
1541
|
}
|
1439
1542
|
function getMaxGas(params) {
|
1440
|
-
const {
|
1543
|
+
const {
|
1544
|
+
gasPerByte,
|
1545
|
+
witnessesLength,
|
1546
|
+
witnessLimit,
|
1547
|
+
minGas,
|
1548
|
+
gasLimit = bn5(0),
|
1549
|
+
maxGasPerTx
|
1550
|
+
} = params;
|
1441
1551
|
let remainingAllowedWitnessGas = bn5(0);
|
1442
1552
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1443
1553
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1444
1554
|
}
|
1445
|
-
|
1555
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1556
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1446
1557
|
}
|
1447
1558
|
function calculateMetadataGasForTxCreate({
|
1448
1559
|
gasCosts,
|
@@ -1464,6 +1575,10 @@ function calculateMetadataGasForTxScript({
|
|
1464
1575
|
}) {
|
1465
1576
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1466
1577
|
}
|
1578
|
+
var calculateGasFee = (params) => {
|
1579
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1580
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1581
|
+
};
|
1467
1582
|
|
1468
1583
|
// src/providers/utils/json.ts
|
1469
1584
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1608,7 +1723,7 @@ var witnessify = (value) => {
|
|
1608
1723
|
// src/providers/transaction-request/transaction-request.ts
|
1609
1724
|
var BaseTransactionRequest = class {
|
1610
1725
|
/** Gas price for transaction */
|
1611
|
-
|
1726
|
+
tip;
|
1612
1727
|
/** Block until which tx cannot be included */
|
1613
1728
|
maturity;
|
1614
1729
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1621,38 +1736,34 @@ var BaseTransactionRequest = class {
|
|
1621
1736
|
outputs = [];
|
1622
1737
|
/** List of witnesses */
|
1623
1738
|
witnesses = [];
|
1624
|
-
/** Base asset ID - should be fetched from the chain */
|
1625
|
-
baseAssetId;
|
1626
1739
|
/**
|
1627
1740
|
* Constructor for initializing a base transaction request.
|
1628
1741
|
*
|
1629
1742
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1630
1743
|
*/
|
1631
1744
|
constructor({
|
1632
|
-
|
1745
|
+
tip,
|
1633
1746
|
maturity,
|
1634
1747
|
maxFee,
|
1635
1748
|
witnessLimit,
|
1636
1749
|
inputs,
|
1637
1750
|
outputs,
|
1638
|
-
witnesses
|
1639
|
-
|
1640
|
-
|
1641
|
-
this.gasPrice = bn7(gasPrice);
|
1751
|
+
witnesses
|
1752
|
+
} = {}) {
|
1753
|
+
this.tip = bn7(tip);
|
1642
1754
|
this.maturity = maturity ?? 0;
|
1643
1755
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1644
1756
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1645
1757
|
this.inputs = inputs ?? [];
|
1646
1758
|
this.outputs = outputs ?? [];
|
1647
1759
|
this.witnesses = witnesses ?? [];
|
1648
|
-
this.baseAssetId = baseAssetId;
|
1649
1760
|
}
|
1650
1761
|
static getPolicyMeta(req) {
|
1651
1762
|
let policyTypes = 0;
|
1652
1763
|
const policies = [];
|
1653
|
-
if (req.
|
1654
|
-
policyTypes += PolicyType.
|
1655
|
-
policies.push({ data: req.
|
1764
|
+
if (req.tip) {
|
1765
|
+
policyTypes += PolicyType.Tip;
|
1766
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1656
1767
|
}
|
1657
1768
|
if (req.witnessLimit) {
|
1658
1769
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1836,13 +1947,11 @@ var BaseTransactionRequest = class {
|
|
1836
1947
|
* assetId, if one it was not added yet.
|
1837
1948
|
*
|
1838
1949
|
* @param coin - Coin resource.
|
1839
|
-
* @param predicate - Predicate bytes.
|
1840
|
-
* @param predicateData - Predicate data bytes.
|
1841
1950
|
*/
|
1842
|
-
addCoinInput(coin
|
1951
|
+
addCoinInput(coin) {
|
1843
1952
|
const { assetId, owner, amount } = coin;
|
1844
1953
|
let witnessIndex;
|
1845
|
-
if (predicate) {
|
1954
|
+
if (coin.predicate) {
|
1846
1955
|
witnessIndex = 0;
|
1847
1956
|
} else {
|
1848
1957
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1857,8 +1966,7 @@ var BaseTransactionRequest = class {
|
|
1857
1966
|
amount,
|
1858
1967
|
assetId,
|
1859
1968
|
txPointer: "0x00000000000000000000000000000000",
|
1860
|
-
witnessIndex
|
1861
|
-
predicate: predicate?.bytes
|
1969
|
+
witnessIndex
|
1862
1970
|
};
|
1863
1971
|
this.pushInput(input);
|
1864
1972
|
this.addChangeOutput(owner, assetId);
|
@@ -1868,12 +1976,12 @@ var BaseTransactionRequest = class {
|
|
1868
1976
|
* baseAssetId, if one it was not added yet.
|
1869
1977
|
*
|
1870
1978
|
* @param message - Message resource.
|
1871
|
-
* @param predicate - Predicate bytes.
|
1872
1979
|
*/
|
1873
|
-
addMessageInput(message
|
1980
|
+
addMessageInput(message) {
|
1874
1981
|
const { recipient, sender, amount } = message;
|
1982
|
+
const assetId = BaseAssetId2;
|
1875
1983
|
let witnessIndex;
|
1876
|
-
if (predicate) {
|
1984
|
+
if (message.predicate) {
|
1877
1985
|
witnessIndex = 0;
|
1878
1986
|
} else {
|
1879
1987
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1887,11 +1995,10 @@ var BaseTransactionRequest = class {
|
|
1887
1995
|
sender: sender.toB256(),
|
1888
1996
|
recipient: recipient.toB256(),
|
1889
1997
|
amount,
|
1890
|
-
witnessIndex
|
1891
|
-
predicate: predicate?.bytes
|
1998
|
+
witnessIndex
|
1892
1999
|
};
|
1893
2000
|
this.pushInput(input);
|
1894
|
-
this.addChangeOutput(recipient,
|
2001
|
+
this.addChangeOutput(recipient, assetId);
|
1895
2002
|
}
|
1896
2003
|
/**
|
1897
2004
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1919,32 +2026,6 @@ var BaseTransactionRequest = class {
|
|
1919
2026
|
resources.forEach((resource) => this.addResource(resource));
|
1920
2027
|
return this;
|
1921
2028
|
}
|
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
2029
|
/**
|
1949
2030
|
* Adds a coin output to the transaction.
|
1950
2031
|
*
|
@@ -1952,12 +2033,12 @@ var BaseTransactionRequest = class {
|
|
1952
2033
|
* @param amount - Amount of coin.
|
1953
2034
|
* @param assetId - Asset ID of coin.
|
1954
2035
|
*/
|
1955
|
-
addCoinOutput(to, amount, assetId) {
|
2036
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1956
2037
|
this.pushOutput({
|
1957
2038
|
type: OutputType2.Coin,
|
1958
2039
|
to: addressify(to).toB256(),
|
1959
2040
|
amount,
|
1960
|
-
assetId
|
2041
|
+
assetId
|
1961
2042
|
});
|
1962
2043
|
return this;
|
1963
2044
|
}
|
@@ -1984,7 +2065,7 @@ var BaseTransactionRequest = class {
|
|
1984
2065
|
* @param to - Address of the owner.
|
1985
2066
|
* @param assetId - Asset ID of coin.
|
1986
2067
|
*/
|
1987
|
-
addChangeOutput(to, assetId) {
|
2068
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1988
2069
|
const changeOutput = this.getChangeOutputs().find(
|
1989
2070
|
(output) => hexlify7(output.assetId) === assetId
|
1990
2071
|
);
|
@@ -1992,7 +2073,7 @@ var BaseTransactionRequest = class {
|
|
1992
2073
|
this.pushOutput({
|
1993
2074
|
type: OutputType2.Change,
|
1994
2075
|
to: addressify(to).toB256(),
|
1995
|
-
assetId
|
2076
|
+
assetId
|
1996
2077
|
});
|
1997
2078
|
}
|
1998
2079
|
}
|
@@ -2024,7 +2105,7 @@ var BaseTransactionRequest = class {
|
|
2024
2105
|
}
|
2025
2106
|
calculateMaxGas(chainInfo, minGas) {
|
2026
2107
|
const { consensusParameters } = chainInfo;
|
2027
|
-
const { gasPerByte } = consensusParameters;
|
2108
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2028
2109
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2029
2110
|
(acc, wit) => acc + wit.dataLength,
|
2030
2111
|
0
|
@@ -2033,7 +2114,8 @@ var BaseTransactionRequest = class {
|
|
2033
2114
|
gasPerByte,
|
2034
2115
|
minGas,
|
2035
2116
|
witnessesLength,
|
2036
|
-
witnessLimit: this.witnessLimit
|
2117
|
+
witnessLimit: this.witnessLimit,
|
2118
|
+
maxGasPerTx
|
2037
2119
|
});
|
2038
2120
|
}
|
2039
2121
|
/**
|
@@ -2051,24 +2133,27 @@ var BaseTransactionRequest = class {
|
|
2051
2133
|
});
|
2052
2134
|
const updateAssetInput = (assetId, quantity) => {
|
2053
2135
|
const assetInput = findAssetInput(assetId);
|
2136
|
+
let usedQuantity = quantity;
|
2137
|
+
if (assetId === BaseAssetId2) {
|
2138
|
+
usedQuantity = bn7("1000000000000000000");
|
2139
|
+
}
|
2054
2140
|
if (assetInput && "assetId" in assetInput) {
|
2055
2141
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2056
|
-
assetInput.amount =
|
2142
|
+
assetInput.amount = usedQuantity;
|
2057
2143
|
} else {
|
2058
2144
|
this.addResources([
|
2059
2145
|
{
|
2060
2146
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2061
|
-
amount:
|
2147
|
+
amount: usedQuantity,
|
2062
2148
|
assetId,
|
2063
2149
|
owner: resourcesOwner || Address.fromRandom(),
|
2064
|
-
maturity: 0,
|
2065
2150
|
blockCreated: bn7(1),
|
2066
2151
|
txCreatedIdx: bn7(1)
|
2067
2152
|
}
|
2068
2153
|
]);
|
2069
2154
|
}
|
2070
2155
|
};
|
2071
|
-
updateAssetInput(
|
2156
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2072
2157
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2073
2158
|
}
|
2074
2159
|
/**
|
@@ -2093,7 +2178,7 @@ var BaseTransactionRequest = class {
|
|
2093
2178
|
toJSON() {
|
2094
2179
|
return normalizeJSON(this);
|
2095
2180
|
}
|
2096
|
-
|
2181
|
+
updatePredicateGasUsed(inputs) {
|
2097
2182
|
this.inputs.forEach((i) => {
|
2098
2183
|
let correspondingInput;
|
2099
2184
|
switch (i.type) {
|
@@ -2115,6 +2200,15 @@ var BaseTransactionRequest = class {
|
|
2115
2200
|
}
|
2116
2201
|
});
|
2117
2202
|
}
|
2203
|
+
shiftPredicateData() {
|
2204
|
+
this.inputs.forEach((input) => {
|
2205
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2206
|
+
input.predicateData = input.paddPredicateData(
|
2207
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2208
|
+
);
|
2209
|
+
}
|
2210
|
+
});
|
2211
|
+
}
|
2118
2212
|
};
|
2119
2213
|
|
2120
2214
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2238,7 +2332,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2238
2332
|
*
|
2239
2333
|
* @param createTransactionRequestLike - The initial values for the instance
|
2240
2334
|
*/
|
2241
|
-
constructor({
|
2335
|
+
constructor({
|
2336
|
+
bytecodeWitnessIndex,
|
2337
|
+
salt,
|
2338
|
+
storageSlots,
|
2339
|
+
...rest
|
2340
|
+
} = {}) {
|
2242
2341
|
super(rest);
|
2243
2342
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2244
2343
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2256,9 +2355,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2256
2355
|
return {
|
2257
2356
|
type: TransactionType3.Create,
|
2258
2357
|
...baseTransaction,
|
2259
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2260
2358
|
bytecodeWitnessIndex,
|
2261
|
-
storageSlotsCount: storageSlots.length,
|
2359
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2262
2360
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2263
2361
|
storageSlots
|
2264
2362
|
};
|
@@ -2362,7 +2460,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2362
2460
|
*
|
2363
2461
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2364
2462
|
*/
|
2365
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2463
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2366
2464
|
super(rest);
|
2367
2465
|
this.gasLimit = bn10(gasLimit);
|
2368
2466
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -2381,8 +2479,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2381
2479
|
type: TransactionType4.Script,
|
2382
2480
|
scriptGasLimit: this.gasLimit,
|
2383
2481
|
...super.getBaseTransaction(),
|
2384
|
-
scriptLength: script.length,
|
2385
|
-
scriptDataLength: scriptData.length,
|
2482
|
+
scriptLength: bn10(script.length),
|
2483
|
+
scriptDataLength: bn10(scriptData.length),
|
2386
2484
|
receiptsRoot: ZeroBytes327,
|
2387
2485
|
script: hexlify10(script),
|
2388
2486
|
scriptData: hexlify10(scriptData)
|
@@ -2446,7 +2544,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2446
2544
|
}
|
2447
2545
|
calculateMaxGas(chainInfo, minGas) {
|
2448
2546
|
const { consensusParameters } = chainInfo;
|
2449
|
-
const { gasPerByte } = consensusParameters;
|
2547
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2450
2548
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2451
2549
|
(acc, wit) => acc + wit.dataLength,
|
2452
2550
|
0
|
@@ -2456,7 +2554,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2456
2554
|
minGas,
|
2457
2555
|
witnessesLength,
|
2458
2556
|
witnessLimit: this.witnessLimit,
|
2459
|
-
gasLimit: this.gasLimit
|
2557
|
+
gasLimit: this.gasLimit,
|
2558
|
+
maxGasPerTx
|
2460
2559
|
});
|
2461
2560
|
}
|
2462
2561
|
/**
|
@@ -2513,7 +2612,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2513
2612
|
|
2514
2613
|
// src/providers/transaction-request/utils.ts
|
2515
2614
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2516
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2615
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2517
2616
|
var transactionRequestify = (obj) => {
|
2518
2617
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2519
2618
|
return obj;
|
@@ -2531,14 +2630,31 @@ var transactionRequestify = (obj) => {
|
|
2531
2630
|
}
|
2532
2631
|
}
|
2533
2632
|
};
|
2633
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2634
|
+
(acc, input) => {
|
2635
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2636
|
+
acc.utxos.push(input.id);
|
2637
|
+
}
|
2638
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2639
|
+
acc.messages.push(input.nonce);
|
2640
|
+
}
|
2641
|
+
return acc;
|
2642
|
+
},
|
2643
|
+
{
|
2644
|
+
utxos: [],
|
2645
|
+
messages: []
|
2646
|
+
}
|
2647
|
+
);
|
2534
2648
|
|
2535
2649
|
// src/providers/transaction-response/transaction-response.ts
|
2536
2650
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2537
|
-
import { bn as
|
2651
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2538
2652
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2539
2653
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2540
2654
|
|
2541
2655
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2656
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2657
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2542
2658
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2543
2659
|
|
2544
2660
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2547,9 +2663,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2547
2663
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2548
2664
|
var calculateTransactionFee = (params) => {
|
2549
2665
|
const {
|
2550
|
-
|
2666
|
+
gasPrice,
|
2551
2667
|
rawPayload,
|
2552
|
-
|
2668
|
+
tip,
|
2669
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2553
2670
|
} = params;
|
2554
2671
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2555
2672
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2559,8 +2676,7 @@ var calculateTransactionFee = (params) => {
|
|
2559
2676
|
return {
|
2560
2677
|
fee: bn11(0),
|
2561
2678
|
minFee: bn11(0),
|
2562
|
-
maxFee: bn11(0)
|
2563
|
-
feeFromGasUsed: bn11(0)
|
2679
|
+
maxFee: bn11(0)
|
2564
2680
|
};
|
2565
2681
|
}
|
2566
2682
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2592,7 +2708,6 @@ var calculateTransactionFee = (params) => {
|
|
2592
2708
|
metadataGas,
|
2593
2709
|
txBytesSize: transactionBytes.length
|
2594
2710
|
});
|
2595
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2596
2711
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2597
2712
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2598
2713
|
const maxGas = getMaxGas({
|
@@ -2600,17 +2715,25 @@ var calculateTransactionFee = (params) => {
|
|
2600
2715
|
minGas,
|
2601
2716
|
witnessesLength,
|
2602
2717
|
gasLimit,
|
2603
|
-
witnessLimit
|
2718
|
+
witnessLimit,
|
2719
|
+
maxGasPerTx
|
2720
|
+
});
|
2721
|
+
const minFee = calculateGasFee({
|
2722
|
+
gasPrice,
|
2723
|
+
gas: minGas,
|
2724
|
+
priceFactor: gasPriceFactor,
|
2725
|
+
tip
|
2726
|
+
});
|
2727
|
+
const maxFee = calculateGasFee({
|
2728
|
+
gasPrice,
|
2729
|
+
gas: maxGas,
|
2730
|
+
priceFactor: gasPriceFactor,
|
2731
|
+
tip
|
2604
2732
|
});
|
2605
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2606
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2607
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2608
|
-
const fee = minFee.add(feeFromGasUsed);
|
2609
2733
|
return {
|
2610
|
-
fee,
|
2611
2734
|
minFee,
|
2612
2735
|
maxFee,
|
2613
|
-
|
2736
|
+
fee: maxFee
|
2614
2737
|
};
|
2615
2738
|
};
|
2616
2739
|
|
@@ -2666,7 +2789,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2666
2789
|
|
2667
2790
|
// src/providers/transaction-summary/input.ts
|
2668
2791
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2669
|
-
import { InputType as
|
2792
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2670
2793
|
function getInputsByTypes(inputs, types) {
|
2671
2794
|
return inputs.filter((i) => types.includes(i.type));
|
2672
2795
|
}
|
@@ -2674,16 +2797,16 @@ function getInputsByType(inputs, type) {
|
|
2674
2797
|
return inputs.filter((i) => i.type === type);
|
2675
2798
|
}
|
2676
2799
|
function getInputsCoin(inputs) {
|
2677
|
-
return getInputsByType(inputs,
|
2800
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2678
2801
|
}
|
2679
2802
|
function getInputsMessage(inputs) {
|
2680
|
-
return getInputsByType(inputs,
|
2803
|
+
return getInputsByType(inputs, InputType6.Message);
|
2681
2804
|
}
|
2682
2805
|
function getInputsCoinAndMessage(inputs) {
|
2683
|
-
return getInputsByTypes(inputs, [
|
2806
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2684
2807
|
}
|
2685
2808
|
function getInputsContract(inputs) {
|
2686
|
-
return getInputsByType(inputs,
|
2809
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2687
2810
|
}
|
2688
2811
|
function getInputFromAssetId(inputs, assetId) {
|
2689
2812
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2702,7 +2825,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2702
2825
|
if (!contractInput) {
|
2703
2826
|
return void 0;
|
2704
2827
|
}
|
2705
|
-
if (contractInput.type !==
|
2828
|
+
if (contractInput.type !== InputType6.Contract) {
|
2706
2829
|
throw new FuelError9(
|
2707
2830
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2708
2831
|
`Contract input should be of type 'contract'.`
|
@@ -2711,10 +2834,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2711
2834
|
return contractInput;
|
2712
2835
|
}
|
2713
2836
|
function getInputAccountAddress(input) {
|
2714
|
-
if (input.type ===
|
2837
|
+
if (input.type === InputType6.Coin) {
|
2715
2838
|
return input.owner.toString();
|
2716
2839
|
}
|
2717
|
-
if (input.type ===
|
2840
|
+
if (input.type === InputType6.Message) {
|
2718
2841
|
return input.recipient.toString();
|
2719
2842
|
}
|
2720
2843
|
return "";
|
@@ -3177,7 +3300,9 @@ function assembleTransactionSummary(params) {
|
|
3177
3300
|
gqlTransactionStatus,
|
3178
3301
|
abiMap = {},
|
3179
3302
|
maxInputs,
|
3180
|
-
gasCosts
|
3303
|
+
gasCosts,
|
3304
|
+
maxGasPerTx,
|
3305
|
+
gasPrice
|
3181
3306
|
} = params;
|
3182
3307
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3183
3308
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3191,11 +3316,14 @@ function assembleTransactionSummary(params) {
|
|
3191
3316
|
maxInputs
|
3192
3317
|
});
|
3193
3318
|
const typeName = getTransactionTypeName(transaction.type);
|
3319
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3194
3320
|
const { fee } = calculateTransactionFee({
|
3195
|
-
|
3321
|
+
gasPrice,
|
3196
3322
|
rawPayload,
|
3323
|
+
tip,
|
3197
3324
|
consensusParameters: {
|
3198
3325
|
gasCosts,
|
3326
|
+
maxGasPerTx,
|
3199
3327
|
feeParams: {
|
3200
3328
|
gasPerByte,
|
3201
3329
|
gasPriceFactor
|
@@ -3255,7 +3383,7 @@ var TransactionResponse = class {
|
|
3255
3383
|
/** Current provider */
|
3256
3384
|
provider;
|
3257
3385
|
/** Gas used on the transaction */
|
3258
|
-
gasUsed =
|
3386
|
+
gasUsed = bn15(0);
|
3259
3387
|
/** The graphql Transaction with receipts object. */
|
3260
3388
|
gqlTransaction;
|
3261
3389
|
abis;
|
@@ -3333,8 +3461,13 @@ var TransactionResponse = class {
|
|
3333
3461
|
const decodedTransaction = this.decodeTransaction(
|
3334
3462
|
transaction
|
3335
3463
|
);
|
3336
|
-
|
3337
|
-
|
3464
|
+
let txReceipts = [];
|
3465
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3466
|
+
txReceipts = transaction.status.receipts;
|
3467
|
+
}
|
3468
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3469
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3470
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3338
3471
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3339
3472
|
const transactionSummary = assembleTransactionSummary({
|
3340
3473
|
id: this.id,
|
@@ -3346,7 +3479,9 @@ var TransactionResponse = class {
|
|
3346
3479
|
gasPriceFactor,
|
3347
3480
|
abiMap: contractsAbiMap,
|
3348
3481
|
maxInputs,
|
3349
|
-
gasCosts
|
3482
|
+
gasCosts,
|
3483
|
+
maxGasPerTx,
|
3484
|
+
gasPrice
|
3350
3485
|
});
|
3351
3486
|
return transactionSummary;
|
3352
3487
|
}
|
@@ -3473,30 +3608,29 @@ var processGqlChain = (chain) => {
|
|
3473
3608
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3474
3609
|
return {
|
3475
3610
|
name,
|
3476
|
-
baseChainHeight:
|
3611
|
+
baseChainHeight: bn16(daHeight),
|
3477
3612
|
consensusParameters: {
|
3478
|
-
contractMaxSize:
|
3479
|
-
maxInputs:
|
3480
|
-
maxOutputs:
|
3481
|
-
maxWitnesses:
|
3482
|
-
maxGasPerTx:
|
3483
|
-
maxScriptLength:
|
3484
|
-
maxScriptDataLength:
|
3485
|
-
maxStorageSlots:
|
3486
|
-
maxPredicateLength:
|
3487
|
-
maxPredicateDataLength:
|
3488
|
-
maxGasPerPredicate:
|
3489
|
-
gasPriceFactor:
|
3490
|
-
gasPerByte:
|
3491
|
-
maxMessageDataLength:
|
3492
|
-
chainId:
|
3493
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3613
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3614
|
+
maxInputs: bn16(txParams.maxInputs),
|
3615
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3616
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3617
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3618
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3619
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3620
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3621
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3622
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3623
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3624
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3625
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3626
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3627
|
+
chainId: bn16(consensusParameters.chainId),
|
3494
3628
|
gasCosts
|
3495
3629
|
},
|
3496
3630
|
gasCosts,
|
3497
3631
|
latestBlock: {
|
3498
3632
|
id: latestBlock.id,
|
3499
|
-
height:
|
3633
|
+
height: bn16(latestBlock.height),
|
3500
3634
|
time: latestBlock.header.time,
|
3501
3635
|
transactions: latestBlock.transactions.map((i) => ({
|
3502
3636
|
id: i.id
|
@@ -3590,10 +3724,8 @@ var _Provider = class {
|
|
3590
3724
|
* Returns some helpful parameters related to gas fees.
|
3591
3725
|
*/
|
3592
3726
|
getGasConfig() {
|
3593
|
-
const { minGasPrice } = this.getNode();
|
3594
3727
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3595
3728
|
return {
|
3596
|
-
minGasPrice,
|
3597
3729
|
maxGasPerTx,
|
3598
3730
|
maxGasPerPredicate,
|
3599
3731
|
gasPriceFactor,
|
@@ -3691,7 +3823,7 @@ var _Provider = class {
|
|
3691
3823
|
*/
|
3692
3824
|
async getBlockNumber() {
|
3693
3825
|
const { chain } = await this.operations.getChain();
|
3694
|
-
return
|
3826
|
+
return bn16(chain.latestBlock.height, 10);
|
3695
3827
|
}
|
3696
3828
|
/**
|
3697
3829
|
* Returns the chain information.
|
@@ -3701,13 +3833,11 @@ var _Provider = class {
|
|
3701
3833
|
async fetchNode() {
|
3702
3834
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3703
3835
|
const processedNodeInfo = {
|
3704
|
-
maxDepth:
|
3705
|
-
maxTx:
|
3706
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3836
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3837
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3707
3838
|
nodeVersion: nodeInfo.nodeVersion,
|
3708
3839
|
utxoValidation: nodeInfo.utxoValidation,
|
3709
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3710
|
-
peers: nodeInfo.peers
|
3840
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3711
3841
|
};
|
3712
3842
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3713
3843
|
return processedNodeInfo;
|
@@ -3733,17 +3863,6 @@ var _Provider = class {
|
|
3733
3863
|
} = this.getChain();
|
3734
3864
|
return chainId.toNumber();
|
3735
3865
|
}
|
3736
|
-
/**
|
3737
|
-
* Returns the base asset ID
|
3738
|
-
*
|
3739
|
-
* @returns A promise that resolves to the base asset ID
|
3740
|
-
*/
|
3741
|
-
getBaseAssetId() {
|
3742
|
-
const {
|
3743
|
-
consensusParameters: { baseAssetId }
|
3744
|
-
} = this.getChain();
|
3745
|
-
return baseAssetId;
|
3746
|
-
}
|
3747
3866
|
/**
|
3748
3867
|
* Submits a transaction to the chain to be executed.
|
3749
3868
|
*
|
@@ -3804,14 +3923,13 @@ var _Provider = class {
|
|
3804
3923
|
return this.estimateTxDependencies(transactionRequest);
|
3805
3924
|
}
|
3806
3925
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3807
|
-
const { dryRun:
|
3808
|
-
encodedTransaction,
|
3926
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3927
|
+
encodedTransactions: encodedTransaction,
|
3809
3928
|
utxoValidation: utxoValidation || false
|
3810
3929
|
});
|
3811
|
-
const receipts =
|
3812
|
-
|
3813
|
-
|
3814
|
-
};
|
3930
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3931
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3932
|
+
return { receipts, dryrunStatus: status };
|
3815
3933
|
}
|
3816
3934
|
/**
|
3817
3935
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3837,7 +3955,7 @@ var _Provider = class {
|
|
3837
3955
|
} = response;
|
3838
3956
|
if (inputs) {
|
3839
3957
|
inputs.forEach((input, index) => {
|
3840
|
-
if ("predicateGasUsed" in input &&
|
3958
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3841
3959
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3842
3960
|
}
|
3843
3961
|
});
|
@@ -3850,9 +3968,6 @@ var _Provider = class {
|
|
3850
3968
|
* If there are missing variable outputs,
|
3851
3969
|
* `addVariableOutputs` is called on the transaction.
|
3852
3970
|
*
|
3853
|
-
* @privateRemarks
|
3854
|
-
* TODO: Investigate support for missing contract IDs
|
3855
|
-
* TODO: Add support for missing output messages
|
3856
3971
|
*
|
3857
3972
|
* @param transactionRequest - The transaction request object.
|
3858
3973
|
* @returns A promise.
|
@@ -3865,16 +3980,19 @@ var _Provider = class {
|
|
3865
3980
|
missingContractIds: []
|
3866
3981
|
};
|
3867
3982
|
}
|
3868
|
-
await this.estimatePredicates(transactionRequest);
|
3869
3983
|
let receipts = [];
|
3870
3984
|
const missingContractIds = [];
|
3871
3985
|
let outputVariables = 0;
|
3986
|
+
let dryrunStatus;
|
3872
3987
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3873
|
-
const {
|
3874
|
-
|
3988
|
+
const {
|
3989
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3990
|
+
} = await this.operations.dryRun({
|
3991
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3875
3992
|
utxoValidation: false
|
3876
3993
|
});
|
3877
|
-
receipts =
|
3994
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3995
|
+
dryrunStatus = status;
|
3878
3996
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3879
3997
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3880
3998
|
if (hasMissingOutputs) {
|
@@ -3884,6 +4002,10 @@ var _Provider = class {
|
|
3884
4002
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3885
4003
|
missingContractIds.push(contractId);
|
3886
4004
|
});
|
4005
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4006
|
+
transactionRequest
|
4007
|
+
});
|
4008
|
+
transactionRequest.maxFee = maxFee;
|
3887
4009
|
} else {
|
3888
4010
|
break;
|
3889
4011
|
}
|
@@ -3891,37 +4013,139 @@ var _Provider = class {
|
|
3891
4013
|
return {
|
3892
4014
|
receipts,
|
3893
4015
|
outputVariables,
|
3894
|
-
missingContractIds
|
4016
|
+
missingContractIds,
|
4017
|
+
dryrunStatus
|
3895
4018
|
};
|
3896
4019
|
}
|
4020
|
+
/**
|
4021
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4022
|
+
*
|
4023
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4024
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4025
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4026
|
+
*
|
4027
|
+
* @param transactionRequests - Array of transaction request objects.
|
4028
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4029
|
+
*/
|
4030
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4031
|
+
const results = transactionRequests.map(() => ({
|
4032
|
+
receipts: [],
|
4033
|
+
outputVariables: 0,
|
4034
|
+
missingContractIds: [],
|
4035
|
+
dryrunStatus: void 0
|
4036
|
+
}));
|
4037
|
+
const allRequests = clone3(transactionRequests);
|
4038
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4039
|
+
allRequests.forEach((req, index) => {
|
4040
|
+
if (req.type === TransactionType8.Script) {
|
4041
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4042
|
+
}
|
4043
|
+
});
|
4044
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4045
|
+
let attempt = 0;
|
4046
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4047
|
+
const encodedTransactions = transactionsToProcess.map(
|
4048
|
+
(index) => serializedTransactionsMap.get(index)
|
4049
|
+
);
|
4050
|
+
const dryRunResults = await this.operations.dryRun({
|
4051
|
+
encodedTransactions,
|
4052
|
+
utxoValidation: false
|
4053
|
+
});
|
4054
|
+
const nextRoundTransactions = [];
|
4055
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4056
|
+
const currentResultIndex = transactionsToProcess[i];
|
4057
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4058
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4059
|
+
results[currentResultIndex].dryrunStatus = status;
|
4060
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4061
|
+
results[currentResultIndex].receipts
|
4062
|
+
);
|
4063
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4064
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4065
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4066
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4067
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4068
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4069
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4070
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4071
|
+
});
|
4072
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4073
|
+
transactionRequest: requestToProcess
|
4074
|
+
});
|
4075
|
+
requestToProcess.maxFee = maxFee;
|
4076
|
+
serializedTransactionsMap.set(
|
4077
|
+
currentResultIndex,
|
4078
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4079
|
+
);
|
4080
|
+
nextRoundTransactions.push(currentResultIndex);
|
4081
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4082
|
+
}
|
4083
|
+
}
|
4084
|
+
transactionsToProcess = nextRoundTransactions;
|
4085
|
+
attempt += 1;
|
4086
|
+
}
|
4087
|
+
return results;
|
4088
|
+
}
|
4089
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4090
|
+
if (estimateTxDependencies) {
|
4091
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4092
|
+
}
|
4093
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4094
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4095
|
+
encodedTransactions,
|
4096
|
+
utxoValidation: utxoValidation || false
|
4097
|
+
});
|
4098
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4099
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4100
|
+
return { receipts, dryrunStatus: status };
|
4101
|
+
});
|
4102
|
+
return results;
|
4103
|
+
}
|
3897
4104
|
/**
|
3898
4105
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3899
4106
|
* @param transactionRequest - The transaction request object.
|
3900
4107
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3901
4108
|
*/
|
3902
|
-
estimateTxGasAndFee(params) {
|
4109
|
+
async estimateTxGasAndFee(params) {
|
3903
4110
|
const { transactionRequest } = params;
|
3904
|
-
|
4111
|
+
let { gasPrice } = params;
|
3905
4112
|
const chainInfo = this.getChain();
|
3906
|
-
const
|
3907
|
-
transactionRequest.gasPrice = gasPrice;
|
4113
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3908
4114
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3909
|
-
|
4115
|
+
if (!gasPrice) {
|
4116
|
+
gasPrice = await this.estimateGasPrice(10);
|
4117
|
+
}
|
4118
|
+
const minFee = calculateGasFee({
|
4119
|
+
gasPrice: bn16(gasPrice),
|
4120
|
+
gas: minGas,
|
4121
|
+
priceFactor: gasPriceFactor,
|
4122
|
+
tip: transactionRequest.tip
|
4123
|
+
}).add(1);
|
4124
|
+
let gasLimit = bn16(0);
|
3910
4125
|
if (transactionRequest.type === TransactionType8.Script) {
|
4126
|
+
gasLimit = transactionRequest.gasLimit;
|
3911
4127
|
if (transactionRequest.gasLimit.eq(0)) {
|
3912
4128
|
transactionRequest.gasLimit = minGas;
|
3913
4129
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3914
4130
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3915
4131
|
);
|
4132
|
+
gasLimit = transactionRequest.gasLimit;
|
3916
4133
|
}
|
3917
4134
|
}
|
3918
4135
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3919
|
-
const maxFee =
|
4136
|
+
const maxFee = calculateGasFee({
|
4137
|
+
gasPrice: bn16(gasPrice),
|
4138
|
+
gas: maxGas,
|
4139
|
+
priceFactor: gasPriceFactor,
|
4140
|
+
tip: transactionRequest.tip
|
4141
|
+
}).add(1);
|
3920
4142
|
return {
|
3921
4143
|
minGas,
|
3922
4144
|
minFee,
|
3923
4145
|
maxGas,
|
3924
|
-
maxFee
|
4146
|
+
maxFee,
|
4147
|
+
gasPrice,
|
4148
|
+
gasLimit
|
3925
4149
|
};
|
3926
4150
|
}
|
3927
4151
|
/**
|
@@ -3939,15 +4163,17 @@ var _Provider = class {
|
|
3939
4163
|
if (estimateTxDependencies) {
|
3940
4164
|
return this.estimateTxDependencies(transactionRequest);
|
3941
4165
|
}
|
3942
|
-
const
|
3943
|
-
const { dryRun:
|
3944
|
-
|
4166
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4167
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4168
|
+
encodedTransactions,
|
3945
4169
|
utxoValidation: true
|
3946
4170
|
});
|
3947
|
-
const
|
3948
|
-
|
3949
|
-
receipts
|
3950
|
-
|
4171
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4172
|
+
const { id, receipts, status } = dryRunStatus;
|
4173
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4174
|
+
return { id, receipts: processedReceipts, status };
|
4175
|
+
});
|
4176
|
+
return { receipts: callResult[0].receipts };
|
3951
4177
|
}
|
3952
4178
|
/**
|
3953
4179
|
* Returns a transaction cost to enable user
|
@@ -3964,77 +4190,79 @@ var _Provider = class {
|
|
3964
4190
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3965
4191
|
* @returns A promise that resolves to the transaction cost object.
|
3966
4192
|
*/
|
3967
|
-
async getTransactionCost(transactionRequestLike,
|
3968
|
-
estimateTxDependencies = true,
|
3969
|
-
estimatePredicates = true,
|
3970
|
-
resourcesOwner,
|
3971
|
-
signatureCallback
|
3972
|
-
} = {}) {
|
4193
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3973
4194
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3974
|
-
const { minGasPrice } = this.getGasConfig();
|
3975
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3976
4195
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3977
4196
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3978
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4197
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3979
4198
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4199
|
+
txRequestClone.maxFee = bn16(0);
|
3980
4200
|
if (isScriptTransaction) {
|
3981
|
-
txRequestClone.gasLimit =
|
4201
|
+
txRequestClone.gasLimit = bn16(0);
|
3982
4202
|
}
|
3983
|
-
if (
|
3984
|
-
|
3985
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3986
|
-
}
|
3987
|
-
await this.estimatePredicates(txRequestClone);
|
4203
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4204
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3988
4205
|
}
|
4206
|
+
const signedRequest = clone3(txRequestClone);
|
4207
|
+
let addedSignatures = 0;
|
3989
4208
|
if (signatureCallback && isScriptTransaction) {
|
3990
|
-
|
4209
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4210
|
+
await signatureCallback(signedRequest);
|
4211
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3991
4212
|
}
|
3992
|
-
|
3993
|
-
|
4213
|
+
await this.estimatePredicates(signedRequest);
|
4214
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4215
|
+
transactionRequest: signedRequest
|
3994
4216
|
});
|
3995
4217
|
let receipts = [];
|
3996
4218
|
let missingContractIds = [];
|
3997
4219
|
let outputVariables = 0;
|
3998
|
-
let gasUsed =
|
3999
|
-
|
4000
|
-
|
4220
|
+
let gasUsed = bn16(0);
|
4221
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4222
|
+
txRequestClone.maxFee = maxFee;
|
4223
|
+
if (isScriptTransaction) {
|
4224
|
+
txRequestClone.gasLimit = gasLimit;
|
4225
|
+
if (signatureCallback) {
|
4226
|
+
await signatureCallback(txRequestClone);
|
4227
|
+
}
|
4001
4228
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4002
4229
|
receipts = result.receipts;
|
4003
4230
|
outputVariables = result.outputVariables;
|
4004
4231
|
missingContractIds = result.missingContractIds;
|
4005
4232
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4006
4233
|
txRequestClone.gasLimit = gasUsed;
|
4007
|
-
|
4008
|
-
|
4009
|
-
|
4234
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4235
|
+
transactionRequest: txRequestClone,
|
4236
|
+
gasPrice
|
4010
4237
|
}));
|
4011
4238
|
}
|
4012
4239
|
return {
|
4013
4240
|
requiredQuantities: allQuantities,
|
4014
4241
|
receipts,
|
4015
4242
|
gasUsed,
|
4016
|
-
|
4017
|
-
gasPrice: setGasPrice,
|
4243
|
+
gasPrice,
|
4018
4244
|
minGas,
|
4019
4245
|
maxGas,
|
4020
4246
|
minFee,
|
4021
4247
|
maxFee,
|
4022
|
-
estimatedInputs: txRequestClone.inputs,
|
4023
4248
|
outputVariables,
|
4024
|
-
missingContractIds
|
4249
|
+
missingContractIds,
|
4250
|
+
addedSignatures,
|
4251
|
+
estimatedPredicates: txRequestClone.inputs
|
4025
4252
|
};
|
4026
4253
|
}
|
4027
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4254
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4028
4255
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4029
4256
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4030
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4257
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4258
|
+
quantitiesToContract
|
4259
|
+
});
|
4031
4260
|
transactionRequest.addResources(
|
4032
4261
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4033
4262
|
);
|
4034
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4035
|
-
|
4036
|
-
|
4037
|
-
);
|
4263
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4264
|
+
quantitiesToContract
|
4265
|
+
});
|
4038
4266
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4039
4267
|
return {
|
4040
4268
|
resources,
|
@@ -4056,11 +4284,10 @@ var _Provider = class {
|
|
4056
4284
|
return coins.map((coin) => ({
|
4057
4285
|
id: coin.utxoId,
|
4058
4286
|
assetId: coin.assetId,
|
4059
|
-
amount:
|
4287
|
+
amount: bn16(coin.amount),
|
4060
4288
|
owner: Address2.fromAddressOrString(coin.owner),
|
4061
|
-
|
4062
|
-
|
4063
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4289
|
+
blockCreated: bn16(coin.blockCreated),
|
4290
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4064
4291
|
}));
|
4065
4292
|
}
|
4066
4293
|
/**
|
@@ -4097,9 +4324,9 @@ var _Provider = class {
|
|
4097
4324
|
switch (coin.__typename) {
|
4098
4325
|
case "MessageCoin":
|
4099
4326
|
return {
|
4100
|
-
amount:
|
4327
|
+
amount: bn16(coin.amount),
|
4101
4328
|
assetId: coin.assetId,
|
4102
|
-
daHeight:
|
4329
|
+
daHeight: bn16(coin.daHeight),
|
4103
4330
|
sender: Address2.fromAddressOrString(coin.sender),
|
4104
4331
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4105
4332
|
nonce: coin.nonce
|
@@ -4107,12 +4334,11 @@ var _Provider = class {
|
|
4107
4334
|
case "Coin":
|
4108
4335
|
return {
|
4109
4336
|
id: coin.utxoId,
|
4110
|
-
amount:
|
4337
|
+
amount: bn16(coin.amount),
|
4111
4338
|
assetId: coin.assetId,
|
4112
4339
|
owner: Address2.fromAddressOrString(coin.owner),
|
4113
|
-
|
4114
|
-
|
4115
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4340
|
+
blockCreated: bn16(coin.blockCreated),
|
4341
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4116
4342
|
};
|
4117
4343
|
default:
|
4118
4344
|
return null;
|
@@ -4129,13 +4355,13 @@ var _Provider = class {
|
|
4129
4355
|
async getBlock(idOrHeight) {
|
4130
4356
|
let variables;
|
4131
4357
|
if (typeof idOrHeight === "number") {
|
4132
|
-
variables = { height:
|
4358
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4133
4359
|
} else if (idOrHeight === "latest") {
|
4134
4360
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4135
4361
|
} else if (idOrHeight.length === 66) {
|
4136
4362
|
variables = { blockId: idOrHeight };
|
4137
4363
|
} else {
|
4138
|
-
variables = { blockId:
|
4364
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4139
4365
|
}
|
4140
4366
|
const { block } = await this.operations.getBlock(variables);
|
4141
4367
|
if (!block) {
|
@@ -4143,7 +4369,7 @@ var _Provider = class {
|
|
4143
4369
|
}
|
4144
4370
|
return {
|
4145
4371
|
id: block.id,
|
4146
|
-
height:
|
4372
|
+
height: bn16(block.height),
|
4147
4373
|
time: block.header.time,
|
4148
4374
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4149
4375
|
};
|
@@ -4158,7 +4384,7 @@ var _Provider = class {
|
|
4158
4384
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4159
4385
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4160
4386
|
id: block.id,
|
4161
|
-
height:
|
4387
|
+
height: bn16(block.height),
|
4162
4388
|
time: block.header.time,
|
4163
4389
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4164
4390
|
}));
|
@@ -4173,7 +4399,7 @@ var _Provider = class {
|
|
4173
4399
|
async getBlockWithTransactions(idOrHeight) {
|
4174
4400
|
let variables;
|
4175
4401
|
if (typeof idOrHeight === "number") {
|
4176
|
-
variables = { blockHeight:
|
4402
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4177
4403
|
} else if (idOrHeight === "latest") {
|
4178
4404
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4179
4405
|
} else {
|
@@ -4185,7 +4411,7 @@ var _Provider = class {
|
|
4185
4411
|
}
|
4186
4412
|
return {
|
4187
4413
|
id: block.id,
|
4188
|
-
height:
|
4414
|
+
height: bn16(block.height, 10),
|
4189
4415
|
time: block.header.time,
|
4190
4416
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4191
4417
|
transactions: block.transactions.map(
|
@@ -4234,7 +4460,7 @@ var _Provider = class {
|
|
4234
4460
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4235
4461
|
asset: hexlify12(assetId)
|
4236
4462
|
});
|
4237
|
-
return
|
4463
|
+
return bn16(contractBalance.amount, 10);
|
4238
4464
|
}
|
4239
4465
|
/**
|
4240
4466
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4248,7 +4474,7 @@ var _Provider = class {
|
|
4248
4474
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4249
4475
|
assetId: hexlify12(assetId)
|
4250
4476
|
});
|
4251
|
-
return
|
4477
|
+
return bn16(balance.amount, 10);
|
4252
4478
|
}
|
4253
4479
|
/**
|
4254
4480
|
* Returns balances for the given owner.
|
@@ -4266,7 +4492,7 @@ var _Provider = class {
|
|
4266
4492
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4267
4493
|
return balances.map((balance) => ({
|
4268
4494
|
assetId: balance.assetId,
|
4269
|
-
amount:
|
4495
|
+
amount: bn16(balance.amount)
|
4270
4496
|
}));
|
4271
4497
|
}
|
4272
4498
|
/**
|
@@ -4288,15 +4514,15 @@ var _Provider = class {
|
|
4288
4514
|
sender: message.sender,
|
4289
4515
|
recipient: message.recipient,
|
4290
4516
|
nonce: message.nonce,
|
4291
|
-
amount:
|
4517
|
+
amount: bn16(message.amount),
|
4292
4518
|
data: message.data
|
4293
4519
|
}),
|
4294
4520
|
sender: Address2.fromAddressOrString(message.sender),
|
4295
4521
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4296
4522
|
nonce: message.nonce,
|
4297
|
-
amount:
|
4523
|
+
amount: bn16(message.amount),
|
4298
4524
|
data: InputMessageCoder.decodeData(message.data),
|
4299
|
-
daHeight:
|
4525
|
+
daHeight: bn16(message.daHeight)
|
4300
4526
|
}));
|
4301
4527
|
}
|
4302
4528
|
/**
|
@@ -4349,44 +4575,60 @@ var _Provider = class {
|
|
4349
4575
|
} = result.messageProof;
|
4350
4576
|
return {
|
4351
4577
|
messageProof: {
|
4352
|
-
proofIndex:
|
4578
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4353
4579
|
proofSet: messageProof.proofSet
|
4354
4580
|
},
|
4355
4581
|
blockProof: {
|
4356
|
-
proofIndex:
|
4582
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4357
4583
|
proofSet: blockProof.proofSet
|
4358
4584
|
},
|
4359
4585
|
messageBlockHeader: {
|
4360
4586
|
id: messageBlockHeader.id,
|
4361
|
-
daHeight:
|
4362
|
-
transactionsCount:
|
4587
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4588
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4363
4589
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4364
|
-
height:
|
4590
|
+
height: bn16(messageBlockHeader.height),
|
4365
4591
|
prevRoot: messageBlockHeader.prevRoot,
|
4366
4592
|
time: messageBlockHeader.time,
|
4367
4593
|
applicationHash: messageBlockHeader.applicationHash,
|
4368
|
-
|
4369
|
-
|
4594
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4595
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4596
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4597
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4598
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4370
4599
|
},
|
4371
4600
|
commitBlockHeader: {
|
4372
4601
|
id: commitBlockHeader.id,
|
4373
|
-
daHeight:
|
4374
|
-
transactionsCount:
|
4602
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4603
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4375
4604
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4376
|
-
height:
|
4605
|
+
height: bn16(commitBlockHeader.height),
|
4377
4606
|
prevRoot: commitBlockHeader.prevRoot,
|
4378
4607
|
time: commitBlockHeader.time,
|
4379
4608
|
applicationHash: commitBlockHeader.applicationHash,
|
4380
|
-
|
4381
|
-
|
4609
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4610
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4611
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4612
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4613
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4382
4614
|
},
|
4383
4615
|
sender: Address2.fromAddressOrString(sender),
|
4384
4616
|
recipient: Address2.fromAddressOrString(recipient),
|
4385
4617
|
nonce,
|
4386
|
-
amount:
|
4618
|
+
amount: bn16(amount),
|
4387
4619
|
data
|
4388
4620
|
};
|
4389
4621
|
}
|
4622
|
+
async getLatestGasPrice() {
|
4623
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4624
|
+
return bn16(latestGasPrice.gasPrice);
|
4625
|
+
}
|
4626
|
+
async estimateGasPrice(blockHorizon) {
|
4627
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4628
|
+
blockHorizon: String(blockHorizon)
|
4629
|
+
});
|
4630
|
+
return bn16(estimateGasPrice.gasPrice);
|
4631
|
+
}
|
4390
4632
|
/**
|
4391
4633
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4392
4634
|
*
|
@@ -4406,10 +4648,10 @@ var _Provider = class {
|
|
4406
4648
|
*/
|
4407
4649
|
async produceBlocks(amount, startTime) {
|
4408
4650
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4409
|
-
blocksToProduce:
|
4651
|
+
blocksToProduce: bn16(amount).toString(10),
|
4410
4652
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4411
4653
|
});
|
4412
|
-
return
|
4654
|
+
return bn16(latestBlockHeight);
|
4413
4655
|
}
|
4414
4656
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4415
4657
|
async getTransactionResponse(transactionId) {
|
@@ -4423,7 +4665,7 @@ cacheInputs_fn = function(inputs) {
|
|
4423
4665
|
return;
|
4424
4666
|
}
|
4425
4667
|
inputs.forEach((input) => {
|
4426
|
-
if (input.type ===
|
4668
|
+
if (input.type === InputType7.Coin) {
|
4427
4669
|
this.cache?.set(input.id);
|
4428
4670
|
}
|
4429
4671
|
});
|
@@ -4433,7 +4675,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4433
4675
|
|
4434
4676
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4435
4677
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4436
|
-
import { bn as
|
4678
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4437
4679
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4438
4680
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4439
4681
|
|
@@ -4641,9 +4883,8 @@ var Account = class extends AbstractAccount {
|
|
4641
4883
|
* @param assetId - The asset ID to check the balance for.
|
4642
4884
|
* @returns A promise that resolves to the balance amount.
|
4643
4885
|
*/
|
4644
|
-
async getBalance(assetId) {
|
4645
|
-
const
|
4646
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4886
|
+
async getBalance(assetId = BaseAssetId3) {
|
4887
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4647
4888
|
return amount;
|
4648
4889
|
}
|
4649
4890
|
/**
|
@@ -4680,37 +4921,33 @@ var Account = class extends AbstractAccount {
|
|
4680
4921
|
* @param fee - The estimated transaction fee.
|
4681
4922
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4682
4923
|
*/
|
4683
|
-
async fund(request,
|
4684
|
-
const
|
4685
|
-
const
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4924
|
+
async fund(request, params) {
|
4925
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4926
|
+
const txRequest = request;
|
4927
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4928
|
+
amount: bn18(fee),
|
4929
|
+
assetId: BaseAssetId3,
|
4930
|
+
coinQuantities: requiredQuantities
|
4689
4931
|
});
|
4690
4932
|
const quantitiesDict = {};
|
4691
|
-
|
4933
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4692
4934
|
quantitiesDict[assetId] = {
|
4693
4935
|
required: amount,
|
4694
|
-
owned:
|
4936
|
+
owned: bn18(0)
|
4695
4937
|
};
|
4696
4938
|
});
|
4697
|
-
|
4698
|
-
const cachedMessages = [];
|
4699
|
-
const owner = this.address.toB256();
|
4700
|
-
request.inputs.forEach((input) => {
|
4939
|
+
txRequest.inputs.forEach((input) => {
|
4701
4940
|
const isResource = "amount" in input;
|
4702
4941
|
if (isResource) {
|
4703
4942
|
const isCoin2 = "owner" in input;
|
4704
4943
|
if (isCoin2) {
|
4705
4944
|
const assetId = String(input.assetId);
|
4706
|
-
if (
|
4707
|
-
const amount =
|
4945
|
+
if (quantitiesDict[assetId]) {
|
4946
|
+
const amount = bn18(input.amount);
|
4708
4947
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4709
|
-
cachedUtxos.push(input.id);
|
4710
4948
|
}
|
4711
|
-
} else if (input.
|
4712
|
-
quantitiesDict[
|
4713
|
-
cachedMessages.push(input.nonce);
|
4949
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4950
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4714
4951
|
}
|
4715
4952
|
}
|
4716
4953
|
});
|
@@ -4725,12 +4962,23 @@ var Account = class extends AbstractAccount {
|
|
4725
4962
|
});
|
4726
4963
|
const needsToBeFunded = missingQuantities.length;
|
4727
4964
|
if (needsToBeFunded) {
|
4728
|
-
const
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4965
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4966
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4967
|
+
txRequest.addResources(resources);
|
4968
|
+
}
|
4969
|
+
txRequest.shiftPredicateData();
|
4970
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4971
|
+
const requestToBeReEstimate = clone4(txRequest);
|
4972
|
+
if (addedSignatures) {
|
4973
|
+
Array.from({ length: addedSignatures }).forEach(
|
4974
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4975
|
+
);
|
4733
4976
|
}
|
4977
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4978
|
+
transactionRequest: requestToBeReEstimate
|
4979
|
+
});
|
4980
|
+
txRequest.maxFee = maxFee;
|
4981
|
+
return txRequest;
|
4734
4982
|
}
|
4735
4983
|
/**
|
4736
4984
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4738,30 +4986,25 @@ var Account = class extends AbstractAccount {
|
|
4738
4986
|
* @param destination - The address of the destination.
|
4739
4987
|
* @param amount - The amount of coins to transfer.
|
4740
4988
|
* @param assetId - The asset ID of the coins to transfer.
|
4741
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4989
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4742
4990
|
* @returns A promise that resolves to the prepared transaction request.
|
4743
4991
|
*/
|
4744
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4745
|
-
const
|
4746
|
-
|
4747
|
-
const
|
4748
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4749
|
-
const request = new ScriptTransactionRequest(params);
|
4750
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4751
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4992
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4993
|
+
const request = new ScriptTransactionRequest(txParams);
|
4994
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4995
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4752
4996
|
estimateTxDependencies: true,
|
4753
4997
|
resourcesOwner: this
|
4754
4998
|
});
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
await this.fund(request,
|
4764
|
-
request.updatePredicateInputs(estimatedInputs);
|
4999
|
+
if ("gasLimit" in txParams) {
|
5000
|
+
this.validateGas({
|
5001
|
+
gasUsed: txCost.gasUsed,
|
5002
|
+
gasLimit: request.gasLimit
|
5003
|
+
});
|
5004
|
+
}
|
5005
|
+
request.gasLimit = txCost.gasUsed;
|
5006
|
+
request.maxFee = txCost.maxFee;
|
5007
|
+
await this.fund(request, txCost);
|
4765
5008
|
return request;
|
4766
5009
|
}
|
4767
5010
|
/**
|
@@ -4773,15 +5016,14 @@ var Account = class extends AbstractAccount {
|
|
4773
5016
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4774
5017
|
* @returns A promise that resolves to the transaction response.
|
4775
5018
|
*/
|
4776
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4777
|
-
if (
|
5019
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5020
|
+
if (bn18(amount).lte(0)) {
|
4778
5021
|
throw new FuelError15(
|
4779
5022
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4780
5023
|
"Transfer amount must be a positive number."
|
4781
5024
|
);
|
4782
5025
|
}
|
4783
|
-
const
|
4784
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5026
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4785
5027
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4786
5028
|
}
|
4787
5029
|
/**
|
@@ -4793,41 +5035,38 @@ var Account = class extends AbstractAccount {
|
|
4793
5035
|
* @param txParams - The optional transaction parameters.
|
4794
5036
|
* @returns A promise that resolves to the transaction response.
|
4795
5037
|
*/
|
4796
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4797
|
-
if (
|
5038
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5039
|
+
if (bn18(amount).lte(0)) {
|
4798
5040
|
throw new FuelError15(
|
4799
5041
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4800
5042
|
"Transfer amount must be a positive number."
|
4801
5043
|
);
|
4802
5044
|
}
|
4803
5045
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4804
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4805
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4806
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4807
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4808
5046
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4809
5047
|
hexlifiedContractId: contractAddress.toB256(),
|
4810
|
-
amountToTransfer:
|
4811
|
-
assetId
|
5048
|
+
amountToTransfer: bn18(amount),
|
5049
|
+
assetId
|
4812
5050
|
});
|
4813
5051
|
const request = new ScriptTransactionRequest({
|
4814
|
-
...
|
5052
|
+
...txParams,
|
4815
5053
|
script,
|
4816
5054
|
scriptData
|
4817
5055
|
});
|
4818
5056
|
request.addContractInputAndOutput(contractAddress);
|
4819
|
-
const
|
4820
|
-
|
4821
|
-
[{ amount:
|
4822
|
-
);
|
4823
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4824
|
-
this.validateGas({
|
4825
|
-
gasUsed,
|
4826
|
-
gasPrice: request.gasPrice,
|
4827
|
-
gasLimit: request.gasLimit,
|
4828
|
-
minGasPrice
|
5057
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5058
|
+
resourcesOwner: this,
|
5059
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
4829
5060
|
});
|
4830
|
-
|
5061
|
+
if (txParams.gasLimit) {
|
5062
|
+
this.validateGas({
|
5063
|
+
gasUsed: txCost.gasUsed,
|
5064
|
+
gasLimit: request.gasLimit
|
5065
|
+
});
|
5066
|
+
}
|
5067
|
+
request.gasLimit = txCost.gasUsed;
|
5068
|
+
request.maxFee = txCost.maxFee;
|
5069
|
+
await this.fund(request, txCost);
|
4831
5070
|
return this.sendTransaction(request);
|
4832
5071
|
}
|
4833
5072
|
/**
|
@@ -4839,40 +5078,31 @@ var Account = class extends AbstractAccount {
|
|
4839
5078
|
* @returns A promise that resolves to the transaction response.
|
4840
5079
|
*/
|
4841
5080
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4842
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4843
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4844
5081
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4845
5082
|
const recipientDataArray = arrayify14(
|
4846
5083
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4847
5084
|
);
|
4848
5085
|
const amountDataArray = arrayify14(
|
4849
|
-
"0x".concat(
|
5086
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4850
5087
|
);
|
4851
5088
|
const script = new Uint8Array([
|
4852
5089
|
...arrayify14(withdrawScript.bytes),
|
4853
5090
|
...recipientDataArray,
|
4854
5091
|
...amountDataArray
|
4855
5092
|
]);
|
4856
|
-
const params = {
|
4857
|
-
script,
|
4858
|
-
gasPrice: minGasPrice,
|
4859
|
-
baseAssetId,
|
4860
|
-
...txParams
|
4861
|
-
};
|
5093
|
+
const params = { script, ...txParams };
|
4862
5094
|
const request = new ScriptTransactionRequest(params);
|
4863
|
-
const
|
4864
|
-
const
|
4865
|
-
|
4866
|
-
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
|
4871
|
-
|
4872
|
-
|
4873
|
-
|
4874
|
-
});
|
4875
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5095
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5096
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5097
|
+
if (txParams.gasLimit) {
|
5098
|
+
this.validateGas({
|
5099
|
+
gasUsed: txCost.gasUsed,
|
5100
|
+
gasLimit: request.gasLimit
|
5101
|
+
});
|
5102
|
+
}
|
5103
|
+
request.maxFee = txCost.maxFee;
|
5104
|
+
request.gasLimit = txCost.gasUsed;
|
5105
|
+
await this.fund(request, txCost);
|
4876
5106
|
return this.sendTransaction(request);
|
4877
5107
|
}
|
4878
5108
|
async signMessage(message) {
|
@@ -4930,18 +5160,7 @@ var Account = class extends AbstractAccount {
|
|
4930
5160
|
}
|
4931
5161
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4932
5162
|
}
|
4933
|
-
validateGas({
|
4934
|
-
gasUsed,
|
4935
|
-
gasPrice,
|
4936
|
-
gasLimit,
|
4937
|
-
minGasPrice
|
4938
|
-
}) {
|
4939
|
-
if (minGasPrice.gt(gasPrice)) {
|
4940
|
-
throw new FuelError15(
|
4941
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4942
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4943
|
-
);
|
4944
|
-
}
|
5163
|
+
validateGas({ gasUsed, gasLimit }) {
|
4945
5164
|
if (gasUsed.gt(gasLimit)) {
|
4946
5165
|
throw new FuelError15(
|
4947
5166
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5233,7 +5452,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5233
5452
|
* @param transactionRequestLike - The transaction request to send.
|
5234
5453
|
* @returns A promise that resolves to the TransactionResponse object.
|
5235
5454
|
*/
|
5236
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5455
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5237
5456
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5238
5457
|
if (estimateTxDependencies) {
|
5239
5458
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5274,7 +5493,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5274
5493
|
// src/hdwallet/hdwallet.ts
|
5275
5494
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5276
5495
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5277
|
-
import { bn as
|
5496
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5278
5497
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5279
5498
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5280
5499
|
|
@@ -7740,7 +7959,7 @@ var HDWallet = class {
|
|
7740
7959
|
const IR = bytes.slice(32);
|
7741
7960
|
if (privateKey) {
|
7742
7961
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7743
|
-
const ki =
|
7962
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7744
7963
|
return new HDWallet({
|
7745
7964
|
privateKey: ki,
|
7746
7965
|
chainCode: IR,
|
@@ -8011,16 +8230,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8011
8230
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8012
8231
|
wallet.provider
|
8013
8232
|
);
|
8014
|
-
const
|
8015
|
-
|
8016
|
-
|
8017
|
-
|
8018
|
-
baseAssetId,
|
8019
|
-
gasLimit: 1e4,
|
8020
|
-
gasPrice: minGasPrice
|
8233
|
+
const request = new ScriptTransactionRequest();
|
8234
|
+
quantities.forEach((quantity) => {
|
8235
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8236
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
8021
8237
|
});
|
8022
|
-
|
8023
|
-
|
8238
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8239
|
+
request.gasLimit = txCost.gasUsed;
|
8240
|
+
request.maxFee = txCost.maxFee;
|
8241
|
+
await genesisWallet.fund(request, txCost);
|
8024
8242
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8025
8243
|
};
|
8026
8244
|
|
@@ -8034,9 +8252,10 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8034
8252
|
};
|
8035
8253
|
|
8036
8254
|
// src/test-utils/launchNode.ts
|
8037
|
-
import {
|
8038
|
-
import {
|
8039
|
-
import {
|
8255
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8256
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8257
|
+
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8258
|
+
import { defaultChainConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8040
8259
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8041
8260
|
import { spawn } from "child_process";
|
8042
8261
|
import { randomUUID } from "crypto";
|
@@ -8088,12 +8307,12 @@ var launchNode = async ({
|
|
8088
8307
|
// eslint-disable-next-line no-async-promise-executor
|
8089
8308
|
new Promise(async (resolve, reject) => {
|
8090
8309
|
const remainingArgs = extractRemainingArgs(args, [
|
8091
|
-
"--
|
8310
|
+
"--snapshot",
|
8092
8311
|
"--consensus-key",
|
8093
8312
|
"--db-type",
|
8094
8313
|
"--poa-instant"
|
8095
8314
|
]);
|
8096
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8315
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8097
8316
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8098
8317
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8099
8318
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8112,36 +8331,54 @@ var launchNode = async ({
|
|
8112
8331
|
let chainConfigPathToUse;
|
8113
8332
|
const prefix = basePath || os.tmpdir();
|
8114
8333
|
const suffix = basePath ? "" : randomUUID();
|
8115
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8334
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "chainConfigs");
|
8116
8335
|
if (chainConfigPath) {
|
8117
8336
|
chainConfigPathToUse = chainConfigPath;
|
8118
8337
|
} else {
|
8119
8338
|
if (!existsSync(tempDirPath)) {
|
8120
8339
|
mkdirSync(tempDirPath, { recursive: true });
|
8121
8340
|
}
|
8122
|
-
|
8123
|
-
|
8341
|
+
let { stateConfigJson } = defaultChainConfigs;
|
8342
|
+
const { chainConfigJson, metadataJson } = defaultChainConfigs;
|
8343
|
+
stateConfigJson = {
|
8344
|
+
...stateConfigJson,
|
8345
|
+
coins: [
|
8346
|
+
...stateConfigJson.coins.map((coin) => ({
|
8347
|
+
...coin,
|
8348
|
+
amount: "18446744073709551615"
|
8349
|
+
}))
|
8350
|
+
],
|
8351
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8352
|
+
...message,
|
8353
|
+
amount: "18446744073709551615"
|
8354
|
+
}))
|
8355
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8356
|
+
};
|
8124
8357
|
if (!process.env.GENESIS_SECRET) {
|
8125
8358
|
const pk = Signer.generatePrivateKey();
|
8126
8359
|
const signer = new Signer(pk);
|
8127
8360
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8128
|
-
|
8129
|
-
|
8130
|
-
|
8131
|
-
|
8132
|
-
|
8133
|
-
|
8134
|
-
|
8135
|
-
|
8136
|
-
|
8137
|
-
|
8138
|
-
}
|
8139
|
-
]
|
8140
|
-
}
|
8141
|
-
};
|
8361
|
+
stateConfigJson.coins.push({
|
8362
|
+
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8363
|
+
owner: signer.address.toHexString(),
|
8364
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8365
|
+
amount: "18446744073709551615",
|
8366
|
+
asset_id: BaseAssetId4,
|
8367
|
+
output_index: 0,
|
8368
|
+
tx_pointer_block_height: 0,
|
8369
|
+
tx_pointer_tx_idx: 0
|
8370
|
+
});
|
8142
8371
|
}
|
8143
|
-
|
8144
|
-
|
8372
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8373
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8374
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8375
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8376
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8377
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8378
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8379
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8380
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8381
|
+
chainConfigPathToUse = tempDirPath;
|
8145
8382
|
}
|
8146
8383
|
const child = spawn(
|
8147
8384
|
command,
|
@@ -8150,10 +8387,10 @@ var launchNode = async ({
|
|
8150
8387
|
["--ip", ipToUse],
|
8151
8388
|
["--port", portToUse],
|
8152
8389
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8153
|
-
["--min-gas-price", "
|
8390
|
+
["--min-gas-price", "1"],
|
8154
8391
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8155
8392
|
["--consensus-key", consensusKey],
|
8156
|
-
["--
|
8393
|
+
["--snapshot", chainConfigPathToUse],
|
8157
8394
|
"--vm-backtrace",
|
8158
8395
|
"--utxo-validation",
|
8159
8396
|
"--debug",
|
@@ -8200,10 +8437,9 @@ var launchNode = async ({
|
|
8200
8437
|
})
|
8201
8438
|
);
|
8202
8439
|
var generateWallets = async (count, provider) => {
|
8203
|
-
const baseAssetId = provider.getBaseAssetId();
|
8204
8440
|
const wallets = [];
|
8205
8441
|
for (let i = 0; i < count; i += 1) {
|
8206
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8442
|
+
const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
|
8207
8443
|
wallets.push(wallet);
|
8208
8444
|
}
|
8209
8445
|
return wallets;
|
@@ -8213,7 +8449,7 @@ var launchNodeAndGetWallets = async ({
|
|
8213
8449
|
walletCount = 10
|
8214
8450
|
} = {}) => {
|
8215
8451
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8216
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8452
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8217
8453
|
const wallets = await generateWallets(walletCount, provider);
|
8218
8454
|
const cleanup = () => {
|
8219
8455
|
closeNode();
|