@fuel-ts/account 0.0.0-rc-2021-20240410132122 → 0.0.0-rc-2034-20240410133013
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 +560 -793
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +523 -760
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +404 -640
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -11
- 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 +1059 -1506
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +519 -735
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +413 -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,8 @@ var BaseTransactionRequest = class {
|
|
1924
1844
|
amount,
|
1925
1845
|
assetId,
|
1926
1846
|
txPointer: "0x00000000000000000000000000000000",
|
1927
|
-
witnessIndex
|
1847
|
+
witnessIndex,
|
1848
|
+
predicate: predicate?.bytes
|
1928
1849
|
};
|
1929
1850
|
this.pushInput(input);
|
1930
1851
|
this.addChangeOutput(owner, assetId);
|
@@ -1937,11 +1858,11 @@ var BaseTransactionRequest = class {
|
|
1937
1858
|
* @param predicate - Predicate bytes.
|
1938
1859
|
* @param predicateData - Predicate data bytes.
|
1939
1860
|
*/
|
1940
|
-
addMessageInput(message) {
|
1861
|
+
addMessageInput(message, predicate) {
|
1941
1862
|
const { recipient, sender, amount } = message;
|
1942
1863
|
const assetId = BaseAssetId2;
|
1943
1864
|
let witnessIndex;
|
1944
|
-
if (
|
1865
|
+
if (predicate) {
|
1945
1866
|
witnessIndex = 0;
|
1946
1867
|
} else {
|
1947
1868
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1955,7 +1876,8 @@ var BaseTransactionRequest = class {
|
|
1955
1876
|
sender: sender.toB256(),
|
1956
1877
|
recipient: recipient.toB256(),
|
1957
1878
|
amount,
|
1958
|
-
witnessIndex
|
1879
|
+
witnessIndex,
|
1880
|
+
predicate: predicate?.bytes
|
1959
1881
|
};
|
1960
1882
|
this.pushInput(input);
|
1961
1883
|
this.addChangeOutput(recipient, assetId);
|
@@ -1986,6 +1908,32 @@ var BaseTransactionRequest = class {
|
|
1986
1908
|
resources.forEach((resource) => this.addResource(resource));
|
1987
1909
|
return this;
|
1988
1910
|
}
|
1911
|
+
/**
|
1912
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1913
|
+
* outputs from the related assetIds.
|
1914
|
+
*
|
1915
|
+
* @param resources - The resources to add.
|
1916
|
+
* @returns This transaction.
|
1917
|
+
*/
|
1918
|
+
addPredicateResource(resource, predicate) {
|
1919
|
+
if (isCoin(resource)) {
|
1920
|
+
this.addCoinInput(resource, predicate);
|
1921
|
+
} else {
|
1922
|
+
this.addMessageInput(resource, predicate);
|
1923
|
+
}
|
1924
|
+
return this;
|
1925
|
+
}
|
1926
|
+
/**
|
1927
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1928
|
+
* from the related assetIds.
|
1929
|
+
*
|
1930
|
+
* @param resources - The resources to add.
|
1931
|
+
* @returns This transaction.
|
1932
|
+
*/
|
1933
|
+
addPredicateResources(resources, predicate) {
|
1934
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1935
|
+
return this;
|
1936
|
+
}
|
1989
1937
|
/**
|
1990
1938
|
* Adds a coin output to the transaction.
|
1991
1939
|
*
|
@@ -2065,7 +2013,7 @@ var BaseTransactionRequest = class {
|
|
2065
2013
|
}
|
2066
2014
|
calculateMaxGas(chainInfo, minGas) {
|
2067
2015
|
const { consensusParameters } = chainInfo;
|
2068
|
-
const { gasPerByte
|
2016
|
+
const { gasPerByte } = consensusParameters;
|
2069
2017
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2070
2018
|
(acc, wit) => acc + wit.dataLength,
|
2071
2019
|
0
|
@@ -2074,8 +2022,7 @@ var BaseTransactionRequest = class {
|
|
2074
2022
|
gasPerByte,
|
2075
2023
|
minGas,
|
2076
2024
|
witnessesLength,
|
2077
|
-
witnessLimit: this.witnessLimit
|
2078
|
-
maxGasPerTx
|
2025
|
+
witnessLimit: this.witnessLimit
|
2079
2026
|
});
|
2080
2027
|
}
|
2081
2028
|
/**
|
@@ -2093,20 +2040,17 @@ var BaseTransactionRequest = class {
|
|
2093
2040
|
});
|
2094
2041
|
const updateAssetInput = (assetId, quantity) => {
|
2095
2042
|
const assetInput = findAssetInput(assetId);
|
2096
|
-
let usedQuantity = quantity;
|
2097
|
-
if (assetId === BaseAssetId2) {
|
2098
|
-
usedQuantity = bn7("1000000000000000000");
|
2099
|
-
}
|
2100
2043
|
if (assetInput && "assetId" in assetInput) {
|
2101
|
-
assetInput.id = hexlify7(randomBytes(
|
2102
|
-
assetInput.amount =
|
2044
|
+
assetInput.id = hexlify7(randomBytes(33));
|
2045
|
+
assetInput.amount = quantity;
|
2103
2046
|
} else {
|
2104
2047
|
this.addResources([
|
2105
2048
|
{
|
2106
|
-
id: hexlify7(randomBytes(
|
2107
|
-
amount:
|
2049
|
+
id: hexlify7(randomBytes(33)),
|
2050
|
+
amount: quantity,
|
2108
2051
|
assetId,
|
2109
2052
|
owner: resourcesOwner || Address.fromRandom(),
|
2053
|
+
maturity: 0,
|
2110
2054
|
blockCreated: bn7(1),
|
2111
2055
|
txCreatedIdx: bn7(1)
|
2112
2056
|
}
|
@@ -2138,7 +2082,7 @@ var BaseTransactionRequest = class {
|
|
2138
2082
|
toJSON() {
|
2139
2083
|
return normalizeJSON(this);
|
2140
2084
|
}
|
2141
|
-
|
2085
|
+
updatePredicateInputs(inputs) {
|
2142
2086
|
this.inputs.forEach((i) => {
|
2143
2087
|
let correspondingInput;
|
2144
2088
|
switch (i.type) {
|
@@ -2160,15 +2104,6 @@ var BaseTransactionRequest = class {
|
|
2160
2104
|
}
|
2161
2105
|
});
|
2162
2106
|
}
|
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
2107
|
};
|
2173
2108
|
|
2174
2109
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2315,8 +2250,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2315
2250
|
return {
|
2316
2251
|
type: TransactionType3.Create,
|
2317
2252
|
...baseTransaction,
|
2253
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2318
2254
|
bytecodeWitnessIndex,
|
2319
|
-
storageSlotsCount:
|
2255
|
+
storageSlotsCount: storageSlots.length,
|
2320
2256
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2321
2257
|
storageSlots
|
2322
2258
|
};
|
@@ -2439,8 +2375,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2439
2375
|
type: TransactionType4.Script,
|
2440
2376
|
scriptGasLimit: this.gasLimit,
|
2441
2377
|
...super.getBaseTransaction(),
|
2442
|
-
scriptLength:
|
2443
|
-
scriptDataLength:
|
2378
|
+
scriptLength: script.length,
|
2379
|
+
scriptDataLength: scriptData.length,
|
2444
2380
|
receiptsRoot: ZeroBytes327,
|
2445
2381
|
script: hexlify10(script),
|
2446
2382
|
scriptData: hexlify10(scriptData)
|
@@ -2504,7 +2440,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2504
2440
|
}
|
2505
2441
|
calculateMaxGas(chainInfo, minGas) {
|
2506
2442
|
const { consensusParameters } = chainInfo;
|
2507
|
-
const { gasPerByte
|
2443
|
+
const { gasPerByte } = consensusParameters;
|
2508
2444
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2509
2445
|
(acc, wit) => acc + wit.dataLength,
|
2510
2446
|
0
|
@@ -2514,8 +2450,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2514
2450
|
minGas,
|
2515
2451
|
witnessesLength,
|
2516
2452
|
witnessLimit: this.witnessLimit,
|
2517
|
-
gasLimit: this.gasLimit
|
2518
|
-
maxGasPerTx
|
2453
|
+
gasLimit: this.gasLimit
|
2519
2454
|
});
|
2520
2455
|
}
|
2521
2456
|
/**
|
@@ -2572,7 +2507,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2572
2507
|
|
2573
2508
|
// src/providers/transaction-request/utils.ts
|
2574
2509
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2575
|
-
import { TransactionType as TransactionType5
|
2510
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2576
2511
|
var transactionRequestify = (obj) => {
|
2577
2512
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2578
2513
|
return obj;
|
@@ -2590,31 +2525,14 @@ var transactionRequestify = (obj) => {
|
|
2590
2525
|
}
|
2591
2526
|
}
|
2592
2527
|
};
|
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
2528
|
|
2609
2529
|
// src/providers/transaction-response/transaction-response.ts
|
2610
2530
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2611
|
-
import { bn as
|
2531
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2612
2532
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2613
2533
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2614
2534
|
|
2615
2535
|
// 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
2536
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2619
2537
|
|
2620
2538
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2623,10 +2541,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2623
2541
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2624
2542
|
var calculateTransactionFee = (params) => {
|
2625
2543
|
const {
|
2626
|
-
|
2544
|
+
gasUsed,
|
2627
2545
|
rawPayload,
|
2628
|
-
|
2629
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2546
|
+
consensusParameters: { gasCosts, feeParams }
|
2630
2547
|
} = params;
|
2631
2548
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2632
2549
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2636,7 +2553,8 @@ var calculateTransactionFee = (params) => {
|
|
2636
2553
|
return {
|
2637
2554
|
fee: bn11(0),
|
2638
2555
|
minFee: bn11(0),
|
2639
|
-
maxFee: bn11(0)
|
2556
|
+
maxFee: bn11(0),
|
2557
|
+
feeFromGasUsed: bn11(0)
|
2640
2558
|
};
|
2641
2559
|
}
|
2642
2560
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2668,6 +2586,7 @@ var calculateTransactionFee = (params) => {
|
|
2668
2586
|
metadataGas,
|
2669
2587
|
txBytesSize: transactionBytes.length
|
2670
2588
|
});
|
2589
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2671
2590
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2672
2591
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2673
2592
|
const maxGas = getMaxGas({
|
@@ -2675,25 +2594,17 @@ var calculateTransactionFee = (params) => {
|
|
2675
2594
|
minGas,
|
2676
2595
|
witnessesLength,
|
2677
2596
|
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
|
2597
|
+
witnessLimit
|
2692
2598
|
});
|
2599
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2600
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2601
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2602
|
+
const fee = minFee.add(feeFromGasUsed);
|
2693
2603
|
return {
|
2604
|
+
fee,
|
2694
2605
|
minFee,
|
2695
2606
|
maxFee,
|
2696
|
-
|
2607
|
+
feeFromGasUsed
|
2697
2608
|
};
|
2698
2609
|
};
|
2699
2610
|
|
@@ -2749,7 +2660,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2749
2660
|
|
2750
2661
|
// src/providers/transaction-summary/input.ts
|
2751
2662
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2752
|
-
import { InputType as
|
2663
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2753
2664
|
function getInputsByTypes(inputs, types) {
|
2754
2665
|
return inputs.filter((i) => types.includes(i.type));
|
2755
2666
|
}
|
@@ -2757,16 +2668,16 @@ function getInputsByType(inputs, type) {
|
|
2757
2668
|
return inputs.filter((i) => i.type === type);
|
2758
2669
|
}
|
2759
2670
|
function getInputsCoin(inputs) {
|
2760
|
-
return getInputsByType(inputs,
|
2671
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2761
2672
|
}
|
2762
2673
|
function getInputsMessage(inputs) {
|
2763
|
-
return getInputsByType(inputs,
|
2674
|
+
return getInputsByType(inputs, InputType5.Message);
|
2764
2675
|
}
|
2765
2676
|
function getInputsCoinAndMessage(inputs) {
|
2766
|
-
return getInputsByTypes(inputs, [
|
2677
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2767
2678
|
}
|
2768
2679
|
function getInputsContract(inputs) {
|
2769
|
-
return getInputsByType(inputs,
|
2680
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2770
2681
|
}
|
2771
2682
|
function getInputFromAssetId(inputs, assetId) {
|
2772
2683
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2785,7 +2696,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2785
2696
|
if (!contractInput) {
|
2786
2697
|
return void 0;
|
2787
2698
|
}
|
2788
|
-
if (contractInput.type !==
|
2699
|
+
if (contractInput.type !== InputType5.Contract) {
|
2789
2700
|
throw new FuelError9(
|
2790
2701
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2791
2702
|
`Contract input should be of type 'contract'.`
|
@@ -2794,10 +2705,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2794
2705
|
return contractInput;
|
2795
2706
|
}
|
2796
2707
|
function getInputAccountAddress(input) {
|
2797
|
-
if (input.type ===
|
2708
|
+
if (input.type === InputType5.Coin) {
|
2798
2709
|
return input.owner.toString();
|
2799
2710
|
}
|
2800
|
-
if (input.type ===
|
2711
|
+
if (input.type === InputType5.Message) {
|
2801
2712
|
return input.recipient.toString();
|
2802
2713
|
}
|
2803
2714
|
return "";
|
@@ -3260,9 +3171,7 @@ function assembleTransactionSummary(params) {
|
|
3260
3171
|
gqlTransactionStatus,
|
3261
3172
|
abiMap = {},
|
3262
3173
|
maxInputs,
|
3263
|
-
gasCosts
|
3264
|
-
maxGasPerTx,
|
3265
|
-
gasPrice
|
3174
|
+
gasCosts
|
3266
3175
|
} = params;
|
3267
3176
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3268
3177
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3276,14 +3185,11 @@ function assembleTransactionSummary(params) {
|
|
3276
3185
|
maxInputs
|
3277
3186
|
});
|
3278
3187
|
const typeName = getTransactionTypeName(transaction.type);
|
3279
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3280
3188
|
const { fee } = calculateTransactionFee({
|
3281
|
-
|
3189
|
+
gasUsed,
|
3282
3190
|
rawPayload,
|
3283
|
-
tip,
|
3284
3191
|
consensusParameters: {
|
3285
3192
|
gasCosts,
|
3286
|
-
maxGasPerTx,
|
3287
3193
|
feeParams: {
|
3288
3194
|
gasPerByte,
|
3289
3195
|
gasPriceFactor
|
@@ -3343,7 +3249,7 @@ var TransactionResponse = class {
|
|
3343
3249
|
/** Current provider */
|
3344
3250
|
provider;
|
3345
3251
|
/** Gas used on the transaction */
|
3346
|
-
gasUsed =
|
3252
|
+
gasUsed = bn14(0);
|
3347
3253
|
/** The graphql Transaction with receipts object. */
|
3348
3254
|
gqlTransaction;
|
3349
3255
|
abis;
|
@@ -3421,13 +3327,8 @@ var TransactionResponse = class {
|
|
3421
3327
|
const decodedTransaction = this.decodeTransaction(
|
3422
3328
|
transaction
|
3423
3329
|
);
|
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();
|
3330
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3331
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3431
3332
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3432
3333
|
const transactionSummary = assembleTransactionSummary({
|
3433
3334
|
id: this.id,
|
@@ -3439,9 +3340,7 @@ var TransactionResponse = class {
|
|
3439
3340
|
gasPriceFactor,
|
3440
3341
|
abiMap: contractsAbiMap,
|
3441
3342
|
maxInputs,
|
3442
|
-
gasCosts
|
3443
|
-
maxGasPerTx,
|
3444
|
-
gasPrice
|
3343
|
+
gasCosts
|
3445
3344
|
});
|
3446
3345
|
return transactionSummary;
|
3447
3346
|
}
|
@@ -3568,29 +3467,29 @@ var processGqlChain = (chain) => {
|
|
3568
3467
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3569
3468
|
return {
|
3570
3469
|
name,
|
3571
|
-
baseChainHeight:
|
3470
|
+
baseChainHeight: bn15(daHeight),
|
3572
3471
|
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:
|
3472
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3473
|
+
maxInputs: bn15(txParams.maxInputs),
|
3474
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3475
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3476
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3477
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3478
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3479
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3480
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3481
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3482
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3483
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3484
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3485
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3486
|
+
chainId: bn15(consensusParameters.chainId),
|
3588
3487
|
gasCosts
|
3589
3488
|
},
|
3590
3489
|
gasCosts,
|
3591
3490
|
latestBlock: {
|
3592
3491
|
id: latestBlock.id,
|
3593
|
-
height:
|
3492
|
+
height: bn15(latestBlock.header.height),
|
3594
3493
|
time: latestBlock.header.time,
|
3595
3494
|
transactions: latestBlock.transactions.map((i) => ({
|
3596
3495
|
id: i.id
|
@@ -3684,8 +3583,10 @@ var _Provider = class {
|
|
3684
3583
|
* Returns some helpful parameters related to gas fees.
|
3685
3584
|
*/
|
3686
3585
|
getGasConfig() {
|
3586
|
+
const { minGasPrice } = this.getNode();
|
3687
3587
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3688
3588
|
return {
|
3589
|
+
minGasPrice,
|
3689
3590
|
maxGasPerTx,
|
3690
3591
|
maxGasPerPredicate,
|
3691
3592
|
gasPriceFactor,
|
@@ -3783,7 +3684,7 @@ var _Provider = class {
|
|
3783
3684
|
*/
|
3784
3685
|
async getBlockNumber() {
|
3785
3686
|
const { chain } = await this.operations.getChain();
|
3786
|
-
return
|
3687
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3787
3688
|
}
|
3788
3689
|
/**
|
3789
3690
|
* Returns the chain information.
|
@@ -3793,11 +3694,13 @@ var _Provider = class {
|
|
3793
3694
|
async fetchNode() {
|
3794
3695
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3795
3696
|
const processedNodeInfo = {
|
3796
|
-
maxDepth:
|
3797
|
-
maxTx:
|
3697
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3698
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3699
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3798
3700
|
nodeVersion: nodeInfo.nodeVersion,
|
3799
3701
|
utxoValidation: nodeInfo.utxoValidation,
|
3800
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3702
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3703
|
+
peers: nodeInfo.peers
|
3801
3704
|
};
|
3802
3705
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3803
3706
|
return processedNodeInfo;
|
@@ -3883,13 +3786,14 @@ var _Provider = class {
|
|
3883
3786
|
return this.estimateTxDependencies(transactionRequest);
|
3884
3787
|
}
|
3885
3788
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3886
|
-
const { dryRun:
|
3887
|
-
|
3789
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3790
|
+
encodedTransaction,
|
3888
3791
|
utxoValidation: utxoValidation || false
|
3889
3792
|
});
|
3890
|
-
const
|
3891
|
-
|
3892
|
-
|
3793
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3794
|
+
return {
|
3795
|
+
receipts
|
3796
|
+
};
|
3893
3797
|
}
|
3894
3798
|
/**
|
3895
3799
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3915,7 +3819,7 @@ var _Provider = class {
|
|
3915
3819
|
} = response;
|
3916
3820
|
if (inputs) {
|
3917
3821
|
inputs.forEach((input, index) => {
|
3918
|
-
if ("predicateGasUsed" in input &&
|
3822
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3919
3823
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3920
3824
|
}
|
3921
3825
|
});
|
@@ -3928,6 +3832,9 @@ var _Provider = class {
|
|
3928
3832
|
* If there are missing variable outputs,
|
3929
3833
|
* `addVariableOutputs` is called on the transaction.
|
3930
3834
|
*
|
3835
|
+
* @privateRemarks
|
3836
|
+
* TODO: Investigate support for missing contract IDs
|
3837
|
+
* TODO: Add support for missing output messages
|
3931
3838
|
*
|
3932
3839
|
* @param transactionRequest - The transaction request object.
|
3933
3840
|
* @returns A promise.
|
@@ -3940,19 +3847,16 @@ var _Provider = class {
|
|
3940
3847
|
missingContractIds: []
|
3941
3848
|
};
|
3942
3849
|
}
|
3850
|
+
await this.estimatePredicates(transactionRequest);
|
3943
3851
|
let receipts = [];
|
3944
3852
|
const missingContractIds = [];
|
3945
3853
|
let outputVariables = 0;
|
3946
|
-
let dryrunStatus;
|
3947
3854
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3948
|
-
const {
|
3949
|
-
|
3950
|
-
} = await this.operations.dryRun({
|
3951
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3855
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3856
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3952
3857
|
utxoValidation: false
|
3953
3858
|
});
|
3954
|
-
receipts =
|
3955
|
-
dryrunStatus = status;
|
3859
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3956
3860
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3957
3861
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3958
3862
|
if (hasMissingOutputs) {
|
@@ -3962,11 +3866,6 @@ var _Provider = class {
|
|
3962
3866
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3963
3867
|
missingContractIds.push(contractId);
|
3964
3868
|
});
|
3965
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3966
|
-
transactionRequest,
|
3967
|
-
optimizeGas: false
|
3968
|
-
});
|
3969
|
-
transactionRequest.maxFee = maxFee;
|
3970
3869
|
} else {
|
3971
3870
|
break;
|
3972
3871
|
}
|
@@ -3974,133 +3873,38 @@ var _Provider = class {
|
|
3974
3873
|
return {
|
3975
3874
|
receipts,
|
3976
3875
|
outputVariables,
|
3977
|
-
missingContractIds
|
3978
|
-
dryrunStatus
|
3876
|
+
missingContractIds
|
3979
3877
|
};
|
3980
3878
|
}
|
3981
3879
|
/**
|
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.
|
3880
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3881
|
+
* @param transactionRequest - The transaction request object.
|
3882
|
+
* @param optimizeGas - Optional. Specifies whether to optimize the gas. Default is false.
|
3883
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3990
3884
|
*/
|
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;
|
3885
|
+
estimateTxGasAndFee(params) {
|
3886
|
+
const { transactionRequest } = params;
|
3887
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4069
3888
|
const chainInfo = this.getChain();
|
4070
|
-
const
|
3889
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3890
|
+
transactionRequest.gasPrice = gasPrice;
|
4071
3891
|
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);
|
3892
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4082
3893
|
if (transactionRequest.type === TransactionType8.Script) {
|
4083
|
-
|
4084
|
-
if (!optimizeGas) {
|
3894
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4085
3895
|
transactionRequest.gasLimit = minGas;
|
4086
|
-
gasLimit =
|
4087
|
-
|
3896
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3897
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3898
|
+
);
|
4088
3899
|
}
|
4089
3900
|
}
|
4090
3901
|
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);
|
3902
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4097
3903
|
return {
|
4098
3904
|
minGas,
|
4099
3905
|
minFee,
|
4100
3906
|
maxGas,
|
4101
|
-
maxFee
|
4102
|
-
gasPrice,
|
4103
|
-
gasLimit
|
3907
|
+
maxFee
|
4104
3908
|
};
|
4105
3909
|
}
|
4106
3910
|
/**
|
@@ -4118,17 +3922,15 @@ var _Provider = class {
|
|
4118
3922
|
if (estimateTxDependencies) {
|
4119
3923
|
return this.estimateTxDependencies(transactionRequest);
|
4120
3924
|
}
|
4121
|
-
const
|
4122
|
-
const { dryRun:
|
4123
|
-
|
3925
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3926
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3927
|
+
encodedTransaction,
|
4124
3928
|
utxoValidation: true
|
4125
3929
|
});
|
4126
|
-
const
|
4127
|
-
|
4128
|
-
|
4129
|
-
|
4130
|
-
});
|
4131
|
-
return { receipts: callResult[0].receipts };
|
3930
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3931
|
+
return {
|
3932
|
+
receipts
|
3933
|
+
};
|
4132
3934
|
}
|
4133
3935
|
/**
|
4134
3936
|
* Returns a transaction cost to enable user
|
@@ -4145,80 +3947,77 @@ var _Provider = class {
|
|
4145
3947
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4146
3948
|
* @returns A promise that resolves to the transaction cost object.
|
4147
3949
|
*/
|
4148
|
-
async getTransactionCost(transactionRequestLike,
|
3950
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3951
|
+
estimateTxDependencies = true,
|
3952
|
+
estimatePredicates = true,
|
3953
|
+
resourcesOwner,
|
3954
|
+
signatureCallback
|
3955
|
+
} = {}) {
|
4149
3956
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3957
|
+
const { minGasPrice } = this.getGasConfig();
|
3958
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4150
3959
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4151
3960
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4152
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3961
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4153
3962
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4154
|
-
txRequestClone.maxFee = bn16(0);
|
4155
3963
|
if (isScriptTransaction) {
|
4156
|
-
txRequestClone.gasLimit =
|
3964
|
+
txRequestClone.gasLimit = bn15(0);
|
4157
3965
|
}
|
4158
|
-
if (
|
4159
|
-
resourcesOwner
|
3966
|
+
if (estimatePredicates) {
|
3967
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3968
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3969
|
+
}
|
3970
|
+
await this.estimatePredicates(txRequestClone);
|
4160
3971
|
}
|
4161
|
-
const signedRequest = clone3(txRequestClone);
|
4162
|
-
let addedSignatures = 0;
|
4163
3972
|
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
|
3973
|
+
await signatureCallback(txRequestClone);
|
3974
|
+
}
|
3975
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3976
|
+
transactionRequest: txRequestClone
|
4172
3977
|
});
|
4173
|
-
txRequestClone.maxFee = maxFee;
|
4174
3978
|
let receipts = [];
|
4175
3979
|
let missingContractIds = [];
|
4176
3980
|
let outputVariables = 0;
|
4177
|
-
let gasUsed =
|
4178
|
-
|
4179
|
-
|
4180
|
-
if (signatureCallback) {
|
4181
|
-
await signatureCallback(txRequestClone);
|
4182
|
-
}
|
4183
|
-
txRequestClone.gasLimit = gasLimit;
|
3981
|
+
let gasUsed = bn15(0);
|
3982
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3983
|
+
txRequestClone.gasPrice = bn15(0);
|
4184
3984
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4185
3985
|
receipts = result.receipts;
|
4186
3986
|
outputVariables = result.outputVariables;
|
4187
3987
|
missingContractIds = result.missingContractIds;
|
4188
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
3988
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4189
3989
|
txRequestClone.gasLimit = gasUsed;
|
4190
|
-
|
4191
|
-
|
4192
|
-
|
3990
|
+
txRequestClone.gasPrice = setGasPrice;
|
3991
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3992
|
+
transactionRequest: txRequestClone
|
4193
3993
|
}));
|
4194
3994
|
}
|
4195
3995
|
return {
|
4196
3996
|
requiredQuantities: allQuantities,
|
4197
3997
|
receipts,
|
4198
3998
|
gasUsed,
|
4199
|
-
|
3999
|
+
minGasPrice,
|
4000
|
+
gasPrice: setGasPrice,
|
4200
4001
|
minGas,
|
4201
4002
|
maxGas,
|
4202
4003
|
minFee,
|
4203
4004
|
maxFee,
|
4005
|
+
estimatedInputs: txRequestClone.inputs,
|
4204
4006
|
outputVariables,
|
4205
|
-
missingContractIds
|
4206
|
-
addedSignatures,
|
4207
|
-
estimatedPredicates: txRequestClone.inputs
|
4007
|
+
missingContractIds
|
4208
4008
|
};
|
4209
4009
|
}
|
4210
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4010
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4211
4011
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4212
4012
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4213
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4214
|
-
quantitiesToContract
|
4215
|
-
});
|
4013
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4216
4014
|
transactionRequest.addResources(
|
4217
4015
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4218
4016
|
);
|
4219
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4220
|
-
|
4221
|
-
|
4017
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4018
|
+
transactionRequest,
|
4019
|
+
forwardingQuantities
|
4020
|
+
);
|
4222
4021
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4223
4022
|
return {
|
4224
4023
|
resources,
|
@@ -4240,10 +4039,11 @@ var _Provider = class {
|
|
4240
4039
|
return coins.map((coin) => ({
|
4241
4040
|
id: coin.utxoId,
|
4242
4041
|
assetId: coin.assetId,
|
4243
|
-
amount:
|
4042
|
+
amount: bn15(coin.amount),
|
4244
4043
|
owner: Address2.fromAddressOrString(coin.owner),
|
4245
|
-
|
4246
|
-
|
4044
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4045
|
+
blockCreated: bn15(coin.blockCreated),
|
4046
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4247
4047
|
}));
|
4248
4048
|
}
|
4249
4049
|
/**
|
@@ -4280,9 +4080,9 @@ var _Provider = class {
|
|
4280
4080
|
switch (coin.__typename) {
|
4281
4081
|
case "MessageCoin":
|
4282
4082
|
return {
|
4283
|
-
amount:
|
4083
|
+
amount: bn15(coin.amount),
|
4284
4084
|
assetId: coin.assetId,
|
4285
|
-
daHeight:
|
4085
|
+
daHeight: bn15(coin.daHeight),
|
4286
4086
|
sender: Address2.fromAddressOrString(coin.sender),
|
4287
4087
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4288
4088
|
nonce: coin.nonce
|
@@ -4290,11 +4090,12 @@ var _Provider = class {
|
|
4290
4090
|
case "Coin":
|
4291
4091
|
return {
|
4292
4092
|
id: coin.utxoId,
|
4293
|
-
amount:
|
4093
|
+
amount: bn15(coin.amount),
|
4294
4094
|
assetId: coin.assetId,
|
4295
4095
|
owner: Address2.fromAddressOrString(coin.owner),
|
4296
|
-
|
4297
|
-
|
4096
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4097
|
+
blockCreated: bn15(coin.blockCreated),
|
4098
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4298
4099
|
};
|
4299
4100
|
default:
|
4300
4101
|
return null;
|
@@ -4311,13 +4112,13 @@ var _Provider = class {
|
|
4311
4112
|
async getBlock(idOrHeight) {
|
4312
4113
|
let variables;
|
4313
4114
|
if (typeof idOrHeight === "number") {
|
4314
|
-
variables = { height:
|
4115
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4315
4116
|
} else if (idOrHeight === "latest") {
|
4316
4117
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4317
4118
|
} else if (idOrHeight.length === 66) {
|
4318
4119
|
variables = { blockId: idOrHeight };
|
4319
4120
|
} else {
|
4320
|
-
variables = { blockId:
|
4121
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4321
4122
|
}
|
4322
4123
|
const { block } = await this.operations.getBlock(variables);
|
4323
4124
|
if (!block) {
|
@@ -4325,7 +4126,7 @@ var _Provider = class {
|
|
4325
4126
|
}
|
4326
4127
|
return {
|
4327
4128
|
id: block.id,
|
4328
|
-
height:
|
4129
|
+
height: bn15(block.header.height),
|
4329
4130
|
time: block.header.time,
|
4330
4131
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4331
4132
|
};
|
@@ -4340,7 +4141,7 @@ var _Provider = class {
|
|
4340
4141
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4341
4142
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4342
4143
|
id: block.id,
|
4343
|
-
height:
|
4144
|
+
height: bn15(block.header.height),
|
4344
4145
|
time: block.header.time,
|
4345
4146
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4346
4147
|
}));
|
@@ -4355,7 +4156,7 @@ var _Provider = class {
|
|
4355
4156
|
async getBlockWithTransactions(idOrHeight) {
|
4356
4157
|
let variables;
|
4357
4158
|
if (typeof idOrHeight === "number") {
|
4358
|
-
variables = { blockHeight:
|
4159
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4359
4160
|
} else if (idOrHeight === "latest") {
|
4360
4161
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4361
4162
|
} else {
|
@@ -4367,7 +4168,7 @@ var _Provider = class {
|
|
4367
4168
|
}
|
4368
4169
|
return {
|
4369
4170
|
id: block.id,
|
4370
|
-
height:
|
4171
|
+
height: bn15(block.header.height, 10),
|
4371
4172
|
time: block.header.time,
|
4372
4173
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4373
4174
|
transactions: block.transactions.map(
|
@@ -4416,7 +4217,7 @@ var _Provider = class {
|
|
4416
4217
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4417
4218
|
asset: hexlify12(assetId)
|
4418
4219
|
});
|
4419
|
-
return
|
4220
|
+
return bn15(contractBalance.amount, 10);
|
4420
4221
|
}
|
4421
4222
|
/**
|
4422
4223
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4430,7 +4231,7 @@ var _Provider = class {
|
|
4430
4231
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4431
4232
|
assetId: hexlify12(assetId)
|
4432
4233
|
});
|
4433
|
-
return
|
4234
|
+
return bn15(balance.amount, 10);
|
4434
4235
|
}
|
4435
4236
|
/**
|
4436
4237
|
* Returns balances for the given owner.
|
@@ -4448,7 +4249,7 @@ var _Provider = class {
|
|
4448
4249
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4449
4250
|
return balances.map((balance) => ({
|
4450
4251
|
assetId: balance.assetId,
|
4451
|
-
amount:
|
4252
|
+
amount: bn15(balance.amount)
|
4452
4253
|
}));
|
4453
4254
|
}
|
4454
4255
|
/**
|
@@ -4470,15 +4271,15 @@ var _Provider = class {
|
|
4470
4271
|
sender: message.sender,
|
4471
4272
|
recipient: message.recipient,
|
4472
4273
|
nonce: message.nonce,
|
4473
|
-
amount:
|
4274
|
+
amount: bn15(message.amount),
|
4474
4275
|
data: message.data
|
4475
4276
|
}),
|
4476
4277
|
sender: Address2.fromAddressOrString(message.sender),
|
4477
4278
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4478
4279
|
nonce: message.nonce,
|
4479
|
-
amount:
|
4280
|
+
amount: bn15(message.amount),
|
4480
4281
|
data: InputMessageCoder.decodeData(message.data),
|
4481
|
-
daHeight:
|
4282
|
+
daHeight: bn15(message.daHeight)
|
4482
4283
|
}));
|
4483
4284
|
}
|
4484
4285
|
/**
|
@@ -4531,52 +4332,44 @@ var _Provider = class {
|
|
4531
4332
|
} = result.messageProof;
|
4532
4333
|
return {
|
4533
4334
|
messageProof: {
|
4534
|
-
proofIndex:
|
4335
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4535
4336
|
proofSet: messageProof.proofSet
|
4536
4337
|
},
|
4537
4338
|
blockProof: {
|
4538
|
-
proofIndex:
|
4339
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4539
4340
|
proofSet: blockProof.proofSet
|
4540
4341
|
},
|
4541
4342
|
messageBlockHeader: {
|
4542
4343
|
id: messageBlockHeader.id,
|
4543
|
-
daHeight:
|
4544
|
-
transactionsCount:
|
4344
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4345
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4545
4346
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4546
|
-
height:
|
4347
|
+
height: bn15(messageBlockHeader.height),
|
4547
4348
|
prevRoot: messageBlockHeader.prevRoot,
|
4548
4349
|
time: messageBlockHeader.time,
|
4549
4350
|
applicationHash: messageBlockHeader.applicationHash,
|
4550
|
-
|
4351
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4352
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4551
4353
|
},
|
4552
4354
|
commitBlockHeader: {
|
4553
4355
|
id: commitBlockHeader.id,
|
4554
|
-
daHeight:
|
4555
|
-
transactionsCount:
|
4356
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4357
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4556
4358
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4557
|
-
height:
|
4359
|
+
height: bn15(commitBlockHeader.height),
|
4558
4360
|
prevRoot: commitBlockHeader.prevRoot,
|
4559
4361
|
time: commitBlockHeader.time,
|
4560
4362
|
applicationHash: commitBlockHeader.applicationHash,
|
4561
|
-
|
4363
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4364
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4562
4365
|
},
|
4563
4366
|
sender: Address2.fromAddressOrString(sender),
|
4564
4367
|
recipient: Address2.fromAddressOrString(recipient),
|
4565
4368
|
nonce,
|
4566
|
-
amount:
|
4369
|
+
amount: bn15(amount),
|
4567
4370
|
data
|
4568
4371
|
};
|
4569
4372
|
}
|
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
4373
|
/**
|
4581
4374
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4582
4375
|
*
|
@@ -4596,10 +4389,10 @@ var _Provider = class {
|
|
4596
4389
|
*/
|
4597
4390
|
async produceBlocks(amount, startTime) {
|
4598
4391
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4599
|
-
blocksToProduce:
|
4392
|
+
blocksToProduce: bn15(amount).toString(10),
|
4600
4393
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4601
4394
|
});
|
4602
|
-
return
|
4395
|
+
return bn15(latestBlockHeight);
|
4603
4396
|
}
|
4604
4397
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4605
4398
|
async getTransactionResponse(transactionId) {
|
@@ -4613,7 +4406,7 @@ cacheInputs_fn = function(inputs) {
|
|
4613
4406
|
return;
|
4614
4407
|
}
|
4615
4408
|
inputs.forEach((input) => {
|
4616
|
-
if (input.type ===
|
4409
|
+
if (input.type === InputType6.Coin) {
|
4617
4410
|
this.cache?.set(input.id);
|
4618
4411
|
}
|
4619
4412
|
});
|
@@ -4623,7 +4416,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4623
4416
|
|
4624
4417
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4625
4418
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4626
|
-
import { bn as
|
4419
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4627
4420
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4628
4421
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4629
4422
|
|
@@ -4869,33 +4662,36 @@ var Account = class extends AbstractAccount {
|
|
4869
4662
|
* @param fee - The estimated transaction fee.
|
4870
4663
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4871
4664
|
*/
|
4872
|
-
async fund(request,
|
4873
|
-
const
|
4874
|
-
|
4875
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4876
|
-
amount: bn18(fee),
|
4665
|
+
async fund(request, coinQuantities, fee) {
|
4666
|
+
const updatedQuantities = addAmountToAsset({
|
4667
|
+
amount: bn17(fee),
|
4877
4668
|
assetId: BaseAssetId3,
|
4878
|
-
coinQuantities
|
4669
|
+
coinQuantities
|
4879
4670
|
});
|
4880
4671
|
const quantitiesDict = {};
|
4881
|
-
|
4672
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4882
4673
|
quantitiesDict[assetId] = {
|
4883
4674
|
required: amount,
|
4884
|
-
owned:
|
4675
|
+
owned: bn17(0)
|
4885
4676
|
};
|
4886
4677
|
});
|
4887
|
-
|
4678
|
+
const cachedUtxos = [];
|
4679
|
+
const cachedMessages = [];
|
4680
|
+
const owner = this.address.toB256();
|
4681
|
+
request.inputs.forEach((input) => {
|
4888
4682
|
const isResource = "amount" in input;
|
4889
4683
|
if (isResource) {
|
4890
4684
|
const isCoin2 = "owner" in input;
|
4891
4685
|
if (isCoin2) {
|
4892
4686
|
const assetId = String(input.assetId);
|
4893
|
-
if (quantitiesDict[assetId]) {
|
4894
|
-
const amount =
|
4687
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4688
|
+
const amount = bn17(input.amount);
|
4895
4689
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4690
|
+
cachedUtxos.push(input.id);
|
4896
4691
|
}
|
4897
|
-
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4692
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4898
4693
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4694
|
+
cachedMessages.push(input.nonce);
|
4899
4695
|
}
|
4900
4696
|
}
|
4901
4697
|
});
|
@@ -4910,23 +4706,12 @@ var Account = class extends AbstractAccount {
|
|
4910
4706
|
});
|
4911
4707
|
const needsToBeFunded = missingQuantities.length;
|
4912
4708
|
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
|
-
);
|
4709
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4710
|
+
messages: cachedMessages,
|
4711
|
+
utxos: cachedUtxos
|
4712
|
+
});
|
4713
|
+
request.addResources(resources);
|
4924
4714
|
}
|
4925
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4926
|
-
transactionRequest: requestToBeReEstimate
|
4927
|
-
});
|
4928
|
-
txRequest.maxFee = maxFee;
|
4929
|
-
return txRequest;
|
4930
4715
|
}
|
4931
4716
|
/**
|
4932
4717
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4934,25 +4719,28 @@ var Account = class extends AbstractAccount {
|
|
4934
4719
|
* @param destination - The address of the destination.
|
4935
4720
|
* @param amount - The amount of coins to transfer.
|
4936
4721
|
* @param assetId - The asset ID of the coins to transfer.
|
4937
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4722
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4938
4723
|
* @returns A promise that resolves to the prepared transaction request.
|
4939
4724
|
*/
|
4940
4725
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4941
|
-
const
|
4726
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4727
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4728
|
+
const request = new ScriptTransactionRequest(params);
|
4942
4729
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4943
|
-
const
|
4730
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4944
4731
|
estimateTxDependencies: true,
|
4945
4732
|
resourcesOwner: this
|
4946
4733
|
});
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
await this.fund(request,
|
4734
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4735
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4736
|
+
this.validateGas({
|
4737
|
+
gasUsed,
|
4738
|
+
gasPrice: request.gasPrice,
|
4739
|
+
gasLimit: request.gasLimit,
|
4740
|
+
minGasPrice
|
4741
|
+
});
|
4742
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4743
|
+
request.updatePredicateInputs(estimatedInputs);
|
4956
4744
|
return request;
|
4957
4745
|
}
|
4958
4746
|
/**
|
@@ -4965,7 +4753,7 @@ var Account = class extends AbstractAccount {
|
|
4965
4753
|
* @returns A promise that resolves to the transaction response.
|
4966
4754
|
*/
|
4967
4755
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4968
|
-
if (
|
4756
|
+
if (bn17(amount).lte(0)) {
|
4969
4757
|
throw new FuelError15(
|
4970
4758
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4971
4759
|
"Transfer amount must be a positive number."
|
@@ -4984,37 +4772,38 @@ var Account = class extends AbstractAccount {
|
|
4984
4772
|
* @returns A promise that resolves to the transaction response.
|
4985
4773
|
*/
|
4986
4774
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4987
|
-
if (
|
4775
|
+
if (bn17(amount).lte(0)) {
|
4988
4776
|
throw new FuelError15(
|
4989
4777
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4990
4778
|
"Transfer amount must be a positive number."
|
4991
4779
|
);
|
4992
4780
|
}
|
4993
4781
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4782
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4783
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4994
4784
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4995
4785
|
hexlifiedContractId: contractAddress.toB256(),
|
4996
|
-
amountToTransfer:
|
4786
|
+
amountToTransfer: bn17(amount),
|
4997
4787
|
assetId
|
4998
4788
|
});
|
4999
4789
|
const request = new ScriptTransactionRequest({
|
5000
|
-
...
|
4790
|
+
...params,
|
5001
4791
|
script,
|
5002
4792
|
scriptData
|
5003
4793
|
});
|
5004
4794
|
request.addContractInputAndOutput(contractAddress);
|
5005
|
-
const
|
5006
|
-
|
5007
|
-
|
4795
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4796
|
+
request,
|
4797
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4798
|
+
);
|
4799
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4800
|
+
this.validateGas({
|
4801
|
+
gasUsed,
|
4802
|
+
gasPrice: request.gasPrice,
|
4803
|
+
gasLimit: request.gasLimit,
|
4804
|
+
minGasPrice
|
5008
4805
|
});
|
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);
|
4806
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5018
4807
|
return this.sendTransaction(request);
|
5019
4808
|
}
|
5020
4809
|
/**
|
@@ -5026,31 +4815,34 @@ var Account = class extends AbstractAccount {
|
|
5026
4815
|
* @returns A promise that resolves to the transaction response.
|
5027
4816
|
*/
|
5028
4817
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4818
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5029
4819
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5030
4820
|
const recipientDataArray = arrayify14(
|
5031
4821
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5032
4822
|
);
|
5033
4823
|
const amountDataArray = arrayify14(
|
5034
|
-
"0x".concat(
|
4824
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5035
4825
|
);
|
5036
4826
|
const script = new Uint8Array([
|
5037
4827
|
...arrayify14(withdrawScript.bytes),
|
5038
4828
|
...recipientDataArray,
|
5039
4829
|
...amountDataArray
|
5040
4830
|
]);
|
5041
|
-
const params = { script, ...txParams };
|
4831
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5042
4832
|
const request = new ScriptTransactionRequest(params);
|
5043
|
-
const
|
5044
|
-
const
|
5045
|
-
|
5046
|
-
|
5047
|
-
|
5048
|
-
|
5049
|
-
|
5050
|
-
|
5051
|
-
|
5052
|
-
|
5053
|
-
|
4833
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4834
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4835
|
+
request,
|
4836
|
+
forwardingQuantities
|
4837
|
+
);
|
4838
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4839
|
+
this.validateGas({
|
4840
|
+
gasUsed,
|
4841
|
+
gasPrice: request.gasPrice,
|
4842
|
+
gasLimit: request.gasLimit,
|
4843
|
+
minGasPrice
|
4844
|
+
});
|
4845
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5054
4846
|
return this.sendTransaction(request);
|
5055
4847
|
}
|
5056
4848
|
async signMessage(message) {
|
@@ -5108,7 +4900,18 @@ var Account = class extends AbstractAccount {
|
|
5108
4900
|
}
|
5109
4901
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5110
4902
|
}
|
5111
|
-
validateGas({
|
4903
|
+
validateGas({
|
4904
|
+
gasUsed,
|
4905
|
+
gasPrice,
|
4906
|
+
gasLimit,
|
4907
|
+
minGasPrice
|
4908
|
+
}) {
|
4909
|
+
if (minGasPrice.gt(gasPrice)) {
|
4910
|
+
throw new FuelError15(
|
4911
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4912
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4913
|
+
);
|
4914
|
+
}
|
5112
4915
|
if (gasUsed.gt(gasLimit)) {
|
5113
4916
|
throw new FuelError15(
|
5114
4917
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5400,7 +5203,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5400
5203
|
* @param transactionRequestLike - The transaction request to send.
|
5401
5204
|
* @returns A promise that resolves to the TransactionResponse object.
|
5402
5205
|
*/
|
5403
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5206
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5404
5207
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5405
5208
|
if (estimateTxDependencies) {
|
5406
5209
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5441,7 +5244,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5441
5244
|
// src/hdwallet/hdwallet.ts
|
5442
5245
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5443
5246
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5444
|
-
import { bn as
|
5247
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5445
5248
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5446
5249
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5447
5250
|
|
@@ -7907,7 +7710,7 @@ var HDWallet = class {
|
|
7907
7710
|
const IR = bytes.slice(32);
|
7908
7711
|
if (privateKey) {
|
7909
7712
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7910
|
-
const ki =
|
7713
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7911
7714
|
return new HDWallet({
|
7912
7715
|
privateKey: ki,
|
7913
7716
|
chainCode: IR,
|
@@ -8178,15 +7981,14 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8178
7981
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8179
7982
|
wallet.provider
|
8180
7983
|
);
|
8181
|
-
const
|
8182
|
-
|
8183
|
-
|
8184
|
-
|
7984
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7985
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7986
|
+
const request = new ScriptTransactionRequest({
|
7987
|
+
gasLimit: 1e4,
|
7988
|
+
gasPrice: minGasPrice
|
8185
7989
|
});
|
8186
|
-
|
8187
|
-
request.
|
8188
|
-
request.maxFee = txCost.maxFee;
|
8189
|
-
await genesisWallet.fund(request, txCost);
|
7990
|
+
request.addResources(resources);
|
7991
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8190
7992
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8191
7993
|
};
|
8192
7994
|
|
@@ -8201,11 +8003,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8201
8003
|
|
8202
8004
|
// src/test-utils/launchNode.ts
|
8203
8005
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8204
|
-
import {
|
8006
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8007
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8205
8008
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8206
8009
|
import { spawn } from "child_process";
|
8207
8010
|
import { randomUUID } from "crypto";
|
8208
|
-
import { randomBytes as randomBytes6 } from "ethers";
|
8209
8011
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8210
8012
|
import os from "os";
|
8211
8013
|
import path from "path";
|
@@ -8254,12 +8056,12 @@ var launchNode = async ({
|
|
8254
8056
|
// eslint-disable-next-line no-async-promise-executor
|
8255
8057
|
new Promise(async (resolve, reject) => {
|
8256
8058
|
const remainingArgs = extractRemainingArgs(args, [
|
8257
|
-
"--
|
8059
|
+
"--chain",
|
8258
8060
|
"--consensus-key",
|
8259
8061
|
"--db-type",
|
8260
8062
|
"--poa-instant"
|
8261
8063
|
]);
|
8262
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8064
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8263
8065
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8264
8066
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8265
8067
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8278,54 +8080,36 @@ var launchNode = async ({
|
|
8278
8080
|
let chainConfigPathToUse;
|
8279
8081
|
const prefix = basePath || os.tmpdir();
|
8280
8082
|
const suffix = basePath ? "" : randomUUID();
|
8281
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8083
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8282
8084
|
if (chainConfigPath) {
|
8283
8085
|
chainConfigPathToUse = chainConfigPath;
|
8284
8086
|
} else {
|
8285
8087
|
if (!existsSync(tempDirPath)) {
|
8286
8088
|
mkdirSync(tempDirPath, { recursive: true });
|
8287
8089
|
}
|
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
|
-
};
|
8090
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8091
|
+
let chainConfig = defaultChainConfig;
|
8304
8092
|
if (!process.env.GENESIS_SECRET) {
|
8305
8093
|
const pk = Signer.generatePrivateKey();
|
8306
8094
|
const signer = new Signer(pk);
|
8307
8095
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8308
|
-
|
8309
|
-
|
8310
|
-
|
8311
|
-
|
8312
|
-
|
8313
|
-
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8096
|
+
chainConfig = {
|
8097
|
+
...defaultChainConfig,
|
8098
|
+
initial_state: {
|
8099
|
+
...defaultChainConfig.initial_state,
|
8100
|
+
coins: [
|
8101
|
+
...defaultChainConfig.initial_state.coins,
|
8102
|
+
{
|
8103
|
+
owner: signer.address.toHexString(),
|
8104
|
+
amount: toHex2(1e9),
|
8105
|
+
asset_id: BaseAssetId4
|
8106
|
+
}
|
8107
|
+
]
|
8108
|
+
}
|
8109
|
+
};
|
8318
8110
|
}
|
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;
|
8111
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8112
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8329
8113
|
}
|
8330
8114
|
const child = spawn(
|
8331
8115
|
command,
|
@@ -8334,10 +8118,10 @@ var launchNode = async ({
|
|
8334
8118
|
["--ip", ipToUse],
|
8335
8119
|
["--port", portToUse],
|
8336
8120
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8337
|
-
["--min-gas-price", "
|
8121
|
+
["--min-gas-price", "0"],
|
8338
8122
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8339
8123
|
["--consensus-key", consensusKey],
|
8340
|
-
["--
|
8124
|
+
["--chain", chainConfigPathToUse],
|
8341
8125
|
"--vm-backtrace",
|
8342
8126
|
"--utxo-validation",
|
8343
8127
|
"--debug",
|
@@ -8396,7 +8180,7 @@ var launchNodeAndGetWallets = async ({
|
|
8396
8180
|
walletCount = 10
|
8397
8181
|
} = {}) => {
|
8398
8182
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8399
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8183
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8400
8184
|
const wallets = await generateWallets(walletCount, provider);
|
8401
8185
|
const cleanup = () => {
|
8402
8186
|
closeNode();
|