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