@fuel-ts/account 0.0.0-rc-2021-20240415193305 → 0.0.0-rc-2045-20240416150348
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +545 -796
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +507 -762
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +388 -642
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +329 -911
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- 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 +1 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -37
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +25 -8
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1057 -1546
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +503 -740
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +397 -634
- 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
@@ -27,9 +27,8 @@ import { Address as Address3 } from "@fuel-ts/address";
|
|
27
27
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
30
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
31
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
-
import { clone as clone4 } from "ramda";
|
33
32
|
|
34
33
|
// src/providers/coin-quantity.ts
|
35
34
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
@@ -55,7 +54,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
55
54
|
max: max2 ? bn(max2) : void 0
|
56
55
|
};
|
57
56
|
};
|
58
|
-
var
|
57
|
+
var addAmountToAsset = (params) => {
|
59
58
|
const { amount, assetId } = params;
|
60
59
|
const coinQuantities = [...params.coinQuantities];
|
61
60
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -70,9 +69,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
70
69
|
// src/providers/provider.ts
|
71
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
72
71
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
73
|
-
import { BN, bn as
|
72
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
74
73
|
import {
|
75
|
-
InputType as
|
74
|
+
InputType as InputType6,
|
76
75
|
TransactionType as TransactionType8,
|
77
76
|
InputMessageCoder,
|
78
77
|
TransactionCoder as TransactionCoder5
|
@@ -88,10 +87,14 @@ import { clone as clone3 } from "ramda";
|
|
88
87
|
import gql from "graphql-tag";
|
89
88
|
var ReceiptFragmentFragmentDoc = gql`
|
90
89
|
fragment receiptFragment on Receipt {
|
91
|
-
|
90
|
+
contract {
|
91
|
+
id
|
92
|
+
}
|
92
93
|
pc
|
93
94
|
is
|
94
|
-
to
|
95
|
+
to {
|
96
|
+
id
|
97
|
+
}
|
95
98
|
toAddress
|
96
99
|
amount
|
97
100
|
assetId
|
@@ -129,16 +132,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
129
132
|
id
|
130
133
|
}
|
131
134
|
time
|
132
|
-
receipts {
|
133
|
-
...receiptFragment
|
134
|
-
}
|
135
135
|
programState {
|
136
136
|
returnType
|
137
137
|
data
|
138
138
|
}
|
139
|
-
receipts {
|
140
|
-
...receiptFragment
|
141
|
-
}
|
142
139
|
}
|
143
140
|
... on FailureStatus {
|
144
141
|
block {
|
@@ -146,24 +143,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
146
143
|
}
|
147
144
|
time
|
148
145
|
reason
|
149
|
-
receipts {
|
150
|
-
...receiptFragment
|
151
|
-
}
|
152
146
|
}
|
153
147
|
... on SqueezedOutStatus {
|
154
148
|
reason
|
155
149
|
}
|
156
150
|
}
|
157
|
-
|
151
|
+
`;
|
158
152
|
var TransactionFragmentFragmentDoc = gql`
|
159
153
|
fragment transactionFragment on Transaction {
|
160
154
|
id
|
161
155
|
rawPayload
|
156
|
+
gasPrice
|
157
|
+
receipts {
|
158
|
+
...receiptFragment
|
159
|
+
}
|
162
160
|
status {
|
163
161
|
...transactionStatusFragment
|
164
162
|
}
|
165
163
|
}
|
166
|
-
${
|
164
|
+
${ReceiptFragmentFragmentDoc}
|
165
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
167
166
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
168
167
|
fragment inputEstimatePredicatesFragment on Input {
|
169
168
|
... on InputCoin {
|
@@ -181,46 +180,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
181
180
|
}
|
182
181
|
}
|
183
182
|
${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}`;
|
224
183
|
var CoinFragmentFragmentDoc = gql`
|
225
184
|
fragment coinFragment on Coin {
|
226
185
|
__typename
|
@@ -228,6 +187,7 @@ var CoinFragmentFragmentDoc = gql`
|
|
228
187
|
owner
|
229
188
|
amount
|
230
189
|
assetId
|
190
|
+
maturity
|
231
191
|
blockCreated
|
232
192
|
txCreatedIdx
|
233
193
|
}
|
@@ -266,32 +226,26 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
266
226
|
messageBlockHeader {
|
267
227
|
id
|
268
228
|
daHeight
|
269
|
-
consensusParametersVersion
|
270
|
-
stateTransitionBytecodeVersion
|
271
229
|
transactionsCount
|
272
|
-
messageReceiptCount
|
273
230
|
transactionsRoot
|
274
|
-
messageOutboxRoot
|
275
|
-
eventInboxRoot
|
276
231
|
height
|
277
232
|
prevRoot
|
278
233
|
time
|
279
234
|
applicationHash
|
235
|
+
messageReceiptRoot
|
236
|
+
messageReceiptCount
|
280
237
|
}
|
281
238
|
commitBlockHeader {
|
282
239
|
id
|
283
240
|
daHeight
|
284
|
-
consensusParametersVersion
|
285
|
-
stateTransitionBytecodeVersion
|
286
241
|
transactionsCount
|
287
|
-
messageReceiptCount
|
288
242
|
transactionsRoot
|
289
|
-
messageOutboxRoot
|
290
|
-
eventInboxRoot
|
291
243
|
height
|
292
244
|
prevRoot
|
293
245
|
time
|
294
246
|
applicationHash
|
247
|
+
messageReceiptRoot
|
248
|
+
messageReceiptCount
|
295
249
|
}
|
296
250
|
sender
|
297
251
|
recipient
|
@@ -310,8 +264,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
310
264
|
var BlockFragmentFragmentDoc = gql`
|
311
265
|
fragment blockFragment on Block {
|
312
266
|
id
|
313
|
-
height
|
314
267
|
header {
|
268
|
+
height
|
315
269
|
time
|
316
270
|
}
|
317
271
|
transactions {
|
@@ -369,11 +323,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
369
323
|
`;
|
370
324
|
var GasCostsFragmentFragmentDoc = gql`
|
371
325
|
fragment GasCostsFragment on GasCosts {
|
372
|
-
version {
|
373
|
-
... on Version {
|
374
|
-
value
|
375
|
-
}
|
376
|
-
}
|
377
326
|
add
|
378
327
|
addi
|
379
328
|
aloc
|
@@ -386,6 +335,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
386
335
|
cb
|
387
336
|
cfei
|
388
337
|
cfsi
|
338
|
+
croo
|
389
339
|
div
|
390
340
|
divi
|
391
341
|
ecr1
|
@@ -468,9 +418,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
468
418
|
ccp {
|
469
419
|
...DependentCostFragment
|
470
420
|
}
|
471
|
-
croo {
|
472
|
-
...DependentCostFragment
|
473
|
-
}
|
474
421
|
csiz {
|
475
422
|
...DependentCostFragment
|
476
423
|
}
|
@@ -530,11 +477,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
530
477
|
${DependentCostFragmentFragmentDoc}`;
|
531
478
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
532
479
|
fragment consensusParametersFragment on ConsensusParameters {
|
533
|
-
version {
|
534
|
-
... on Version {
|
535
|
-
value
|
536
|
-
}
|
537
|
-
}
|
538
480
|
txParams {
|
539
481
|
...TxParametersFragment
|
540
482
|
}
|
@@ -594,9 +536,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
594
536
|
fragment nodeInfoFragment on NodeInfo {
|
595
537
|
utxoValidation
|
596
538
|
vmBacktrace
|
539
|
+
minGasPrice
|
597
540
|
maxTx
|
598
541
|
maxDepth
|
599
542
|
nodeVersion
|
543
|
+
peers {
|
544
|
+
id
|
545
|
+
addresses
|
546
|
+
clientVersion
|
547
|
+
blockHeight
|
548
|
+
lastHeartbeatMs
|
549
|
+
appScore
|
550
|
+
}
|
600
551
|
}
|
601
552
|
`;
|
602
553
|
var GetVersionDocument = gql`
|
@@ -631,9 +582,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
631
582
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
632
583
|
transaction(id: $transactionId) {
|
633
584
|
...transactionFragment
|
585
|
+
receipts {
|
586
|
+
...receiptFragment
|
587
|
+
}
|
634
588
|
}
|
635
589
|
}
|
636
|
-
${TransactionFragmentFragmentDoc}
|
590
|
+
${TransactionFragmentFragmentDoc}
|
591
|
+
${ReceiptFragmentFragmentDoc}`;
|
637
592
|
var GetTransactionsDocument = gql`
|
638
593
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
639
594
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -761,20 +716,6 @@ var GetBalanceDocument = gql`
|
|
761
716
|
}
|
762
717
|
}
|
763
718
|
${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
|
-
`;
|
778
719
|
var GetBalancesDocument = gql`
|
779
720
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
780
721
|
balances(
|
@@ -829,12 +770,12 @@ var GetMessageStatusDocument = gql`
|
|
829
770
|
}
|
830
771
|
`;
|
831
772
|
var DryRunDocument = gql`
|
832
|
-
mutation dryRun($
|
833
|
-
dryRun(
|
834
|
-
...
|
773
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
774
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
775
|
+
...receiptFragment
|
835
776
|
}
|
836
777
|
}
|
837
|
-
${
|
778
|
+
${ReceiptFragmentFragmentDoc}`;
|
838
779
|
var SubmitDocument = gql`
|
839
780
|
mutation submit($encodedTransaction: HexString!) {
|
840
781
|
submit(tx: $encodedTransaction) {
|
@@ -917,12 +858,6 @@ function getSdk(requester) {
|
|
917
858
|
getBalance(variables, options) {
|
918
859
|
return requester(GetBalanceDocument, variables, options);
|
919
860
|
},
|
920
|
-
getLatestGasPrice(variables, options) {
|
921
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
922
|
-
},
|
923
|
-
estimateGasPrice(variables, options) {
|
924
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
925
|
-
},
|
926
861
|
getBalances(variables, options) {
|
927
862
|
return requester(GetBalancesDocument, variables, options);
|
928
863
|
},
|
@@ -992,14 +927,11 @@ var _FuelGraphqlSubscriber = class {
|
|
992
927
|
let data;
|
993
928
|
let errors;
|
994
929
|
try {
|
995
|
-
|
996
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
930
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
997
931
|
} catch (e) {
|
998
932
|
throw new FuelError(
|
999
933
|
ErrorCode.STREAM_PARSING_ERROR,
|
1000
|
-
`Error while parsing stream data response: ${text}
|
1001
|
-
|
1002
|
-
Thrown error: ${e}`
|
934
|
+
`Error while parsing stream data response: ${text}`
|
1003
935
|
);
|
1004
936
|
}
|
1005
937
|
if (Array.isArray(errors)) {
|
@@ -1110,9 +1042,10 @@ var inputify = (value) => {
|
|
1110
1042
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1111
1043
|
},
|
1112
1044
|
witnessIndex: value.witnessIndex,
|
1045
|
+
maturity: value.maturity ?? 0,
|
1113
1046
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1114
|
-
predicateLength:
|
1115
|
-
predicateDataLength:
|
1047
|
+
predicateLength: predicate.length,
|
1048
|
+
predicateDataLength: predicateData.length,
|
1116
1049
|
predicate: hexlify3(predicate),
|
1117
1050
|
predicateData: hexlify3(predicateData)
|
1118
1051
|
};
|
@@ -1143,8 +1076,8 @@ var inputify = (value) => {
|
|
1143
1076
|
nonce: hexlify3(value.nonce),
|
1144
1077
|
witnessIndex: value.witnessIndex,
|
1145
1078
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1146
|
-
predicateLength:
|
1147
|
-
predicateDataLength:
|
1079
|
+
predicateLength: predicate.length,
|
1080
|
+
predicateDataLength: predicateData.length,
|
1148
1081
|
predicate: hexlify3(predicate),
|
1149
1082
|
predicateData: hexlify3(predicateData),
|
1150
1083
|
data: hexlify3(data),
|
@@ -1271,8 +1204,8 @@ function assembleReceiptByType(receipt) {
|
|
1271
1204
|
case "CALL" /* Call */: {
|
1272
1205
|
const callReceipt = {
|
1273
1206
|
type: ReceiptType.Call,
|
1274
|
-
from: hexOrZero(receipt.id
|
1275
|
-
to: hexOrZero(receipt?.to),
|
1207
|
+
from: hexOrZero(receipt.contract?.id),
|
1208
|
+
to: hexOrZero(receipt?.to?.id),
|
1276
1209
|
amount: bn4(receipt.amount),
|
1277
1210
|
assetId: hexOrZero(receipt.assetId),
|
1278
1211
|
gas: bn4(receipt.gas),
|
@@ -1286,7 +1219,7 @@ function assembleReceiptByType(receipt) {
|
|
1286
1219
|
case "RETURN" /* Return */: {
|
1287
1220
|
const returnReceipt = {
|
1288
1221
|
type: ReceiptType.Return,
|
1289
|
-
id: hexOrZero(receipt.id
|
1222
|
+
id: hexOrZero(receipt.contract?.id),
|
1290
1223
|
val: bn4(receipt.val),
|
1291
1224
|
pc: bn4(receipt.pc),
|
1292
1225
|
is: bn4(receipt.is)
|
@@ -1296,7 +1229,7 @@ function assembleReceiptByType(receipt) {
|
|
1296
1229
|
case "RETURN_DATA" /* ReturnData */: {
|
1297
1230
|
const returnDataReceipt = {
|
1298
1231
|
type: ReceiptType.ReturnData,
|
1299
|
-
id: hexOrZero(receipt.id
|
1232
|
+
id: hexOrZero(receipt.contract?.id),
|
1300
1233
|
ptr: bn4(receipt.ptr),
|
1301
1234
|
len: bn4(receipt.len),
|
1302
1235
|
digest: hexOrZero(receipt.digest),
|
@@ -1308,7 +1241,7 @@ function assembleReceiptByType(receipt) {
|
|
1308
1241
|
case "PANIC" /* Panic */: {
|
1309
1242
|
const panicReceipt = {
|
1310
1243
|
type: ReceiptType.Panic,
|
1311
|
-
id: hexOrZero(receipt.id),
|
1244
|
+
id: hexOrZero(receipt.contract?.id),
|
1312
1245
|
reason: bn4(receipt.reason),
|
1313
1246
|
pc: bn4(receipt.pc),
|
1314
1247
|
is: bn4(receipt.is),
|
@@ -1319,7 +1252,7 @@ function assembleReceiptByType(receipt) {
|
|
1319
1252
|
case "REVERT" /* Revert */: {
|
1320
1253
|
const revertReceipt = {
|
1321
1254
|
type: ReceiptType.Revert,
|
1322
|
-
id: hexOrZero(receipt.id
|
1255
|
+
id: hexOrZero(receipt.contract?.id),
|
1323
1256
|
val: bn4(receipt.ra),
|
1324
1257
|
pc: bn4(receipt.pc),
|
1325
1258
|
is: bn4(receipt.is)
|
@@ -1329,7 +1262,7 @@ function assembleReceiptByType(receipt) {
|
|
1329
1262
|
case "LOG" /* Log */: {
|
1330
1263
|
const logReceipt = {
|
1331
1264
|
type: ReceiptType.Log,
|
1332
|
-
id: hexOrZero(receipt.id
|
1265
|
+
id: hexOrZero(receipt.contract?.id),
|
1333
1266
|
val0: bn4(receipt.ra),
|
1334
1267
|
val1: bn4(receipt.rb),
|
1335
1268
|
val2: bn4(receipt.rc),
|
@@ -1342,7 +1275,7 @@ function assembleReceiptByType(receipt) {
|
|
1342
1275
|
case "LOG_DATA" /* LogData */: {
|
1343
1276
|
const logDataReceipt = {
|
1344
1277
|
type: ReceiptType.LogData,
|
1345
|
-
id: hexOrZero(receipt.id
|
1278
|
+
id: hexOrZero(receipt.contract?.id),
|
1346
1279
|
val0: bn4(receipt.ra),
|
1347
1280
|
val1: bn4(receipt.rb),
|
1348
1281
|
ptr: bn4(receipt.ptr),
|
@@ -1356,8 +1289,8 @@ function assembleReceiptByType(receipt) {
|
|
1356
1289
|
case "TRANSFER" /* Transfer */: {
|
1357
1290
|
const transferReceipt = {
|
1358
1291
|
type: ReceiptType.Transfer,
|
1359
|
-
from: hexOrZero(receipt.id
|
1360
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1292
|
+
from: hexOrZero(receipt.contract?.id),
|
1293
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1361
1294
|
amount: bn4(receipt.amount),
|
1362
1295
|
assetId: hexOrZero(receipt.assetId),
|
1363
1296
|
pc: bn4(receipt.pc),
|
@@ -1368,8 +1301,8 @@ function assembleReceiptByType(receipt) {
|
|
1368
1301
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1369
1302
|
const transferOutReceipt = {
|
1370
1303
|
type: ReceiptType.TransferOut,
|
1371
|
-
from: hexOrZero(receipt.id
|
1372
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1304
|
+
from: hexOrZero(receipt.contract?.id),
|
1305
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1373
1306
|
amount: bn4(receipt.amount),
|
1374
1307
|
assetId: hexOrZero(receipt.assetId),
|
1375
1308
|
pc: bn4(receipt.pc),
|
@@ -1412,7 +1345,7 @@ function assembleReceiptByType(receipt) {
|
|
1412
1345
|
return receiptMessageOut;
|
1413
1346
|
}
|
1414
1347
|
case "MINT" /* Mint */: {
|
1415
|
-
const contractId = hexOrZero(receipt.id
|
1348
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1416
1349
|
const subId = hexOrZero(receipt.subId);
|
1417
1350
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1418
1351
|
const mintReceipt = {
|
@@ -1427,7 +1360,7 @@ function assembleReceiptByType(receipt) {
|
|
1427
1360
|
return mintReceipt;
|
1428
1361
|
}
|
1429
1362
|
case "BURN" /* Burn */: {
|
1430
|
-
const contractId = hexOrZero(receipt.id
|
1363
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1431
1364
|
const subId = hexOrZero(receipt.subId);
|
1432
1365
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1433
1366
|
const burnReceipt = {
|
@@ -1453,6 +1386,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1453
1386
|
import { bn as bn5 } from "@fuel-ts/math";
|
1454
1387
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1455
1388
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1389
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1456
1390
|
var getGasUsedFromReceipts = (receipts) => {
|
1457
1391
|
const scriptResult = receipts.filter(
|
1458
1392
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1473,28 +1407,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1473
1407
|
}
|
1474
1408
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1475
1409
|
const witnessCache = [];
|
1476
|
-
const
|
1477
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1478
|
-
if (isCoinOrMessage) {
|
1479
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1480
|
-
return true;
|
1481
|
-
}
|
1482
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1483
|
-
witnessCache.push(input.witnessIndex);
|
1484
|
-
return true;
|
1485
|
-
}
|
1486
|
-
}
|
1487
|
-
return false;
|
1488
|
-
});
|
1489
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1490
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1410
|
+
const totalGas = inputs.reduce((total, input) => {
|
1491
1411
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1492
1412
|
return total.add(
|
1493
|
-
|
1413
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1494
1414
|
);
|
1495
1415
|
}
|
1496
|
-
|
1497
|
-
|
1416
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1417
|
+
witnessCache.push(input.witnessIndex);
|
1418
|
+
return total.add(gasCosts.ecr1);
|
1419
|
+
}
|
1420
|
+
return total;
|
1421
|
+
}, bn5());
|
1498
1422
|
return totalGas;
|
1499
1423
|
}
|
1500
1424
|
function getMinGas(params) {
|
@@ -1506,20 +1430,12 @@ function getMinGas(params) {
|
|
1506
1430
|
return minGas;
|
1507
1431
|
}
|
1508
1432
|
function getMaxGas(params) {
|
1509
|
-
const {
|
1510
|
-
gasPerByte,
|
1511
|
-
witnessesLength,
|
1512
|
-
witnessLimit,
|
1513
|
-
minGas,
|
1514
|
-
gasLimit = bn5(0),
|
1515
|
-
maxGasPerTx
|
1516
|
-
} = params;
|
1433
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1517
1434
|
let remainingAllowedWitnessGas = bn5(0);
|
1518
1435
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1519
1436
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1520
1437
|
}
|
1521
|
-
|
1522
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1438
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1523
1439
|
}
|
1524
1440
|
function calculateMetadataGasForTxCreate({
|
1525
1441
|
gasCosts,
|
@@ -1541,10 +1457,6 @@ function calculateMetadataGasForTxScript({
|
|
1541
1457
|
}) {
|
1542
1458
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1543
1459
|
}
|
1544
|
-
var calculateGasFee = (params) => {
|
1545
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1546
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1547
|
-
};
|
1548
1460
|
|
1549
1461
|
// src/providers/utils/json.ts
|
1550
1462
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1689,7 +1601,7 @@ var witnessify = (value) => {
|
|
1689
1601
|
// src/providers/transaction-request/transaction-request.ts
|
1690
1602
|
var BaseTransactionRequest = class {
|
1691
1603
|
/** Gas price for transaction */
|
1692
|
-
|
1604
|
+
gasPrice;
|
1693
1605
|
/** Block until which tx cannot be included */
|
1694
1606
|
maturity;
|
1695
1607
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1708,7 +1620,7 @@ var BaseTransactionRequest = class {
|
|
1708
1620
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1709
1621
|
*/
|
1710
1622
|
constructor({
|
1711
|
-
|
1623
|
+
gasPrice,
|
1712
1624
|
maturity,
|
1713
1625
|
maxFee,
|
1714
1626
|
witnessLimit,
|
@@ -1716,7 +1628,7 @@ var BaseTransactionRequest = class {
|
|
1716
1628
|
outputs,
|
1717
1629
|
witnesses
|
1718
1630
|
} = {}) {
|
1719
|
-
this.
|
1631
|
+
this.gasPrice = bn7(gasPrice);
|
1720
1632
|
this.maturity = maturity ?? 0;
|
1721
1633
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1722
1634
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1727,9 +1639,9 @@ var BaseTransactionRequest = class {
|
|
1727
1639
|
static getPolicyMeta(req) {
|
1728
1640
|
let policyTypes = 0;
|
1729
1641
|
const policies = [];
|
1730
|
-
if (req.
|
1731
|
-
policyTypes += PolicyType.
|
1732
|
-
policies.push({ data: req.
|
1642
|
+
if (req.gasPrice) {
|
1643
|
+
policyTypes += PolicyType.GasPrice;
|
1644
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1733
1645
|
}
|
1734
1646
|
if (req.witnessLimit) {
|
1735
1647
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1916,10 +1828,10 @@ var BaseTransactionRequest = class {
|
|
1916
1828
|
* @param predicate - Predicate bytes.
|
1917
1829
|
* @param predicateData - Predicate data bytes.
|
1918
1830
|
*/
|
1919
|
-
addCoinInput(coin) {
|
1831
|
+
addCoinInput(coin, predicate) {
|
1920
1832
|
const { assetId, owner, amount } = coin;
|
1921
1833
|
let witnessIndex;
|
1922
|
-
if (
|
1834
|
+
if (predicate) {
|
1923
1835
|
witnessIndex = 0;
|
1924
1836
|
} else {
|
1925
1837
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1934,7 +1846,8 @@ var BaseTransactionRequest = class {
|
|
1934
1846
|
amount,
|
1935
1847
|
assetId,
|
1936
1848
|
txPointer: "0x00000000000000000000000000000000",
|
1937
|
-
witnessIndex
|
1849
|
+
witnessIndex,
|
1850
|
+
predicate: predicate?.bytes
|
1938
1851
|
};
|
1939
1852
|
this.pushInput(input);
|
1940
1853
|
this.addChangeOutput(owner, assetId);
|
@@ -1947,11 +1860,11 @@ var BaseTransactionRequest = class {
|
|
1947
1860
|
* @param predicate - Predicate bytes.
|
1948
1861
|
* @param predicateData - Predicate data bytes.
|
1949
1862
|
*/
|
1950
|
-
addMessageInput(message) {
|
1863
|
+
addMessageInput(message, predicate) {
|
1951
1864
|
const { recipient, sender, amount } = message;
|
1952
1865
|
const assetId = BaseAssetId2;
|
1953
1866
|
let witnessIndex;
|
1954
|
-
if (
|
1867
|
+
if (predicate) {
|
1955
1868
|
witnessIndex = 0;
|
1956
1869
|
} else {
|
1957
1870
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1965,7 +1878,8 @@ var BaseTransactionRequest = class {
|
|
1965
1878
|
sender: sender.toB256(),
|
1966
1879
|
recipient: recipient.toB256(),
|
1967
1880
|
amount,
|
1968
|
-
witnessIndex
|
1881
|
+
witnessIndex,
|
1882
|
+
predicate: predicate?.bytes
|
1969
1883
|
};
|
1970
1884
|
this.pushInput(input);
|
1971
1885
|
this.addChangeOutput(recipient, assetId);
|
@@ -1996,6 +1910,32 @@ var BaseTransactionRequest = class {
|
|
1996
1910
|
resources.forEach((resource) => this.addResource(resource));
|
1997
1911
|
return this;
|
1998
1912
|
}
|
1913
|
+
/**
|
1914
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1915
|
+
* outputs from the related assetIds.
|
1916
|
+
*
|
1917
|
+
* @param resources - The resources to add.
|
1918
|
+
* @returns This transaction.
|
1919
|
+
*/
|
1920
|
+
addPredicateResource(resource, predicate) {
|
1921
|
+
if (isCoin(resource)) {
|
1922
|
+
this.addCoinInput(resource, predicate);
|
1923
|
+
} else {
|
1924
|
+
this.addMessageInput(resource, predicate);
|
1925
|
+
}
|
1926
|
+
return this;
|
1927
|
+
}
|
1928
|
+
/**
|
1929
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1930
|
+
* from the related assetIds.
|
1931
|
+
*
|
1932
|
+
* @param resources - The resources to add.
|
1933
|
+
* @returns This transaction.
|
1934
|
+
*/
|
1935
|
+
addPredicateResources(resources, predicate) {
|
1936
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1937
|
+
return this;
|
1938
|
+
}
|
1999
1939
|
/**
|
2000
1940
|
* Adds a coin output to the transaction.
|
2001
1941
|
*
|
@@ -2075,7 +2015,7 @@ var BaseTransactionRequest = class {
|
|
2075
2015
|
}
|
2076
2016
|
calculateMaxGas(chainInfo, minGas) {
|
2077
2017
|
const { consensusParameters } = chainInfo;
|
2078
|
-
const { gasPerByte
|
2018
|
+
const { gasPerByte } = consensusParameters;
|
2079
2019
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2080
2020
|
(acc, wit) => acc + wit.dataLength,
|
2081
2021
|
0
|
@@ -2084,8 +2024,7 @@ var BaseTransactionRequest = class {
|
|
2084
2024
|
gasPerByte,
|
2085
2025
|
minGas,
|
2086
2026
|
witnessesLength,
|
2087
|
-
witnessLimit: this.witnessLimit
|
2088
|
-
maxGasPerTx
|
2027
|
+
witnessLimit: this.witnessLimit
|
2089
2028
|
});
|
2090
2029
|
}
|
2091
2030
|
/**
|
@@ -2103,20 +2042,17 @@ var BaseTransactionRequest = class {
|
|
2103
2042
|
});
|
2104
2043
|
const updateAssetInput = (assetId, quantity) => {
|
2105
2044
|
const assetInput = findAssetInput(assetId);
|
2106
|
-
let usedQuantity = quantity;
|
2107
|
-
if (assetId === BaseAssetId2) {
|
2108
|
-
usedQuantity = bn7("1000000000000000000");
|
2109
|
-
}
|
2110
2045
|
if (assetInput && "assetId" in assetInput) {
|
2111
2046
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2112
|
-
assetInput.amount =
|
2047
|
+
assetInput.amount = quantity;
|
2113
2048
|
} else {
|
2114
2049
|
this.addResources([
|
2115
2050
|
{
|
2116
2051
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2117
|
-
amount:
|
2052
|
+
amount: quantity,
|
2118
2053
|
assetId,
|
2119
2054
|
owner: resourcesOwner || Address.fromRandom(),
|
2055
|
+
maturity: 0,
|
2120
2056
|
blockCreated: bn7(1),
|
2121
2057
|
txCreatedIdx: bn7(1)
|
2122
2058
|
}
|
@@ -2148,7 +2084,7 @@ var BaseTransactionRequest = class {
|
|
2148
2084
|
toJSON() {
|
2149
2085
|
return normalizeJSON(this);
|
2150
2086
|
}
|
2151
|
-
|
2087
|
+
updatePredicateInputs(inputs) {
|
2152
2088
|
this.inputs.forEach((i) => {
|
2153
2089
|
let correspondingInput;
|
2154
2090
|
switch (i.type) {
|
@@ -2170,15 +2106,6 @@ var BaseTransactionRequest = class {
|
|
2170
2106
|
}
|
2171
2107
|
});
|
2172
2108
|
}
|
2173
|
-
shiftPredicateData() {
|
2174
|
-
this.inputs.forEach((input) => {
|
2175
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2176
|
-
input.predicateData = input.paddPredicateData(
|
2177
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2178
|
-
);
|
2179
|
-
}
|
2180
|
-
});
|
2181
|
-
}
|
2182
2109
|
};
|
2183
2110
|
|
2184
2111
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2325,8 +2252,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2325
2252
|
return {
|
2326
2253
|
type: TransactionType3.Create,
|
2327
2254
|
...baseTransaction,
|
2255
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2328
2256
|
bytecodeWitnessIndex,
|
2329
|
-
storageSlotsCount:
|
2257
|
+
storageSlotsCount: storageSlots.length,
|
2330
2258
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2331
2259
|
storageSlots
|
2332
2260
|
};
|
@@ -2449,8 +2377,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2449
2377
|
type: TransactionType4.Script,
|
2450
2378
|
scriptGasLimit: this.gasLimit,
|
2451
2379
|
...super.getBaseTransaction(),
|
2452
|
-
scriptLength:
|
2453
|
-
scriptDataLength:
|
2380
|
+
scriptLength: script.length,
|
2381
|
+
scriptDataLength: scriptData.length,
|
2454
2382
|
receiptsRoot: ZeroBytes327,
|
2455
2383
|
script: hexlify10(script),
|
2456
2384
|
scriptData: hexlify10(scriptData)
|
@@ -2514,7 +2442,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2514
2442
|
}
|
2515
2443
|
calculateMaxGas(chainInfo, minGas) {
|
2516
2444
|
const { consensusParameters } = chainInfo;
|
2517
|
-
const { gasPerByte
|
2445
|
+
const { gasPerByte } = consensusParameters;
|
2518
2446
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2519
2447
|
(acc, wit) => acc + wit.dataLength,
|
2520
2448
|
0
|
@@ -2524,8 +2452,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2524
2452
|
minGas,
|
2525
2453
|
witnessesLength,
|
2526
2454
|
witnessLimit: this.witnessLimit,
|
2527
|
-
gasLimit: this.gasLimit
|
2528
|
-
maxGasPerTx
|
2455
|
+
gasLimit: this.gasLimit
|
2529
2456
|
});
|
2530
2457
|
}
|
2531
2458
|
/**
|
@@ -2582,7 +2509,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2582
2509
|
|
2583
2510
|
// src/providers/transaction-request/utils.ts
|
2584
2511
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2585
|
-
import { TransactionType as TransactionType5
|
2512
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2586
2513
|
var transactionRequestify = (obj) => {
|
2587
2514
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2588
2515
|
return obj;
|
@@ -2600,31 +2527,14 @@ var transactionRequestify = (obj) => {
|
|
2600
2527
|
}
|
2601
2528
|
}
|
2602
2529
|
};
|
2603
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2604
|
-
(acc, input) => {
|
2605
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2606
|
-
acc.utxos.push(input.id);
|
2607
|
-
}
|
2608
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2609
|
-
acc.messages.push(input.nonce);
|
2610
|
-
}
|
2611
|
-
return acc;
|
2612
|
-
},
|
2613
|
-
{
|
2614
|
-
utxos: [],
|
2615
|
-
messages: []
|
2616
|
-
}
|
2617
|
-
);
|
2618
2530
|
|
2619
2531
|
// src/providers/transaction-response/transaction-response.ts
|
2620
2532
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2621
|
-
import { bn as
|
2533
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2622
2534
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2623
2535
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2624
2536
|
|
2625
2537
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2626
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2627
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2628
2538
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2629
2539
|
|
2630
2540
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2633,10 +2543,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2633
2543
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2634
2544
|
var calculateTransactionFee = (params) => {
|
2635
2545
|
const {
|
2636
|
-
|
2546
|
+
gasUsed,
|
2637
2547
|
rawPayload,
|
2638
|
-
|
2639
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2548
|
+
consensusParameters: { gasCosts, feeParams }
|
2640
2549
|
} = params;
|
2641
2550
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2642
2551
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2646,7 +2555,8 @@ var calculateTransactionFee = (params) => {
|
|
2646
2555
|
return {
|
2647
2556
|
fee: bn11(0),
|
2648
2557
|
minFee: bn11(0),
|
2649
|
-
maxFee: bn11(0)
|
2558
|
+
maxFee: bn11(0),
|
2559
|
+
feeFromGasUsed: bn11(0)
|
2650
2560
|
};
|
2651
2561
|
}
|
2652
2562
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2678,6 +2588,7 @@ var calculateTransactionFee = (params) => {
|
|
2678
2588
|
metadataGas,
|
2679
2589
|
txBytesSize: transactionBytes.length
|
2680
2590
|
});
|
2591
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2681
2592
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2682
2593
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2683
2594
|
const maxGas = getMaxGas({
|
@@ -2685,25 +2596,17 @@ var calculateTransactionFee = (params) => {
|
|
2685
2596
|
minGas,
|
2686
2597
|
witnessesLength,
|
2687
2598
|
gasLimit,
|
2688
|
-
witnessLimit
|
2689
|
-
maxGasPerTx
|
2690
|
-
});
|
2691
|
-
const minFee = calculateGasFee({
|
2692
|
-
gasPrice,
|
2693
|
-
gas: minGas,
|
2694
|
-
priceFactor: gasPriceFactor,
|
2695
|
-
tip
|
2696
|
-
});
|
2697
|
-
const maxFee = calculateGasFee({
|
2698
|
-
gasPrice,
|
2699
|
-
gas: maxGas,
|
2700
|
-
priceFactor: gasPriceFactor,
|
2701
|
-
tip
|
2599
|
+
witnessLimit
|
2702
2600
|
});
|
2601
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2602
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2603
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2604
|
+
const fee = minFee.add(feeFromGasUsed);
|
2703
2605
|
return {
|
2606
|
+
fee,
|
2704
2607
|
minFee,
|
2705
2608
|
maxFee,
|
2706
|
-
|
2609
|
+
feeFromGasUsed
|
2707
2610
|
};
|
2708
2611
|
};
|
2709
2612
|
|
@@ -2759,7 +2662,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2759
2662
|
|
2760
2663
|
// src/providers/transaction-summary/input.ts
|
2761
2664
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2762
|
-
import { InputType as
|
2665
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2763
2666
|
function getInputsByTypes(inputs, types) {
|
2764
2667
|
return inputs.filter((i) => types.includes(i.type));
|
2765
2668
|
}
|
@@ -2767,16 +2670,16 @@ function getInputsByType(inputs, type) {
|
|
2767
2670
|
return inputs.filter((i) => i.type === type);
|
2768
2671
|
}
|
2769
2672
|
function getInputsCoin(inputs) {
|
2770
|
-
return getInputsByType(inputs,
|
2673
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2771
2674
|
}
|
2772
2675
|
function getInputsMessage(inputs) {
|
2773
|
-
return getInputsByType(inputs,
|
2676
|
+
return getInputsByType(inputs, InputType5.Message);
|
2774
2677
|
}
|
2775
2678
|
function getInputsCoinAndMessage(inputs) {
|
2776
|
-
return getInputsByTypes(inputs, [
|
2679
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2777
2680
|
}
|
2778
2681
|
function getInputsContract(inputs) {
|
2779
|
-
return getInputsByType(inputs,
|
2682
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2780
2683
|
}
|
2781
2684
|
function getInputFromAssetId(inputs, assetId) {
|
2782
2685
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2795,7 +2698,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2795
2698
|
if (!contractInput) {
|
2796
2699
|
return void 0;
|
2797
2700
|
}
|
2798
|
-
if (contractInput.type !==
|
2701
|
+
if (contractInput.type !== InputType5.Contract) {
|
2799
2702
|
throw new FuelError9(
|
2800
2703
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2801
2704
|
`Contract input should be of type 'contract'.`
|
@@ -2804,10 +2707,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2804
2707
|
return contractInput;
|
2805
2708
|
}
|
2806
2709
|
function getInputAccountAddress(input) {
|
2807
|
-
if (input.type ===
|
2710
|
+
if (input.type === InputType5.Coin) {
|
2808
2711
|
return input.owner.toString();
|
2809
2712
|
}
|
2810
|
-
if (input.type ===
|
2713
|
+
if (input.type === InputType5.Message) {
|
2811
2714
|
return input.recipient.toString();
|
2812
2715
|
}
|
2813
2716
|
return "";
|
@@ -3270,9 +3173,7 @@ function assembleTransactionSummary(params) {
|
|
3270
3173
|
gqlTransactionStatus,
|
3271
3174
|
abiMap = {},
|
3272
3175
|
maxInputs,
|
3273
|
-
gasCosts
|
3274
|
-
maxGasPerTx,
|
3275
|
-
gasPrice
|
3176
|
+
gasCosts
|
3276
3177
|
} = params;
|
3277
3178
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3278
3179
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3286,14 +3187,11 @@ function assembleTransactionSummary(params) {
|
|
3286
3187
|
maxInputs
|
3287
3188
|
});
|
3288
3189
|
const typeName = getTransactionTypeName(transaction.type);
|
3289
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3290
3190
|
const { fee } = calculateTransactionFee({
|
3291
|
-
|
3191
|
+
gasUsed,
|
3292
3192
|
rawPayload,
|
3293
|
-
tip,
|
3294
3193
|
consensusParameters: {
|
3295
3194
|
gasCosts,
|
3296
|
-
maxGasPerTx,
|
3297
3195
|
feeParams: {
|
3298
3196
|
gasPerByte,
|
3299
3197
|
gasPriceFactor
|
@@ -3353,7 +3251,7 @@ var TransactionResponse = class {
|
|
3353
3251
|
/** Current provider */
|
3354
3252
|
provider;
|
3355
3253
|
/** Gas used on the transaction */
|
3356
|
-
gasUsed =
|
3254
|
+
gasUsed = bn14(0);
|
3357
3255
|
/** The graphql Transaction with receipts object. */
|
3358
3256
|
gqlTransaction;
|
3359
3257
|
abis;
|
@@ -3431,13 +3329,8 @@ var TransactionResponse = class {
|
|
3431
3329
|
const decodedTransaction = this.decodeTransaction(
|
3432
3330
|
transaction
|
3433
3331
|
);
|
3434
|
-
|
3435
|
-
|
3436
|
-
txReceipts = transaction.status.receipts;
|
3437
|
-
}
|
3438
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3439
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3440
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3332
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3333
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3441
3334
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3442
3335
|
const transactionSummary = assembleTransactionSummary({
|
3443
3336
|
id: this.id,
|
@@ -3449,9 +3342,7 @@ var TransactionResponse = class {
|
|
3449
3342
|
gasPriceFactor,
|
3450
3343
|
abiMap: contractsAbiMap,
|
3451
3344
|
maxInputs,
|
3452
|
-
gasCosts
|
3453
|
-
maxGasPerTx,
|
3454
|
-
gasPrice
|
3345
|
+
gasCosts
|
3455
3346
|
});
|
3456
3347
|
return transactionSummary;
|
3457
3348
|
}
|
@@ -3578,29 +3469,29 @@ var processGqlChain = (chain) => {
|
|
3578
3469
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3579
3470
|
return {
|
3580
3471
|
name,
|
3581
|
-
baseChainHeight:
|
3472
|
+
baseChainHeight: bn15(daHeight),
|
3582
3473
|
consensusParameters: {
|
3583
|
-
contractMaxSize:
|
3584
|
-
maxInputs:
|
3585
|
-
maxOutputs:
|
3586
|
-
maxWitnesses:
|
3587
|
-
maxGasPerTx:
|
3588
|
-
maxScriptLength:
|
3589
|
-
maxScriptDataLength:
|
3590
|
-
maxStorageSlots:
|
3591
|
-
maxPredicateLength:
|
3592
|
-
maxPredicateDataLength:
|
3593
|
-
maxGasPerPredicate:
|
3594
|
-
gasPriceFactor:
|
3595
|
-
gasPerByte:
|
3596
|
-
maxMessageDataLength:
|
3597
|
-
chainId:
|
3474
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3475
|
+
maxInputs: bn15(txParams.maxInputs),
|
3476
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3477
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3478
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3479
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3480
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3481
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3482
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3483
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3484
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3485
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3486
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3487
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3488
|
+
chainId: bn15(consensusParameters.chainId),
|
3598
3489
|
gasCosts
|
3599
3490
|
},
|
3600
3491
|
gasCosts,
|
3601
3492
|
latestBlock: {
|
3602
3493
|
id: latestBlock.id,
|
3603
|
-
height:
|
3494
|
+
height: bn15(latestBlock.header.height),
|
3604
3495
|
time: latestBlock.header.time,
|
3605
3496
|
transactions: latestBlock.transactions.map((i) => ({
|
3606
3497
|
id: i.id
|
@@ -3694,8 +3585,10 @@ var _Provider = class {
|
|
3694
3585
|
* Returns some helpful parameters related to gas fees.
|
3695
3586
|
*/
|
3696
3587
|
getGasConfig() {
|
3588
|
+
const { minGasPrice } = this.getNode();
|
3697
3589
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3698
3590
|
return {
|
3591
|
+
minGasPrice,
|
3699
3592
|
maxGasPerTx,
|
3700
3593
|
maxGasPerPredicate,
|
3701
3594
|
gasPriceFactor,
|
@@ -3793,7 +3686,7 @@ var _Provider = class {
|
|
3793
3686
|
*/
|
3794
3687
|
async getBlockNumber() {
|
3795
3688
|
const { chain } = await this.operations.getChain();
|
3796
|
-
return
|
3689
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3797
3690
|
}
|
3798
3691
|
/**
|
3799
3692
|
* Returns the chain information.
|
@@ -3803,11 +3696,13 @@ var _Provider = class {
|
|
3803
3696
|
async fetchNode() {
|
3804
3697
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3805
3698
|
const processedNodeInfo = {
|
3806
|
-
maxDepth:
|
3807
|
-
maxTx:
|
3699
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3700
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3701
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3808
3702
|
nodeVersion: nodeInfo.nodeVersion,
|
3809
3703
|
utxoValidation: nodeInfo.utxoValidation,
|
3810
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3704
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3705
|
+
peers: nodeInfo.peers
|
3811
3706
|
};
|
3812
3707
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3813
3708
|
return processedNodeInfo;
|
@@ -3893,13 +3788,14 @@ var _Provider = class {
|
|
3893
3788
|
return this.estimateTxDependencies(transactionRequest);
|
3894
3789
|
}
|
3895
3790
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3896
|
-
const { dryRun:
|
3897
|
-
|
3791
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3792
|
+
encodedTransaction,
|
3898
3793
|
utxoValidation: utxoValidation || false
|
3899
3794
|
});
|
3900
|
-
const
|
3901
|
-
|
3902
|
-
|
3795
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3796
|
+
return {
|
3797
|
+
receipts
|
3798
|
+
};
|
3903
3799
|
}
|
3904
3800
|
/**
|
3905
3801
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3925,7 +3821,7 @@ var _Provider = class {
|
|
3925
3821
|
} = response;
|
3926
3822
|
if (inputs) {
|
3927
3823
|
inputs.forEach((input, index) => {
|
3928
|
-
if ("predicateGasUsed" in input &&
|
3824
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3929
3825
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3930
3826
|
}
|
3931
3827
|
});
|
@@ -3938,6 +3834,9 @@ var _Provider = class {
|
|
3938
3834
|
* If there are missing variable outputs,
|
3939
3835
|
* `addVariableOutputs` is called on the transaction.
|
3940
3836
|
*
|
3837
|
+
* @privateRemarks
|
3838
|
+
* TODO: Investigate support for missing contract IDs
|
3839
|
+
* TODO: Add support for missing output messages
|
3941
3840
|
*
|
3942
3841
|
* @param transactionRequest - The transaction request object.
|
3943
3842
|
* @returns A promise.
|
@@ -3950,19 +3849,16 @@ var _Provider = class {
|
|
3950
3849
|
missingContractIds: []
|
3951
3850
|
};
|
3952
3851
|
}
|
3852
|
+
await this.estimatePredicates(transactionRequest);
|
3953
3853
|
let receipts = [];
|
3954
3854
|
const missingContractIds = [];
|
3955
3855
|
let outputVariables = 0;
|
3956
|
-
let dryrunStatus;
|
3957
3856
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3958
|
-
const {
|
3959
|
-
|
3960
|
-
} = await this.operations.dryRun({
|
3961
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3857
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3858
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3962
3859
|
utxoValidation: false
|
3963
3860
|
});
|
3964
|
-
receipts =
|
3965
|
-
dryrunStatus = status;
|
3861
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3966
3862
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3967
3863
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3968
3864
|
if (hasMissingOutputs) {
|
@@ -3972,10 +3868,6 @@ var _Provider = class {
|
|
3972
3868
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3973
3869
|
missingContractIds.push(contractId);
|
3974
3870
|
});
|
3975
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3976
|
-
transactionRequest
|
3977
|
-
});
|
3978
|
-
transactionRequest.maxFee = maxFee;
|
3979
3871
|
} else {
|
3980
3872
|
break;
|
3981
3873
|
}
|
@@ -3983,139 +3875,37 @@ var _Provider = class {
|
|
3983
3875
|
return {
|
3984
3876
|
receipts,
|
3985
3877
|
outputVariables,
|
3986
|
-
missingContractIds
|
3987
|
-
dryrunStatus
|
3878
|
+
missingContractIds
|
3988
3879
|
};
|
3989
3880
|
}
|
3990
|
-
/**
|
3991
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3992
|
-
*
|
3993
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3994
|
-
* further modifications are identified. The method iteratively updates these transactions
|
3995
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3996
|
-
*
|
3997
|
-
* @param transactionRequests - Array of transaction request objects.
|
3998
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
3999
|
-
*/
|
4000
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4001
|
-
const results = transactionRequests.map(() => ({
|
4002
|
-
receipts: [],
|
4003
|
-
outputVariables: 0,
|
4004
|
-
missingContractIds: [],
|
4005
|
-
dryrunStatus: void 0
|
4006
|
-
}));
|
4007
|
-
const allRequests = clone3(transactionRequests);
|
4008
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4009
|
-
allRequests.forEach((req, index) => {
|
4010
|
-
if (req.type === TransactionType8.Script) {
|
4011
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4012
|
-
}
|
4013
|
-
});
|
4014
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4015
|
-
let attempt = 0;
|
4016
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4017
|
-
const encodedTransactions = transactionsToProcess.map(
|
4018
|
-
(index) => serializedTransactionsMap.get(index)
|
4019
|
-
);
|
4020
|
-
const dryRunResults = await this.operations.dryRun({
|
4021
|
-
encodedTransactions,
|
4022
|
-
utxoValidation: false
|
4023
|
-
});
|
4024
|
-
const nextRoundTransactions = [];
|
4025
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4026
|
-
const currentResultIndex = transactionsToProcess[i];
|
4027
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4028
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4029
|
-
results[currentResultIndex].dryrunStatus = status;
|
4030
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4031
|
-
results[currentResultIndex].receipts
|
4032
|
-
);
|
4033
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4034
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4035
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4036
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4037
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4038
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4039
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4040
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4041
|
-
});
|
4042
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4043
|
-
transactionRequest: requestToProcess
|
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
3881
|
/**
|
4075
3882
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4076
3883
|
* @param transactionRequest - The transaction request object.
|
4077
3884
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4078
3885
|
*/
|
4079
|
-
|
3886
|
+
estimateTxGasAndFee(params) {
|
4080
3887
|
const { transactionRequest } = params;
|
4081
|
-
|
3888
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4082
3889
|
const chainInfo = this.getChain();
|
4083
|
-
const
|
3890
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3891
|
+
transactionRequest.gasPrice = gasPrice;
|
4084
3892
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4085
|
-
|
4086
|
-
gasPrice = await this.estimateGasPrice(10);
|
4087
|
-
}
|
4088
|
-
const minFee = calculateGasFee({
|
4089
|
-
gasPrice: bn16(gasPrice),
|
4090
|
-
gas: minGas,
|
4091
|
-
priceFactor: gasPriceFactor,
|
4092
|
-
tip: transactionRequest.tip
|
4093
|
-
}).add(1);
|
4094
|
-
let gasLimit = bn16(0);
|
3893
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4095
3894
|
if (transactionRequest.type === TransactionType8.Script) {
|
4096
|
-
gasLimit = transactionRequest.gasLimit;
|
4097
3895
|
if (transactionRequest.gasLimit.eq(0)) {
|
4098
3896
|
transactionRequest.gasLimit = minGas;
|
4099
3897
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4100
3898
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4101
3899
|
);
|
4102
|
-
gasLimit = transactionRequest.gasLimit;
|
4103
3900
|
}
|
4104
3901
|
}
|
4105
3902
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4106
|
-
const maxFee =
|
4107
|
-
gasPrice: bn16(gasPrice),
|
4108
|
-
gas: maxGas,
|
4109
|
-
priceFactor: gasPriceFactor,
|
4110
|
-
tip: transactionRequest.tip
|
4111
|
-
}).add(1);
|
3903
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4112
3904
|
return {
|
4113
3905
|
minGas,
|
4114
3906
|
minFee,
|
4115
3907
|
maxGas,
|
4116
|
-
maxFee
|
4117
|
-
gasPrice,
|
4118
|
-
gasLimit
|
3908
|
+
maxFee
|
4119
3909
|
};
|
4120
3910
|
}
|
4121
3911
|
/**
|
@@ -4133,17 +3923,15 @@ var _Provider = class {
|
|
4133
3923
|
if (estimateTxDependencies) {
|
4134
3924
|
return this.estimateTxDependencies(transactionRequest);
|
4135
3925
|
}
|
4136
|
-
const
|
4137
|
-
const { dryRun:
|
4138
|
-
|
3926
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3927
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3928
|
+
encodedTransaction,
|
4139
3929
|
utxoValidation: true
|
4140
3930
|
});
|
4141
|
-
const
|
4142
|
-
|
4143
|
-
|
4144
|
-
|
4145
|
-
});
|
4146
|
-
return { receipts: callResult[0].receipts };
|
3931
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3932
|
+
return {
|
3933
|
+
receipts
|
3934
|
+
};
|
4147
3935
|
}
|
4148
3936
|
/**
|
4149
3937
|
* Returns a transaction cost to enable user
|
@@ -4160,79 +3948,77 @@ var _Provider = class {
|
|
4160
3948
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4161
3949
|
* @returns A promise that resolves to the transaction cost object.
|
4162
3950
|
*/
|
4163
|
-
async getTransactionCost(transactionRequestLike,
|
3951
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3952
|
+
estimateTxDependencies = true,
|
3953
|
+
estimatePredicates = true,
|
3954
|
+
resourcesOwner,
|
3955
|
+
signatureCallback
|
3956
|
+
} = {}) {
|
4164
3957
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3958
|
+
const { minGasPrice } = this.getGasConfig();
|
3959
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4165
3960
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4166
3961
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4167
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3962
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4168
3963
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4169
|
-
txRequestClone.maxFee = bn16(0);
|
4170
3964
|
if (isScriptTransaction) {
|
4171
|
-
txRequestClone.gasLimit =
|
3965
|
+
txRequestClone.gasLimit = bn15(0);
|
4172
3966
|
}
|
4173
|
-
if (
|
4174
|
-
resourcesOwner
|
3967
|
+
if (estimatePredicates) {
|
3968
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3969
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3970
|
+
}
|
3971
|
+
await this.estimatePredicates(txRequestClone);
|
4175
3972
|
}
|
4176
|
-
const signedRequest = clone3(txRequestClone);
|
4177
|
-
let addedSignatures = 0;
|
4178
3973
|
if (signatureCallback && isScriptTransaction) {
|
4179
|
-
|
4180
|
-
await signatureCallback(signedRequest);
|
4181
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3974
|
+
await signatureCallback(txRequestClone);
|
4182
3975
|
}
|
4183
|
-
|
4184
|
-
|
4185
|
-
transactionRequest: signedRequest
|
3976
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3977
|
+
transactionRequest: txRequestClone
|
4186
3978
|
});
|
4187
3979
|
let receipts = [];
|
4188
3980
|
let missingContractIds = [];
|
4189
3981
|
let outputVariables = 0;
|
4190
|
-
let gasUsed =
|
4191
|
-
|
4192
|
-
|
4193
|
-
if (isScriptTransaction) {
|
4194
|
-
txRequestClone.gasLimit = gasLimit;
|
4195
|
-
if (signatureCallback) {
|
4196
|
-
await signatureCallback(txRequestClone);
|
4197
|
-
}
|
3982
|
+
let gasUsed = bn15(0);
|
3983
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3984
|
+
txRequestClone.gasPrice = bn15(0);
|
4198
3985
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4199
3986
|
receipts = result.receipts;
|
4200
3987
|
outputVariables = result.outputVariables;
|
4201
3988
|
missingContractIds = result.missingContractIds;
|
4202
3989
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4203
3990
|
txRequestClone.gasLimit = gasUsed;
|
4204
|
-
|
4205
|
-
|
4206
|
-
|
3991
|
+
txRequestClone.gasPrice = setGasPrice;
|
3992
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3993
|
+
transactionRequest: txRequestClone
|
4207
3994
|
}));
|
4208
3995
|
}
|
4209
3996
|
return {
|
4210
3997
|
requiredQuantities: allQuantities,
|
4211
3998
|
receipts,
|
4212
3999
|
gasUsed,
|
4213
|
-
|
4000
|
+
minGasPrice,
|
4001
|
+
gasPrice: setGasPrice,
|
4214
4002
|
minGas,
|
4215
4003
|
maxGas,
|
4216
4004
|
minFee,
|
4217
4005
|
maxFee,
|
4006
|
+
estimatedInputs: txRequestClone.inputs,
|
4218
4007
|
outputVariables,
|
4219
|
-
missingContractIds
|
4220
|
-
addedSignatures,
|
4221
|
-
estimatedPredicates: txRequestClone.inputs
|
4008
|
+
missingContractIds
|
4222
4009
|
};
|
4223
4010
|
}
|
4224
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4011
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4225
4012
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4226
4013
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4227
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4228
|
-
quantitiesToContract
|
4229
|
-
});
|
4014
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4230
4015
|
transactionRequest.addResources(
|
4231
4016
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4232
4017
|
);
|
4233
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4234
|
-
|
4235
|
-
|
4018
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4019
|
+
transactionRequest,
|
4020
|
+
forwardingQuantities
|
4021
|
+
);
|
4236
4022
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4237
4023
|
return {
|
4238
4024
|
resources,
|
@@ -4254,10 +4040,11 @@ var _Provider = class {
|
|
4254
4040
|
return coins.map((coin) => ({
|
4255
4041
|
id: coin.utxoId,
|
4256
4042
|
assetId: coin.assetId,
|
4257
|
-
amount:
|
4043
|
+
amount: bn15(coin.amount),
|
4258
4044
|
owner: Address2.fromAddressOrString(coin.owner),
|
4259
|
-
|
4260
|
-
|
4045
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4046
|
+
blockCreated: bn15(coin.blockCreated),
|
4047
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4261
4048
|
}));
|
4262
4049
|
}
|
4263
4050
|
/**
|
@@ -4294,9 +4081,9 @@ var _Provider = class {
|
|
4294
4081
|
switch (coin.__typename) {
|
4295
4082
|
case "MessageCoin":
|
4296
4083
|
return {
|
4297
|
-
amount:
|
4084
|
+
amount: bn15(coin.amount),
|
4298
4085
|
assetId: coin.assetId,
|
4299
|
-
daHeight:
|
4086
|
+
daHeight: bn15(coin.daHeight),
|
4300
4087
|
sender: Address2.fromAddressOrString(coin.sender),
|
4301
4088
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4302
4089
|
nonce: coin.nonce
|
@@ -4304,11 +4091,12 @@ var _Provider = class {
|
|
4304
4091
|
case "Coin":
|
4305
4092
|
return {
|
4306
4093
|
id: coin.utxoId,
|
4307
|
-
amount:
|
4094
|
+
amount: bn15(coin.amount),
|
4308
4095
|
assetId: coin.assetId,
|
4309
4096
|
owner: Address2.fromAddressOrString(coin.owner),
|
4310
|
-
|
4311
|
-
|
4097
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4098
|
+
blockCreated: bn15(coin.blockCreated),
|
4099
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4312
4100
|
};
|
4313
4101
|
default:
|
4314
4102
|
return null;
|
@@ -4325,13 +4113,13 @@ var _Provider = class {
|
|
4325
4113
|
async getBlock(idOrHeight) {
|
4326
4114
|
let variables;
|
4327
4115
|
if (typeof idOrHeight === "number") {
|
4328
|
-
variables = { height:
|
4116
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4329
4117
|
} else if (idOrHeight === "latest") {
|
4330
4118
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4331
4119
|
} else if (idOrHeight.length === 66) {
|
4332
4120
|
variables = { blockId: idOrHeight };
|
4333
4121
|
} else {
|
4334
|
-
variables = { blockId:
|
4122
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4335
4123
|
}
|
4336
4124
|
const { block } = await this.operations.getBlock(variables);
|
4337
4125
|
if (!block) {
|
@@ -4339,7 +4127,7 @@ var _Provider = class {
|
|
4339
4127
|
}
|
4340
4128
|
return {
|
4341
4129
|
id: block.id,
|
4342
|
-
height:
|
4130
|
+
height: bn15(block.header.height),
|
4343
4131
|
time: block.header.time,
|
4344
4132
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4345
4133
|
};
|
@@ -4354,7 +4142,7 @@ var _Provider = class {
|
|
4354
4142
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4355
4143
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4356
4144
|
id: block.id,
|
4357
|
-
height:
|
4145
|
+
height: bn15(block.header.height),
|
4358
4146
|
time: block.header.time,
|
4359
4147
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4360
4148
|
}));
|
@@ -4369,7 +4157,7 @@ var _Provider = class {
|
|
4369
4157
|
async getBlockWithTransactions(idOrHeight) {
|
4370
4158
|
let variables;
|
4371
4159
|
if (typeof idOrHeight === "number") {
|
4372
|
-
variables = { blockHeight:
|
4160
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4373
4161
|
} else if (idOrHeight === "latest") {
|
4374
4162
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4375
4163
|
} else {
|
@@ -4381,7 +4169,7 @@ var _Provider = class {
|
|
4381
4169
|
}
|
4382
4170
|
return {
|
4383
4171
|
id: block.id,
|
4384
|
-
height:
|
4172
|
+
height: bn15(block.header.height, 10),
|
4385
4173
|
time: block.header.time,
|
4386
4174
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4387
4175
|
transactions: block.transactions.map(
|
@@ -4430,7 +4218,7 @@ var _Provider = class {
|
|
4430
4218
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4431
4219
|
asset: hexlify12(assetId)
|
4432
4220
|
});
|
4433
|
-
return
|
4221
|
+
return bn15(contractBalance.amount, 10);
|
4434
4222
|
}
|
4435
4223
|
/**
|
4436
4224
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4444,7 +4232,7 @@ var _Provider = class {
|
|
4444
4232
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4445
4233
|
assetId: hexlify12(assetId)
|
4446
4234
|
});
|
4447
|
-
return
|
4235
|
+
return bn15(balance.amount, 10);
|
4448
4236
|
}
|
4449
4237
|
/**
|
4450
4238
|
* Returns balances for the given owner.
|
@@ -4462,7 +4250,7 @@ var _Provider = class {
|
|
4462
4250
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4463
4251
|
return balances.map((balance) => ({
|
4464
4252
|
assetId: balance.assetId,
|
4465
|
-
amount:
|
4253
|
+
amount: bn15(balance.amount)
|
4466
4254
|
}));
|
4467
4255
|
}
|
4468
4256
|
/**
|
@@ -4484,15 +4272,15 @@ var _Provider = class {
|
|
4484
4272
|
sender: message.sender,
|
4485
4273
|
recipient: message.recipient,
|
4486
4274
|
nonce: message.nonce,
|
4487
|
-
amount:
|
4275
|
+
amount: bn15(message.amount),
|
4488
4276
|
data: message.data
|
4489
4277
|
}),
|
4490
4278
|
sender: Address2.fromAddressOrString(message.sender),
|
4491
4279
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4492
4280
|
nonce: message.nonce,
|
4493
|
-
amount:
|
4281
|
+
amount: bn15(message.amount),
|
4494
4282
|
data: InputMessageCoder.decodeData(message.data),
|
4495
|
-
daHeight:
|
4283
|
+
daHeight: bn15(message.daHeight)
|
4496
4284
|
}));
|
4497
4285
|
}
|
4498
4286
|
/**
|
@@ -4545,60 +4333,44 @@ var _Provider = class {
|
|
4545
4333
|
} = result.messageProof;
|
4546
4334
|
return {
|
4547
4335
|
messageProof: {
|
4548
|
-
proofIndex:
|
4336
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4549
4337
|
proofSet: messageProof.proofSet
|
4550
4338
|
},
|
4551
4339
|
blockProof: {
|
4552
|
-
proofIndex:
|
4340
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4553
4341
|
proofSet: blockProof.proofSet
|
4554
4342
|
},
|
4555
4343
|
messageBlockHeader: {
|
4556
4344
|
id: messageBlockHeader.id,
|
4557
|
-
daHeight:
|
4558
|
-
transactionsCount:
|
4345
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4346
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4559
4347
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4560
|
-
height:
|
4348
|
+
height: bn15(messageBlockHeader.height),
|
4561
4349
|
prevRoot: messageBlockHeader.prevRoot,
|
4562
4350
|
time: messageBlockHeader.time,
|
4563
4351
|
applicationHash: messageBlockHeader.applicationHash,
|
4564
|
-
|
4565
|
-
|
4566
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4567
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4568
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4352
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4353
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4569
4354
|
},
|
4570
4355
|
commitBlockHeader: {
|
4571
4356
|
id: commitBlockHeader.id,
|
4572
|
-
daHeight:
|
4573
|
-
transactionsCount:
|
4357
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4358
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4574
4359
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4575
|
-
height:
|
4360
|
+
height: bn15(commitBlockHeader.height),
|
4576
4361
|
prevRoot: commitBlockHeader.prevRoot,
|
4577
4362
|
time: commitBlockHeader.time,
|
4578
4363
|
applicationHash: commitBlockHeader.applicationHash,
|
4579
|
-
|
4580
|
-
|
4581
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4582
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4583
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4364
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4365
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4584
4366
|
},
|
4585
4367
|
sender: Address2.fromAddressOrString(sender),
|
4586
4368
|
recipient: Address2.fromAddressOrString(recipient),
|
4587
4369
|
nonce,
|
4588
|
-
amount:
|
4370
|
+
amount: bn15(amount),
|
4589
4371
|
data
|
4590
4372
|
};
|
4591
4373
|
}
|
4592
|
-
async getLatestGasPrice() {
|
4593
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4594
|
-
return bn16(latestGasPrice.gasPrice);
|
4595
|
-
}
|
4596
|
-
async estimateGasPrice(blockHorizon) {
|
4597
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4598
|
-
blockHorizon: String(blockHorizon)
|
4599
|
-
});
|
4600
|
-
return bn16(estimateGasPrice.gasPrice);
|
4601
|
-
}
|
4602
4374
|
/**
|
4603
4375
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4604
4376
|
*
|
@@ -4618,10 +4390,10 @@ var _Provider = class {
|
|
4618
4390
|
*/
|
4619
4391
|
async produceBlocks(amount, startTime) {
|
4620
4392
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4621
|
-
blocksToProduce:
|
4393
|
+
blocksToProduce: bn15(amount).toString(10),
|
4622
4394
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4623
4395
|
});
|
4624
|
-
return
|
4396
|
+
return bn15(latestBlockHeight);
|
4625
4397
|
}
|
4626
4398
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4627
4399
|
async getTransactionResponse(transactionId) {
|
@@ -4635,7 +4407,7 @@ cacheInputs_fn = function(inputs) {
|
|
4635
4407
|
return;
|
4636
4408
|
}
|
4637
4409
|
inputs.forEach((input) => {
|
4638
|
-
if (input.type ===
|
4410
|
+
if (input.type === InputType6.Coin) {
|
4639
4411
|
this.cache?.set(input.id);
|
4640
4412
|
}
|
4641
4413
|
});
|
@@ -4645,7 +4417,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4645
4417
|
|
4646
4418
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4647
4419
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4648
|
-
import { bn as
|
4420
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4649
4421
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4650
4422
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4651
4423
|
|
@@ -4891,33 +4663,36 @@ var Account = class extends AbstractAccount {
|
|
4891
4663
|
* @param fee - The estimated transaction fee.
|
4892
4664
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4893
4665
|
*/
|
4894
|
-
async fund(request,
|
4895
|
-
const
|
4896
|
-
|
4897
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4898
|
-
amount: bn18(fee),
|
4666
|
+
async fund(request, coinQuantities, fee) {
|
4667
|
+
const updatedQuantities = addAmountToAsset({
|
4668
|
+
amount: bn17(fee),
|
4899
4669
|
assetId: BaseAssetId3,
|
4900
|
-
coinQuantities
|
4670
|
+
coinQuantities
|
4901
4671
|
});
|
4902
4672
|
const quantitiesDict = {};
|
4903
|
-
|
4673
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4904
4674
|
quantitiesDict[assetId] = {
|
4905
4675
|
required: amount,
|
4906
|
-
owned:
|
4676
|
+
owned: bn17(0)
|
4907
4677
|
};
|
4908
4678
|
});
|
4909
|
-
|
4679
|
+
const cachedUtxos = [];
|
4680
|
+
const cachedMessages = [];
|
4681
|
+
const owner = this.address.toB256();
|
4682
|
+
request.inputs.forEach((input) => {
|
4910
4683
|
const isResource = "amount" in input;
|
4911
4684
|
if (isResource) {
|
4912
4685
|
const isCoin2 = "owner" in input;
|
4913
4686
|
if (isCoin2) {
|
4914
4687
|
const assetId = String(input.assetId);
|
4915
|
-
if (quantitiesDict[assetId]) {
|
4916
|
-
const amount =
|
4688
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4689
|
+
const amount = bn17(input.amount);
|
4917
4690
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4691
|
+
cachedUtxos.push(input.id);
|
4918
4692
|
}
|
4919
|
-
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4693
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4920
4694
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4695
|
+
cachedMessages.push(input.nonce);
|
4921
4696
|
}
|
4922
4697
|
}
|
4923
4698
|
});
|
@@ -4932,23 +4707,12 @@ var Account = class extends AbstractAccount {
|
|
4932
4707
|
});
|
4933
4708
|
const needsToBeFunded = missingQuantities.length;
|
4934
4709
|
if (needsToBeFunded) {
|
4935
|
-
const
|
4936
|
-
|
4937
|
-
|
4938
|
-
|
4939
|
-
|
4940
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4941
|
-
const requestToBeReEstimate = clone4(txRequest);
|
4942
|
-
if (addedSignatures) {
|
4943
|
-
Array.from({ length: addedSignatures }).forEach(
|
4944
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4945
|
-
);
|
4710
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4711
|
+
messages: cachedMessages,
|
4712
|
+
utxos: cachedUtxos
|
4713
|
+
});
|
4714
|
+
request.addResources(resources);
|
4946
4715
|
}
|
4947
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4948
|
-
transactionRequest: requestToBeReEstimate
|
4949
|
-
});
|
4950
|
-
txRequest.maxFee = maxFee;
|
4951
|
-
return txRequest;
|
4952
4716
|
}
|
4953
4717
|
/**
|
4954
4718
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4956,25 +4720,28 @@ var Account = class extends AbstractAccount {
|
|
4956
4720
|
* @param destination - The address of the destination.
|
4957
4721
|
* @param amount - The amount of coins to transfer.
|
4958
4722
|
* @param assetId - The asset ID of the coins to transfer.
|
4959
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4723
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4960
4724
|
* @returns A promise that resolves to the prepared transaction request.
|
4961
4725
|
*/
|
4962
4726
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4963
|
-
const
|
4727
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4728
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4729
|
+
const request = new ScriptTransactionRequest(params);
|
4964
4730
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4965
|
-
const
|
4731
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4966
4732
|
estimateTxDependencies: true,
|
4967
4733
|
resourcesOwner: this
|
4968
4734
|
});
|
4969
|
-
|
4970
|
-
|
4971
|
-
|
4972
|
-
|
4973
|
-
|
4974
|
-
|
4975
|
-
|
4976
|
-
|
4977
|
-
await this.fund(request,
|
4735
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4736
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4737
|
+
this.validateGas({
|
4738
|
+
gasUsed,
|
4739
|
+
gasPrice: request.gasPrice,
|
4740
|
+
gasLimit: request.gasLimit,
|
4741
|
+
minGasPrice
|
4742
|
+
});
|
4743
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4744
|
+
request.updatePredicateInputs(estimatedInputs);
|
4978
4745
|
return request;
|
4979
4746
|
}
|
4980
4747
|
/**
|
@@ -4987,7 +4754,7 @@ var Account = class extends AbstractAccount {
|
|
4987
4754
|
* @returns A promise that resolves to the transaction response.
|
4988
4755
|
*/
|
4989
4756
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4990
|
-
if (
|
4757
|
+
if (bn17(amount).lte(0)) {
|
4991
4758
|
throw new FuelError15(
|
4992
4759
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4993
4760
|
"Transfer amount must be a positive number."
|
@@ -5006,37 +4773,38 @@ var Account = class extends AbstractAccount {
|
|
5006
4773
|
* @returns A promise that resolves to the transaction response.
|
5007
4774
|
*/
|
5008
4775
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5009
|
-
if (
|
4776
|
+
if (bn17(amount).lte(0)) {
|
5010
4777
|
throw new FuelError15(
|
5011
4778
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5012
4779
|
"Transfer amount must be a positive number."
|
5013
4780
|
);
|
5014
4781
|
}
|
5015
4782
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4783
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4784
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5016
4785
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5017
4786
|
hexlifiedContractId: contractAddress.toB256(),
|
5018
|
-
amountToTransfer:
|
4787
|
+
amountToTransfer: bn17(amount),
|
5019
4788
|
assetId
|
5020
4789
|
});
|
5021
4790
|
const request = new ScriptTransactionRequest({
|
5022
|
-
...
|
4791
|
+
...params,
|
5023
4792
|
script,
|
5024
4793
|
scriptData
|
5025
4794
|
});
|
5026
4795
|
request.addContractInputAndOutput(contractAddress);
|
5027
|
-
const
|
5028
|
-
|
5029
|
-
|
4796
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4797
|
+
request,
|
4798
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4799
|
+
);
|
4800
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4801
|
+
this.validateGas({
|
4802
|
+
gasUsed,
|
4803
|
+
gasPrice: request.gasPrice,
|
4804
|
+
gasLimit: request.gasLimit,
|
4805
|
+
minGasPrice
|
5030
4806
|
});
|
5031
|
-
|
5032
|
-
this.validateGas({
|
5033
|
-
gasUsed: txCost.gasUsed,
|
5034
|
-
gasLimit: request.gasLimit
|
5035
|
-
});
|
5036
|
-
}
|
5037
|
-
request.gasLimit = txCost.gasUsed;
|
5038
|
-
request.maxFee = txCost.maxFee;
|
5039
|
-
await this.fund(request, txCost);
|
4807
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5040
4808
|
return this.sendTransaction(request);
|
5041
4809
|
}
|
5042
4810
|
/**
|
@@ -5048,31 +4816,34 @@ var Account = class extends AbstractAccount {
|
|
5048
4816
|
* @returns A promise that resolves to the transaction response.
|
5049
4817
|
*/
|
5050
4818
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4819
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5051
4820
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5052
4821
|
const recipientDataArray = arrayify14(
|
5053
4822
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5054
4823
|
);
|
5055
4824
|
const amountDataArray = arrayify14(
|
5056
|
-
"0x".concat(
|
4825
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5057
4826
|
);
|
5058
4827
|
const script = new Uint8Array([
|
5059
4828
|
...arrayify14(withdrawScript.bytes),
|
5060
4829
|
...recipientDataArray,
|
5061
4830
|
...amountDataArray
|
5062
4831
|
]);
|
5063
|
-
const params = { script, ...txParams };
|
4832
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5064
4833
|
const request = new ScriptTransactionRequest(params);
|
5065
|
-
const
|
5066
|
-
const
|
5067
|
-
|
5068
|
-
|
5069
|
-
|
5070
|
-
|
5071
|
-
|
5072
|
-
|
5073
|
-
|
5074
|
-
|
5075
|
-
|
4834
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4835
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4836
|
+
request,
|
4837
|
+
forwardingQuantities
|
4838
|
+
);
|
4839
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4840
|
+
this.validateGas({
|
4841
|
+
gasUsed,
|
4842
|
+
gasPrice: request.gasPrice,
|
4843
|
+
gasLimit: request.gasLimit,
|
4844
|
+
minGasPrice
|
4845
|
+
});
|
4846
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5076
4847
|
return this.sendTransaction(request);
|
5077
4848
|
}
|
5078
4849
|
async signMessage(message) {
|
@@ -5130,7 +4901,18 @@ var Account = class extends AbstractAccount {
|
|
5130
4901
|
}
|
5131
4902
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5132
4903
|
}
|
5133
|
-
validateGas({
|
4904
|
+
validateGas({
|
4905
|
+
gasUsed,
|
4906
|
+
gasPrice,
|
4907
|
+
gasLimit,
|
4908
|
+
minGasPrice
|
4909
|
+
}) {
|
4910
|
+
if (minGasPrice.gt(gasPrice)) {
|
4911
|
+
throw new FuelError15(
|
4912
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4913
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4914
|
+
);
|
4915
|
+
}
|
5134
4916
|
if (gasUsed.gt(gasLimit)) {
|
5135
4917
|
throw new FuelError15(
|
5136
4918
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5422,7 +5204,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5422
5204
|
* @param transactionRequestLike - The transaction request to send.
|
5423
5205
|
* @returns A promise that resolves to the TransactionResponse object.
|
5424
5206
|
*/
|
5425
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5207
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5426
5208
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5427
5209
|
if (estimateTxDependencies) {
|
5428
5210
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5463,7 +5245,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5463
5245
|
// src/hdwallet/hdwallet.ts
|
5464
5246
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5465
5247
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5466
|
-
import { bn as
|
5248
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5467
5249
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5468
5250
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5469
5251
|
|
@@ -7929,7 +7711,7 @@ var HDWallet = class {
|
|
7929
7711
|
const IR = bytes.slice(32);
|
7930
7712
|
if (privateKey) {
|
7931
7713
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7932
|
-
const ki =
|
7714
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7933
7715
|
return new HDWallet({
|
7934
7716
|
privateKey: ki,
|
7935
7717
|
chainCode: IR,
|
@@ -8200,15 +7982,14 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8200
7982
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8201
7983
|
wallet.provider
|
8202
7984
|
);
|
8203
|
-
const
|
8204
|
-
|
8205
|
-
|
8206
|
-
|
7985
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7986
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7987
|
+
const request = new ScriptTransactionRequest({
|
7988
|
+
gasLimit: 1e4,
|
7989
|
+
gasPrice: minGasPrice
|
8207
7990
|
});
|
8208
|
-
|
8209
|
-
request.
|
8210
|
-
request.maxFee = txCost.maxFee;
|
8211
|
-
await genesisWallet.fund(request, txCost);
|
7991
|
+
request.addResources(resources);
|
7992
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8212
7993
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8213
7994
|
};
|
8214
7995
|
|
@@ -8223,11 +8004,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8223
8004
|
|
8224
8005
|
// src/test-utils/launchNode.ts
|
8225
8006
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8226
|
-
import {
|
8007
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8008
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8227
8009
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8228
8010
|
import { spawn } from "child_process";
|
8229
8011
|
import { randomUUID } from "crypto";
|
8230
|
-
import { randomBytes as randomBytes6 } from "ethers";
|
8231
8012
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8232
8013
|
import os from "os";
|
8233
8014
|
import path from "path";
|
@@ -8276,12 +8057,12 @@ var launchNode = async ({
|
|
8276
8057
|
// eslint-disable-next-line no-async-promise-executor
|
8277
8058
|
new Promise(async (resolve, reject) => {
|
8278
8059
|
const remainingArgs = extractRemainingArgs(args, [
|
8279
|
-
"--
|
8060
|
+
"--chain",
|
8280
8061
|
"--consensus-key",
|
8281
8062
|
"--db-type",
|
8282
8063
|
"--poa-instant"
|
8283
8064
|
]);
|
8284
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8065
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8285
8066
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8286
8067
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8287
8068
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8300,54 +8081,36 @@ var launchNode = async ({
|
|
8300
8081
|
let chainConfigPathToUse;
|
8301
8082
|
const prefix = basePath || os.tmpdir();
|
8302
8083
|
const suffix = basePath ? "" : randomUUID();
|
8303
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8084
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8304
8085
|
if (chainConfigPath) {
|
8305
8086
|
chainConfigPathToUse = chainConfigPath;
|
8306
8087
|
} else {
|
8307
8088
|
if (!existsSync(tempDirPath)) {
|
8308
8089
|
mkdirSync(tempDirPath, { recursive: true });
|
8309
8090
|
}
|
8310
|
-
|
8311
|
-
|
8312
|
-
stateConfigJson = {
|
8313
|
-
...stateConfigJson,
|
8314
|
-
coins: [
|
8315
|
-
...stateConfigJson.coins.map((coin) => ({
|
8316
|
-
...coin,
|
8317
|
-
amount: "18446744073709551615"
|
8318
|
-
}))
|
8319
|
-
],
|
8320
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8321
|
-
...message,
|
8322
|
-
amount: "18446744073709551615"
|
8323
|
-
}))
|
8324
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8325
|
-
};
|
8091
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8092
|
+
let chainConfig = defaultChainConfig;
|
8326
8093
|
if (!process.env.GENESIS_SECRET) {
|
8327
8094
|
const pk = Signer.generatePrivateKey();
|
8328
8095
|
const signer = new Signer(pk);
|
8329
8096
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8330
|
-
|
8331
|
-
|
8332
|
-
|
8333
|
-
|
8334
|
-
|
8335
|
-
|
8336
|
-
|
8337
|
-
|
8338
|
-
|
8339
|
-
|
8097
|
+
chainConfig = {
|
8098
|
+
...defaultChainConfig,
|
8099
|
+
initial_state: {
|
8100
|
+
...defaultChainConfig.initial_state,
|
8101
|
+
coins: [
|
8102
|
+
...defaultChainConfig.initial_state.coins,
|
8103
|
+
{
|
8104
|
+
owner: signer.address.toHexString(),
|
8105
|
+
amount: toHex2(1e9),
|
8106
|
+
asset_id: BaseAssetId4
|
8107
|
+
}
|
8108
|
+
]
|
8109
|
+
}
|
8110
|
+
};
|
8340
8111
|
}
|
8341
|
-
|
8342
|
-
|
8343
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8344
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8345
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8346
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8347
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8348
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8349
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8350
|
-
chainConfigPathToUse = tempDirPath;
|
8112
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8113
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8351
8114
|
}
|
8352
8115
|
const child = spawn(
|
8353
8116
|
command,
|
@@ -8356,10 +8119,10 @@ var launchNode = async ({
|
|
8356
8119
|
["--ip", ipToUse],
|
8357
8120
|
["--port", portToUse],
|
8358
8121
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8359
|
-
["--min-gas-price", "
|
8122
|
+
["--min-gas-price", "0"],
|
8360
8123
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8361
8124
|
["--consensus-key", consensusKey],
|
8362
|
-
["--
|
8125
|
+
["--chain", chainConfigPathToUse],
|
8363
8126
|
"--vm-backtrace",
|
8364
8127
|
"--utxo-validation",
|
8365
8128
|
"--debug",
|
@@ -8418,7 +8181,7 @@ var launchNodeAndGetWallets = async ({
|
|
8418
8181
|
walletCount = 10
|
8419
8182
|
} = {}) => {
|
8420
8183
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8421
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8184
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8422
8185
|
const wallets = await generateWallets(walletCount, provider);
|
8423
8186
|
const cleanup = () => {
|
8424
8187
|
closeNode();
|