@fuel-ts/account 0.0.0-rc-2021-20240409151049 → 0.0.0-rc-2034-20240410011904
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 +623 -868
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +525 -759
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +406 -639
- 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 +328 -894
- 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 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +31 -36
- 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 +1122 -1582
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +521 -735
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +415 -629
- 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";
|
@@ -38,24 +37,24 @@ import { hexlify } from "@fuel-ts/utils";
|
|
38
37
|
var coinQuantityfy = (coinQuantityLike) => {
|
39
38
|
let assetId;
|
40
39
|
let amount;
|
41
|
-
let
|
40
|
+
let max2;
|
42
41
|
if (Array.isArray(coinQuantityLike)) {
|
43
42
|
amount = coinQuantityLike[0];
|
44
43
|
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
45
|
-
|
44
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
46
45
|
} else {
|
47
46
|
amount = coinQuantityLike.amount;
|
48
47
|
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
49
|
-
|
48
|
+
max2 = coinQuantityLike.max ?? void 0;
|
50
49
|
}
|
51
50
|
const bnAmount = bn(amount);
|
52
51
|
return {
|
53
52
|
assetId: hexlify(assetId),
|
54
53
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
55
|
-
max:
|
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
|
}
|
@@ -272,6 +232,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
272
232
|
prevRoot
|
273
233
|
time
|
274
234
|
applicationHash
|
235
|
+
messageReceiptRoot
|
275
236
|
messageReceiptCount
|
276
237
|
}
|
277
238
|
commitBlockHeader {
|
@@ -283,6 +244,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
283
244
|
prevRoot
|
284
245
|
time
|
285
246
|
applicationHash
|
247
|
+
messageReceiptRoot
|
286
248
|
messageReceiptCount
|
287
249
|
}
|
288
250
|
sender
|
@@ -302,8 +264,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
302
264
|
var BlockFragmentFragmentDoc = gql`
|
303
265
|
fragment blockFragment on Block {
|
304
266
|
id
|
305
|
-
height
|
306
267
|
header {
|
268
|
+
height
|
307
269
|
time
|
308
270
|
}
|
309
271
|
transactions {
|
@@ -361,11 +323,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
361
323
|
`;
|
362
324
|
var GasCostsFragmentFragmentDoc = gql`
|
363
325
|
fragment GasCostsFragment on GasCosts {
|
364
|
-
version {
|
365
|
-
... on Version {
|
366
|
-
value
|
367
|
-
}
|
368
|
-
}
|
369
326
|
add
|
370
327
|
addi
|
371
328
|
aloc
|
@@ -378,6 +335,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
378
335
|
cb
|
379
336
|
cfei
|
380
337
|
cfsi
|
338
|
+
croo
|
381
339
|
div
|
382
340
|
divi
|
383
341
|
ecr1
|
@@ -460,9 +418,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
460
418
|
ccp {
|
461
419
|
...DependentCostFragment
|
462
420
|
}
|
463
|
-
croo {
|
464
|
-
...DependentCostFragment
|
465
|
-
}
|
466
421
|
csiz {
|
467
422
|
...DependentCostFragment
|
468
423
|
}
|
@@ -522,11 +477,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
522
477
|
${DependentCostFragmentFragmentDoc}`;
|
523
478
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
524
479
|
fragment consensusParametersFragment on ConsensusParameters {
|
525
|
-
version {
|
526
|
-
... on Version {
|
527
|
-
value
|
528
|
-
}
|
529
|
-
}
|
530
480
|
txParams {
|
531
481
|
...TxParametersFragment
|
532
482
|
}
|
@@ -586,9 +536,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
586
536
|
fragment nodeInfoFragment on NodeInfo {
|
587
537
|
utxoValidation
|
588
538
|
vmBacktrace
|
539
|
+
minGasPrice
|
589
540
|
maxTx
|
590
541
|
maxDepth
|
591
542
|
nodeVersion
|
543
|
+
peers {
|
544
|
+
id
|
545
|
+
addresses
|
546
|
+
clientVersion
|
547
|
+
blockHeight
|
548
|
+
lastHeartbeatMs
|
549
|
+
appScore
|
550
|
+
}
|
592
551
|
}
|
593
552
|
`;
|
594
553
|
var GetVersionDocument = gql`
|
@@ -623,9 +582,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
623
582
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
624
583
|
transaction(id: $transactionId) {
|
625
584
|
...transactionFragment
|
585
|
+
receipts {
|
586
|
+
...receiptFragment
|
587
|
+
}
|
626
588
|
}
|
627
589
|
}
|
628
|
-
${TransactionFragmentFragmentDoc}
|
590
|
+
${TransactionFragmentFragmentDoc}
|
591
|
+
${ReceiptFragmentFragmentDoc}`;
|
629
592
|
var GetTransactionsDocument = gql`
|
630
593
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
631
594
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -753,20 +716,6 @@ var GetBalanceDocument = gql`
|
|
753
716
|
}
|
754
717
|
}
|
755
718
|
${BalanceFragmentFragmentDoc}`;
|
756
|
-
var GetLatestGasPriceDocument = gql`
|
757
|
-
query getLatestGasPrice {
|
758
|
-
latestGasPrice {
|
759
|
-
gasPrice
|
760
|
-
}
|
761
|
-
}
|
762
|
-
`;
|
763
|
-
var EstimateGasPriceDocument = gql`
|
764
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
765
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
766
|
-
gasPrice
|
767
|
-
}
|
768
|
-
}
|
769
|
-
`;
|
770
719
|
var GetBalancesDocument = gql`
|
771
720
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
772
721
|
balances(
|
@@ -821,12 +770,12 @@ var GetMessageStatusDocument = gql`
|
|
821
770
|
}
|
822
771
|
`;
|
823
772
|
var DryRunDocument = gql`
|
824
|
-
mutation dryRun($
|
825
|
-
dryRun(
|
826
|
-
...
|
773
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
774
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
775
|
+
...receiptFragment
|
827
776
|
}
|
828
777
|
}
|
829
|
-
${
|
778
|
+
${ReceiptFragmentFragmentDoc}`;
|
830
779
|
var SubmitDocument = gql`
|
831
780
|
mutation submit($encodedTransaction: HexString!) {
|
832
781
|
submit(tx: $encodedTransaction) {
|
@@ -909,12 +858,6 @@ function getSdk(requester) {
|
|
909
858
|
getBalance(variables, options) {
|
910
859
|
return requester(GetBalanceDocument, variables, options);
|
911
860
|
},
|
912
|
-
getLatestGasPrice(variables, options) {
|
913
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
914
|
-
},
|
915
|
-
estimateGasPrice(variables, options) {
|
916
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
917
|
-
},
|
918
861
|
getBalances(variables, options) {
|
919
862
|
return requester(GetBalancesDocument, variables, options);
|
920
863
|
},
|
@@ -984,14 +927,11 @@ var _FuelGraphqlSubscriber = class {
|
|
984
927
|
let data;
|
985
928
|
let errors;
|
986
929
|
try {
|
987
|
-
|
988
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
930
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
989
931
|
} catch (e) {
|
990
932
|
throw new FuelError(
|
991
933
|
ErrorCode.STREAM_PARSING_ERROR,
|
992
|
-
`Error while parsing stream data response: ${text}
|
993
|
-
|
994
|
-
Thrown error: ${e}`
|
934
|
+
`Error while parsing stream data response: ${text}`
|
995
935
|
);
|
996
936
|
}
|
997
937
|
if (Array.isArray(errors)) {
|
@@ -1092,7 +1032,7 @@ var inputify = (value) => {
|
|
1092
1032
|
return {
|
1093
1033
|
type: InputType.Coin,
|
1094
1034
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1095
|
-
outputIndex: toNumber(arrayify(value.id).slice(32,
|
1035
|
+
outputIndex: toNumber(arrayify(value.id).slice(32, 33)),
|
1096
1036
|
owner: hexlify3(value.owner),
|
1097
1037
|
amount: bn2(value.amount),
|
1098
1038
|
assetId: hexlify3(value.assetId),
|
@@ -1101,9 +1041,10 @@ var inputify = (value) => {
|
|
1101
1041
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1102
1042
|
},
|
1103
1043
|
witnessIndex: value.witnessIndex,
|
1044
|
+
maturity: value.maturity ?? 0,
|
1104
1045
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1105
|
-
predicateLength:
|
1106
|
-
predicateDataLength:
|
1046
|
+
predicateLength: predicate.length,
|
1047
|
+
predicateDataLength: predicateData.length,
|
1107
1048
|
predicate: hexlify3(predicate),
|
1108
1049
|
predicateData: hexlify3(predicateData)
|
1109
1050
|
};
|
@@ -1134,8 +1075,8 @@ var inputify = (value) => {
|
|
1134
1075
|
nonce: hexlify3(value.nonce),
|
1135
1076
|
witnessIndex: value.witnessIndex,
|
1136
1077
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1137
|
-
predicateLength:
|
1138
|
-
predicateDataLength:
|
1078
|
+
predicateLength: predicate.length,
|
1079
|
+
predicateDataLength: predicateData.length,
|
1139
1080
|
predicate: hexlify3(predicate),
|
1140
1081
|
predicateData: hexlify3(predicateData),
|
1141
1082
|
data: hexlify3(data),
|
@@ -1261,8 +1202,8 @@ function assembleReceiptByType(receipt) {
|
|
1261
1202
|
case "CALL" /* Call */: {
|
1262
1203
|
const callReceipt = {
|
1263
1204
|
type: ReceiptType.Call,
|
1264
|
-
from: hexOrZero(receipt.id
|
1265
|
-
to: hexOrZero(receipt?.to),
|
1205
|
+
from: hexOrZero(receipt.contract?.id),
|
1206
|
+
to: hexOrZero(receipt?.to?.id),
|
1266
1207
|
amount: bn4(receipt.amount),
|
1267
1208
|
assetId: hexOrZero(receipt.assetId),
|
1268
1209
|
gas: bn4(receipt.gas),
|
@@ -1276,7 +1217,7 @@ function assembleReceiptByType(receipt) {
|
|
1276
1217
|
case "RETURN" /* Return */: {
|
1277
1218
|
const returnReceipt = {
|
1278
1219
|
type: ReceiptType.Return,
|
1279
|
-
id: hexOrZero(receipt.id
|
1220
|
+
id: hexOrZero(receipt.contract?.id),
|
1280
1221
|
val: bn4(receipt.val),
|
1281
1222
|
pc: bn4(receipt.pc),
|
1282
1223
|
is: bn4(receipt.is)
|
@@ -1286,7 +1227,7 @@ function assembleReceiptByType(receipt) {
|
|
1286
1227
|
case "RETURN_DATA" /* ReturnData */: {
|
1287
1228
|
const returnDataReceipt = {
|
1288
1229
|
type: ReceiptType.ReturnData,
|
1289
|
-
id: hexOrZero(receipt.id
|
1230
|
+
id: hexOrZero(receipt.contract?.id),
|
1290
1231
|
ptr: bn4(receipt.ptr),
|
1291
1232
|
len: bn4(receipt.len),
|
1292
1233
|
digest: hexOrZero(receipt.digest),
|
@@ -1298,7 +1239,7 @@ function assembleReceiptByType(receipt) {
|
|
1298
1239
|
case "PANIC" /* Panic */: {
|
1299
1240
|
const panicReceipt = {
|
1300
1241
|
type: ReceiptType.Panic,
|
1301
|
-
id: hexOrZero(receipt.id),
|
1242
|
+
id: hexOrZero(receipt.contract?.id),
|
1302
1243
|
reason: bn4(receipt.reason),
|
1303
1244
|
pc: bn4(receipt.pc),
|
1304
1245
|
is: bn4(receipt.is),
|
@@ -1309,7 +1250,7 @@ function assembleReceiptByType(receipt) {
|
|
1309
1250
|
case "REVERT" /* Revert */: {
|
1310
1251
|
const revertReceipt = {
|
1311
1252
|
type: ReceiptType.Revert,
|
1312
|
-
id: hexOrZero(receipt.id
|
1253
|
+
id: hexOrZero(receipt.contract?.id),
|
1313
1254
|
val: bn4(receipt.ra),
|
1314
1255
|
pc: bn4(receipt.pc),
|
1315
1256
|
is: bn4(receipt.is)
|
@@ -1319,7 +1260,7 @@ function assembleReceiptByType(receipt) {
|
|
1319
1260
|
case "LOG" /* Log */: {
|
1320
1261
|
const logReceipt = {
|
1321
1262
|
type: ReceiptType.Log,
|
1322
|
-
id: hexOrZero(receipt.id
|
1263
|
+
id: hexOrZero(receipt.contract?.id),
|
1323
1264
|
val0: bn4(receipt.ra),
|
1324
1265
|
val1: bn4(receipt.rb),
|
1325
1266
|
val2: bn4(receipt.rc),
|
@@ -1332,7 +1273,7 @@ function assembleReceiptByType(receipt) {
|
|
1332
1273
|
case "LOG_DATA" /* LogData */: {
|
1333
1274
|
const logDataReceipt = {
|
1334
1275
|
type: ReceiptType.LogData,
|
1335
|
-
id: hexOrZero(receipt.id
|
1276
|
+
id: hexOrZero(receipt.contract?.id),
|
1336
1277
|
val0: bn4(receipt.ra),
|
1337
1278
|
val1: bn4(receipt.rb),
|
1338
1279
|
ptr: bn4(receipt.ptr),
|
@@ -1346,8 +1287,8 @@ function assembleReceiptByType(receipt) {
|
|
1346
1287
|
case "TRANSFER" /* Transfer */: {
|
1347
1288
|
const transferReceipt = {
|
1348
1289
|
type: ReceiptType.Transfer,
|
1349
|
-
from: hexOrZero(receipt.id
|
1350
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1290
|
+
from: hexOrZero(receipt.contract?.id),
|
1291
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1351
1292
|
amount: bn4(receipt.amount),
|
1352
1293
|
assetId: hexOrZero(receipt.assetId),
|
1353
1294
|
pc: bn4(receipt.pc),
|
@@ -1358,8 +1299,8 @@ function assembleReceiptByType(receipt) {
|
|
1358
1299
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1359
1300
|
const transferOutReceipt = {
|
1360
1301
|
type: ReceiptType.TransferOut,
|
1361
|
-
from: hexOrZero(receipt.id
|
1362
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1302
|
+
from: hexOrZero(receipt.contract?.id),
|
1303
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1363
1304
|
amount: bn4(receipt.amount),
|
1364
1305
|
assetId: hexOrZero(receipt.assetId),
|
1365
1306
|
pc: bn4(receipt.pc),
|
@@ -1402,7 +1343,7 @@ function assembleReceiptByType(receipt) {
|
|
1402
1343
|
return receiptMessageOut;
|
1403
1344
|
}
|
1404
1345
|
case "MINT" /* Mint */: {
|
1405
|
-
const contractId = hexOrZero(receipt.id
|
1346
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1406
1347
|
const subId = hexOrZero(receipt.subId);
|
1407
1348
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1408
1349
|
const mintReceipt = {
|
@@ -1417,7 +1358,7 @@ function assembleReceiptByType(receipt) {
|
|
1417
1358
|
return mintReceipt;
|
1418
1359
|
}
|
1419
1360
|
case "BURN" /* Burn */: {
|
1420
|
-
const contractId = hexOrZero(receipt.id
|
1361
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1421
1362
|
const subId = hexOrZero(receipt.subId);
|
1422
1363
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1423
1364
|
const burnReceipt = {
|
@@ -1443,6 +1384,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1443
1384
|
import { bn as bn5 } from "@fuel-ts/math";
|
1444
1385
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1445
1386
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1387
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1446
1388
|
var getGasUsedFromReceipts = (receipts) => {
|
1447
1389
|
const scriptResult = receipts.filter(
|
1448
1390
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1463,28 +1405,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1463
1405
|
}
|
1464
1406
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1465
1407
|
const witnessCache = [];
|
1466
|
-
const
|
1467
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1468
|
-
if (isCoinOrMessage) {
|
1469
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1470
|
-
return true;
|
1471
|
-
}
|
1472
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1473
|
-
witnessCache.push(input.witnessIndex);
|
1474
|
-
return true;
|
1475
|
-
}
|
1476
|
-
}
|
1477
|
-
return false;
|
1478
|
-
});
|
1479
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1480
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1408
|
+
const totalGas = inputs.reduce((total, input) => {
|
1481
1409
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1482
1410
|
return total.add(
|
1483
|
-
|
1411
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1484
1412
|
);
|
1485
1413
|
}
|
1486
|
-
|
1487
|
-
|
1414
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1415
|
+
witnessCache.push(input.witnessIndex);
|
1416
|
+
return total.add(gasCosts.ecr1);
|
1417
|
+
}
|
1418
|
+
return total;
|
1419
|
+
}, bn5());
|
1488
1420
|
return totalGas;
|
1489
1421
|
}
|
1490
1422
|
function getMinGas(params) {
|
@@ -1496,20 +1428,12 @@ function getMinGas(params) {
|
|
1496
1428
|
return minGas;
|
1497
1429
|
}
|
1498
1430
|
function getMaxGas(params) {
|
1499
|
-
const {
|
1500
|
-
gasPerByte,
|
1501
|
-
witnessesLength,
|
1502
|
-
witnessLimit,
|
1503
|
-
minGas,
|
1504
|
-
gasLimit = bn5(0),
|
1505
|
-
maxGasPerTx
|
1506
|
-
} = params;
|
1431
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1507
1432
|
let remainingAllowedWitnessGas = bn5(0);
|
1508
1433
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1509
1434
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1510
1435
|
}
|
1511
|
-
|
1512
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1436
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1513
1437
|
}
|
1514
1438
|
function calculateMetadataGasForTxCreate({
|
1515
1439
|
gasCosts,
|
@@ -1531,10 +1455,6 @@ function calculateMetadataGasForTxScript({
|
|
1531
1455
|
}) {
|
1532
1456
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1533
1457
|
}
|
1534
|
-
var calculateGasFee = (params) => {
|
1535
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1536
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1537
|
-
};
|
1538
1458
|
|
1539
1459
|
// src/providers/utils/json.ts
|
1540
1460
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1679,7 +1599,7 @@ var witnessify = (value) => {
|
|
1679
1599
|
// src/providers/transaction-request/transaction-request.ts
|
1680
1600
|
var BaseTransactionRequest = class {
|
1681
1601
|
/** Gas price for transaction */
|
1682
|
-
|
1602
|
+
gasPrice;
|
1683
1603
|
/** Block until which tx cannot be included */
|
1684
1604
|
maturity;
|
1685
1605
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1698,7 +1618,7 @@ var BaseTransactionRequest = class {
|
|
1698
1618
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1699
1619
|
*/
|
1700
1620
|
constructor({
|
1701
|
-
|
1621
|
+
gasPrice,
|
1702
1622
|
maturity,
|
1703
1623
|
maxFee,
|
1704
1624
|
witnessLimit,
|
@@ -1706,7 +1626,7 @@ var BaseTransactionRequest = class {
|
|
1706
1626
|
outputs,
|
1707
1627
|
witnesses
|
1708
1628
|
} = {}) {
|
1709
|
-
this.
|
1629
|
+
this.gasPrice = bn7(gasPrice);
|
1710
1630
|
this.maturity = maturity ?? 0;
|
1711
1631
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1712
1632
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1717,9 +1637,9 @@ var BaseTransactionRequest = class {
|
|
1717
1637
|
static getPolicyMeta(req) {
|
1718
1638
|
let policyTypes = 0;
|
1719
1639
|
const policies = [];
|
1720
|
-
if (req.
|
1721
|
-
policyTypes += PolicyType.
|
1722
|
-
policies.push({ data: req.
|
1640
|
+
if (req.gasPrice) {
|
1641
|
+
policyTypes += PolicyType.GasPrice;
|
1642
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1723
1643
|
}
|
1724
1644
|
if (req.witnessLimit) {
|
1725
1645
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1906,10 +1826,10 @@ var BaseTransactionRequest = class {
|
|
1906
1826
|
* @param predicate - Predicate bytes.
|
1907
1827
|
* @param predicateData - Predicate data bytes.
|
1908
1828
|
*/
|
1909
|
-
addCoinInput(coin) {
|
1829
|
+
addCoinInput(coin, predicate) {
|
1910
1830
|
const { assetId, owner, amount } = coin;
|
1911
1831
|
let witnessIndex;
|
1912
|
-
if (
|
1832
|
+
if (predicate) {
|
1913
1833
|
witnessIndex = 0;
|
1914
1834
|
} else {
|
1915
1835
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1924,7 +1844,9 @@ var BaseTransactionRequest = class {
|
|
1924
1844
|
amount,
|
1925
1845
|
assetId,
|
1926
1846
|
txPointer: "0x00000000000000000000000000000000",
|
1927
|
-
witnessIndex
|
1847
|
+
witnessIndex,
|
1848
|
+
predicate: predicate?.bytes,
|
1849
|
+
predicateData: predicate?.predicateDataBytes
|
1928
1850
|
};
|
1929
1851
|
this.pushInput(input);
|
1930
1852
|
this.addChangeOutput(owner, assetId);
|
@@ -1937,11 +1859,11 @@ var BaseTransactionRequest = class {
|
|
1937
1859
|
* @param predicate - Predicate bytes.
|
1938
1860
|
* @param predicateData - Predicate data bytes.
|
1939
1861
|
*/
|
1940
|
-
addMessageInput(message) {
|
1862
|
+
addMessageInput(message, predicate) {
|
1941
1863
|
const { recipient, sender, amount } = message;
|
1942
1864
|
const assetId = BaseAssetId2;
|
1943
1865
|
let witnessIndex;
|
1944
|
-
if (
|
1866
|
+
if (predicate) {
|
1945
1867
|
witnessIndex = 0;
|
1946
1868
|
} else {
|
1947
1869
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1955,7 +1877,9 @@ var BaseTransactionRequest = class {
|
|
1955
1877
|
sender: sender.toB256(),
|
1956
1878
|
recipient: recipient.toB256(),
|
1957
1879
|
amount,
|
1958
|
-
witnessIndex
|
1880
|
+
witnessIndex,
|
1881
|
+
predicate: predicate?.bytes,
|
1882
|
+
predicateData: predicate?.predicateDataBytes
|
1959
1883
|
};
|
1960
1884
|
this.pushInput(input);
|
1961
1885
|
this.addChangeOutput(recipient, assetId);
|
@@ -1986,6 +1910,32 @@ var BaseTransactionRequest = class {
|
|
1986
1910
|
resources.forEach((resource) => this.addResource(resource));
|
1987
1911
|
return this;
|
1988
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
|
+
}
|
1989
1939
|
/**
|
1990
1940
|
* Adds a coin output to the transaction.
|
1991
1941
|
*
|
@@ -2065,7 +2015,7 @@ var BaseTransactionRequest = class {
|
|
2065
2015
|
}
|
2066
2016
|
calculateMaxGas(chainInfo, minGas) {
|
2067
2017
|
const { consensusParameters } = chainInfo;
|
2068
|
-
const { gasPerByte
|
2018
|
+
const { gasPerByte } = consensusParameters;
|
2069
2019
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2070
2020
|
(acc, wit) => acc + wit.dataLength,
|
2071
2021
|
0
|
@@ -2074,8 +2024,7 @@ var BaseTransactionRequest = class {
|
|
2074
2024
|
gasPerByte,
|
2075
2025
|
minGas,
|
2076
2026
|
witnessesLength,
|
2077
|
-
witnessLimit: this.witnessLimit
|
2078
|
-
maxGasPerTx
|
2027
|
+
witnessLimit: this.witnessLimit
|
2079
2028
|
});
|
2080
2029
|
}
|
2081
2030
|
/**
|
@@ -2093,20 +2042,17 @@ var BaseTransactionRequest = class {
|
|
2093
2042
|
});
|
2094
2043
|
const updateAssetInput = (assetId, quantity) => {
|
2095
2044
|
const assetInput = findAssetInput(assetId);
|
2096
|
-
let usedQuantity = quantity;
|
2097
|
-
if (assetId === BaseAssetId2) {
|
2098
|
-
usedQuantity = bn7("1000000000000000000");
|
2099
|
-
}
|
2100
2045
|
if (assetInput && "assetId" in assetInput) {
|
2101
|
-
assetInput.id = hexlify7(randomBytes(
|
2102
|
-
assetInput.amount =
|
2046
|
+
assetInput.id = hexlify7(randomBytes(33));
|
2047
|
+
assetInput.amount = quantity;
|
2103
2048
|
} else {
|
2104
2049
|
this.addResources([
|
2105
2050
|
{
|
2106
|
-
id: hexlify7(randomBytes(
|
2107
|
-
amount:
|
2051
|
+
id: hexlify7(randomBytes(33)),
|
2052
|
+
amount: quantity,
|
2108
2053
|
assetId,
|
2109
2054
|
owner: resourcesOwner || Address.fromRandom(),
|
2055
|
+
maturity: 0,
|
2110
2056
|
blockCreated: bn7(1),
|
2111
2057
|
txCreatedIdx: bn7(1)
|
2112
2058
|
}
|
@@ -2138,7 +2084,7 @@ var BaseTransactionRequest = class {
|
|
2138
2084
|
toJSON() {
|
2139
2085
|
return normalizeJSON(this);
|
2140
2086
|
}
|
2141
|
-
|
2087
|
+
updatePredicateInputs(inputs) {
|
2142
2088
|
this.inputs.forEach((i) => {
|
2143
2089
|
let correspondingInput;
|
2144
2090
|
switch (i.type) {
|
@@ -2160,15 +2106,6 @@ var BaseTransactionRequest = class {
|
|
2160
2106
|
}
|
2161
2107
|
});
|
2162
2108
|
}
|
2163
|
-
shiftPredicateData() {
|
2164
|
-
this.inputs.forEach((input) => {
|
2165
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2166
|
-
input.predicateData = input.paddPredicateData(
|
2167
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2168
|
-
);
|
2169
|
-
}
|
2170
|
-
});
|
2171
|
-
}
|
2172
2109
|
};
|
2173
2110
|
|
2174
2111
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2315,8 +2252,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2315
2252
|
return {
|
2316
2253
|
type: TransactionType3.Create,
|
2317
2254
|
...baseTransaction,
|
2255
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2318
2256
|
bytecodeWitnessIndex,
|
2319
|
-
storageSlotsCount:
|
2257
|
+
storageSlotsCount: storageSlots.length,
|
2320
2258
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2321
2259
|
storageSlots
|
2322
2260
|
};
|
@@ -2439,8 +2377,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2439
2377
|
type: TransactionType4.Script,
|
2440
2378
|
scriptGasLimit: this.gasLimit,
|
2441
2379
|
...super.getBaseTransaction(),
|
2442
|
-
scriptLength:
|
2443
|
-
scriptDataLength:
|
2380
|
+
scriptLength: script.length,
|
2381
|
+
scriptDataLength: scriptData.length,
|
2444
2382
|
receiptsRoot: ZeroBytes327,
|
2445
2383
|
script: hexlify10(script),
|
2446
2384
|
scriptData: hexlify10(scriptData)
|
@@ -2504,7 +2442,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2504
2442
|
}
|
2505
2443
|
calculateMaxGas(chainInfo, minGas) {
|
2506
2444
|
const { consensusParameters } = chainInfo;
|
2507
|
-
const { gasPerByte
|
2445
|
+
const { gasPerByte } = consensusParameters;
|
2508
2446
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2509
2447
|
(acc, wit) => acc + wit.dataLength,
|
2510
2448
|
0
|
@@ -2514,8 +2452,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2514
2452
|
minGas,
|
2515
2453
|
witnessesLength,
|
2516
2454
|
witnessLimit: this.witnessLimit,
|
2517
|
-
gasLimit: this.gasLimit
|
2518
|
-
maxGasPerTx
|
2455
|
+
gasLimit: this.gasLimit
|
2519
2456
|
});
|
2520
2457
|
}
|
2521
2458
|
/**
|
@@ -2572,7 +2509,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2572
2509
|
|
2573
2510
|
// src/providers/transaction-request/utils.ts
|
2574
2511
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2575
|
-
import { TransactionType as TransactionType5
|
2512
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2576
2513
|
var transactionRequestify = (obj) => {
|
2577
2514
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2578
2515
|
return obj;
|
@@ -2590,31 +2527,14 @@ var transactionRequestify = (obj) => {
|
|
2590
2527
|
}
|
2591
2528
|
}
|
2592
2529
|
};
|
2593
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2594
|
-
(acc, input) => {
|
2595
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2596
|
-
acc.utxos.push(input.id);
|
2597
|
-
}
|
2598
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2599
|
-
acc.messages.push(input.nonce);
|
2600
|
-
}
|
2601
|
-
return acc;
|
2602
|
-
},
|
2603
|
-
{
|
2604
|
-
utxos: [],
|
2605
|
-
messages: []
|
2606
|
-
}
|
2607
|
-
);
|
2608
2530
|
|
2609
2531
|
// src/providers/transaction-response/transaction-response.ts
|
2610
2532
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2611
|
-
import { bn as
|
2533
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2612
2534
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2613
2535
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2614
2536
|
|
2615
2537
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2616
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2617
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2618
2538
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2619
2539
|
|
2620
2540
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2623,10 +2543,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2623
2543
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2624
2544
|
var calculateTransactionFee = (params) => {
|
2625
2545
|
const {
|
2626
|
-
|
2546
|
+
gasUsed,
|
2627
2547
|
rawPayload,
|
2628
|
-
|
2629
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2548
|
+
consensusParameters: { gasCosts, feeParams }
|
2630
2549
|
} = params;
|
2631
2550
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2632
2551
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2636,7 +2555,8 @@ var calculateTransactionFee = (params) => {
|
|
2636
2555
|
return {
|
2637
2556
|
fee: bn11(0),
|
2638
2557
|
minFee: bn11(0),
|
2639
|
-
maxFee: bn11(0)
|
2558
|
+
maxFee: bn11(0),
|
2559
|
+
feeFromGasUsed: bn11(0)
|
2640
2560
|
};
|
2641
2561
|
}
|
2642
2562
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2668,6 +2588,7 @@ var calculateTransactionFee = (params) => {
|
|
2668
2588
|
metadataGas,
|
2669
2589
|
txBytesSize: transactionBytes.length
|
2670
2590
|
});
|
2591
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2671
2592
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2672
2593
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2673
2594
|
const maxGas = getMaxGas({
|
@@ -2675,25 +2596,17 @@ var calculateTransactionFee = (params) => {
|
|
2675
2596
|
minGas,
|
2676
2597
|
witnessesLength,
|
2677
2598
|
gasLimit,
|
2678
|
-
witnessLimit
|
2679
|
-
maxGasPerTx
|
2680
|
-
});
|
2681
|
-
const minFee = calculateGasFee({
|
2682
|
-
gasPrice,
|
2683
|
-
gas: minGas,
|
2684
|
-
priceFactor: gasPriceFactor,
|
2685
|
-
tip
|
2686
|
-
});
|
2687
|
-
const maxFee = calculateGasFee({
|
2688
|
-
gasPrice,
|
2689
|
-
gas: maxGas,
|
2690
|
-
priceFactor: gasPriceFactor,
|
2691
|
-
tip
|
2599
|
+
witnessLimit
|
2692
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);
|
2693
2605
|
return {
|
2606
|
+
fee,
|
2694
2607
|
minFee,
|
2695
2608
|
maxFee,
|
2696
|
-
|
2609
|
+
feeFromGasUsed
|
2697
2610
|
};
|
2698
2611
|
};
|
2699
2612
|
|
@@ -2749,7 +2662,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2749
2662
|
|
2750
2663
|
// src/providers/transaction-summary/input.ts
|
2751
2664
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2752
|
-
import { InputType as
|
2665
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2753
2666
|
function getInputsByTypes(inputs, types) {
|
2754
2667
|
return inputs.filter((i) => types.includes(i.type));
|
2755
2668
|
}
|
@@ -2757,16 +2670,16 @@ function getInputsByType(inputs, type) {
|
|
2757
2670
|
return inputs.filter((i) => i.type === type);
|
2758
2671
|
}
|
2759
2672
|
function getInputsCoin(inputs) {
|
2760
|
-
return getInputsByType(inputs,
|
2673
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2761
2674
|
}
|
2762
2675
|
function getInputsMessage(inputs) {
|
2763
|
-
return getInputsByType(inputs,
|
2676
|
+
return getInputsByType(inputs, InputType5.Message);
|
2764
2677
|
}
|
2765
2678
|
function getInputsCoinAndMessage(inputs) {
|
2766
|
-
return getInputsByTypes(inputs, [
|
2679
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2767
2680
|
}
|
2768
2681
|
function getInputsContract(inputs) {
|
2769
|
-
return getInputsByType(inputs,
|
2682
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2770
2683
|
}
|
2771
2684
|
function getInputFromAssetId(inputs, assetId) {
|
2772
2685
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2785,7 +2698,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2785
2698
|
if (!contractInput) {
|
2786
2699
|
return void 0;
|
2787
2700
|
}
|
2788
|
-
if (contractInput.type !==
|
2701
|
+
if (contractInput.type !== InputType5.Contract) {
|
2789
2702
|
throw new FuelError9(
|
2790
2703
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2791
2704
|
`Contract input should be of type 'contract'.`
|
@@ -2794,10 +2707,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2794
2707
|
return contractInput;
|
2795
2708
|
}
|
2796
2709
|
function getInputAccountAddress(input) {
|
2797
|
-
if (input.type ===
|
2710
|
+
if (input.type === InputType5.Coin) {
|
2798
2711
|
return input.owner.toString();
|
2799
2712
|
}
|
2800
|
-
if (input.type ===
|
2713
|
+
if (input.type === InputType5.Message) {
|
2801
2714
|
return input.recipient.toString();
|
2802
2715
|
}
|
2803
2716
|
return "";
|
@@ -3260,9 +3173,7 @@ function assembleTransactionSummary(params) {
|
|
3260
3173
|
gqlTransactionStatus,
|
3261
3174
|
abiMap = {},
|
3262
3175
|
maxInputs,
|
3263
|
-
gasCosts
|
3264
|
-
maxGasPerTx,
|
3265
|
-
gasPrice
|
3176
|
+
gasCosts
|
3266
3177
|
} = params;
|
3267
3178
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3268
3179
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3276,14 +3187,11 @@ function assembleTransactionSummary(params) {
|
|
3276
3187
|
maxInputs
|
3277
3188
|
});
|
3278
3189
|
const typeName = getTransactionTypeName(transaction.type);
|
3279
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3280
3190
|
const { fee } = calculateTransactionFee({
|
3281
|
-
|
3191
|
+
gasUsed,
|
3282
3192
|
rawPayload,
|
3283
|
-
tip,
|
3284
3193
|
consensusParameters: {
|
3285
3194
|
gasCosts,
|
3286
|
-
maxGasPerTx,
|
3287
3195
|
feeParams: {
|
3288
3196
|
gasPerByte,
|
3289
3197
|
gasPriceFactor
|
@@ -3343,7 +3251,7 @@ var TransactionResponse = class {
|
|
3343
3251
|
/** Current provider */
|
3344
3252
|
provider;
|
3345
3253
|
/** Gas used on the transaction */
|
3346
|
-
gasUsed =
|
3254
|
+
gasUsed = bn14(0);
|
3347
3255
|
/** The graphql Transaction with receipts object. */
|
3348
3256
|
gqlTransaction;
|
3349
3257
|
abis;
|
@@ -3421,13 +3329,8 @@ var TransactionResponse = class {
|
|
3421
3329
|
const decodedTransaction = this.decodeTransaction(
|
3422
3330
|
transaction
|
3423
3331
|
);
|
3424
|
-
|
3425
|
-
|
3426
|
-
txReceipts = transaction.status.receipts;
|
3427
|
-
}
|
3428
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3429
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3430
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3332
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3333
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3431
3334
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3432
3335
|
const transactionSummary = assembleTransactionSummary({
|
3433
3336
|
id: this.id,
|
@@ -3439,9 +3342,7 @@ var TransactionResponse = class {
|
|
3439
3342
|
gasPriceFactor,
|
3440
3343
|
abiMap: contractsAbiMap,
|
3441
3344
|
maxInputs,
|
3442
|
-
gasCosts
|
3443
|
-
maxGasPerTx,
|
3444
|
-
gasPrice
|
3345
|
+
gasCosts
|
3445
3346
|
});
|
3446
3347
|
return transactionSummary;
|
3447
3348
|
}
|
@@ -3568,29 +3469,29 @@ var processGqlChain = (chain) => {
|
|
3568
3469
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3569
3470
|
return {
|
3570
3471
|
name,
|
3571
|
-
baseChainHeight:
|
3472
|
+
baseChainHeight: bn15(daHeight),
|
3572
3473
|
consensusParameters: {
|
3573
|
-
contractMaxSize:
|
3574
|
-
maxInputs:
|
3575
|
-
maxOutputs:
|
3576
|
-
maxWitnesses:
|
3577
|
-
maxGasPerTx:
|
3578
|
-
maxScriptLength:
|
3579
|
-
maxScriptDataLength:
|
3580
|
-
maxStorageSlots:
|
3581
|
-
maxPredicateLength:
|
3582
|
-
maxPredicateDataLength:
|
3583
|
-
maxGasPerPredicate:
|
3584
|
-
gasPriceFactor:
|
3585
|
-
gasPerByte:
|
3586
|
-
maxMessageDataLength:
|
3587
|
-
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),
|
3588
3489
|
gasCosts
|
3589
3490
|
},
|
3590
3491
|
gasCosts,
|
3591
3492
|
latestBlock: {
|
3592
3493
|
id: latestBlock.id,
|
3593
|
-
height:
|
3494
|
+
height: bn15(latestBlock.header.height),
|
3594
3495
|
time: latestBlock.header.time,
|
3595
3496
|
transactions: latestBlock.transactions.map((i) => ({
|
3596
3497
|
id: i.id
|
@@ -3684,8 +3585,10 @@ var _Provider = class {
|
|
3684
3585
|
* Returns some helpful parameters related to gas fees.
|
3685
3586
|
*/
|
3686
3587
|
getGasConfig() {
|
3588
|
+
const { minGasPrice } = this.getNode();
|
3687
3589
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3688
3590
|
return {
|
3591
|
+
minGasPrice,
|
3689
3592
|
maxGasPerTx,
|
3690
3593
|
maxGasPerPredicate,
|
3691
3594
|
gasPriceFactor,
|
@@ -3783,7 +3686,7 @@ var _Provider = class {
|
|
3783
3686
|
*/
|
3784
3687
|
async getBlockNumber() {
|
3785
3688
|
const { chain } = await this.operations.getChain();
|
3786
|
-
return
|
3689
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3787
3690
|
}
|
3788
3691
|
/**
|
3789
3692
|
* Returns the chain information.
|
@@ -3793,11 +3696,13 @@ var _Provider = class {
|
|
3793
3696
|
async fetchNode() {
|
3794
3697
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3795
3698
|
const processedNodeInfo = {
|
3796
|
-
maxDepth:
|
3797
|
-
maxTx:
|
3699
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3700
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3701
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3798
3702
|
nodeVersion: nodeInfo.nodeVersion,
|
3799
3703
|
utxoValidation: nodeInfo.utxoValidation,
|
3800
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3704
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3705
|
+
peers: nodeInfo.peers
|
3801
3706
|
};
|
3802
3707
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3803
3708
|
return processedNodeInfo;
|
@@ -3883,13 +3788,14 @@ var _Provider = class {
|
|
3883
3788
|
return this.estimateTxDependencies(transactionRequest);
|
3884
3789
|
}
|
3885
3790
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3886
|
-
const { dryRun:
|
3887
|
-
|
3791
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3792
|
+
encodedTransaction,
|
3888
3793
|
utxoValidation: utxoValidation || false
|
3889
3794
|
});
|
3890
|
-
const
|
3891
|
-
|
3892
|
-
|
3795
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3796
|
+
return {
|
3797
|
+
receipts
|
3798
|
+
};
|
3893
3799
|
}
|
3894
3800
|
/**
|
3895
3801
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3915,7 +3821,7 @@ var _Provider = class {
|
|
3915
3821
|
} = response;
|
3916
3822
|
if (inputs) {
|
3917
3823
|
inputs.forEach((input, index) => {
|
3918
|
-
if ("predicateGasUsed" in input &&
|
3824
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3919
3825
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3920
3826
|
}
|
3921
3827
|
});
|
@@ -3928,6 +3834,9 @@ var _Provider = class {
|
|
3928
3834
|
* If there are missing variable outputs,
|
3929
3835
|
* `addVariableOutputs` is called on the transaction.
|
3930
3836
|
*
|
3837
|
+
* @privateRemarks
|
3838
|
+
* TODO: Investigate support for missing contract IDs
|
3839
|
+
* TODO: Add support for missing output messages
|
3931
3840
|
*
|
3932
3841
|
* @param transactionRequest - The transaction request object.
|
3933
3842
|
* @returns A promise.
|
@@ -3940,19 +3849,16 @@ var _Provider = class {
|
|
3940
3849
|
missingContractIds: []
|
3941
3850
|
};
|
3942
3851
|
}
|
3852
|
+
await this.estimatePredicates(transactionRequest);
|
3943
3853
|
let receipts = [];
|
3944
3854
|
const missingContractIds = [];
|
3945
3855
|
let outputVariables = 0;
|
3946
|
-
let dryrunStatus;
|
3947
3856
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3948
|
-
const {
|
3949
|
-
|
3950
|
-
} = await this.operations.dryRun({
|
3951
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3857
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3858
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3952
3859
|
utxoValidation: false
|
3953
3860
|
});
|
3954
|
-
receipts =
|
3955
|
-
dryrunStatus = status;
|
3861
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3956
3862
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3957
3863
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3958
3864
|
if (hasMissingOutputs) {
|
@@ -3962,11 +3868,6 @@ var _Provider = class {
|
|
3962
3868
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3963
3869
|
missingContractIds.push(contractId);
|
3964
3870
|
});
|
3965
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3966
|
-
transactionRequest,
|
3967
|
-
optimizeGas: false
|
3968
|
-
});
|
3969
|
-
transactionRequest.maxFee = maxFee;
|
3970
3871
|
} else {
|
3971
3872
|
break;
|
3972
3873
|
}
|
@@ -3974,133 +3875,38 @@ var _Provider = class {
|
|
3974
3875
|
return {
|
3975
3876
|
receipts,
|
3976
3877
|
outputVariables,
|
3977
|
-
missingContractIds
|
3978
|
-
dryrunStatus
|
3878
|
+
missingContractIds
|
3979
3879
|
};
|
3980
3880
|
}
|
3981
3881
|
/**
|
3982
|
-
*
|
3983
|
-
*
|
3984
|
-
*
|
3985
|
-
*
|
3986
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3987
|
-
*
|
3988
|
-
* @param transactionRequests - Array of transaction request objects.
|
3989
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
3882
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3883
|
+
* @param transactionRequest - The transaction request object.
|
3884
|
+
* @param optimizeGas - Optional. Specifies whether to optimize the gas. Default is false.
|
3885
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3990
3886
|
*/
|
3991
|
-
|
3992
|
-
const
|
3993
|
-
|
3994
|
-
outputVariables: 0,
|
3995
|
-
missingContractIds: [],
|
3996
|
-
dryrunStatus: void 0
|
3997
|
-
}));
|
3998
|
-
const allRequests = clone3(transactionRequests);
|
3999
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4000
|
-
allRequests.forEach((req, index) => {
|
4001
|
-
if (req.type === TransactionType8.Script) {
|
4002
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4003
|
-
}
|
4004
|
-
});
|
4005
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4006
|
-
let attempt = 0;
|
4007
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4008
|
-
const encodedTransactions = transactionsToProcess.map(
|
4009
|
-
(index) => serializedTransactionsMap.get(index)
|
4010
|
-
);
|
4011
|
-
const dryRunResults = await this.operations.dryRun({
|
4012
|
-
encodedTransactions,
|
4013
|
-
utxoValidation: false
|
4014
|
-
});
|
4015
|
-
const nextRoundTransactions = [];
|
4016
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4017
|
-
const currentResultIndex = transactionsToProcess[i];
|
4018
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4019
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4020
|
-
results[currentResultIndex].dryrunStatus = status;
|
4021
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4022
|
-
results[currentResultIndex].receipts
|
4023
|
-
);
|
4024
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4025
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4026
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4027
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4028
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4029
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4030
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4031
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4032
|
-
});
|
4033
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4034
|
-
transactionRequest: requestToProcess,
|
4035
|
-
optimizeGas: false
|
4036
|
-
});
|
4037
|
-
requestToProcess.maxFee = maxFee;
|
4038
|
-
serializedTransactionsMap.set(
|
4039
|
-
currentResultIndex,
|
4040
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4041
|
-
);
|
4042
|
-
nextRoundTransactions.push(currentResultIndex);
|
4043
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4044
|
-
}
|
4045
|
-
}
|
4046
|
-
transactionsToProcess = nextRoundTransactions;
|
4047
|
-
attempt += 1;
|
4048
|
-
}
|
4049
|
-
return results;
|
4050
|
-
}
|
4051
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4052
|
-
if (estimateTxDependencies) {
|
4053
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4054
|
-
}
|
4055
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4056
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4057
|
-
encodedTransactions,
|
4058
|
-
utxoValidation: utxoValidation || false
|
4059
|
-
});
|
4060
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4061
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4062
|
-
return { receipts, dryrunStatus: status };
|
4063
|
-
});
|
4064
|
-
return results;
|
4065
|
-
}
|
4066
|
-
async estimateTxGasAndFee(params) {
|
4067
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4068
|
-
let { gasPrice } = params;
|
3887
|
+
estimateTxGasAndFee(params) {
|
3888
|
+
const { transactionRequest } = params;
|
3889
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4069
3890
|
const chainInfo = this.getChain();
|
4070
|
-
const
|
3891
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3892
|
+
transactionRequest.gasPrice = gasPrice;
|
4071
3893
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4072
|
-
|
4073
|
-
gasPrice = await this.estimateGasPrice(10);
|
4074
|
-
}
|
4075
|
-
const minFee = calculateGasFee({
|
4076
|
-
gasPrice: bn16(gasPrice),
|
4077
|
-
gas: minGas,
|
4078
|
-
priceFactor: gasPriceFactor,
|
4079
|
-
tip: transactionRequest.tip
|
4080
|
-
}).add(1);
|
4081
|
-
let gasLimit = bn16(0);
|
3894
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4082
3895
|
if (transactionRequest.type === TransactionType8.Script) {
|
4083
|
-
|
4084
|
-
if (!optimizeGas) {
|
3896
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4085
3897
|
transactionRequest.gasLimit = minGas;
|
4086
|
-
gasLimit =
|
4087
|
-
|
3898
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3899
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3900
|
+
);
|
4088
3901
|
}
|
4089
3902
|
}
|
4090
3903
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4091
|
-
const maxFee =
|
4092
|
-
gasPrice: bn16(gasPrice),
|
4093
|
-
gas: maxGas,
|
4094
|
-
priceFactor: gasPriceFactor,
|
4095
|
-
tip: transactionRequest.tip
|
4096
|
-
}).add(1);
|
3904
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4097
3905
|
return {
|
4098
3906
|
minGas,
|
4099
3907
|
minFee,
|
4100
3908
|
maxGas,
|
4101
|
-
maxFee
|
4102
|
-
gasPrice,
|
4103
|
-
gasLimit
|
3909
|
+
maxFee
|
4104
3910
|
};
|
4105
3911
|
}
|
4106
3912
|
/**
|
@@ -4118,17 +3924,15 @@ var _Provider = class {
|
|
4118
3924
|
if (estimateTxDependencies) {
|
4119
3925
|
return this.estimateTxDependencies(transactionRequest);
|
4120
3926
|
}
|
4121
|
-
const
|
4122
|
-
const { dryRun:
|
4123
|
-
|
3927
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3928
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3929
|
+
encodedTransaction,
|
4124
3930
|
utxoValidation: true
|
4125
3931
|
});
|
4126
|
-
const
|
4127
|
-
|
4128
|
-
|
4129
|
-
|
4130
|
-
});
|
4131
|
-
return { receipts: callResult[0].receipts };
|
3932
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3933
|
+
return {
|
3934
|
+
receipts
|
3935
|
+
};
|
4132
3936
|
}
|
4133
3937
|
/**
|
4134
3938
|
* Returns a transaction cost to enable user
|
@@ -4145,80 +3949,77 @@ var _Provider = class {
|
|
4145
3949
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4146
3950
|
* @returns A promise that resolves to the transaction cost object.
|
4147
3951
|
*/
|
4148
|
-
async getTransactionCost(transactionRequestLike,
|
3952
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3953
|
+
estimateTxDependencies = true,
|
3954
|
+
estimatePredicates = true,
|
3955
|
+
resourcesOwner,
|
3956
|
+
signatureCallback
|
3957
|
+
} = {}) {
|
4149
3958
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3959
|
+
const { minGasPrice } = this.getGasConfig();
|
3960
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4150
3961
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4151
3962
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4152
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3963
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4153
3964
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4154
|
-
txRequestClone.maxFee = bn16(0);
|
4155
3965
|
if (isScriptTransaction) {
|
4156
|
-
txRequestClone.gasLimit =
|
3966
|
+
txRequestClone.gasLimit = bn15(0);
|
4157
3967
|
}
|
4158
|
-
if (
|
4159
|
-
resourcesOwner
|
3968
|
+
if (estimatePredicates) {
|
3969
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3970
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3971
|
+
}
|
3972
|
+
await this.estimatePredicates(txRequestClone);
|
4160
3973
|
}
|
4161
|
-
const signedRequest = clone3(txRequestClone);
|
4162
|
-
let addedSignatures = 0;
|
4163
3974
|
if (signatureCallback && isScriptTransaction) {
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
await this.estimatePredicates(signedRequest);
|
4169
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4170
|
-
transactionRequest: signedRequest,
|
4171
|
-
optimizeGas: false
|
3975
|
+
await signatureCallback(txRequestClone);
|
3976
|
+
}
|
3977
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3978
|
+
transactionRequest: txRequestClone
|
4172
3979
|
});
|
4173
|
-
txRequestClone.maxFee = maxFee;
|
4174
3980
|
let receipts = [];
|
4175
3981
|
let missingContractIds = [];
|
4176
3982
|
let outputVariables = 0;
|
4177
|
-
let gasUsed =
|
4178
|
-
|
4179
|
-
|
4180
|
-
if (signatureCallback) {
|
4181
|
-
await signatureCallback(txRequestClone);
|
4182
|
-
}
|
4183
|
-
txRequestClone.gasLimit = gasLimit;
|
3983
|
+
let gasUsed = bn15(0);
|
3984
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3985
|
+
txRequestClone.gasPrice = bn15(0);
|
4184
3986
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4185
3987
|
receipts = result.receipts;
|
4186
3988
|
outputVariables = result.outputVariables;
|
4187
3989
|
missingContractIds = result.missingContractIds;
|
4188
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
3990
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4189
3991
|
txRequestClone.gasLimit = gasUsed;
|
4190
|
-
|
4191
|
-
|
4192
|
-
|
3992
|
+
txRequestClone.gasPrice = setGasPrice;
|
3993
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3994
|
+
transactionRequest: txRequestClone
|
4193
3995
|
}));
|
4194
3996
|
}
|
4195
3997
|
return {
|
4196
3998
|
requiredQuantities: allQuantities,
|
4197
3999
|
receipts,
|
4198
4000
|
gasUsed,
|
4199
|
-
|
4001
|
+
minGasPrice,
|
4002
|
+
gasPrice: setGasPrice,
|
4200
4003
|
minGas,
|
4201
4004
|
maxGas,
|
4202
4005
|
minFee,
|
4203
4006
|
maxFee,
|
4007
|
+
estimatedInputs: txRequestClone.inputs,
|
4204
4008
|
outputVariables,
|
4205
|
-
missingContractIds
|
4206
|
-
addedSignatures,
|
4207
|
-
estimatedPredicates: txRequestClone.inputs
|
4009
|
+
missingContractIds
|
4208
4010
|
};
|
4209
4011
|
}
|
4210
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4012
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4211
4013
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4212
4014
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4213
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4214
|
-
quantitiesToContract
|
4215
|
-
});
|
4015
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4216
4016
|
transactionRequest.addResources(
|
4217
4017
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4218
4018
|
);
|
4219
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4220
|
-
|
4221
|
-
|
4019
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4020
|
+
transactionRequest,
|
4021
|
+
forwardingQuantities
|
4022
|
+
);
|
4222
4023
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4223
4024
|
return {
|
4224
4025
|
resources,
|
@@ -4240,10 +4041,11 @@ var _Provider = class {
|
|
4240
4041
|
return coins.map((coin) => ({
|
4241
4042
|
id: coin.utxoId,
|
4242
4043
|
assetId: coin.assetId,
|
4243
|
-
amount:
|
4044
|
+
amount: bn15(coin.amount),
|
4244
4045
|
owner: Address2.fromAddressOrString(coin.owner),
|
4245
|
-
|
4246
|
-
|
4046
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4047
|
+
blockCreated: bn15(coin.blockCreated),
|
4048
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4247
4049
|
}));
|
4248
4050
|
}
|
4249
4051
|
/**
|
@@ -4280,9 +4082,9 @@ var _Provider = class {
|
|
4280
4082
|
switch (coin.__typename) {
|
4281
4083
|
case "MessageCoin":
|
4282
4084
|
return {
|
4283
|
-
amount:
|
4085
|
+
amount: bn15(coin.amount),
|
4284
4086
|
assetId: coin.assetId,
|
4285
|
-
daHeight:
|
4087
|
+
daHeight: bn15(coin.daHeight),
|
4286
4088
|
sender: Address2.fromAddressOrString(coin.sender),
|
4287
4089
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4288
4090
|
nonce: coin.nonce
|
@@ -4290,11 +4092,12 @@ var _Provider = class {
|
|
4290
4092
|
case "Coin":
|
4291
4093
|
return {
|
4292
4094
|
id: coin.utxoId,
|
4293
|
-
amount:
|
4095
|
+
amount: bn15(coin.amount),
|
4294
4096
|
assetId: coin.assetId,
|
4295
4097
|
owner: Address2.fromAddressOrString(coin.owner),
|
4296
|
-
|
4297
|
-
|
4098
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4099
|
+
blockCreated: bn15(coin.blockCreated),
|
4100
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4298
4101
|
};
|
4299
4102
|
default:
|
4300
4103
|
return null;
|
@@ -4311,13 +4114,13 @@ var _Provider = class {
|
|
4311
4114
|
async getBlock(idOrHeight) {
|
4312
4115
|
let variables;
|
4313
4116
|
if (typeof idOrHeight === "number") {
|
4314
|
-
variables = { height:
|
4117
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4315
4118
|
} else if (idOrHeight === "latest") {
|
4316
4119
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4317
4120
|
} else if (idOrHeight.length === 66) {
|
4318
4121
|
variables = { blockId: idOrHeight };
|
4319
4122
|
} else {
|
4320
|
-
variables = { blockId:
|
4123
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4321
4124
|
}
|
4322
4125
|
const { block } = await this.operations.getBlock(variables);
|
4323
4126
|
if (!block) {
|
@@ -4325,7 +4128,7 @@ var _Provider = class {
|
|
4325
4128
|
}
|
4326
4129
|
return {
|
4327
4130
|
id: block.id,
|
4328
|
-
height:
|
4131
|
+
height: bn15(block.header.height),
|
4329
4132
|
time: block.header.time,
|
4330
4133
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4331
4134
|
};
|
@@ -4340,7 +4143,7 @@ var _Provider = class {
|
|
4340
4143
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4341
4144
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4342
4145
|
id: block.id,
|
4343
|
-
height:
|
4146
|
+
height: bn15(block.header.height),
|
4344
4147
|
time: block.header.time,
|
4345
4148
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4346
4149
|
}));
|
@@ -4355,7 +4158,7 @@ var _Provider = class {
|
|
4355
4158
|
async getBlockWithTransactions(idOrHeight) {
|
4356
4159
|
let variables;
|
4357
4160
|
if (typeof idOrHeight === "number") {
|
4358
|
-
variables = { blockHeight:
|
4161
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4359
4162
|
} else if (idOrHeight === "latest") {
|
4360
4163
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4361
4164
|
} else {
|
@@ -4367,7 +4170,7 @@ var _Provider = class {
|
|
4367
4170
|
}
|
4368
4171
|
return {
|
4369
4172
|
id: block.id,
|
4370
|
-
height:
|
4173
|
+
height: bn15(block.header.height, 10),
|
4371
4174
|
time: block.header.time,
|
4372
4175
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4373
4176
|
transactions: block.transactions.map(
|
@@ -4416,7 +4219,7 @@ var _Provider = class {
|
|
4416
4219
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4417
4220
|
asset: hexlify12(assetId)
|
4418
4221
|
});
|
4419
|
-
return
|
4222
|
+
return bn15(contractBalance.amount, 10);
|
4420
4223
|
}
|
4421
4224
|
/**
|
4422
4225
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4430,7 +4233,7 @@ var _Provider = class {
|
|
4430
4233
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4431
4234
|
assetId: hexlify12(assetId)
|
4432
4235
|
});
|
4433
|
-
return
|
4236
|
+
return bn15(balance.amount, 10);
|
4434
4237
|
}
|
4435
4238
|
/**
|
4436
4239
|
* Returns balances for the given owner.
|
@@ -4448,7 +4251,7 @@ var _Provider = class {
|
|
4448
4251
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4449
4252
|
return balances.map((balance) => ({
|
4450
4253
|
assetId: balance.assetId,
|
4451
|
-
amount:
|
4254
|
+
amount: bn15(balance.amount)
|
4452
4255
|
}));
|
4453
4256
|
}
|
4454
4257
|
/**
|
@@ -4470,15 +4273,15 @@ var _Provider = class {
|
|
4470
4273
|
sender: message.sender,
|
4471
4274
|
recipient: message.recipient,
|
4472
4275
|
nonce: message.nonce,
|
4473
|
-
amount:
|
4276
|
+
amount: bn15(message.amount),
|
4474
4277
|
data: message.data
|
4475
4278
|
}),
|
4476
4279
|
sender: Address2.fromAddressOrString(message.sender),
|
4477
4280
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4478
4281
|
nonce: message.nonce,
|
4479
|
-
amount:
|
4282
|
+
amount: bn15(message.amount),
|
4480
4283
|
data: InputMessageCoder.decodeData(message.data),
|
4481
|
-
daHeight:
|
4284
|
+
daHeight: bn15(message.daHeight)
|
4482
4285
|
}));
|
4483
4286
|
}
|
4484
4287
|
/**
|
@@ -4531,52 +4334,44 @@ var _Provider = class {
|
|
4531
4334
|
} = result.messageProof;
|
4532
4335
|
return {
|
4533
4336
|
messageProof: {
|
4534
|
-
proofIndex:
|
4337
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4535
4338
|
proofSet: messageProof.proofSet
|
4536
4339
|
},
|
4537
4340
|
blockProof: {
|
4538
|
-
proofIndex:
|
4341
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4539
4342
|
proofSet: blockProof.proofSet
|
4540
4343
|
},
|
4541
4344
|
messageBlockHeader: {
|
4542
4345
|
id: messageBlockHeader.id,
|
4543
|
-
daHeight:
|
4544
|
-
transactionsCount:
|
4346
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4347
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4545
4348
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4546
|
-
height:
|
4349
|
+
height: bn15(messageBlockHeader.height),
|
4547
4350
|
prevRoot: messageBlockHeader.prevRoot,
|
4548
4351
|
time: messageBlockHeader.time,
|
4549
4352
|
applicationHash: messageBlockHeader.applicationHash,
|
4550
|
-
|
4353
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4354
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4551
4355
|
},
|
4552
4356
|
commitBlockHeader: {
|
4553
4357
|
id: commitBlockHeader.id,
|
4554
|
-
daHeight:
|
4555
|
-
transactionsCount:
|
4358
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4359
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4556
4360
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4557
|
-
height:
|
4361
|
+
height: bn15(commitBlockHeader.height),
|
4558
4362
|
prevRoot: commitBlockHeader.prevRoot,
|
4559
4363
|
time: commitBlockHeader.time,
|
4560
4364
|
applicationHash: commitBlockHeader.applicationHash,
|
4561
|
-
|
4365
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4366
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4562
4367
|
},
|
4563
4368
|
sender: Address2.fromAddressOrString(sender),
|
4564
4369
|
recipient: Address2.fromAddressOrString(recipient),
|
4565
4370
|
nonce,
|
4566
|
-
amount:
|
4371
|
+
amount: bn15(amount),
|
4567
4372
|
data
|
4568
4373
|
};
|
4569
4374
|
}
|
4570
|
-
async getLatestGasPrice() {
|
4571
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4572
|
-
return bn16(latestGasPrice.gasPrice);
|
4573
|
-
}
|
4574
|
-
async estimateGasPrice(blockHorizon) {
|
4575
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4576
|
-
blockHorizon: String(blockHorizon)
|
4577
|
-
});
|
4578
|
-
return bn16(estimateGasPrice.gasPrice);
|
4579
|
-
}
|
4580
4375
|
/**
|
4581
4376
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4582
4377
|
*
|
@@ -4596,10 +4391,10 @@ var _Provider = class {
|
|
4596
4391
|
*/
|
4597
4392
|
async produceBlocks(amount, startTime) {
|
4598
4393
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4599
|
-
blocksToProduce:
|
4394
|
+
blocksToProduce: bn15(amount).toString(10),
|
4600
4395
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4601
4396
|
});
|
4602
|
-
return
|
4397
|
+
return bn15(latestBlockHeight);
|
4603
4398
|
}
|
4604
4399
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4605
4400
|
async getTransactionResponse(transactionId) {
|
@@ -4613,7 +4408,7 @@ cacheInputs_fn = function(inputs) {
|
|
4613
4408
|
return;
|
4614
4409
|
}
|
4615
4410
|
inputs.forEach((input) => {
|
4616
|
-
if (input.type ===
|
4411
|
+
if (input.type === InputType6.Coin) {
|
4617
4412
|
this.cache?.set(input.id);
|
4618
4413
|
}
|
4619
4414
|
});
|
@@ -4623,7 +4418,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4623
4418
|
|
4624
4419
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4625
4420
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4626
|
-
import { bn as
|
4421
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4627
4422
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4628
4423
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4629
4424
|
|
@@ -4869,33 +4664,36 @@ var Account = class extends AbstractAccount {
|
|
4869
4664
|
* @param fee - The estimated transaction fee.
|
4870
4665
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4871
4666
|
*/
|
4872
|
-
async fund(request,
|
4873
|
-
const
|
4874
|
-
|
4875
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4876
|
-
amount: bn18(fee),
|
4667
|
+
async fund(request, coinQuantities, fee) {
|
4668
|
+
const updatedQuantities = addAmountToAsset({
|
4669
|
+
amount: bn17(fee),
|
4877
4670
|
assetId: BaseAssetId3,
|
4878
|
-
coinQuantities
|
4671
|
+
coinQuantities
|
4879
4672
|
});
|
4880
4673
|
const quantitiesDict = {};
|
4881
|
-
|
4674
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4882
4675
|
quantitiesDict[assetId] = {
|
4883
4676
|
required: amount,
|
4884
|
-
owned:
|
4677
|
+
owned: bn17(0)
|
4885
4678
|
};
|
4886
4679
|
});
|
4887
|
-
|
4680
|
+
const cachedUtxos = [];
|
4681
|
+
const cachedMessages = [];
|
4682
|
+
const owner = this.address.toB256();
|
4683
|
+
request.inputs.forEach((input) => {
|
4888
4684
|
const isResource = "amount" in input;
|
4889
4685
|
if (isResource) {
|
4890
4686
|
const isCoin2 = "owner" in input;
|
4891
4687
|
if (isCoin2) {
|
4892
4688
|
const assetId = String(input.assetId);
|
4893
|
-
if (quantitiesDict[assetId]) {
|
4894
|
-
const amount =
|
4689
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4690
|
+
const amount = bn17(input.amount);
|
4895
4691
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4692
|
+
cachedUtxos.push(input.id);
|
4896
4693
|
}
|
4897
|
-
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4694
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4898
4695
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4696
|
+
cachedMessages.push(input.nonce);
|
4899
4697
|
}
|
4900
4698
|
}
|
4901
4699
|
});
|
@@ -4910,23 +4708,12 @@ var Account = class extends AbstractAccount {
|
|
4910
4708
|
});
|
4911
4709
|
const needsToBeFunded = missingQuantities.length;
|
4912
4710
|
if (needsToBeFunded) {
|
4913
|
-
const
|
4914
|
-
|
4915
|
-
|
4916
|
-
|
4917
|
-
|
4918
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4919
|
-
const requestToBeReEstimate = clone4(txRequest);
|
4920
|
-
if (addedSignatures) {
|
4921
|
-
Array.from({ length: addedSignatures }).forEach(
|
4922
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4923
|
-
);
|
4711
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4712
|
+
messages: cachedMessages,
|
4713
|
+
utxos: cachedUtxos
|
4714
|
+
});
|
4715
|
+
request.addResources(resources);
|
4924
4716
|
}
|
4925
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4926
|
-
transactionRequest: requestToBeReEstimate
|
4927
|
-
});
|
4928
|
-
txRequest.maxFee = maxFee;
|
4929
|
-
return txRequest;
|
4930
4717
|
}
|
4931
4718
|
/**
|
4932
4719
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4934,25 +4721,28 @@ var Account = class extends AbstractAccount {
|
|
4934
4721
|
* @param destination - The address of the destination.
|
4935
4722
|
* @param amount - The amount of coins to transfer.
|
4936
4723
|
* @param assetId - The asset ID of the coins to transfer.
|
4937
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4724
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4938
4725
|
* @returns A promise that resolves to the prepared transaction request.
|
4939
4726
|
*/
|
4940
4727
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4941
|
-
const
|
4728
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4729
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4730
|
+
const request = new ScriptTransactionRequest(params);
|
4942
4731
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4943
|
-
const
|
4732
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4944
4733
|
estimateTxDependencies: true,
|
4945
4734
|
resourcesOwner: this
|
4946
4735
|
});
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
await this.fund(request,
|
4736
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4737
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4738
|
+
this.validateGas({
|
4739
|
+
gasUsed,
|
4740
|
+
gasPrice: request.gasPrice,
|
4741
|
+
gasLimit: request.gasLimit,
|
4742
|
+
minGasPrice
|
4743
|
+
});
|
4744
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4745
|
+
request.updatePredicateInputs(estimatedInputs);
|
4956
4746
|
return request;
|
4957
4747
|
}
|
4958
4748
|
/**
|
@@ -4965,7 +4755,7 @@ var Account = class extends AbstractAccount {
|
|
4965
4755
|
* @returns A promise that resolves to the transaction response.
|
4966
4756
|
*/
|
4967
4757
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4968
|
-
if (
|
4758
|
+
if (bn17(amount).lte(0)) {
|
4969
4759
|
throw new FuelError15(
|
4970
4760
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4971
4761
|
"Transfer amount must be a positive number."
|
@@ -4984,37 +4774,38 @@ var Account = class extends AbstractAccount {
|
|
4984
4774
|
* @returns A promise that resolves to the transaction response.
|
4985
4775
|
*/
|
4986
4776
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4987
|
-
if (
|
4777
|
+
if (bn17(amount).lte(0)) {
|
4988
4778
|
throw new FuelError15(
|
4989
4779
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4990
4780
|
"Transfer amount must be a positive number."
|
4991
4781
|
);
|
4992
4782
|
}
|
4993
4783
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4784
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4785
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4994
4786
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4995
4787
|
hexlifiedContractId: contractAddress.toB256(),
|
4996
|
-
amountToTransfer:
|
4788
|
+
amountToTransfer: bn17(amount),
|
4997
4789
|
assetId
|
4998
4790
|
});
|
4999
4791
|
const request = new ScriptTransactionRequest({
|
5000
|
-
...
|
4792
|
+
...params,
|
5001
4793
|
script,
|
5002
4794
|
scriptData
|
5003
4795
|
});
|
5004
4796
|
request.addContractInputAndOutput(contractAddress);
|
5005
|
-
const
|
5006
|
-
|
5007
|
-
|
4797
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4798
|
+
request,
|
4799
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4800
|
+
);
|
4801
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4802
|
+
this.validateGas({
|
4803
|
+
gasUsed,
|
4804
|
+
gasPrice: request.gasPrice,
|
4805
|
+
gasLimit: request.gasLimit,
|
4806
|
+
minGasPrice
|
5008
4807
|
});
|
5009
|
-
|
5010
|
-
this.validateGas({
|
5011
|
-
gasUsed: txCost.gasUsed,
|
5012
|
-
gasLimit: request.gasLimit
|
5013
|
-
});
|
5014
|
-
}
|
5015
|
-
request.gasLimit = txCost.gasUsed;
|
5016
|
-
request.maxFee = txCost.maxFee;
|
5017
|
-
await this.fund(request, txCost);
|
4808
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5018
4809
|
return this.sendTransaction(request);
|
5019
4810
|
}
|
5020
4811
|
/**
|
@@ -5026,31 +4817,34 @@ var Account = class extends AbstractAccount {
|
|
5026
4817
|
* @returns A promise that resolves to the transaction response.
|
5027
4818
|
*/
|
5028
4819
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4820
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5029
4821
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5030
4822
|
const recipientDataArray = arrayify14(
|
5031
4823
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5032
4824
|
);
|
5033
4825
|
const amountDataArray = arrayify14(
|
5034
|
-
"0x".concat(
|
4826
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5035
4827
|
);
|
5036
4828
|
const script = new Uint8Array([
|
5037
4829
|
...arrayify14(withdrawScript.bytes),
|
5038
4830
|
...recipientDataArray,
|
5039
4831
|
...amountDataArray
|
5040
4832
|
]);
|
5041
|
-
const params = { script, ...txParams };
|
4833
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5042
4834
|
const request = new ScriptTransactionRequest(params);
|
5043
|
-
const
|
5044
|
-
const
|
5045
|
-
|
5046
|
-
|
5047
|
-
|
5048
|
-
|
5049
|
-
|
5050
|
-
|
5051
|
-
|
5052
|
-
|
5053
|
-
|
4835
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4836
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4837
|
+
request,
|
4838
|
+
forwardingQuantities
|
4839
|
+
);
|
4840
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4841
|
+
this.validateGas({
|
4842
|
+
gasUsed,
|
4843
|
+
gasPrice: request.gasPrice,
|
4844
|
+
gasLimit: request.gasLimit,
|
4845
|
+
minGasPrice
|
4846
|
+
});
|
4847
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5054
4848
|
return this.sendTransaction(request);
|
5055
4849
|
}
|
5056
4850
|
async signMessage(message) {
|
@@ -5108,7 +4902,18 @@ var Account = class extends AbstractAccount {
|
|
5108
4902
|
}
|
5109
4903
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5110
4904
|
}
|
5111
|
-
validateGas({
|
4905
|
+
validateGas({
|
4906
|
+
gasUsed,
|
4907
|
+
gasPrice,
|
4908
|
+
gasLimit,
|
4909
|
+
minGasPrice
|
4910
|
+
}) {
|
4911
|
+
if (minGasPrice.gt(gasPrice)) {
|
4912
|
+
throw new FuelError15(
|
4913
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4914
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4915
|
+
);
|
4916
|
+
}
|
5112
4917
|
if (gasUsed.gt(gasLimit)) {
|
5113
4918
|
throw new FuelError15(
|
5114
4919
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5400,7 +5205,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5400
5205
|
* @param transactionRequestLike - The transaction request to send.
|
5401
5206
|
* @returns A promise that resolves to the TransactionResponse object.
|
5402
5207
|
*/
|
5403
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5208
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5404
5209
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5405
5210
|
if (estimateTxDependencies) {
|
5406
5211
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5441,7 +5246,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5441
5246
|
// src/hdwallet/hdwallet.ts
|
5442
5247
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5443
5248
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5444
|
-
import { bn as
|
5249
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5445
5250
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5446
5251
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5447
5252
|
|
@@ -7907,7 +7712,7 @@ var HDWallet = class {
|
|
7907
7712
|
const IR = bytes.slice(32);
|
7908
7713
|
if (privateKey) {
|
7909
7714
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7910
|
-
const ki =
|
7715
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7911
7716
|
return new HDWallet({
|
7912
7717
|
privateKey: ki,
|
7913
7718
|
chainCode: IR,
|
@@ -8178,15 +7983,14 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8178
7983
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8179
7984
|
wallet.provider
|
8180
7985
|
);
|
8181
|
-
const
|
8182
|
-
|
8183
|
-
|
8184
|
-
|
7986
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7987
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7988
|
+
const request = new ScriptTransactionRequest({
|
7989
|
+
gasLimit: 1e4,
|
7990
|
+
gasPrice: minGasPrice
|
8185
7991
|
});
|
8186
|
-
|
8187
|
-
request.
|
8188
|
-
request.maxFee = txCost.maxFee;
|
8189
|
-
await genesisWallet.fund(request, txCost);
|
7992
|
+
request.addResources(resources);
|
7993
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8190
7994
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8191
7995
|
};
|
8192
7996
|
|
@@ -8201,11 +8005,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8201
8005
|
|
8202
8006
|
// src/test-utils/launchNode.ts
|
8203
8007
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8204
|
-
import {
|
8008
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8009
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8205
8010
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8206
8011
|
import { spawn } from "child_process";
|
8207
8012
|
import { randomUUID } from "crypto";
|
8208
|
-
import { randomBytes as randomBytes6 } from "ethers";
|
8209
8013
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8210
8014
|
import os from "os";
|
8211
8015
|
import path from "path";
|
@@ -8254,12 +8058,12 @@ var launchNode = async ({
|
|
8254
8058
|
// eslint-disable-next-line no-async-promise-executor
|
8255
8059
|
new Promise(async (resolve, reject) => {
|
8256
8060
|
const remainingArgs = extractRemainingArgs(args, [
|
8257
|
-
"--
|
8061
|
+
"--chain",
|
8258
8062
|
"--consensus-key",
|
8259
8063
|
"--db-type",
|
8260
8064
|
"--poa-instant"
|
8261
8065
|
]);
|
8262
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8066
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8263
8067
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8264
8068
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8265
8069
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8278,54 +8082,36 @@ var launchNode = async ({
|
|
8278
8082
|
let chainConfigPathToUse;
|
8279
8083
|
const prefix = basePath || os.tmpdir();
|
8280
8084
|
const suffix = basePath ? "" : randomUUID();
|
8281
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8085
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8282
8086
|
if (chainConfigPath) {
|
8283
8087
|
chainConfigPathToUse = chainConfigPath;
|
8284
8088
|
} else {
|
8285
8089
|
if (!existsSync(tempDirPath)) {
|
8286
8090
|
mkdirSync(tempDirPath, { recursive: true });
|
8287
8091
|
}
|
8288
|
-
|
8289
|
-
|
8290
|
-
stateConfigJson = {
|
8291
|
-
...stateConfigJson,
|
8292
|
-
coins: [
|
8293
|
-
...stateConfigJson.coins.map((coin) => ({
|
8294
|
-
...coin,
|
8295
|
-
amount: "18446744073709551615"
|
8296
|
-
}))
|
8297
|
-
],
|
8298
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8299
|
-
...message,
|
8300
|
-
amount: "18446744073709551615"
|
8301
|
-
}))
|
8302
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8303
|
-
};
|
8092
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8093
|
+
let chainConfig = defaultChainConfig;
|
8304
8094
|
if (!process.env.GENESIS_SECRET) {
|
8305
8095
|
const pk = Signer.generatePrivateKey();
|
8306
8096
|
const signer = new Signer(pk);
|
8307
8097
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8308
|
-
|
8309
|
-
|
8310
|
-
|
8311
|
-
|
8312
|
-
|
8313
|
-
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8098
|
+
chainConfig = {
|
8099
|
+
...defaultChainConfig,
|
8100
|
+
initial_state: {
|
8101
|
+
...defaultChainConfig.initial_state,
|
8102
|
+
coins: [
|
8103
|
+
...defaultChainConfig.initial_state.coins,
|
8104
|
+
{
|
8105
|
+
owner: signer.address.toHexString(),
|
8106
|
+
amount: toHex2(1e9),
|
8107
|
+
asset_id: BaseAssetId4
|
8108
|
+
}
|
8109
|
+
]
|
8110
|
+
}
|
8111
|
+
};
|
8318
8112
|
}
|
8319
|
-
|
8320
|
-
|
8321
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8322
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8323
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8324
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8325
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8326
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8327
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8328
|
-
chainConfigPathToUse = tempDirPath;
|
8113
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8114
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8329
8115
|
}
|
8330
8116
|
const child = spawn(
|
8331
8117
|
command,
|
@@ -8334,10 +8120,10 @@ var launchNode = async ({
|
|
8334
8120
|
["--ip", ipToUse],
|
8335
8121
|
["--port", portToUse],
|
8336
8122
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8337
|
-
["--min-gas-price", "
|
8123
|
+
["--min-gas-price", "0"],
|
8338
8124
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8339
8125
|
["--consensus-key", consensusKey],
|
8340
|
-
["--
|
8126
|
+
["--chain", chainConfigPathToUse],
|
8341
8127
|
"--vm-backtrace",
|
8342
8128
|
"--utxo-validation",
|
8343
8129
|
"--debug",
|
@@ -8396,7 +8182,7 @@ var launchNodeAndGetWallets = async ({
|
|
8396
8182
|
walletCount = 10
|
8397
8183
|
} = {}) => {
|
8398
8184
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8399
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8185
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8400
8186
|
const wallets = await generateWallets(walletCount, provider);
|
8401
8187
|
const cleanup = () => {
|
8402
8188
|
closeNode();
|