@fuel-ts/account 0.0.0-rc-1976-20240411153008 → 0.0.0-rc-2021-20240411154255
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +896 -629
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +874 -621
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +716 -464
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +906 -324
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +45 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1613 -1132
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +852 -620
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +710 -478
- 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,35 +24,38 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
27
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
30
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
30
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
+
import { clone as clone4 } from "ramda";
|
31
33
|
|
32
34
|
// src/providers/coin-quantity.ts
|
35
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
33
36
|
import { bn } from "@fuel-ts/math";
|
34
37
|
import { hexlify } from "@fuel-ts/utils";
|
35
38
|
var coinQuantityfy = (coinQuantityLike) => {
|
36
39
|
let assetId;
|
37
40
|
let amount;
|
38
|
-
let
|
41
|
+
let max;
|
39
42
|
if (Array.isArray(coinQuantityLike)) {
|
40
43
|
amount = coinQuantityLike[0];
|
41
|
-
assetId = coinQuantityLike[1];
|
42
|
-
|
44
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
45
|
+
max = coinQuantityLike[2] ?? void 0;
|
43
46
|
} else {
|
44
47
|
amount = coinQuantityLike.amount;
|
45
|
-
assetId = coinQuantityLike.assetId;
|
46
|
-
|
48
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
49
|
+
max = coinQuantityLike.max ?? void 0;
|
47
50
|
}
|
48
51
|
const bnAmount = bn(amount);
|
49
52
|
return {
|
50
53
|
assetId: hexlify(assetId),
|
51
54
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
52
|
-
max:
|
55
|
+
max: max ? bn(max) : void 0
|
53
56
|
};
|
54
57
|
};
|
55
|
-
var
|
58
|
+
var addAmountToCoinQuantities = (params) => {
|
56
59
|
const { amount, assetId } = params;
|
57
60
|
const coinQuantities = [...params.coinQuantities];
|
58
61
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -67,9 +70,9 @@ var addAmountToAsset = (params) => {
|
|
67
70
|
// src/providers/provider.ts
|
68
71
|
import { Address as Address2 } from "@fuel-ts/address";
|
69
72
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
70
|
-
import { BN, bn as
|
73
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
71
74
|
import {
|
72
|
-
InputType as
|
75
|
+
InputType as InputType7,
|
73
76
|
TransactionType as TransactionType8,
|
74
77
|
InputMessageCoder,
|
75
78
|
TransactionCoder as TransactionCoder5
|
@@ -85,14 +88,10 @@ import { clone as clone3 } from "ramda";
|
|
85
88
|
import gql from "graphql-tag";
|
86
89
|
var ReceiptFragmentFragmentDoc = gql`
|
87
90
|
fragment receiptFragment on Receipt {
|
88
|
-
|
89
|
-
id
|
90
|
-
}
|
91
|
+
id
|
91
92
|
pc
|
92
93
|
is
|
93
|
-
to
|
94
|
-
id
|
95
|
-
}
|
94
|
+
to
|
96
95
|
toAddress
|
97
96
|
amount
|
98
97
|
assetId
|
@@ -130,10 +129,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
130
129
|
id
|
131
130
|
}
|
132
131
|
time
|
132
|
+
receipts {
|
133
|
+
...receiptFragment
|
134
|
+
}
|
133
135
|
programState {
|
134
136
|
returnType
|
135
137
|
data
|
136
138
|
}
|
139
|
+
receipts {
|
140
|
+
...receiptFragment
|
141
|
+
}
|
137
142
|
}
|
138
143
|
... on FailureStatus {
|
139
144
|
block {
|
@@ -141,26 +146,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
141
146
|
}
|
142
147
|
time
|
143
148
|
reason
|
149
|
+
receipts {
|
150
|
+
...receiptFragment
|
151
|
+
}
|
144
152
|
}
|
145
153
|
... on SqueezedOutStatus {
|
146
154
|
reason
|
147
155
|
}
|
148
156
|
}
|
149
|
-
`;
|
157
|
+
${ReceiptFragmentFragmentDoc}`;
|
150
158
|
var TransactionFragmentFragmentDoc = gql`
|
151
159
|
fragment transactionFragment on Transaction {
|
152
160
|
id
|
153
161
|
rawPayload
|
154
|
-
gasPrice
|
155
|
-
receipts {
|
156
|
-
...receiptFragment
|
157
|
-
}
|
158
162
|
status {
|
159
163
|
...transactionStatusFragment
|
160
164
|
}
|
161
165
|
}
|
162
|
-
${
|
163
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
166
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
164
167
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
165
168
|
fragment inputEstimatePredicatesFragment on Input {
|
166
169
|
... on InputCoin {
|
@@ -178,6 +181,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
178
181
|
}
|
179
182
|
}
|
180
183
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
184
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
185
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
186
|
+
reason
|
187
|
+
programState {
|
188
|
+
returnType
|
189
|
+
data
|
190
|
+
}
|
191
|
+
}
|
192
|
+
`;
|
193
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
194
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
195
|
+
programState {
|
196
|
+
returnType
|
197
|
+
data
|
198
|
+
}
|
199
|
+
}
|
200
|
+
`;
|
201
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
202
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
203
|
+
... on DryRunFailureStatus {
|
204
|
+
...dryRunFailureStatusFragment
|
205
|
+
}
|
206
|
+
... on DryRunSuccessStatus {
|
207
|
+
...dryRunSuccessStatusFragment
|
208
|
+
}
|
209
|
+
}
|
210
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
211
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
212
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
213
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
214
|
+
id
|
215
|
+
status {
|
216
|
+
...dryRunTransactionStatusFragment
|
217
|
+
}
|
218
|
+
receipts {
|
219
|
+
...receiptFragment
|
220
|
+
}
|
221
|
+
}
|
222
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
223
|
+
${ReceiptFragmentFragmentDoc}`;
|
181
224
|
var CoinFragmentFragmentDoc = gql`
|
182
225
|
fragment coinFragment on Coin {
|
183
226
|
__typename
|
@@ -185,7 +228,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
185
228
|
owner
|
186
229
|
amount
|
187
230
|
assetId
|
188
|
-
maturity
|
189
231
|
blockCreated
|
190
232
|
txCreatedIdx
|
191
233
|
}
|
@@ -224,26 +266,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
224
266
|
messageBlockHeader {
|
225
267
|
id
|
226
268
|
daHeight
|
269
|
+
consensusParametersVersion
|
270
|
+
stateTransitionBytecodeVersion
|
227
271
|
transactionsCount
|
272
|
+
messageReceiptCount
|
228
273
|
transactionsRoot
|
274
|
+
messageOutboxRoot
|
275
|
+
eventInboxRoot
|
229
276
|
height
|
230
277
|
prevRoot
|
231
278
|
time
|
232
279
|
applicationHash
|
233
|
-
messageReceiptRoot
|
234
|
-
messageReceiptCount
|
235
280
|
}
|
236
281
|
commitBlockHeader {
|
237
282
|
id
|
238
283
|
daHeight
|
284
|
+
consensusParametersVersion
|
285
|
+
stateTransitionBytecodeVersion
|
239
286
|
transactionsCount
|
287
|
+
messageReceiptCount
|
240
288
|
transactionsRoot
|
289
|
+
messageOutboxRoot
|
290
|
+
eventInboxRoot
|
241
291
|
height
|
242
292
|
prevRoot
|
243
293
|
time
|
244
294
|
applicationHash
|
245
|
-
messageReceiptRoot
|
246
|
-
messageReceiptCount
|
247
295
|
}
|
248
296
|
sender
|
249
297
|
recipient
|
@@ -262,8 +310,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
262
310
|
var BlockFragmentFragmentDoc = gql`
|
263
311
|
fragment blockFragment on Block {
|
264
312
|
id
|
313
|
+
height
|
265
314
|
header {
|
266
|
-
height
|
267
315
|
time
|
268
316
|
}
|
269
317
|
transactions {
|
@@ -321,6 +369,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
321
369
|
`;
|
322
370
|
var GasCostsFragmentFragmentDoc = gql`
|
323
371
|
fragment GasCostsFragment on GasCosts {
|
372
|
+
version {
|
373
|
+
... on Version {
|
374
|
+
value
|
375
|
+
}
|
376
|
+
}
|
324
377
|
add
|
325
378
|
addi
|
326
379
|
aloc
|
@@ -333,7 +386,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
333
386
|
cb
|
334
387
|
cfei
|
335
388
|
cfsi
|
336
|
-
croo
|
337
389
|
div
|
338
390
|
divi
|
339
391
|
ecr1
|
@@ -416,6 +468,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
416
468
|
ccp {
|
417
469
|
...DependentCostFragment
|
418
470
|
}
|
471
|
+
croo {
|
472
|
+
...DependentCostFragment
|
473
|
+
}
|
419
474
|
csiz {
|
420
475
|
...DependentCostFragment
|
421
476
|
}
|
@@ -475,6 +530,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
475
530
|
${DependentCostFragmentFragmentDoc}`;
|
476
531
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
477
532
|
fragment consensusParametersFragment on ConsensusParameters {
|
533
|
+
version {
|
534
|
+
... on Version {
|
535
|
+
value
|
536
|
+
}
|
537
|
+
}
|
478
538
|
txParams {
|
479
539
|
...TxParametersFragment
|
480
540
|
}
|
@@ -534,18 +594,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
534
594
|
fragment nodeInfoFragment on NodeInfo {
|
535
595
|
utxoValidation
|
536
596
|
vmBacktrace
|
537
|
-
minGasPrice
|
538
597
|
maxTx
|
539
598
|
maxDepth
|
540
599
|
nodeVersion
|
541
|
-
peers {
|
542
|
-
id
|
543
|
-
addresses
|
544
|
-
clientVersion
|
545
|
-
blockHeight
|
546
|
-
lastHeartbeatMs
|
547
|
-
appScore
|
548
|
-
}
|
549
600
|
}
|
550
601
|
`;
|
551
602
|
var GetVersionDocument = gql`
|
@@ -580,13 +631,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
580
631
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
581
632
|
transaction(id: $transactionId) {
|
582
633
|
...transactionFragment
|
583
|
-
receipts {
|
584
|
-
...receiptFragment
|
585
|
-
}
|
586
634
|
}
|
587
635
|
}
|
588
|
-
${TransactionFragmentFragmentDoc}
|
589
|
-
${ReceiptFragmentFragmentDoc}`;
|
636
|
+
${TransactionFragmentFragmentDoc}`;
|
590
637
|
var GetTransactionsDocument = gql`
|
591
638
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
592
639
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -714,6 +761,20 @@ var GetBalanceDocument = gql`
|
|
714
761
|
}
|
715
762
|
}
|
716
763
|
${BalanceFragmentFragmentDoc}`;
|
764
|
+
var GetLatestGasPriceDocument = gql`
|
765
|
+
query getLatestGasPrice {
|
766
|
+
latestGasPrice {
|
767
|
+
gasPrice
|
768
|
+
}
|
769
|
+
}
|
770
|
+
`;
|
771
|
+
var EstimateGasPriceDocument = gql`
|
772
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
773
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
774
|
+
gasPrice
|
775
|
+
}
|
776
|
+
}
|
777
|
+
`;
|
717
778
|
var GetBalancesDocument = gql`
|
718
779
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
719
780
|
balances(
|
@@ -768,12 +829,12 @@ var GetMessageStatusDocument = gql`
|
|
768
829
|
}
|
769
830
|
`;
|
770
831
|
var DryRunDocument = gql`
|
771
|
-
mutation dryRun($
|
772
|
-
dryRun(
|
773
|
-
...
|
832
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
833
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
834
|
+
...dryRunTransactionExecutionStatusFragment
|
774
835
|
}
|
775
836
|
}
|
776
|
-
${
|
837
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
777
838
|
var SubmitDocument = gql`
|
778
839
|
mutation submit($encodedTransaction: HexString!) {
|
779
840
|
submit(tx: $encodedTransaction) {
|
@@ -856,6 +917,12 @@ function getSdk(requester) {
|
|
856
917
|
getBalance(variables, options) {
|
857
918
|
return requester(GetBalanceDocument, variables, options);
|
858
919
|
},
|
920
|
+
getLatestGasPrice(variables, options) {
|
921
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
922
|
+
},
|
923
|
+
estimateGasPrice(variables, options) {
|
924
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
925
|
+
},
|
859
926
|
getBalances(variables, options) {
|
860
927
|
return requester(GetBalancesDocument, variables, options);
|
861
928
|
},
|
@@ -925,11 +992,14 @@ var _FuelGraphqlSubscriber = class {
|
|
925
992
|
let data;
|
926
993
|
let errors;
|
927
994
|
try {
|
928
|
-
|
995
|
+
const sanitizedText = text.replace(/\s/g, "");
|
996
|
+
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
929
997
|
} catch (e) {
|
930
998
|
throw new FuelError(
|
931
999
|
ErrorCode.STREAM_PARSING_ERROR,
|
932
|
-
`Error while parsing stream data response: ${text}
|
1000
|
+
`Error while parsing stream data response: ${text}
|
1001
|
+
|
1002
|
+
Thrown error: ${e}`
|
933
1003
|
);
|
934
1004
|
}
|
935
1005
|
if (Array.isArray(errors)) {
|
@@ -1030,7 +1100,7 @@ var inputify = (value) => {
|
|
1030
1100
|
return {
|
1031
1101
|
type: InputType.Coin,
|
1032
1102
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1033
|
-
outputIndex: arrayify(value.id)
|
1103
|
+
outputIndex: toNumber(arrayify(value.id).slice(32, 34)),
|
1034
1104
|
owner: hexlify3(value.owner),
|
1035
1105
|
amount: bn2(value.amount),
|
1036
1106
|
assetId: hexlify3(value.assetId),
|
@@ -1039,10 +1109,9 @@ var inputify = (value) => {
|
|
1039
1109
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1040
1110
|
},
|
1041
1111
|
witnessIndex: value.witnessIndex,
|
1042
|
-
maturity: value.maturity ?? 0,
|
1043
1112
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1044
|
-
predicateLength: predicate.length,
|
1045
|
-
predicateDataLength: predicateData.length,
|
1113
|
+
predicateLength: bn2(predicate.length),
|
1114
|
+
predicateDataLength: bn2(predicateData.length),
|
1046
1115
|
predicate: hexlify3(predicate),
|
1047
1116
|
predicateData: hexlify3(predicateData)
|
1048
1117
|
};
|
@@ -1073,8 +1142,8 @@ var inputify = (value) => {
|
|
1073
1142
|
nonce: hexlify3(value.nonce),
|
1074
1143
|
witnessIndex: value.witnessIndex,
|
1075
1144
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1076
|
-
predicateLength: predicate.length,
|
1077
|
-
predicateDataLength: predicateData.length,
|
1145
|
+
predicateLength: bn2(predicate.length),
|
1146
|
+
predicateDataLength: bn2(predicateData.length),
|
1078
1147
|
predicate: hexlify3(predicate),
|
1079
1148
|
predicateData: hexlify3(predicateData),
|
1080
1149
|
data: hexlify3(data),
|
@@ -1149,7 +1218,7 @@ var outputify = (value) => {
|
|
1149
1218
|
|
1150
1219
|
// src/providers/transaction-request/transaction-request.ts
|
1151
1220
|
import { Address, addressify } from "@fuel-ts/address";
|
1152
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1221
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1153
1222
|
import { bn as bn7 } from "@fuel-ts/math";
|
1154
1223
|
import {
|
1155
1224
|
PolicyType,
|
@@ -1159,6 +1228,7 @@ import {
|
|
1159
1228
|
TransactionType
|
1160
1229
|
} from "@fuel-ts/transactions";
|
1161
1230
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1231
|
+
import { randomBytes } from "ethers";
|
1162
1232
|
|
1163
1233
|
// src/providers/resource.ts
|
1164
1234
|
var isCoin = (resource) => "id" in resource;
|
@@ -1199,8 +1269,8 @@ function assembleReceiptByType(receipt) {
|
|
1199
1269
|
case "CALL" /* Call */: {
|
1200
1270
|
const callReceipt = {
|
1201
1271
|
type: ReceiptType.Call,
|
1202
|
-
from: hexOrZero(receipt.
|
1203
|
-
to: hexOrZero(receipt?.to
|
1272
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1273
|
+
to: hexOrZero(receipt?.to),
|
1204
1274
|
amount: bn4(receipt.amount),
|
1205
1275
|
assetId: hexOrZero(receipt.assetId),
|
1206
1276
|
gas: bn4(receipt.gas),
|
@@ -1214,7 +1284,7 @@ function assembleReceiptByType(receipt) {
|
|
1214
1284
|
case "RETURN" /* Return */: {
|
1215
1285
|
const returnReceipt = {
|
1216
1286
|
type: ReceiptType.Return,
|
1217
|
-
id: hexOrZero(receipt.
|
1287
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1218
1288
|
val: bn4(receipt.val),
|
1219
1289
|
pc: bn4(receipt.pc),
|
1220
1290
|
is: bn4(receipt.is)
|
@@ -1224,7 +1294,7 @@ function assembleReceiptByType(receipt) {
|
|
1224
1294
|
case "RETURN_DATA" /* ReturnData */: {
|
1225
1295
|
const returnDataReceipt = {
|
1226
1296
|
type: ReceiptType.ReturnData,
|
1227
|
-
id: hexOrZero(receipt.
|
1297
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1228
1298
|
ptr: bn4(receipt.ptr),
|
1229
1299
|
len: bn4(receipt.len),
|
1230
1300
|
digest: hexOrZero(receipt.digest),
|
@@ -1236,7 +1306,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1306
|
case "PANIC" /* Panic */: {
|
1237
1307
|
const panicReceipt = {
|
1238
1308
|
type: ReceiptType.Panic,
|
1239
|
-
id: hexOrZero(receipt.
|
1309
|
+
id: hexOrZero(receipt.id),
|
1240
1310
|
reason: bn4(receipt.reason),
|
1241
1311
|
pc: bn4(receipt.pc),
|
1242
1312
|
is: bn4(receipt.is),
|
@@ -1247,7 +1317,7 @@ function assembleReceiptByType(receipt) {
|
|
1247
1317
|
case "REVERT" /* Revert */: {
|
1248
1318
|
const revertReceipt = {
|
1249
1319
|
type: ReceiptType.Revert,
|
1250
|
-
id: hexOrZero(receipt.
|
1320
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1251
1321
|
val: bn4(receipt.ra),
|
1252
1322
|
pc: bn4(receipt.pc),
|
1253
1323
|
is: bn4(receipt.is)
|
@@ -1257,7 +1327,7 @@ function assembleReceiptByType(receipt) {
|
|
1257
1327
|
case "LOG" /* Log */: {
|
1258
1328
|
const logReceipt = {
|
1259
1329
|
type: ReceiptType.Log,
|
1260
|
-
id: hexOrZero(receipt.
|
1330
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1261
1331
|
val0: bn4(receipt.ra),
|
1262
1332
|
val1: bn4(receipt.rb),
|
1263
1333
|
val2: bn4(receipt.rc),
|
@@ -1270,7 +1340,7 @@ function assembleReceiptByType(receipt) {
|
|
1270
1340
|
case "LOG_DATA" /* LogData */: {
|
1271
1341
|
const logDataReceipt = {
|
1272
1342
|
type: ReceiptType.LogData,
|
1273
|
-
id: hexOrZero(receipt.
|
1343
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1274
1344
|
val0: bn4(receipt.ra),
|
1275
1345
|
val1: bn4(receipt.rb),
|
1276
1346
|
ptr: bn4(receipt.ptr),
|
@@ -1284,8 +1354,8 @@ function assembleReceiptByType(receipt) {
|
|
1284
1354
|
case "TRANSFER" /* Transfer */: {
|
1285
1355
|
const transferReceipt = {
|
1286
1356
|
type: ReceiptType.Transfer,
|
1287
|
-
from: hexOrZero(receipt.
|
1288
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1357
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1358
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1289
1359
|
amount: bn4(receipt.amount),
|
1290
1360
|
assetId: hexOrZero(receipt.assetId),
|
1291
1361
|
pc: bn4(receipt.pc),
|
@@ -1296,8 +1366,8 @@ function assembleReceiptByType(receipt) {
|
|
1296
1366
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1297
1367
|
const transferOutReceipt = {
|
1298
1368
|
type: ReceiptType.TransferOut,
|
1299
|
-
from: hexOrZero(receipt.
|
1300
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1369
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1370
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1301
1371
|
amount: bn4(receipt.amount),
|
1302
1372
|
assetId: hexOrZero(receipt.assetId),
|
1303
1373
|
pc: bn4(receipt.pc),
|
@@ -1340,7 +1410,7 @@ function assembleReceiptByType(receipt) {
|
|
1340
1410
|
return receiptMessageOut;
|
1341
1411
|
}
|
1342
1412
|
case "MINT" /* Mint */: {
|
1343
|
-
const contractId = hexOrZero(receipt.
|
1413
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1344
1414
|
const subId = hexOrZero(receipt.subId);
|
1345
1415
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1346
1416
|
const mintReceipt = {
|
@@ -1355,7 +1425,7 @@ function assembleReceiptByType(receipt) {
|
|
1355
1425
|
return mintReceipt;
|
1356
1426
|
}
|
1357
1427
|
case "BURN" /* Burn */: {
|
1358
|
-
const contractId = hexOrZero(receipt.
|
1428
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1359
1429
|
const subId = hexOrZero(receipt.subId);
|
1360
1430
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1361
1431
|
const burnReceipt = {
|
@@ -1381,7 +1451,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1381
1451
|
import { bn as bn5 } from "@fuel-ts/math";
|
1382
1452
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1383
1453
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1384
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1385
1454
|
var getGasUsedFromReceipts = (receipts) => {
|
1386
1455
|
const scriptResult = receipts.filter(
|
1387
1456
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1402,18 +1471,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1402
1471
|
}
|
1403
1472
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1404
1473
|
const witnessCache = [];
|
1405
|
-
const
|
1474
|
+
const chargeableInputs = inputs.filter((input) => {
|
1475
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1476
|
+
if (isCoinOrMessage) {
|
1477
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1478
|
+
return true;
|
1479
|
+
}
|
1480
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1481
|
+
witnessCache.push(input.witnessIndex);
|
1482
|
+
return true;
|
1483
|
+
}
|
1484
|
+
}
|
1485
|
+
return false;
|
1486
|
+
});
|
1487
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1488
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1406
1489
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1407
1490
|
return total.add(
|
1408
|
-
|
1491
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1409
1492
|
);
|
1410
1493
|
}
|
1411
|
-
|
1412
|
-
|
1413
|
-
return total.add(gasCosts.ecr1);
|
1414
|
-
}
|
1415
|
-
return total;
|
1416
|
-
}, bn5());
|
1494
|
+
return total.add(gasCosts.ecr1);
|
1495
|
+
}, bn5(0));
|
1417
1496
|
return totalGas;
|
1418
1497
|
}
|
1419
1498
|
function getMinGas(params) {
|
@@ -1425,12 +1504,20 @@ function getMinGas(params) {
|
|
1425
1504
|
return minGas;
|
1426
1505
|
}
|
1427
1506
|
function getMaxGas(params) {
|
1428
|
-
const {
|
1507
|
+
const {
|
1508
|
+
gasPerByte,
|
1509
|
+
witnessesLength,
|
1510
|
+
witnessLimit,
|
1511
|
+
minGas,
|
1512
|
+
gasLimit = bn5(0),
|
1513
|
+
maxGasPerTx
|
1514
|
+
} = params;
|
1429
1515
|
let remainingAllowedWitnessGas = bn5(0);
|
1430
1516
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1431
1517
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1432
1518
|
}
|
1433
|
-
|
1519
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1520
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1434
1521
|
}
|
1435
1522
|
function calculateMetadataGasForTxCreate({
|
1436
1523
|
gasCosts,
|
@@ -1452,6 +1539,10 @@ function calculateMetadataGasForTxScript({
|
|
1452
1539
|
}) {
|
1453
1540
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1454
1541
|
}
|
1542
|
+
var calculateGasFee = (params) => {
|
1543
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1544
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1545
|
+
};
|
1455
1546
|
|
1456
1547
|
// src/providers/utils/json.ts
|
1457
1548
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1596,7 +1687,7 @@ var witnessify = (value) => {
|
|
1596
1687
|
// src/providers/transaction-request/transaction-request.ts
|
1597
1688
|
var BaseTransactionRequest = class {
|
1598
1689
|
/** Gas price for transaction */
|
1599
|
-
|
1690
|
+
tip;
|
1600
1691
|
/** Block until which tx cannot be included */
|
1601
1692
|
maturity;
|
1602
1693
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1609,38 +1700,34 @@ var BaseTransactionRequest = class {
|
|
1609
1700
|
outputs = [];
|
1610
1701
|
/** List of witnesses */
|
1611
1702
|
witnesses = [];
|
1612
|
-
/** Base asset ID - should be fetched from the chain */
|
1613
|
-
baseAssetId;
|
1614
1703
|
/**
|
1615
1704
|
* Constructor for initializing a base transaction request.
|
1616
1705
|
*
|
1617
1706
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1618
1707
|
*/
|
1619
1708
|
constructor({
|
1620
|
-
|
1709
|
+
tip,
|
1621
1710
|
maturity,
|
1622
1711
|
maxFee,
|
1623
1712
|
witnessLimit,
|
1624
1713
|
inputs,
|
1625
1714
|
outputs,
|
1626
|
-
witnesses
|
1627
|
-
|
1628
|
-
|
1629
|
-
this.gasPrice = bn7(gasPrice);
|
1715
|
+
witnesses
|
1716
|
+
} = {}) {
|
1717
|
+
this.tip = bn7(tip);
|
1630
1718
|
this.maturity = maturity ?? 0;
|
1631
1719
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1632
1720
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1633
1721
|
this.inputs = inputs ?? [];
|
1634
1722
|
this.outputs = outputs ?? [];
|
1635
1723
|
this.witnesses = witnesses ?? [];
|
1636
|
-
this.baseAssetId = baseAssetId;
|
1637
1724
|
}
|
1638
1725
|
static getPolicyMeta(req) {
|
1639
1726
|
let policyTypes = 0;
|
1640
1727
|
const policies = [];
|
1641
|
-
if (req.
|
1642
|
-
policyTypes += PolicyType.
|
1643
|
-
policies.push({ data: req.
|
1728
|
+
if (req.tip) {
|
1729
|
+
policyTypes += PolicyType.Tip;
|
1730
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1644
1731
|
}
|
1645
1732
|
if (req.witnessLimit) {
|
1646
1733
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1827,10 +1914,10 @@ var BaseTransactionRequest = class {
|
|
1827
1914
|
* @param predicate - Predicate bytes.
|
1828
1915
|
* @param predicateData - Predicate data bytes.
|
1829
1916
|
*/
|
1830
|
-
addCoinInput(coin
|
1917
|
+
addCoinInput(coin) {
|
1831
1918
|
const { assetId, owner, amount } = coin;
|
1832
1919
|
let witnessIndex;
|
1833
|
-
if (predicate) {
|
1920
|
+
if (coin.predicate) {
|
1834
1921
|
witnessIndex = 0;
|
1835
1922
|
} else {
|
1836
1923
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1845,8 +1932,7 @@ var BaseTransactionRequest = class {
|
|
1845
1932
|
amount,
|
1846
1933
|
assetId,
|
1847
1934
|
txPointer: "0x00000000000000000000000000000000",
|
1848
|
-
witnessIndex
|
1849
|
-
predicate: predicate?.bytes
|
1935
|
+
witnessIndex
|
1850
1936
|
};
|
1851
1937
|
this.pushInput(input);
|
1852
1938
|
this.addChangeOutput(owner, assetId);
|
@@ -1857,11 +1943,13 @@ var BaseTransactionRequest = class {
|
|
1857
1943
|
*
|
1858
1944
|
* @param message - Message resource.
|
1859
1945
|
* @param predicate - Predicate bytes.
|
1946
|
+
* @param predicateData - Predicate data bytes.
|
1860
1947
|
*/
|
1861
|
-
addMessageInput(message
|
1948
|
+
addMessageInput(message) {
|
1862
1949
|
const { recipient, sender, amount } = message;
|
1950
|
+
const assetId = BaseAssetId2;
|
1863
1951
|
let witnessIndex;
|
1864
|
-
if (predicate) {
|
1952
|
+
if (message.predicate) {
|
1865
1953
|
witnessIndex = 0;
|
1866
1954
|
} else {
|
1867
1955
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1875,11 +1963,10 @@ var BaseTransactionRequest = class {
|
|
1875
1963
|
sender: sender.toB256(),
|
1876
1964
|
recipient: recipient.toB256(),
|
1877
1965
|
amount,
|
1878
|
-
witnessIndex
|
1879
|
-
predicate: predicate?.bytes
|
1966
|
+
witnessIndex
|
1880
1967
|
};
|
1881
1968
|
this.pushInput(input);
|
1882
|
-
this.addChangeOutput(recipient,
|
1969
|
+
this.addChangeOutput(recipient, assetId);
|
1883
1970
|
}
|
1884
1971
|
/**
|
1885
1972
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1907,32 +1994,6 @@ var BaseTransactionRequest = class {
|
|
1907
1994
|
resources.forEach((resource) => this.addResource(resource));
|
1908
1995
|
return this;
|
1909
1996
|
}
|
1910
|
-
/**
|
1911
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1912
|
-
* outputs from the related assetIds.
|
1913
|
-
*
|
1914
|
-
* @param resources - The resources to add.
|
1915
|
-
* @returns This transaction.
|
1916
|
-
*/
|
1917
|
-
addPredicateResource(resource, predicate) {
|
1918
|
-
if (isCoin(resource)) {
|
1919
|
-
this.addCoinInput(resource, predicate);
|
1920
|
-
} else {
|
1921
|
-
this.addMessageInput(resource, predicate);
|
1922
|
-
}
|
1923
|
-
return this;
|
1924
|
-
}
|
1925
|
-
/**
|
1926
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1927
|
-
* from the related assetIds.
|
1928
|
-
*
|
1929
|
-
* @param resources - The resources to add.
|
1930
|
-
* @returns This transaction.
|
1931
|
-
*/
|
1932
|
-
addPredicateResources(resources, predicate) {
|
1933
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1934
|
-
return this;
|
1935
|
-
}
|
1936
1997
|
/**
|
1937
1998
|
* Adds a coin output to the transaction.
|
1938
1999
|
*
|
@@ -1940,12 +2001,12 @@ var BaseTransactionRequest = class {
|
|
1940
2001
|
* @param amount - Amount of coin.
|
1941
2002
|
* @param assetId - Asset ID of coin.
|
1942
2003
|
*/
|
1943
|
-
addCoinOutput(to, amount, assetId) {
|
2004
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1944
2005
|
this.pushOutput({
|
1945
2006
|
type: OutputType2.Coin,
|
1946
2007
|
to: addressify(to).toB256(),
|
1947
2008
|
amount,
|
1948
|
-
assetId
|
2009
|
+
assetId
|
1949
2010
|
});
|
1950
2011
|
return this;
|
1951
2012
|
}
|
@@ -1972,7 +2033,7 @@ var BaseTransactionRequest = class {
|
|
1972
2033
|
* @param to - Address of the owner.
|
1973
2034
|
* @param assetId - Asset ID of coin.
|
1974
2035
|
*/
|
1975
|
-
addChangeOutput(to, assetId) {
|
2036
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1976
2037
|
const changeOutput = this.getChangeOutputs().find(
|
1977
2038
|
(output) => hexlify7(output.assetId) === assetId
|
1978
2039
|
);
|
@@ -1980,7 +2041,7 @@ var BaseTransactionRequest = class {
|
|
1980
2041
|
this.pushOutput({
|
1981
2042
|
type: OutputType2.Change,
|
1982
2043
|
to: addressify(to).toB256(),
|
1983
|
-
assetId
|
2044
|
+
assetId
|
1984
2045
|
});
|
1985
2046
|
}
|
1986
2047
|
}
|
@@ -2012,7 +2073,7 @@ var BaseTransactionRequest = class {
|
|
2012
2073
|
}
|
2013
2074
|
calculateMaxGas(chainInfo, minGas) {
|
2014
2075
|
const { consensusParameters } = chainInfo;
|
2015
|
-
const { gasPerByte } = consensusParameters;
|
2076
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2016
2077
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2017
2078
|
(acc, wit) => acc + wit.dataLength,
|
2018
2079
|
0
|
@@ -2021,7 +2082,8 @@ var BaseTransactionRequest = class {
|
|
2021
2082
|
gasPerByte,
|
2022
2083
|
minGas,
|
2023
2084
|
witnessesLength,
|
2024
|
-
witnessLimit: this.witnessLimit
|
2085
|
+
witnessLimit: this.witnessLimit,
|
2086
|
+
maxGasPerTx
|
2025
2087
|
});
|
2026
2088
|
}
|
2027
2089
|
/**
|
@@ -2031,12 +2093,6 @@ var BaseTransactionRequest = class {
|
|
2031
2093
|
* @param quantities - CoinQuantity Array.
|
2032
2094
|
*/
|
2033
2095
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2034
|
-
let idCounter = 0;
|
2035
|
-
const generateId = () => {
|
2036
|
-
const counterString = String(idCounter++);
|
2037
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2038
|
-
return id;
|
2039
|
-
};
|
2040
2096
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2041
2097
|
if ("assetId" in input) {
|
2042
2098
|
return input.assetId === assetId;
|
@@ -2045,24 +2101,27 @@ var BaseTransactionRequest = class {
|
|
2045
2101
|
});
|
2046
2102
|
const updateAssetInput = (assetId, quantity) => {
|
2047
2103
|
const assetInput = findAssetInput(assetId);
|
2104
|
+
let usedQuantity = quantity;
|
2105
|
+
if (assetId === BaseAssetId2) {
|
2106
|
+
usedQuantity = bn7("1000000000000000000");
|
2107
|
+
}
|
2048
2108
|
if (assetInput && "assetId" in assetInput) {
|
2049
|
-
assetInput.id =
|
2050
|
-
assetInput.amount =
|
2109
|
+
assetInput.id = hexlify7(randomBytes(34));
|
2110
|
+
assetInput.amount = usedQuantity;
|
2051
2111
|
} else {
|
2052
2112
|
this.addResources([
|
2053
2113
|
{
|
2054
|
-
id:
|
2055
|
-
amount:
|
2114
|
+
id: hexlify7(randomBytes(34)),
|
2115
|
+
amount: usedQuantity,
|
2056
2116
|
assetId,
|
2057
2117
|
owner: resourcesOwner || Address.fromRandom(),
|
2058
|
-
maturity: 0,
|
2059
2118
|
blockCreated: bn7(1),
|
2060
2119
|
txCreatedIdx: bn7(1)
|
2061
2120
|
}
|
2062
2121
|
]);
|
2063
2122
|
}
|
2064
2123
|
};
|
2065
|
-
updateAssetInput(
|
2124
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2066
2125
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2067
2126
|
}
|
2068
2127
|
/**
|
@@ -2087,7 +2146,7 @@ var BaseTransactionRequest = class {
|
|
2087
2146
|
toJSON() {
|
2088
2147
|
return normalizeJSON(this);
|
2089
2148
|
}
|
2090
|
-
|
2149
|
+
updatePredicateGasUsed(inputs) {
|
2091
2150
|
this.inputs.forEach((i) => {
|
2092
2151
|
let correspondingInput;
|
2093
2152
|
switch (i.type) {
|
@@ -2109,6 +2168,15 @@ var BaseTransactionRequest = class {
|
|
2109
2168
|
}
|
2110
2169
|
});
|
2111
2170
|
}
|
2171
|
+
shiftPredicateData() {
|
2172
|
+
this.inputs.forEach((input) => {
|
2173
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2174
|
+
input.predicateData = input.paddPredicateData(
|
2175
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2176
|
+
);
|
2177
|
+
}
|
2178
|
+
});
|
2179
|
+
}
|
2112
2180
|
};
|
2113
2181
|
|
2114
2182
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2232,7 +2300,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2232
2300
|
*
|
2233
2301
|
* @param createTransactionRequestLike - The initial values for the instance
|
2234
2302
|
*/
|
2235
|
-
constructor({
|
2303
|
+
constructor({
|
2304
|
+
bytecodeWitnessIndex,
|
2305
|
+
salt,
|
2306
|
+
storageSlots,
|
2307
|
+
...rest
|
2308
|
+
} = {}) {
|
2236
2309
|
super(rest);
|
2237
2310
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2238
2311
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2250,9 +2323,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2250
2323
|
return {
|
2251
2324
|
type: TransactionType3.Create,
|
2252
2325
|
...baseTransaction,
|
2253
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2254
2326
|
bytecodeWitnessIndex,
|
2255
|
-
storageSlotsCount: storageSlots.length,
|
2327
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2256
2328
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2257
2329
|
storageSlots
|
2258
2330
|
};
|
@@ -2356,7 +2428,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2356
2428
|
*
|
2357
2429
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2358
2430
|
*/
|
2359
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2431
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2360
2432
|
super(rest);
|
2361
2433
|
this.gasLimit = bn10(gasLimit);
|
2362
2434
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -2375,8 +2447,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2375
2447
|
type: TransactionType4.Script,
|
2376
2448
|
scriptGasLimit: this.gasLimit,
|
2377
2449
|
...super.getBaseTransaction(),
|
2378
|
-
scriptLength: script.length,
|
2379
|
-
scriptDataLength: scriptData.length,
|
2450
|
+
scriptLength: bn10(script.length),
|
2451
|
+
scriptDataLength: bn10(scriptData.length),
|
2380
2452
|
receiptsRoot: ZeroBytes327,
|
2381
2453
|
script: hexlify10(script),
|
2382
2454
|
scriptData: hexlify10(scriptData)
|
@@ -2440,7 +2512,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2440
2512
|
}
|
2441
2513
|
calculateMaxGas(chainInfo, minGas) {
|
2442
2514
|
const { consensusParameters } = chainInfo;
|
2443
|
-
const { gasPerByte } = consensusParameters;
|
2515
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2444
2516
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2445
2517
|
(acc, wit) => acc + wit.dataLength,
|
2446
2518
|
0
|
@@ -2450,7 +2522,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2450
2522
|
minGas,
|
2451
2523
|
witnessesLength,
|
2452
2524
|
witnessLimit: this.witnessLimit,
|
2453
|
-
gasLimit: this.gasLimit
|
2525
|
+
gasLimit: this.gasLimit,
|
2526
|
+
maxGasPerTx
|
2454
2527
|
});
|
2455
2528
|
}
|
2456
2529
|
/**
|
@@ -2507,7 +2580,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2507
2580
|
|
2508
2581
|
// src/providers/transaction-request/utils.ts
|
2509
2582
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2510
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2583
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2511
2584
|
var transactionRequestify = (obj) => {
|
2512
2585
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2513
2586
|
return obj;
|
@@ -2525,14 +2598,31 @@ var transactionRequestify = (obj) => {
|
|
2525
2598
|
}
|
2526
2599
|
}
|
2527
2600
|
};
|
2601
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2602
|
+
(acc, input) => {
|
2603
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2604
|
+
acc.utxos.push(input.id);
|
2605
|
+
}
|
2606
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2607
|
+
acc.messages.push(input.nonce);
|
2608
|
+
}
|
2609
|
+
return acc;
|
2610
|
+
},
|
2611
|
+
{
|
2612
|
+
utxos: [],
|
2613
|
+
messages: []
|
2614
|
+
}
|
2615
|
+
);
|
2528
2616
|
|
2529
2617
|
// src/providers/transaction-response/transaction-response.ts
|
2530
2618
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2531
|
-
import { bn as
|
2619
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2532
2620
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2533
2621
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2534
2622
|
|
2535
2623
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2624
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2625
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2536
2626
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2537
2627
|
|
2538
2628
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2541,9 +2631,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2541
2631
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2542
2632
|
var calculateTransactionFee = (params) => {
|
2543
2633
|
const {
|
2544
|
-
|
2634
|
+
gasPrice,
|
2545
2635
|
rawPayload,
|
2546
|
-
|
2636
|
+
tip,
|
2637
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2547
2638
|
} = params;
|
2548
2639
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2549
2640
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2553,8 +2644,7 @@ var calculateTransactionFee = (params) => {
|
|
2553
2644
|
return {
|
2554
2645
|
fee: bn11(0),
|
2555
2646
|
minFee: bn11(0),
|
2556
|
-
maxFee: bn11(0)
|
2557
|
-
feeFromGasUsed: bn11(0)
|
2647
|
+
maxFee: bn11(0)
|
2558
2648
|
};
|
2559
2649
|
}
|
2560
2650
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2586,7 +2676,6 @@ var calculateTransactionFee = (params) => {
|
|
2586
2676
|
metadataGas,
|
2587
2677
|
txBytesSize: transactionBytes.length
|
2588
2678
|
});
|
2589
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2590
2679
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2591
2680
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2592
2681
|
const maxGas = getMaxGas({
|
@@ -2594,17 +2683,25 @@ var calculateTransactionFee = (params) => {
|
|
2594
2683
|
minGas,
|
2595
2684
|
witnessesLength,
|
2596
2685
|
gasLimit,
|
2597
|
-
witnessLimit
|
2686
|
+
witnessLimit,
|
2687
|
+
maxGasPerTx
|
2688
|
+
});
|
2689
|
+
const minFee = calculateGasFee({
|
2690
|
+
gasPrice,
|
2691
|
+
gas: minGas,
|
2692
|
+
priceFactor: gasPriceFactor,
|
2693
|
+
tip
|
2694
|
+
});
|
2695
|
+
const maxFee = calculateGasFee({
|
2696
|
+
gasPrice,
|
2697
|
+
gas: maxGas,
|
2698
|
+
priceFactor: gasPriceFactor,
|
2699
|
+
tip
|
2598
2700
|
});
|
2599
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2600
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2601
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2602
|
-
const fee = minFee.add(feeFromGasUsed);
|
2603
2701
|
return {
|
2604
|
-
fee,
|
2605
2702
|
minFee,
|
2606
2703
|
maxFee,
|
2607
|
-
|
2704
|
+
fee: maxFee
|
2608
2705
|
};
|
2609
2706
|
};
|
2610
2707
|
|
@@ -2660,7 +2757,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2660
2757
|
|
2661
2758
|
// src/providers/transaction-summary/input.ts
|
2662
2759
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2663
|
-
import { InputType as
|
2760
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2664
2761
|
function getInputsByTypes(inputs, types) {
|
2665
2762
|
return inputs.filter((i) => types.includes(i.type));
|
2666
2763
|
}
|
@@ -2668,16 +2765,16 @@ function getInputsByType(inputs, type) {
|
|
2668
2765
|
return inputs.filter((i) => i.type === type);
|
2669
2766
|
}
|
2670
2767
|
function getInputsCoin(inputs) {
|
2671
|
-
return getInputsByType(inputs,
|
2768
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2672
2769
|
}
|
2673
2770
|
function getInputsMessage(inputs) {
|
2674
|
-
return getInputsByType(inputs,
|
2771
|
+
return getInputsByType(inputs, InputType6.Message);
|
2675
2772
|
}
|
2676
2773
|
function getInputsCoinAndMessage(inputs) {
|
2677
|
-
return getInputsByTypes(inputs, [
|
2774
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2678
2775
|
}
|
2679
2776
|
function getInputsContract(inputs) {
|
2680
|
-
return getInputsByType(inputs,
|
2777
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2681
2778
|
}
|
2682
2779
|
function getInputFromAssetId(inputs, assetId) {
|
2683
2780
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2696,7 +2793,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2696
2793
|
if (!contractInput) {
|
2697
2794
|
return void 0;
|
2698
2795
|
}
|
2699
|
-
if (contractInput.type !==
|
2796
|
+
if (contractInput.type !== InputType6.Contract) {
|
2700
2797
|
throw new FuelError9(
|
2701
2798
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2702
2799
|
`Contract input should be of type 'contract'.`
|
@@ -2705,10 +2802,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2705
2802
|
return contractInput;
|
2706
2803
|
}
|
2707
2804
|
function getInputAccountAddress(input) {
|
2708
|
-
if (input.type ===
|
2805
|
+
if (input.type === InputType6.Coin) {
|
2709
2806
|
return input.owner.toString();
|
2710
2807
|
}
|
2711
|
-
if (input.type ===
|
2808
|
+
if (input.type === InputType6.Message) {
|
2712
2809
|
return input.recipient.toString();
|
2713
2810
|
}
|
2714
2811
|
return "";
|
@@ -3171,7 +3268,9 @@ function assembleTransactionSummary(params) {
|
|
3171
3268
|
gqlTransactionStatus,
|
3172
3269
|
abiMap = {},
|
3173
3270
|
maxInputs,
|
3174
|
-
gasCosts
|
3271
|
+
gasCosts,
|
3272
|
+
maxGasPerTx,
|
3273
|
+
gasPrice
|
3175
3274
|
} = params;
|
3176
3275
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3177
3276
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3185,11 +3284,14 @@ function assembleTransactionSummary(params) {
|
|
3185
3284
|
maxInputs
|
3186
3285
|
});
|
3187
3286
|
const typeName = getTransactionTypeName(transaction.type);
|
3287
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3188
3288
|
const { fee } = calculateTransactionFee({
|
3189
|
-
|
3289
|
+
gasPrice,
|
3190
3290
|
rawPayload,
|
3291
|
+
tip,
|
3191
3292
|
consensusParameters: {
|
3192
3293
|
gasCosts,
|
3294
|
+
maxGasPerTx,
|
3193
3295
|
feeParams: {
|
3194
3296
|
gasPerByte,
|
3195
3297
|
gasPriceFactor
|
@@ -3249,7 +3351,7 @@ var TransactionResponse = class {
|
|
3249
3351
|
/** Current provider */
|
3250
3352
|
provider;
|
3251
3353
|
/** Gas used on the transaction */
|
3252
|
-
gasUsed =
|
3354
|
+
gasUsed = bn15(0);
|
3253
3355
|
/** The graphql Transaction with receipts object. */
|
3254
3356
|
gqlTransaction;
|
3255
3357
|
abis;
|
@@ -3327,8 +3429,13 @@ var TransactionResponse = class {
|
|
3327
3429
|
const decodedTransaction = this.decodeTransaction(
|
3328
3430
|
transaction
|
3329
3431
|
);
|
3330
|
-
|
3331
|
-
|
3432
|
+
let txReceipts = [];
|
3433
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3434
|
+
txReceipts = transaction.status.receipts;
|
3435
|
+
}
|
3436
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3437
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3438
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3332
3439
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3333
3440
|
const transactionSummary = assembleTransactionSummary({
|
3334
3441
|
id: this.id,
|
@@ -3340,7 +3447,9 @@ var TransactionResponse = class {
|
|
3340
3447
|
gasPriceFactor,
|
3341
3448
|
abiMap: contractsAbiMap,
|
3342
3449
|
maxInputs,
|
3343
|
-
gasCosts
|
3450
|
+
gasCosts,
|
3451
|
+
maxGasPerTx,
|
3452
|
+
gasPrice
|
3344
3453
|
});
|
3345
3454
|
return transactionSummary;
|
3346
3455
|
}
|
@@ -3467,30 +3576,29 @@ var processGqlChain = (chain) => {
|
|
3467
3576
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3468
3577
|
return {
|
3469
3578
|
name,
|
3470
|
-
baseChainHeight:
|
3579
|
+
baseChainHeight: bn16(daHeight),
|
3471
3580
|
consensusParameters: {
|
3472
|
-
contractMaxSize:
|
3473
|
-
maxInputs:
|
3474
|
-
maxOutputs:
|
3475
|
-
maxWitnesses:
|
3476
|
-
maxGasPerTx:
|
3477
|
-
maxScriptLength:
|
3478
|
-
maxScriptDataLength:
|
3479
|
-
maxStorageSlots:
|
3480
|
-
maxPredicateLength:
|
3481
|
-
maxPredicateDataLength:
|
3482
|
-
maxGasPerPredicate:
|
3483
|
-
gasPriceFactor:
|
3484
|
-
gasPerByte:
|
3485
|
-
maxMessageDataLength:
|
3486
|
-
chainId:
|
3487
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3581
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3582
|
+
maxInputs: bn16(txParams.maxInputs),
|
3583
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3584
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3585
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3586
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3587
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3588
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3589
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3590
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3591
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3592
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3593
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3594
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3595
|
+
chainId: bn16(consensusParameters.chainId),
|
3488
3596
|
gasCosts
|
3489
3597
|
},
|
3490
3598
|
gasCosts,
|
3491
3599
|
latestBlock: {
|
3492
3600
|
id: latestBlock.id,
|
3493
|
-
height:
|
3601
|
+
height: bn16(latestBlock.height),
|
3494
3602
|
time: latestBlock.header.time,
|
3495
3603
|
transactions: latestBlock.transactions.map((i) => ({
|
3496
3604
|
id: i.id
|
@@ -3584,10 +3692,8 @@ var _Provider = class {
|
|
3584
3692
|
* Returns some helpful parameters related to gas fees.
|
3585
3693
|
*/
|
3586
3694
|
getGasConfig() {
|
3587
|
-
const { minGasPrice } = this.getNode();
|
3588
3695
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3589
3696
|
return {
|
3590
|
-
minGasPrice,
|
3591
3697
|
maxGasPerTx,
|
3592
3698
|
maxGasPerPredicate,
|
3593
3699
|
gasPriceFactor,
|
@@ -3685,7 +3791,7 @@ var _Provider = class {
|
|
3685
3791
|
*/
|
3686
3792
|
async getBlockNumber() {
|
3687
3793
|
const { chain } = await this.operations.getChain();
|
3688
|
-
return
|
3794
|
+
return bn16(chain.latestBlock.height, 10);
|
3689
3795
|
}
|
3690
3796
|
/**
|
3691
3797
|
* Returns the chain information.
|
@@ -3695,13 +3801,11 @@ var _Provider = class {
|
|
3695
3801
|
async fetchNode() {
|
3696
3802
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3697
3803
|
const processedNodeInfo = {
|
3698
|
-
maxDepth:
|
3699
|
-
maxTx:
|
3700
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3804
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3805
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3701
3806
|
nodeVersion: nodeInfo.nodeVersion,
|
3702
3807
|
utxoValidation: nodeInfo.utxoValidation,
|
3703
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3704
|
-
peers: nodeInfo.peers
|
3808
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3705
3809
|
};
|
3706
3810
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3707
3811
|
return processedNodeInfo;
|
@@ -3727,17 +3831,6 @@ var _Provider = class {
|
|
3727
3831
|
} = this.getChain();
|
3728
3832
|
return chainId.toNumber();
|
3729
3833
|
}
|
3730
|
-
/**
|
3731
|
-
* Returns the base asset ID
|
3732
|
-
*
|
3733
|
-
* @returns A promise that resolves to the base asset ID
|
3734
|
-
*/
|
3735
|
-
getBaseAssetId() {
|
3736
|
-
const {
|
3737
|
-
consensusParameters: { baseAssetId }
|
3738
|
-
} = this.getChain();
|
3739
|
-
return baseAssetId;
|
3740
|
-
}
|
3741
3834
|
/**
|
3742
3835
|
* Submits a transaction to the chain to be executed.
|
3743
3836
|
*
|
@@ -3798,14 +3891,13 @@ var _Provider = class {
|
|
3798
3891
|
return this.estimateTxDependencies(transactionRequest);
|
3799
3892
|
}
|
3800
3893
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3801
|
-
const { dryRun:
|
3802
|
-
encodedTransaction,
|
3894
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3895
|
+
encodedTransactions: encodedTransaction,
|
3803
3896
|
utxoValidation: utxoValidation || false
|
3804
3897
|
});
|
3805
|
-
const receipts =
|
3806
|
-
|
3807
|
-
|
3808
|
-
};
|
3898
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3899
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3900
|
+
return { receipts, dryrunStatus: status };
|
3809
3901
|
}
|
3810
3902
|
/**
|
3811
3903
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3831,7 +3923,7 @@ var _Provider = class {
|
|
3831
3923
|
} = response;
|
3832
3924
|
if (inputs) {
|
3833
3925
|
inputs.forEach((input, index) => {
|
3834
|
-
if ("predicateGasUsed" in input &&
|
3926
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3835
3927
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3836
3928
|
}
|
3837
3929
|
});
|
@@ -3844,9 +3936,6 @@ var _Provider = class {
|
|
3844
3936
|
* If there are missing variable outputs,
|
3845
3937
|
* `addVariableOutputs` is called on the transaction.
|
3846
3938
|
*
|
3847
|
-
* @privateRemarks
|
3848
|
-
* TODO: Investigate support for missing contract IDs
|
3849
|
-
* TODO: Add support for missing output messages
|
3850
3939
|
*
|
3851
3940
|
* @param transactionRequest - The transaction request object.
|
3852
3941
|
* @returns A promise.
|
@@ -3859,16 +3948,19 @@ var _Provider = class {
|
|
3859
3948
|
missingContractIds: []
|
3860
3949
|
};
|
3861
3950
|
}
|
3862
|
-
await this.estimatePredicates(transactionRequest);
|
3863
3951
|
let receipts = [];
|
3864
3952
|
const missingContractIds = [];
|
3865
3953
|
let outputVariables = 0;
|
3954
|
+
let dryrunStatus;
|
3866
3955
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3867
|
-
const {
|
3868
|
-
|
3956
|
+
const {
|
3957
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3958
|
+
} = await this.operations.dryRun({
|
3959
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3869
3960
|
utxoValidation: false
|
3870
3961
|
});
|
3871
|
-
receipts =
|
3962
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3963
|
+
dryrunStatus = status;
|
3872
3964
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3873
3965
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3874
3966
|
if (hasMissingOutputs) {
|
@@ -3878,6 +3970,11 @@ var _Provider = class {
|
|
3878
3970
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3879
3971
|
missingContractIds.push(contractId);
|
3880
3972
|
});
|
3973
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3974
|
+
transactionRequest,
|
3975
|
+
optimizeGas: false
|
3976
|
+
});
|
3977
|
+
transactionRequest.maxFee = maxFee;
|
3881
3978
|
} else {
|
3882
3979
|
break;
|
3883
3980
|
}
|
@@ -3885,7 +3982,133 @@ var _Provider = class {
|
|
3885
3982
|
return {
|
3886
3983
|
receipts,
|
3887
3984
|
outputVariables,
|
3888
|
-
missingContractIds
|
3985
|
+
missingContractIds,
|
3986
|
+
dryrunStatus
|
3987
|
+
};
|
3988
|
+
}
|
3989
|
+
/**
|
3990
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3991
|
+
*
|
3992
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3993
|
+
* further modifications are identified. The method iteratively updates these transactions
|
3994
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3995
|
+
*
|
3996
|
+
* @param transactionRequests - Array of transaction request objects.
|
3997
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
3998
|
+
*/
|
3999
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4000
|
+
const results = transactionRequests.map(() => ({
|
4001
|
+
receipts: [],
|
4002
|
+
outputVariables: 0,
|
4003
|
+
missingContractIds: [],
|
4004
|
+
dryrunStatus: void 0
|
4005
|
+
}));
|
4006
|
+
const allRequests = clone3(transactionRequests);
|
4007
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4008
|
+
allRequests.forEach((req, index) => {
|
4009
|
+
if (req.type === TransactionType8.Script) {
|
4010
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4011
|
+
}
|
4012
|
+
});
|
4013
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4014
|
+
let attempt = 0;
|
4015
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4016
|
+
const encodedTransactions = transactionsToProcess.map(
|
4017
|
+
(index) => serializedTransactionsMap.get(index)
|
4018
|
+
);
|
4019
|
+
const dryRunResults = await this.operations.dryRun({
|
4020
|
+
encodedTransactions,
|
4021
|
+
utxoValidation: false
|
4022
|
+
});
|
4023
|
+
const nextRoundTransactions = [];
|
4024
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4025
|
+
const currentResultIndex = transactionsToProcess[i];
|
4026
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4027
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4028
|
+
results[currentResultIndex].dryrunStatus = status;
|
4029
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4030
|
+
results[currentResultIndex].receipts
|
4031
|
+
);
|
4032
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4033
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4034
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4035
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4036
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4037
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4038
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4039
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4040
|
+
});
|
4041
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4042
|
+
transactionRequest: requestToProcess,
|
4043
|
+
optimizeGas: false
|
4044
|
+
});
|
4045
|
+
requestToProcess.maxFee = maxFee;
|
4046
|
+
serializedTransactionsMap.set(
|
4047
|
+
currentResultIndex,
|
4048
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4049
|
+
);
|
4050
|
+
nextRoundTransactions.push(currentResultIndex);
|
4051
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4052
|
+
}
|
4053
|
+
}
|
4054
|
+
transactionsToProcess = nextRoundTransactions;
|
4055
|
+
attempt += 1;
|
4056
|
+
}
|
4057
|
+
return results;
|
4058
|
+
}
|
4059
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4060
|
+
if (estimateTxDependencies) {
|
4061
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4062
|
+
}
|
4063
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4064
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4065
|
+
encodedTransactions,
|
4066
|
+
utxoValidation: utxoValidation || false
|
4067
|
+
});
|
4068
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4069
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4070
|
+
return { receipts, dryrunStatus: status };
|
4071
|
+
});
|
4072
|
+
return results;
|
4073
|
+
}
|
4074
|
+
async estimateTxGasAndFee(params) {
|
4075
|
+
const { transactionRequest, optimizeGas = true } = params;
|
4076
|
+
let { gasPrice } = params;
|
4077
|
+
const chainInfo = this.getChain();
|
4078
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4079
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4080
|
+
if (!gasPrice) {
|
4081
|
+
gasPrice = await this.estimateGasPrice(10);
|
4082
|
+
}
|
4083
|
+
const minFee = calculateGasFee({
|
4084
|
+
gasPrice: bn16(gasPrice),
|
4085
|
+
gas: minGas,
|
4086
|
+
priceFactor: gasPriceFactor,
|
4087
|
+
tip: transactionRequest.tip
|
4088
|
+
}).add(1);
|
4089
|
+
let gasLimit = bn16(0);
|
4090
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
4091
|
+
gasLimit = transactionRequest.gasLimit;
|
4092
|
+
if (!optimizeGas) {
|
4093
|
+
transactionRequest.gasLimit = minGas;
|
4094
|
+
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4095
|
+
transactionRequest.gasLimit = gasLimit;
|
4096
|
+
}
|
4097
|
+
}
|
4098
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4099
|
+
const maxFee = calculateGasFee({
|
4100
|
+
gasPrice: bn16(gasPrice),
|
4101
|
+
gas: maxGas,
|
4102
|
+
priceFactor: gasPriceFactor,
|
4103
|
+
tip: transactionRequest.tip
|
4104
|
+
}).add(1);
|
4105
|
+
return {
|
4106
|
+
minGas,
|
4107
|
+
minFee,
|
4108
|
+
maxGas,
|
4109
|
+
maxFee,
|
4110
|
+
gasPrice,
|
4111
|
+
gasLimit
|
3889
4112
|
};
|
3890
4113
|
}
|
3891
4114
|
/**
|
@@ -3903,15 +4126,17 @@ var _Provider = class {
|
|
3903
4126
|
if (estimateTxDependencies) {
|
3904
4127
|
return this.estimateTxDependencies(transactionRequest);
|
3905
4128
|
}
|
3906
|
-
const
|
3907
|
-
const { dryRun:
|
3908
|
-
|
4129
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4130
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4131
|
+
encodedTransactions,
|
3909
4132
|
utxoValidation: true
|
3910
4133
|
});
|
3911
|
-
const
|
3912
|
-
|
3913
|
-
receipts
|
3914
|
-
|
4134
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4135
|
+
const { id, receipts, status } = dryRunStatus;
|
4136
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4137
|
+
return { id, receipts: processedReceipts, status };
|
4138
|
+
});
|
4139
|
+
return { receipts: callResult[0].receipts };
|
3915
4140
|
}
|
3916
4141
|
/**
|
3917
4142
|
* Returns a transaction cost to enable user
|
@@ -3928,80 +4153,80 @@ var _Provider = class {
|
|
3928
4153
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3929
4154
|
* @returns A promise that resolves to the transaction cost object.
|
3930
4155
|
*/
|
3931
|
-
async getTransactionCost(transactionRequestLike,
|
3932
|
-
estimateTxDependencies = true,
|
3933
|
-
estimatePredicates = true,
|
3934
|
-
resourcesOwner,
|
3935
|
-
signatureCallback
|
3936
|
-
} = {}) {
|
4156
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3937
4157
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3938
|
-
const chainInfo = this.getChain();
|
3939
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3940
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3941
4158
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3942
4159
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3943
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4160
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3944
4161
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3945
|
-
|
3946
|
-
|
3947
|
-
|
3948
|
-
}
|
3949
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3950
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3951
|
-
}
|
3952
|
-
await this.estimatePredicates(txRequestClone);
|
4162
|
+
txRequestClone.maxFee = bn16(0);
|
4163
|
+
if (isScriptTransaction) {
|
4164
|
+
txRequestClone.gasLimit = bn16(0);
|
3953
4165
|
}
|
3954
|
-
if (
|
3955
|
-
|
4166
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4167
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3956
4168
|
}
|
3957
|
-
const
|
3958
|
-
|
4169
|
+
const signedRequest = clone3(txRequestClone);
|
4170
|
+
let addedSignatures = 0;
|
4171
|
+
if (signatureCallback && isScriptTransaction) {
|
4172
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4173
|
+
await signatureCallback(signedRequest);
|
4174
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4175
|
+
}
|
4176
|
+
await this.estimatePredicates(signedRequest);
|
4177
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4178
|
+
transactionRequest: signedRequest,
|
4179
|
+
optimizeGas: false
|
4180
|
+
});
|
4181
|
+
txRequestClone.maxFee = maxFee;
|
3959
4182
|
let receipts = [];
|
3960
4183
|
let missingContractIds = [];
|
3961
4184
|
let outputVariables = 0;
|
3962
|
-
|
3963
|
-
|
3964
|
-
|
4185
|
+
let gasUsed = bn16(0);
|
4186
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4187
|
+
if (isScriptTransaction) {
|
4188
|
+
if (signatureCallback) {
|
4189
|
+
await signatureCallback(txRequestClone);
|
4190
|
+
}
|
4191
|
+
txRequestClone.gasLimit = gasLimit;
|
3965
4192
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3966
4193
|
receipts = result.receipts;
|
3967
4194
|
outputVariables = result.outputVariables;
|
3968
4195
|
missingContractIds = result.missingContractIds;
|
4196
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4197
|
+
txRequestClone.gasLimit = gasUsed;
|
4198
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4199
|
+
transactionRequest: txRequestClone,
|
4200
|
+
gasPrice
|
4201
|
+
}));
|
3969
4202
|
}
|
3970
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3971
|
-
const usedFee = calculatePriceWithFactor(
|
3972
|
-
gasUsed,
|
3973
|
-
gasPrice,
|
3974
|
-
gasPriceFactor
|
3975
|
-
).normalizeZeroToOne();
|
3976
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3977
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3978
4203
|
return {
|
3979
4204
|
requiredQuantities: allQuantities,
|
3980
4205
|
receipts,
|
3981
4206
|
gasUsed,
|
3982
|
-
minGasPrice,
|
3983
4207
|
gasPrice,
|
3984
4208
|
minGas,
|
3985
4209
|
maxGas,
|
3986
|
-
usedFee,
|
3987
4210
|
minFee,
|
3988
4211
|
maxFee,
|
3989
|
-
estimatedInputs: txRequestClone.inputs,
|
3990
4212
|
outputVariables,
|
3991
|
-
missingContractIds
|
4213
|
+
missingContractIds,
|
4214
|
+
addedSignatures,
|
4215
|
+
estimatedPredicates: txRequestClone.inputs
|
3992
4216
|
};
|
3993
4217
|
}
|
3994
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4218
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
3995
4219
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
3996
4220
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
3997
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4221
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4222
|
+
quantitiesToContract
|
4223
|
+
});
|
3998
4224
|
transactionRequest.addResources(
|
3999
4225
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4000
4226
|
);
|
4001
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4002
|
-
|
4003
|
-
|
4004
|
-
);
|
4227
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4228
|
+
quantitiesToContract
|
4229
|
+
});
|
4005
4230
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4006
4231
|
return {
|
4007
4232
|
resources,
|
@@ -4023,11 +4248,10 @@ var _Provider = class {
|
|
4023
4248
|
return coins.map((coin) => ({
|
4024
4249
|
id: coin.utxoId,
|
4025
4250
|
assetId: coin.assetId,
|
4026
|
-
amount:
|
4251
|
+
amount: bn16(coin.amount),
|
4027
4252
|
owner: Address2.fromAddressOrString(coin.owner),
|
4028
|
-
|
4029
|
-
|
4030
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4253
|
+
blockCreated: bn16(coin.blockCreated),
|
4254
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4031
4255
|
}));
|
4032
4256
|
}
|
4033
4257
|
/**
|
@@ -4064,9 +4288,9 @@ var _Provider = class {
|
|
4064
4288
|
switch (coin.__typename) {
|
4065
4289
|
case "MessageCoin":
|
4066
4290
|
return {
|
4067
|
-
amount:
|
4291
|
+
amount: bn16(coin.amount),
|
4068
4292
|
assetId: coin.assetId,
|
4069
|
-
daHeight:
|
4293
|
+
daHeight: bn16(coin.daHeight),
|
4070
4294
|
sender: Address2.fromAddressOrString(coin.sender),
|
4071
4295
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4072
4296
|
nonce: coin.nonce
|
@@ -4074,12 +4298,11 @@ var _Provider = class {
|
|
4074
4298
|
case "Coin":
|
4075
4299
|
return {
|
4076
4300
|
id: coin.utxoId,
|
4077
|
-
amount:
|
4301
|
+
amount: bn16(coin.amount),
|
4078
4302
|
assetId: coin.assetId,
|
4079
4303
|
owner: Address2.fromAddressOrString(coin.owner),
|
4080
|
-
|
4081
|
-
|
4082
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4304
|
+
blockCreated: bn16(coin.blockCreated),
|
4305
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4083
4306
|
};
|
4084
4307
|
default:
|
4085
4308
|
return null;
|
@@ -4096,13 +4319,13 @@ var _Provider = class {
|
|
4096
4319
|
async getBlock(idOrHeight) {
|
4097
4320
|
let variables;
|
4098
4321
|
if (typeof idOrHeight === "number") {
|
4099
|
-
variables = { height:
|
4322
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4100
4323
|
} else if (idOrHeight === "latest") {
|
4101
4324
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4102
4325
|
} else if (idOrHeight.length === 66) {
|
4103
4326
|
variables = { blockId: idOrHeight };
|
4104
4327
|
} else {
|
4105
|
-
variables = { blockId:
|
4328
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4106
4329
|
}
|
4107
4330
|
const { block } = await this.operations.getBlock(variables);
|
4108
4331
|
if (!block) {
|
@@ -4110,7 +4333,7 @@ var _Provider = class {
|
|
4110
4333
|
}
|
4111
4334
|
return {
|
4112
4335
|
id: block.id,
|
4113
|
-
height:
|
4336
|
+
height: bn16(block.height),
|
4114
4337
|
time: block.header.time,
|
4115
4338
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4116
4339
|
};
|
@@ -4125,7 +4348,7 @@ var _Provider = class {
|
|
4125
4348
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4126
4349
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4127
4350
|
id: block.id,
|
4128
|
-
height:
|
4351
|
+
height: bn16(block.height),
|
4129
4352
|
time: block.header.time,
|
4130
4353
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4131
4354
|
}));
|
@@ -4140,7 +4363,7 @@ var _Provider = class {
|
|
4140
4363
|
async getBlockWithTransactions(idOrHeight) {
|
4141
4364
|
let variables;
|
4142
4365
|
if (typeof idOrHeight === "number") {
|
4143
|
-
variables = { blockHeight:
|
4366
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4144
4367
|
} else if (idOrHeight === "latest") {
|
4145
4368
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4146
4369
|
} else {
|
@@ -4152,7 +4375,7 @@ var _Provider = class {
|
|
4152
4375
|
}
|
4153
4376
|
return {
|
4154
4377
|
id: block.id,
|
4155
|
-
height:
|
4378
|
+
height: bn16(block.height, 10),
|
4156
4379
|
time: block.header.time,
|
4157
4380
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4158
4381
|
transactions: block.transactions.map(
|
@@ -4201,7 +4424,7 @@ var _Provider = class {
|
|
4201
4424
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4202
4425
|
asset: hexlify12(assetId)
|
4203
4426
|
});
|
4204
|
-
return
|
4427
|
+
return bn16(contractBalance.amount, 10);
|
4205
4428
|
}
|
4206
4429
|
/**
|
4207
4430
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4215,7 +4438,7 @@ var _Provider = class {
|
|
4215
4438
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4216
4439
|
assetId: hexlify12(assetId)
|
4217
4440
|
});
|
4218
|
-
return
|
4441
|
+
return bn16(balance.amount, 10);
|
4219
4442
|
}
|
4220
4443
|
/**
|
4221
4444
|
* Returns balances for the given owner.
|
@@ -4233,7 +4456,7 @@ var _Provider = class {
|
|
4233
4456
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4234
4457
|
return balances.map((balance) => ({
|
4235
4458
|
assetId: balance.assetId,
|
4236
|
-
amount:
|
4459
|
+
amount: bn16(balance.amount)
|
4237
4460
|
}));
|
4238
4461
|
}
|
4239
4462
|
/**
|
@@ -4255,15 +4478,15 @@ var _Provider = class {
|
|
4255
4478
|
sender: message.sender,
|
4256
4479
|
recipient: message.recipient,
|
4257
4480
|
nonce: message.nonce,
|
4258
|
-
amount:
|
4481
|
+
amount: bn16(message.amount),
|
4259
4482
|
data: message.data
|
4260
4483
|
}),
|
4261
4484
|
sender: Address2.fromAddressOrString(message.sender),
|
4262
4485
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4263
4486
|
nonce: message.nonce,
|
4264
|
-
amount:
|
4487
|
+
amount: bn16(message.amount),
|
4265
4488
|
data: InputMessageCoder.decodeData(message.data),
|
4266
|
-
daHeight:
|
4489
|
+
daHeight: bn16(message.daHeight)
|
4267
4490
|
}));
|
4268
4491
|
}
|
4269
4492
|
/**
|
@@ -4316,44 +4539,60 @@ var _Provider = class {
|
|
4316
4539
|
} = result.messageProof;
|
4317
4540
|
return {
|
4318
4541
|
messageProof: {
|
4319
|
-
proofIndex:
|
4542
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4320
4543
|
proofSet: messageProof.proofSet
|
4321
4544
|
},
|
4322
4545
|
blockProof: {
|
4323
|
-
proofIndex:
|
4546
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4324
4547
|
proofSet: blockProof.proofSet
|
4325
4548
|
},
|
4326
4549
|
messageBlockHeader: {
|
4327
4550
|
id: messageBlockHeader.id,
|
4328
|
-
daHeight:
|
4329
|
-
transactionsCount:
|
4551
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4552
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4330
4553
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4331
|
-
height:
|
4554
|
+
height: bn16(messageBlockHeader.height),
|
4332
4555
|
prevRoot: messageBlockHeader.prevRoot,
|
4333
4556
|
time: messageBlockHeader.time,
|
4334
4557
|
applicationHash: messageBlockHeader.applicationHash,
|
4335
|
-
|
4336
|
-
|
4558
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4559
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4560
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4561
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4562
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4337
4563
|
},
|
4338
4564
|
commitBlockHeader: {
|
4339
4565
|
id: commitBlockHeader.id,
|
4340
|
-
daHeight:
|
4341
|
-
transactionsCount:
|
4566
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4567
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4342
4568
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4343
|
-
height:
|
4569
|
+
height: bn16(commitBlockHeader.height),
|
4344
4570
|
prevRoot: commitBlockHeader.prevRoot,
|
4345
4571
|
time: commitBlockHeader.time,
|
4346
4572
|
applicationHash: commitBlockHeader.applicationHash,
|
4347
|
-
|
4348
|
-
|
4573
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4574
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4575
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4576
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4577
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4349
4578
|
},
|
4350
4579
|
sender: Address2.fromAddressOrString(sender),
|
4351
4580
|
recipient: Address2.fromAddressOrString(recipient),
|
4352
4581
|
nonce,
|
4353
|
-
amount:
|
4582
|
+
amount: bn16(amount),
|
4354
4583
|
data
|
4355
4584
|
};
|
4356
4585
|
}
|
4586
|
+
async getLatestGasPrice() {
|
4587
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4588
|
+
return bn16(latestGasPrice.gasPrice);
|
4589
|
+
}
|
4590
|
+
async estimateGasPrice(blockHorizon) {
|
4591
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4592
|
+
blockHorizon: String(blockHorizon)
|
4593
|
+
});
|
4594
|
+
return bn16(estimateGasPrice.gasPrice);
|
4595
|
+
}
|
4357
4596
|
/**
|
4358
4597
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4359
4598
|
*
|
@@ -4373,10 +4612,10 @@ var _Provider = class {
|
|
4373
4612
|
*/
|
4374
4613
|
async produceBlocks(amount, startTime) {
|
4375
4614
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4376
|
-
blocksToProduce:
|
4615
|
+
blocksToProduce: bn16(amount).toString(10),
|
4377
4616
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4378
4617
|
});
|
4379
|
-
return
|
4618
|
+
return bn16(latestBlockHeight);
|
4380
4619
|
}
|
4381
4620
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4382
4621
|
async getTransactionResponse(transactionId) {
|
@@ -4390,7 +4629,7 @@ cacheInputs_fn = function(inputs) {
|
|
4390
4629
|
return;
|
4391
4630
|
}
|
4392
4631
|
inputs.forEach((input) => {
|
4393
|
-
if (input.type ===
|
4632
|
+
if (input.type === InputType7.Coin) {
|
4394
4633
|
this.cache?.set(input.id);
|
4395
4634
|
}
|
4396
4635
|
});
|
@@ -4400,7 +4639,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4400
4639
|
|
4401
4640
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4402
4641
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4403
|
-
import { bn as
|
4642
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4404
4643
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4405
4644
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4406
4645
|
|
@@ -4608,9 +4847,8 @@ var Account = class extends AbstractAccount {
|
|
4608
4847
|
* @param assetId - The asset ID to check the balance for.
|
4609
4848
|
* @returns A promise that resolves to the balance amount.
|
4610
4849
|
*/
|
4611
|
-
async getBalance(assetId) {
|
4612
|
-
const
|
4613
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4850
|
+
async getBalance(assetId = BaseAssetId3) {
|
4851
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4614
4852
|
return amount;
|
4615
4853
|
}
|
4616
4854
|
/**
|
@@ -4647,37 +4885,33 @@ var Account = class extends AbstractAccount {
|
|
4647
4885
|
* @param fee - The estimated transaction fee.
|
4648
4886
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4649
4887
|
*/
|
4650
|
-
async fund(request,
|
4651
|
-
const
|
4652
|
-
const
|
4653
|
-
|
4654
|
-
|
4655
|
-
|
4888
|
+
async fund(request, params) {
|
4889
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4890
|
+
const txRequest = request;
|
4891
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4892
|
+
amount: bn18(fee),
|
4893
|
+
assetId: BaseAssetId3,
|
4894
|
+
coinQuantities: requiredQuantities
|
4656
4895
|
});
|
4657
4896
|
const quantitiesDict = {};
|
4658
|
-
|
4897
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4659
4898
|
quantitiesDict[assetId] = {
|
4660
4899
|
required: amount,
|
4661
|
-
owned:
|
4900
|
+
owned: bn18(0)
|
4662
4901
|
};
|
4663
4902
|
});
|
4664
|
-
|
4665
|
-
const cachedMessages = [];
|
4666
|
-
const owner = this.address.toB256();
|
4667
|
-
request.inputs.forEach((input) => {
|
4903
|
+
txRequest.inputs.forEach((input) => {
|
4668
4904
|
const isResource = "amount" in input;
|
4669
4905
|
if (isResource) {
|
4670
4906
|
const isCoin2 = "owner" in input;
|
4671
4907
|
if (isCoin2) {
|
4672
4908
|
const assetId = String(input.assetId);
|
4673
|
-
if (
|
4674
|
-
const amount =
|
4909
|
+
if (quantitiesDict[assetId]) {
|
4910
|
+
const amount = bn18(input.amount);
|
4675
4911
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4676
|
-
cachedUtxos.push(input.id);
|
4677
4912
|
}
|
4678
|
-
} else if (input.
|
4679
|
-
quantitiesDict[
|
4680
|
-
cachedMessages.push(input.nonce);
|
4913
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4914
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4681
4915
|
}
|
4682
4916
|
}
|
4683
4917
|
});
|
@@ -4692,12 +4926,23 @@ var Account = class extends AbstractAccount {
|
|
4692
4926
|
});
|
4693
4927
|
const needsToBeFunded = missingQuantities.length;
|
4694
4928
|
if (needsToBeFunded) {
|
4695
|
-
const
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4929
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4930
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4931
|
+
txRequest.addResources(resources);
|
4932
|
+
}
|
4933
|
+
txRequest.shiftPredicateData();
|
4934
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4935
|
+
const requestToBeReEstimate = clone4(txRequest);
|
4936
|
+
if (addedSignatures) {
|
4937
|
+
Array.from({ length: addedSignatures }).forEach(
|
4938
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4939
|
+
);
|
4700
4940
|
}
|
4941
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4942
|
+
transactionRequest: requestToBeReEstimate
|
4943
|
+
});
|
4944
|
+
txRequest.maxFee = maxFee;
|
4945
|
+
return txRequest;
|
4701
4946
|
}
|
4702
4947
|
/**
|
4703
4948
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4705,30 +4950,25 @@ var Account = class extends AbstractAccount {
|
|
4705
4950
|
* @param destination - The address of the destination.
|
4706
4951
|
* @param amount - The amount of coins to transfer.
|
4707
4952
|
* @param assetId - The asset ID of the coins to transfer.
|
4708
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4953
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4709
4954
|
* @returns A promise that resolves to the prepared transaction request.
|
4710
4955
|
*/
|
4711
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4712
|
-
const
|
4713
|
-
|
4714
|
-
const
|
4715
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4716
|
-
const request = new ScriptTransactionRequest(params);
|
4717
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4718
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4956
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4957
|
+
const request = new ScriptTransactionRequest(txParams);
|
4958
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4959
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4719
4960
|
estimateTxDependencies: true,
|
4720
4961
|
resourcesOwner: this
|
4721
4962
|
});
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4729
|
-
|
4730
|
-
await this.fund(request,
|
4731
|
-
request.updatePredicateInputs(estimatedInputs);
|
4963
|
+
if ("gasLimit" in txParams) {
|
4964
|
+
this.validateGas({
|
4965
|
+
gasUsed: txCost.gasUsed,
|
4966
|
+
gasLimit: request.gasLimit
|
4967
|
+
});
|
4968
|
+
}
|
4969
|
+
request.gasLimit = txCost.gasUsed;
|
4970
|
+
request.maxFee = txCost.maxFee;
|
4971
|
+
await this.fund(request, txCost);
|
4732
4972
|
return request;
|
4733
4973
|
}
|
4734
4974
|
/**
|
@@ -4740,15 +4980,14 @@ var Account = class extends AbstractAccount {
|
|
4740
4980
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4741
4981
|
* @returns A promise that resolves to the transaction response.
|
4742
4982
|
*/
|
4743
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4744
|
-
if (
|
4983
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4984
|
+
if (bn18(amount).lte(0)) {
|
4745
4985
|
throw new FuelError15(
|
4746
4986
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4747
4987
|
"Transfer amount must be a positive number."
|
4748
4988
|
);
|
4749
4989
|
}
|
4750
|
-
const
|
4751
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4990
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4752
4991
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4753
4992
|
}
|
4754
4993
|
/**
|
@@ -4760,41 +4999,38 @@ var Account = class extends AbstractAccount {
|
|
4760
4999
|
* @param txParams - The optional transaction parameters.
|
4761
5000
|
* @returns A promise that resolves to the transaction response.
|
4762
5001
|
*/
|
4763
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4764
|
-
if (
|
5002
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5003
|
+
if (bn18(amount).lte(0)) {
|
4765
5004
|
throw new FuelError15(
|
4766
5005
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4767
5006
|
"Transfer amount must be a positive number."
|
4768
5007
|
);
|
4769
5008
|
}
|
4770
5009
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4771
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4772
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4773
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4774
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4775
5010
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4776
5011
|
hexlifiedContractId: contractAddress.toB256(),
|
4777
|
-
amountToTransfer:
|
4778
|
-
assetId
|
5012
|
+
amountToTransfer: bn18(amount),
|
5013
|
+
assetId
|
4779
5014
|
});
|
4780
5015
|
const request = new ScriptTransactionRequest({
|
4781
|
-
...
|
5016
|
+
...txParams,
|
4782
5017
|
script,
|
4783
5018
|
scriptData
|
4784
5019
|
});
|
4785
5020
|
request.addContractInputAndOutput(contractAddress);
|
4786
|
-
const
|
4787
|
-
|
4788
|
-
[{ amount:
|
4789
|
-
);
|
4790
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4791
|
-
this.validateGas({
|
4792
|
-
gasUsed,
|
4793
|
-
gasPrice: request.gasPrice,
|
4794
|
-
gasLimit: request.gasLimit,
|
4795
|
-
minGasPrice
|
5021
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5022
|
+
resourcesOwner: this,
|
5023
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
4796
5024
|
});
|
4797
|
-
|
5025
|
+
if (txParams.gasLimit) {
|
5026
|
+
this.validateGas({
|
5027
|
+
gasUsed: txCost.gasUsed,
|
5028
|
+
gasLimit: request.gasLimit
|
5029
|
+
});
|
5030
|
+
}
|
5031
|
+
request.gasLimit = txCost.gasUsed;
|
5032
|
+
request.maxFee = txCost.maxFee;
|
5033
|
+
await this.fund(request, txCost);
|
4798
5034
|
return this.sendTransaction(request);
|
4799
5035
|
}
|
4800
5036
|
/**
|
@@ -4806,40 +5042,31 @@ var Account = class extends AbstractAccount {
|
|
4806
5042
|
* @returns A promise that resolves to the transaction response.
|
4807
5043
|
*/
|
4808
5044
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4809
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4810
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4811
5045
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4812
5046
|
const recipientDataArray = arrayify14(
|
4813
5047
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4814
5048
|
);
|
4815
5049
|
const amountDataArray = arrayify14(
|
4816
|
-
"0x".concat(
|
5050
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4817
5051
|
);
|
4818
5052
|
const script = new Uint8Array([
|
4819
5053
|
...arrayify14(withdrawScript.bytes),
|
4820
5054
|
...recipientDataArray,
|
4821
5055
|
...amountDataArray
|
4822
5056
|
]);
|
4823
|
-
const params = {
|
4824
|
-
script,
|
4825
|
-
gasPrice: minGasPrice,
|
4826
|
-
baseAssetId,
|
4827
|
-
...txParams
|
4828
|
-
};
|
5057
|
+
const params = { script, ...txParams };
|
4829
5058
|
const request = new ScriptTransactionRequest(params);
|
4830
|
-
const
|
4831
|
-
const
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
});
|
4842
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5059
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5060
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5061
|
+
if (txParams.gasLimit) {
|
5062
|
+
this.validateGas({
|
5063
|
+
gasUsed: txCost.gasUsed,
|
5064
|
+
gasLimit: request.gasLimit
|
5065
|
+
});
|
5066
|
+
}
|
5067
|
+
request.maxFee = txCost.maxFee;
|
5068
|
+
request.gasLimit = txCost.gasUsed;
|
5069
|
+
await this.fund(request, txCost);
|
4843
5070
|
return this.sendTransaction(request);
|
4844
5071
|
}
|
4845
5072
|
async signMessage(message) {
|
@@ -4897,18 +5124,7 @@ var Account = class extends AbstractAccount {
|
|
4897
5124
|
}
|
4898
5125
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4899
5126
|
}
|
4900
|
-
validateGas({
|
4901
|
-
gasUsed,
|
4902
|
-
gasPrice,
|
4903
|
-
gasLimit,
|
4904
|
-
minGasPrice
|
4905
|
-
}) {
|
4906
|
-
if (minGasPrice.gt(gasPrice)) {
|
4907
|
-
throw new FuelError15(
|
4908
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4909
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4910
|
-
);
|
4911
|
-
}
|
5127
|
+
validateGas({ gasUsed, gasLimit }) {
|
4912
5128
|
if (gasUsed.gt(gasLimit)) {
|
4913
5129
|
throw new FuelError15(
|
4914
5130
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -4920,7 +5136,7 @@ var Account = class extends AbstractAccount {
|
|
4920
5136
|
|
4921
5137
|
// src/signer/signer.ts
|
4922
5138
|
import { Address as Address4 } from "@fuel-ts/address";
|
4923
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5139
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
4924
5140
|
import { hash } from "@fuel-ts/hasher";
|
4925
5141
|
import { toBytes } from "@fuel-ts/math";
|
4926
5142
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5013,7 +5229,7 @@ var Signer = class {
|
|
5013
5229
|
* @returns random 32-byte hashed
|
5014
5230
|
*/
|
5015
5231
|
static generatePrivateKey(entropy) {
|
5016
|
-
return entropy ? hash(concat3([
|
5232
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5017
5233
|
}
|
5018
5234
|
/**
|
5019
5235
|
* Extended publicKey from a compact publicKey
|
@@ -5032,7 +5248,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5032
5248
|
import {
|
5033
5249
|
bufferFromString,
|
5034
5250
|
keccak256,
|
5035
|
-
randomBytes as
|
5251
|
+
randomBytes as randomBytes3,
|
5036
5252
|
scrypt,
|
5037
5253
|
stringFromBuffer,
|
5038
5254
|
decryptJsonWalletData,
|
@@ -5055,7 +5271,7 @@ var removeHexPrefix = (hexString) => {
|
|
5055
5271
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5056
5272
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5057
5273
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5058
|
-
const salt =
|
5274
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5059
5275
|
const key = scrypt({
|
5060
5276
|
password: bufferFromString(password),
|
5061
5277
|
salt,
|
@@ -5064,7 +5280,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5064
5280
|
r: DEFAULT_KDF_PARAMS_R,
|
5065
5281
|
p: DEFAULT_KDF_PARAMS_P
|
5066
5282
|
});
|
5067
|
-
const iv =
|
5283
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5068
5284
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5069
5285
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5070
5286
|
const macHashUint8Array = keccak256(data);
|
@@ -5200,7 +5416,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5200
5416
|
* @param transactionRequestLike - The transaction request to send.
|
5201
5417
|
* @returns A promise that resolves to the TransactionResponse object.
|
5202
5418
|
*/
|
5203
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5419
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5204
5420
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5205
5421
|
if (estimateTxDependencies) {
|
5206
5422
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5241,12 +5457,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5241
5457
|
// src/hdwallet/hdwallet.ts
|
5242
5458
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5243
5459
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5244
|
-
import { bn as
|
5460
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5245
5461
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5246
5462
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5247
5463
|
|
5248
5464
|
// src/mnemonic/mnemonic.ts
|
5249
|
-
import { randomBytes as
|
5465
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5250
5466
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5251
5467
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5252
5468
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7601,7 +7817,7 @@ var Mnemonic = class {
|
|
7601
7817
|
* @returns A randomly generated mnemonic
|
7602
7818
|
*/
|
7603
7819
|
static generate(size = 32, extraEntropy = "") {
|
7604
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7820
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7605
7821
|
return Mnemonic.entropyToMnemonic(entropy);
|
7606
7822
|
}
|
7607
7823
|
};
|
@@ -7707,7 +7923,7 @@ var HDWallet = class {
|
|
7707
7923
|
const IR = bytes.slice(32);
|
7708
7924
|
if (privateKey) {
|
7709
7925
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7710
|
-
const ki =
|
7926
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7711
7927
|
return new HDWallet({
|
7712
7928
|
privateKey: ki,
|
7713
7929
|
chainCode: IR,
|
@@ -7972,22 +8188,21 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7972
8188
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7973
8189
|
|
7974
8190
|
// src/test-utils/seedTestWallet.ts
|
7975
|
-
import { randomBytes as
|
8191
|
+
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7976
8192
|
var seedTestWallet = async (wallet, quantities) => {
|
7977
8193
|
const genesisWallet = new WalletUnlocked(
|
7978
|
-
process.env.GENESIS_SECRET ||
|
8194
|
+
process.env.GENESIS_SECRET || randomBytes5(32),
|
7979
8195
|
wallet.provider
|
7980
8196
|
);
|
7981
|
-
const
|
7982
|
-
|
7983
|
-
|
7984
|
-
|
7985
|
-
baseAssetId,
|
7986
|
-
gasLimit: 1e4,
|
7987
|
-
gasPrice: minGasPrice
|
8197
|
+
const request = new ScriptTransactionRequest();
|
8198
|
+
quantities.forEach((quantity) => {
|
8199
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8200
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7988
8201
|
});
|
7989
|
-
|
7990
|
-
|
8202
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8203
|
+
request.gasLimit = txCost.gasUsed;
|
8204
|
+
request.maxFee = txCost.maxFee;
|
8205
|
+
await genesisWallet.fund(request, txCost);
|
7991
8206
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
7992
8207
|
};
|
7993
8208
|
|
@@ -8001,12 +8216,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8001
8216
|
};
|
8002
8217
|
|
8003
8218
|
// src/test-utils/launchNode.ts
|
8004
|
-
import {
|
8005
|
-
import {
|
8006
|
-
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8219
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8220
|
+
import { defaultChainConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8007
8221
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8008
8222
|
import { spawn } from "child_process";
|
8009
8223
|
import { randomUUID } from "crypto";
|
8224
|
+
import { randomBytes as randomBytes6 } from "ethers";
|
8010
8225
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8011
8226
|
import os from "os";
|
8012
8227
|
import path from "path";
|
@@ -8055,12 +8270,12 @@ var launchNode = async ({
|
|
8055
8270
|
// eslint-disable-next-line no-async-promise-executor
|
8056
8271
|
new Promise(async (resolve, reject) => {
|
8057
8272
|
const remainingArgs = extractRemainingArgs(args, [
|
8058
|
-
"--
|
8273
|
+
"--snapshot",
|
8059
8274
|
"--consensus-key",
|
8060
8275
|
"--db-type",
|
8061
8276
|
"--poa-instant"
|
8062
8277
|
]);
|
8063
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8278
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8064
8279
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8065
8280
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8066
8281
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8079,36 +8294,54 @@ var launchNode = async ({
|
|
8079
8294
|
let chainConfigPathToUse;
|
8080
8295
|
const prefix = basePath || os.tmpdir();
|
8081
8296
|
const suffix = basePath ? "" : randomUUID();
|
8082
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8297
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "chainConfigs");
|
8083
8298
|
if (chainConfigPath) {
|
8084
8299
|
chainConfigPathToUse = chainConfigPath;
|
8085
8300
|
} else {
|
8086
8301
|
if (!existsSync(tempDirPath)) {
|
8087
8302
|
mkdirSync(tempDirPath, { recursive: true });
|
8088
8303
|
}
|
8089
|
-
|
8090
|
-
|
8304
|
+
let { stateConfigJson } = defaultChainConfigs;
|
8305
|
+
const { chainConfigJson, metadataJson } = defaultChainConfigs;
|
8306
|
+
stateConfigJson = {
|
8307
|
+
...stateConfigJson,
|
8308
|
+
coins: [
|
8309
|
+
...stateConfigJson.coins.map((coin) => ({
|
8310
|
+
...coin,
|
8311
|
+
amount: "18446744073709551615"
|
8312
|
+
}))
|
8313
|
+
],
|
8314
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8315
|
+
...message,
|
8316
|
+
amount: "18446744073709551615"
|
8317
|
+
}))
|
8318
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8319
|
+
};
|
8091
8320
|
if (!process.env.GENESIS_SECRET) {
|
8092
8321
|
const pk = Signer.generatePrivateKey();
|
8093
8322
|
const signer = new Signer(pk);
|
8094
8323
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8095
|
-
|
8096
|
-
|
8097
|
-
|
8098
|
-
|
8099
|
-
|
8100
|
-
|
8101
|
-
|
8102
|
-
|
8103
|
-
|
8104
|
-
|
8105
|
-
}
|
8106
|
-
]
|
8107
|
-
}
|
8108
|
-
};
|
8324
|
+
stateConfigJson.coins.push({
|
8325
|
+
tx_id: hexlify18(randomBytes6(34)),
|
8326
|
+
owner: signer.address.toHexString(),
|
8327
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8328
|
+
amount: "18446744073709551615",
|
8329
|
+
asset_id: BaseAssetId4,
|
8330
|
+
output_index: 0,
|
8331
|
+
tx_pointer_block_height: 0,
|
8332
|
+
tx_pointer_tx_idx: 0
|
8333
|
+
});
|
8109
8334
|
}
|
8110
|
-
|
8111
|
-
|
8335
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8336
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8337
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8338
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8339
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8340
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8341
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8342
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8343
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8344
|
+
chainConfigPathToUse = tempDirPath;
|
8112
8345
|
}
|
8113
8346
|
const child = spawn(
|
8114
8347
|
command,
|
@@ -8117,10 +8350,10 @@ var launchNode = async ({
|
|
8117
8350
|
["--ip", ipToUse],
|
8118
8351
|
["--port", portToUse],
|
8119
8352
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8120
|
-
["--min-gas-price", "
|
8353
|
+
["--min-gas-price", "1"],
|
8121
8354
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8122
8355
|
["--consensus-key", consensusKey],
|
8123
|
-
["--
|
8356
|
+
["--snapshot", chainConfigPathToUse],
|
8124
8357
|
"--vm-backtrace",
|
8125
8358
|
"--utxo-validation",
|
8126
8359
|
"--debug",
|
@@ -8167,10 +8400,9 @@ var launchNode = async ({
|
|
8167
8400
|
})
|
8168
8401
|
);
|
8169
8402
|
var generateWallets = async (count, provider) => {
|
8170
|
-
const baseAssetId = provider.getBaseAssetId();
|
8171
8403
|
const wallets = [];
|
8172
8404
|
for (let i = 0; i < count; i += 1) {
|
8173
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8405
|
+
const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
|
8174
8406
|
wallets.push(wallet);
|
8175
8407
|
}
|
8176
8408
|
return wallets;
|
@@ -8180,7 +8412,7 @@ var launchNodeAndGetWallets = async ({
|
|
8180
8412
|
walletCount = 10
|
8181
8413
|
} = {}) => {
|
8182
8414
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8183
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8415
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8184
8416
|
const wallets = await generateWallets(walletCount, provider);
|
8185
8417
|
const cleanup = () => {
|
8186
8418
|
closeNode();
|