@fuel-ts/account 0.0.0-rc-1976-20240406124842 → 0.0.0-rc-2021-20240408141516
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +865 -615
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +845 -609
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +687 -452
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +888 -322
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +3 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +45 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.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 +9 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1580 -1116
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +821 -606
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +679 -464
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/test-utils.mjs
CHANGED
@@ -24,35 +24,38 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
27
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
30
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
30
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
+
import { clone as clone4 } from "ramda";
|
31
33
|
|
32
34
|
// src/providers/coin-quantity.ts
|
35
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
33
36
|
import { bn } from "@fuel-ts/math";
|
34
37
|
import { hexlify } from "@fuel-ts/utils";
|
35
38
|
var coinQuantityfy = (coinQuantityLike) => {
|
36
39
|
let assetId;
|
37
40
|
let amount;
|
38
|
-
let
|
41
|
+
let max;
|
39
42
|
if (Array.isArray(coinQuantityLike)) {
|
40
43
|
amount = coinQuantityLike[0];
|
41
|
-
assetId = coinQuantityLike[1];
|
42
|
-
|
44
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
45
|
+
max = coinQuantityLike[2] ?? void 0;
|
43
46
|
} else {
|
44
47
|
amount = coinQuantityLike.amount;
|
45
|
-
assetId = coinQuantityLike.assetId;
|
46
|
-
|
48
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
49
|
+
max = coinQuantityLike.max ?? void 0;
|
47
50
|
}
|
48
51
|
const bnAmount = bn(amount);
|
49
52
|
return {
|
50
53
|
assetId: hexlify(assetId),
|
51
54
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
52
|
-
max:
|
55
|
+
max: max ? bn(max) : void 0
|
53
56
|
};
|
54
57
|
};
|
55
|
-
var
|
58
|
+
var addAmountToCoinQuantities = (params) => {
|
56
59
|
const { amount, assetId } = params;
|
57
60
|
const coinQuantities = [...params.coinQuantities];
|
58
61
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -67,9 +70,9 @@ var addAmountToAsset = (params) => {
|
|
67
70
|
// src/providers/provider.ts
|
68
71
|
import { Address as Address2 } from "@fuel-ts/address";
|
69
72
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
70
|
-
import { BN, bn as
|
73
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
71
74
|
import {
|
72
|
-
InputType as
|
75
|
+
InputType as InputType7,
|
73
76
|
TransactionType as TransactionType8,
|
74
77
|
InputMessageCoder,
|
75
78
|
TransactionCoder as TransactionCoder5
|
@@ -85,14 +88,10 @@ import { clone as clone3 } from "ramda";
|
|
85
88
|
import gql from "graphql-tag";
|
86
89
|
var ReceiptFragmentFragmentDoc = gql`
|
87
90
|
fragment receiptFragment on Receipt {
|
88
|
-
|
89
|
-
id
|
90
|
-
}
|
91
|
+
id
|
91
92
|
pc
|
92
93
|
is
|
93
|
-
to
|
94
|
-
id
|
95
|
-
}
|
94
|
+
to
|
96
95
|
toAddress
|
97
96
|
amount
|
98
97
|
assetId
|
@@ -130,10 +129,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
130
129
|
id
|
131
130
|
}
|
132
131
|
time
|
132
|
+
receipts {
|
133
|
+
...receiptFragment
|
134
|
+
}
|
133
135
|
programState {
|
134
136
|
returnType
|
135
137
|
data
|
136
138
|
}
|
139
|
+
receipts {
|
140
|
+
...receiptFragment
|
141
|
+
}
|
137
142
|
}
|
138
143
|
... on FailureStatus {
|
139
144
|
block {
|
@@ -141,26 +146,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
141
146
|
}
|
142
147
|
time
|
143
148
|
reason
|
149
|
+
receipts {
|
150
|
+
...receiptFragment
|
151
|
+
}
|
144
152
|
}
|
145
153
|
... on SqueezedOutStatus {
|
146
154
|
reason
|
147
155
|
}
|
148
156
|
}
|
149
|
-
`;
|
157
|
+
${ReceiptFragmentFragmentDoc}`;
|
150
158
|
var TransactionFragmentFragmentDoc = gql`
|
151
159
|
fragment transactionFragment on Transaction {
|
152
160
|
id
|
153
161
|
rawPayload
|
154
|
-
gasPrice
|
155
|
-
receipts {
|
156
|
-
...receiptFragment
|
157
|
-
}
|
158
162
|
status {
|
159
163
|
...transactionStatusFragment
|
160
164
|
}
|
161
165
|
}
|
162
|
-
${
|
163
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
166
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
164
167
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
165
168
|
fragment inputEstimatePredicatesFragment on Input {
|
166
169
|
... on InputCoin {
|
@@ -178,6 +181,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
178
181
|
}
|
179
182
|
}
|
180
183
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
184
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
185
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
186
|
+
reason
|
187
|
+
programState {
|
188
|
+
returnType
|
189
|
+
data
|
190
|
+
}
|
191
|
+
}
|
192
|
+
`;
|
193
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
194
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
195
|
+
programState {
|
196
|
+
returnType
|
197
|
+
data
|
198
|
+
}
|
199
|
+
}
|
200
|
+
`;
|
201
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
202
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
203
|
+
... on DryRunFailureStatus {
|
204
|
+
...dryRunFailureStatusFragment
|
205
|
+
}
|
206
|
+
... on DryRunSuccessStatus {
|
207
|
+
...dryRunSuccessStatusFragment
|
208
|
+
}
|
209
|
+
}
|
210
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
211
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
212
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
213
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
214
|
+
id
|
215
|
+
status {
|
216
|
+
...dryRunTransactionStatusFragment
|
217
|
+
}
|
218
|
+
receipts {
|
219
|
+
...receiptFragment
|
220
|
+
}
|
221
|
+
}
|
222
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
223
|
+
${ReceiptFragmentFragmentDoc}`;
|
181
224
|
var CoinFragmentFragmentDoc = gql`
|
182
225
|
fragment coinFragment on Coin {
|
183
226
|
__typename
|
@@ -185,7 +228,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
185
228
|
owner
|
186
229
|
amount
|
187
230
|
assetId
|
188
|
-
maturity
|
189
231
|
blockCreated
|
190
232
|
txCreatedIdx
|
191
233
|
}
|
@@ -230,7 +272,6 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
230
272
|
prevRoot
|
231
273
|
time
|
232
274
|
applicationHash
|
233
|
-
messageReceiptRoot
|
234
275
|
messageReceiptCount
|
235
276
|
}
|
236
277
|
commitBlockHeader {
|
@@ -242,7 +283,6 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
242
283
|
prevRoot
|
243
284
|
time
|
244
285
|
applicationHash
|
245
|
-
messageReceiptRoot
|
246
286
|
messageReceiptCount
|
247
287
|
}
|
248
288
|
sender
|
@@ -262,8 +302,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
262
302
|
var BlockFragmentFragmentDoc = gql`
|
263
303
|
fragment blockFragment on Block {
|
264
304
|
id
|
305
|
+
height
|
265
306
|
header {
|
266
|
-
height
|
267
307
|
time
|
268
308
|
}
|
269
309
|
transactions {
|
@@ -321,6 +361,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
321
361
|
`;
|
322
362
|
var GasCostsFragmentFragmentDoc = gql`
|
323
363
|
fragment GasCostsFragment on GasCosts {
|
364
|
+
version {
|
365
|
+
... on Version {
|
366
|
+
value
|
367
|
+
}
|
368
|
+
}
|
324
369
|
add
|
325
370
|
addi
|
326
371
|
aloc
|
@@ -333,7 +378,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
333
378
|
cb
|
334
379
|
cfei
|
335
380
|
cfsi
|
336
|
-
croo
|
337
381
|
div
|
338
382
|
divi
|
339
383
|
ecr1
|
@@ -416,6 +460,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
416
460
|
ccp {
|
417
461
|
...DependentCostFragment
|
418
462
|
}
|
463
|
+
croo {
|
464
|
+
...DependentCostFragment
|
465
|
+
}
|
419
466
|
csiz {
|
420
467
|
...DependentCostFragment
|
421
468
|
}
|
@@ -475,6 +522,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
475
522
|
${DependentCostFragmentFragmentDoc}`;
|
476
523
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
477
524
|
fragment consensusParametersFragment on ConsensusParameters {
|
525
|
+
version {
|
526
|
+
... on Version {
|
527
|
+
value
|
528
|
+
}
|
529
|
+
}
|
478
530
|
txParams {
|
479
531
|
...TxParametersFragment
|
480
532
|
}
|
@@ -534,18 +586,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
534
586
|
fragment nodeInfoFragment on NodeInfo {
|
535
587
|
utxoValidation
|
536
588
|
vmBacktrace
|
537
|
-
minGasPrice
|
538
589
|
maxTx
|
539
590
|
maxDepth
|
540
591
|
nodeVersion
|
541
|
-
peers {
|
542
|
-
id
|
543
|
-
addresses
|
544
|
-
clientVersion
|
545
|
-
blockHeight
|
546
|
-
lastHeartbeatMs
|
547
|
-
appScore
|
548
|
-
}
|
549
592
|
}
|
550
593
|
`;
|
551
594
|
var GetVersionDocument = gql`
|
@@ -580,13 +623,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
580
623
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
581
624
|
transaction(id: $transactionId) {
|
582
625
|
...transactionFragment
|
583
|
-
receipts {
|
584
|
-
...receiptFragment
|
585
|
-
}
|
586
626
|
}
|
587
627
|
}
|
588
|
-
${TransactionFragmentFragmentDoc}
|
589
|
-
${ReceiptFragmentFragmentDoc}`;
|
628
|
+
${TransactionFragmentFragmentDoc}`;
|
590
629
|
var GetTransactionsDocument = gql`
|
591
630
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
592
631
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -714,6 +753,20 @@ var GetBalanceDocument = gql`
|
|
714
753
|
}
|
715
754
|
}
|
716
755
|
${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
|
+
`;
|
717
770
|
var GetBalancesDocument = gql`
|
718
771
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
719
772
|
balances(
|
@@ -768,12 +821,12 @@ var GetMessageStatusDocument = gql`
|
|
768
821
|
}
|
769
822
|
`;
|
770
823
|
var DryRunDocument = gql`
|
771
|
-
mutation dryRun($
|
772
|
-
dryRun(
|
773
|
-
...
|
824
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
825
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
826
|
+
...dryRunTransactionExecutionStatusFragment
|
774
827
|
}
|
775
828
|
}
|
776
|
-
${
|
829
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
777
830
|
var SubmitDocument = gql`
|
778
831
|
mutation submit($encodedTransaction: HexString!) {
|
779
832
|
submit(tx: $encodedTransaction) {
|
@@ -856,6 +909,12 @@ function getSdk(requester) {
|
|
856
909
|
getBalance(variables, options) {
|
857
910
|
return requester(GetBalanceDocument, variables, options);
|
858
911
|
},
|
912
|
+
getLatestGasPrice(variables, options) {
|
913
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
914
|
+
},
|
915
|
+
estimateGasPrice(variables, options) {
|
916
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
917
|
+
},
|
859
918
|
getBalances(variables, options) {
|
860
919
|
return requester(GetBalancesDocument, variables, options);
|
861
920
|
},
|
@@ -1030,7 +1089,7 @@ var inputify = (value) => {
|
|
1030
1089
|
return {
|
1031
1090
|
type: InputType.Coin,
|
1032
1091
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1033
|
-
outputIndex: arrayify(value.id)
|
1092
|
+
outputIndex: toNumber(arrayify(value.id).slice(32, 34)),
|
1034
1093
|
owner: hexlify3(value.owner),
|
1035
1094
|
amount: bn2(value.amount),
|
1036
1095
|
assetId: hexlify3(value.assetId),
|
@@ -1039,10 +1098,9 @@ var inputify = (value) => {
|
|
1039
1098
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1040
1099
|
},
|
1041
1100
|
witnessIndex: value.witnessIndex,
|
1042
|
-
maturity: value.maturity ?? 0,
|
1043
1101
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1044
|
-
predicateLength: predicate.length,
|
1045
|
-
predicateDataLength: predicateData.length,
|
1102
|
+
predicateLength: bn2(predicate.length),
|
1103
|
+
predicateDataLength: bn2(predicateData.length),
|
1046
1104
|
predicate: hexlify3(predicate),
|
1047
1105
|
predicateData: hexlify3(predicateData)
|
1048
1106
|
};
|
@@ -1073,8 +1131,8 @@ var inputify = (value) => {
|
|
1073
1131
|
nonce: hexlify3(value.nonce),
|
1074
1132
|
witnessIndex: value.witnessIndex,
|
1075
1133
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1076
|
-
predicateLength: predicate.length,
|
1077
|
-
predicateDataLength: predicateData.length,
|
1134
|
+
predicateLength: bn2(predicate.length),
|
1135
|
+
predicateDataLength: bn2(predicateData.length),
|
1078
1136
|
predicate: hexlify3(predicate),
|
1079
1137
|
predicateData: hexlify3(predicateData),
|
1080
1138
|
data: hexlify3(data),
|
@@ -1149,7 +1207,7 @@ var outputify = (value) => {
|
|
1149
1207
|
|
1150
1208
|
// src/providers/transaction-request/transaction-request.ts
|
1151
1209
|
import { Address, addressify } from "@fuel-ts/address";
|
1152
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1210
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1153
1211
|
import { bn as bn7 } from "@fuel-ts/math";
|
1154
1212
|
import {
|
1155
1213
|
PolicyType,
|
@@ -1159,6 +1217,7 @@ import {
|
|
1159
1217
|
TransactionType
|
1160
1218
|
} from "@fuel-ts/transactions";
|
1161
1219
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1220
|
+
import { randomBytes } from "ethers";
|
1162
1221
|
|
1163
1222
|
// src/providers/resource.ts
|
1164
1223
|
var isCoin = (resource) => "id" in resource;
|
@@ -1199,8 +1258,8 @@ function assembleReceiptByType(receipt) {
|
|
1199
1258
|
case "CALL" /* Call */: {
|
1200
1259
|
const callReceipt = {
|
1201
1260
|
type: ReceiptType.Call,
|
1202
|
-
from: hexOrZero(receipt.
|
1203
|
-
to: hexOrZero(receipt?.to
|
1261
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1262
|
+
to: hexOrZero(receipt?.to),
|
1204
1263
|
amount: bn4(receipt.amount),
|
1205
1264
|
assetId: hexOrZero(receipt.assetId),
|
1206
1265
|
gas: bn4(receipt.gas),
|
@@ -1214,7 +1273,7 @@ function assembleReceiptByType(receipt) {
|
|
1214
1273
|
case "RETURN" /* Return */: {
|
1215
1274
|
const returnReceipt = {
|
1216
1275
|
type: ReceiptType.Return,
|
1217
|
-
id: hexOrZero(receipt.
|
1276
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1218
1277
|
val: bn4(receipt.val),
|
1219
1278
|
pc: bn4(receipt.pc),
|
1220
1279
|
is: bn4(receipt.is)
|
@@ -1224,7 +1283,7 @@ function assembleReceiptByType(receipt) {
|
|
1224
1283
|
case "RETURN_DATA" /* ReturnData */: {
|
1225
1284
|
const returnDataReceipt = {
|
1226
1285
|
type: ReceiptType.ReturnData,
|
1227
|
-
id: hexOrZero(receipt.
|
1286
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1228
1287
|
ptr: bn4(receipt.ptr),
|
1229
1288
|
len: bn4(receipt.len),
|
1230
1289
|
digest: hexOrZero(receipt.digest),
|
@@ -1236,7 +1295,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1295
|
case "PANIC" /* Panic */: {
|
1237
1296
|
const panicReceipt = {
|
1238
1297
|
type: ReceiptType.Panic,
|
1239
|
-
id: hexOrZero(receipt.
|
1298
|
+
id: hexOrZero(receipt.id),
|
1240
1299
|
reason: bn4(receipt.reason),
|
1241
1300
|
pc: bn4(receipt.pc),
|
1242
1301
|
is: bn4(receipt.is),
|
@@ -1247,7 +1306,7 @@ function assembleReceiptByType(receipt) {
|
|
1247
1306
|
case "REVERT" /* Revert */: {
|
1248
1307
|
const revertReceipt = {
|
1249
1308
|
type: ReceiptType.Revert,
|
1250
|
-
id: hexOrZero(receipt.
|
1309
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1251
1310
|
val: bn4(receipt.ra),
|
1252
1311
|
pc: bn4(receipt.pc),
|
1253
1312
|
is: bn4(receipt.is)
|
@@ -1257,7 +1316,7 @@ function assembleReceiptByType(receipt) {
|
|
1257
1316
|
case "LOG" /* Log */: {
|
1258
1317
|
const logReceipt = {
|
1259
1318
|
type: ReceiptType.Log,
|
1260
|
-
id: hexOrZero(receipt.
|
1319
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1261
1320
|
val0: bn4(receipt.ra),
|
1262
1321
|
val1: bn4(receipt.rb),
|
1263
1322
|
val2: bn4(receipt.rc),
|
@@ -1270,7 +1329,7 @@ function assembleReceiptByType(receipt) {
|
|
1270
1329
|
case "LOG_DATA" /* LogData */: {
|
1271
1330
|
const logDataReceipt = {
|
1272
1331
|
type: ReceiptType.LogData,
|
1273
|
-
id: hexOrZero(receipt.
|
1332
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1274
1333
|
val0: bn4(receipt.ra),
|
1275
1334
|
val1: bn4(receipt.rb),
|
1276
1335
|
ptr: bn4(receipt.ptr),
|
@@ -1284,8 +1343,8 @@ function assembleReceiptByType(receipt) {
|
|
1284
1343
|
case "TRANSFER" /* Transfer */: {
|
1285
1344
|
const transferReceipt = {
|
1286
1345
|
type: ReceiptType.Transfer,
|
1287
|
-
from: hexOrZero(receipt.
|
1288
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1346
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1347
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1289
1348
|
amount: bn4(receipt.amount),
|
1290
1349
|
assetId: hexOrZero(receipt.assetId),
|
1291
1350
|
pc: bn4(receipt.pc),
|
@@ -1296,8 +1355,8 @@ function assembleReceiptByType(receipt) {
|
|
1296
1355
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1297
1356
|
const transferOutReceipt = {
|
1298
1357
|
type: ReceiptType.TransferOut,
|
1299
|
-
from: hexOrZero(receipt.
|
1300
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1358
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1359
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1301
1360
|
amount: bn4(receipt.amount),
|
1302
1361
|
assetId: hexOrZero(receipt.assetId),
|
1303
1362
|
pc: bn4(receipt.pc),
|
@@ -1340,7 +1399,7 @@ function assembleReceiptByType(receipt) {
|
|
1340
1399
|
return receiptMessageOut;
|
1341
1400
|
}
|
1342
1401
|
case "MINT" /* Mint */: {
|
1343
|
-
const contractId = hexOrZero(receipt.
|
1402
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1344
1403
|
const subId = hexOrZero(receipt.subId);
|
1345
1404
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1346
1405
|
const mintReceipt = {
|
@@ -1355,7 +1414,7 @@ function assembleReceiptByType(receipt) {
|
|
1355
1414
|
return mintReceipt;
|
1356
1415
|
}
|
1357
1416
|
case "BURN" /* Burn */: {
|
1358
|
-
const contractId = hexOrZero(receipt.
|
1417
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1359
1418
|
const subId = hexOrZero(receipt.subId);
|
1360
1419
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1361
1420
|
const burnReceipt = {
|
@@ -1381,7 +1440,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1381
1440
|
import { bn as bn5 } from "@fuel-ts/math";
|
1382
1441
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1383
1442
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1384
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1385
1443
|
var getGasUsedFromReceipts = (receipts) => {
|
1386
1444
|
const scriptResult = receipts.filter(
|
1387
1445
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1402,18 +1460,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1402
1460
|
}
|
1403
1461
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1404
1462
|
const witnessCache = [];
|
1405
|
-
const
|
1463
|
+
const chargeableInputs = inputs.filter((input) => {
|
1464
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1465
|
+
if (isCoinOrMessage) {
|
1466
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1467
|
+
return true;
|
1468
|
+
}
|
1469
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1470
|
+
witnessCache.push(input.witnessIndex);
|
1471
|
+
return true;
|
1472
|
+
}
|
1473
|
+
}
|
1474
|
+
return false;
|
1475
|
+
});
|
1476
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1477
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1406
1478
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1407
1479
|
return total.add(
|
1408
|
-
|
1480
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1409
1481
|
);
|
1410
1482
|
}
|
1411
|
-
|
1412
|
-
|
1413
|
-
return total.add(gasCosts.ecr1);
|
1414
|
-
}
|
1415
|
-
return total;
|
1416
|
-
}, bn5());
|
1483
|
+
return total.add(gasCosts.ecr1);
|
1484
|
+
}, bn5(0));
|
1417
1485
|
return totalGas;
|
1418
1486
|
}
|
1419
1487
|
function getMinGas(params) {
|
@@ -1425,12 +1493,20 @@ function getMinGas(params) {
|
|
1425
1493
|
return minGas;
|
1426
1494
|
}
|
1427
1495
|
function getMaxGas(params) {
|
1428
|
-
const {
|
1496
|
+
const {
|
1497
|
+
gasPerByte,
|
1498
|
+
witnessesLength,
|
1499
|
+
witnessLimit,
|
1500
|
+
minGas,
|
1501
|
+
gasLimit = bn5(0),
|
1502
|
+
maxGasPerTx
|
1503
|
+
} = params;
|
1429
1504
|
let remainingAllowedWitnessGas = bn5(0);
|
1430
1505
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1431
1506
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1432
1507
|
}
|
1433
|
-
|
1508
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1509
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1434
1510
|
}
|
1435
1511
|
function calculateMetadataGasForTxCreate({
|
1436
1512
|
gasCosts,
|
@@ -1452,6 +1528,10 @@ function calculateMetadataGasForTxScript({
|
|
1452
1528
|
}) {
|
1453
1529
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1454
1530
|
}
|
1531
|
+
var calculateGasFee = (params) => {
|
1532
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1533
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1534
|
+
};
|
1455
1535
|
|
1456
1536
|
// src/providers/utils/json.ts
|
1457
1537
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1596,7 +1676,7 @@ var witnessify = (value) => {
|
|
1596
1676
|
// src/providers/transaction-request/transaction-request.ts
|
1597
1677
|
var BaseTransactionRequest = class {
|
1598
1678
|
/** Gas price for transaction */
|
1599
|
-
|
1679
|
+
tip;
|
1600
1680
|
/** Block until which tx cannot be included */
|
1601
1681
|
maturity;
|
1602
1682
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1609,38 +1689,34 @@ var BaseTransactionRequest = class {
|
|
1609
1689
|
outputs = [];
|
1610
1690
|
/** List of witnesses */
|
1611
1691
|
witnesses = [];
|
1612
|
-
/** Base asset ID - should be fetched from the chain */
|
1613
|
-
baseAssetId = ZeroBytes324;
|
1614
1692
|
/**
|
1615
1693
|
* Constructor for initializing a base transaction request.
|
1616
1694
|
*
|
1617
1695
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1618
1696
|
*/
|
1619
1697
|
constructor({
|
1620
|
-
|
1698
|
+
tip,
|
1621
1699
|
maturity,
|
1622
1700
|
maxFee,
|
1623
1701
|
witnessLimit,
|
1624
1702
|
inputs,
|
1625
1703
|
outputs,
|
1626
|
-
witnesses
|
1627
|
-
baseAssetId
|
1704
|
+
witnesses
|
1628
1705
|
} = {}) {
|
1629
|
-
this.
|
1706
|
+
this.tip = bn7(tip);
|
1630
1707
|
this.maturity = maturity ?? 0;
|
1631
1708
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1632
1709
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1633
1710
|
this.inputs = inputs ?? [];
|
1634
1711
|
this.outputs = outputs ?? [];
|
1635
1712
|
this.witnesses = witnesses ?? [];
|
1636
|
-
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1637
1713
|
}
|
1638
1714
|
static getPolicyMeta(req) {
|
1639
1715
|
let policyTypes = 0;
|
1640
1716
|
const policies = [];
|
1641
|
-
if (req.
|
1642
|
-
policyTypes += PolicyType.
|
1643
|
-
policies.push({ data: req.
|
1717
|
+
if (req.tip) {
|
1718
|
+
policyTypes += PolicyType.Tip;
|
1719
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1644
1720
|
}
|
1645
1721
|
if (req.witnessLimit) {
|
1646
1722
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1827,10 +1903,10 @@ var BaseTransactionRequest = class {
|
|
1827
1903
|
* @param predicate - Predicate bytes.
|
1828
1904
|
* @param predicateData - Predicate data bytes.
|
1829
1905
|
*/
|
1830
|
-
addCoinInput(coin
|
1906
|
+
addCoinInput(coin) {
|
1831
1907
|
const { assetId, owner, amount } = coin;
|
1832
1908
|
let witnessIndex;
|
1833
|
-
if (predicate) {
|
1909
|
+
if (coin.predicate) {
|
1834
1910
|
witnessIndex = 0;
|
1835
1911
|
} else {
|
1836
1912
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1845,9 +1921,7 @@ var BaseTransactionRequest = class {
|
|
1845
1921
|
amount,
|
1846
1922
|
assetId,
|
1847
1923
|
txPointer: "0x00000000000000000000000000000000",
|
1848
|
-
witnessIndex
|
1849
|
-
predicate: predicate?.bytes,
|
1850
|
-
predicateData: predicate?.predicateDataBytes
|
1924
|
+
witnessIndex
|
1851
1925
|
};
|
1852
1926
|
this.pushInput(input);
|
1853
1927
|
this.addChangeOutput(owner, assetId);
|
@@ -1858,11 +1932,13 @@ var BaseTransactionRequest = class {
|
|
1858
1932
|
*
|
1859
1933
|
* @param message - Message resource.
|
1860
1934
|
* @param predicate - Predicate bytes.
|
1935
|
+
* @param predicateData - Predicate data bytes.
|
1861
1936
|
*/
|
1862
|
-
addMessageInput(message
|
1937
|
+
addMessageInput(message) {
|
1863
1938
|
const { recipient, sender, amount } = message;
|
1939
|
+
const assetId = BaseAssetId2;
|
1864
1940
|
let witnessIndex;
|
1865
|
-
if (predicate) {
|
1941
|
+
if (message.predicate) {
|
1866
1942
|
witnessIndex = 0;
|
1867
1943
|
} else {
|
1868
1944
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1876,12 +1952,10 @@ var BaseTransactionRequest = class {
|
|
1876
1952
|
sender: sender.toB256(),
|
1877
1953
|
recipient: recipient.toB256(),
|
1878
1954
|
amount,
|
1879
|
-
witnessIndex
|
1880
|
-
predicate: predicate?.bytes,
|
1881
|
-
predicateData: predicate?.predicateDataBytes
|
1955
|
+
witnessIndex
|
1882
1956
|
};
|
1883
1957
|
this.pushInput(input);
|
1884
|
-
this.addChangeOutput(recipient,
|
1958
|
+
this.addChangeOutput(recipient, assetId);
|
1885
1959
|
}
|
1886
1960
|
/**
|
1887
1961
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1909,32 +1983,6 @@ var BaseTransactionRequest = class {
|
|
1909
1983
|
resources.forEach((resource) => this.addResource(resource));
|
1910
1984
|
return this;
|
1911
1985
|
}
|
1912
|
-
/**
|
1913
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1914
|
-
* outputs from the related assetIds.
|
1915
|
-
*
|
1916
|
-
* @param resources - The resources to add.
|
1917
|
-
* @returns This transaction.
|
1918
|
-
*/
|
1919
|
-
addPredicateResource(resource, predicate) {
|
1920
|
-
if (isCoin(resource)) {
|
1921
|
-
this.addCoinInput(resource, predicate);
|
1922
|
-
} else {
|
1923
|
-
this.addMessageInput(resource, predicate);
|
1924
|
-
}
|
1925
|
-
return this;
|
1926
|
-
}
|
1927
|
-
/**
|
1928
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1929
|
-
* from the related assetIds.
|
1930
|
-
*
|
1931
|
-
* @param resources - The resources to add.
|
1932
|
-
* @returns This transaction.
|
1933
|
-
*/
|
1934
|
-
addPredicateResources(resources, predicate) {
|
1935
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1936
|
-
return this;
|
1937
|
-
}
|
1938
1986
|
/**
|
1939
1987
|
* Adds a coin output to the transaction.
|
1940
1988
|
*
|
@@ -1942,12 +1990,12 @@ var BaseTransactionRequest = class {
|
|
1942
1990
|
* @param amount - Amount of coin.
|
1943
1991
|
* @param assetId - Asset ID of coin.
|
1944
1992
|
*/
|
1945
|
-
addCoinOutput(to, amount, assetId) {
|
1993
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1946
1994
|
this.pushOutput({
|
1947
1995
|
type: OutputType2.Coin,
|
1948
1996
|
to: addressify(to).toB256(),
|
1949
1997
|
amount,
|
1950
|
-
assetId
|
1998
|
+
assetId
|
1951
1999
|
});
|
1952
2000
|
return this;
|
1953
2001
|
}
|
@@ -1974,7 +2022,7 @@ var BaseTransactionRequest = class {
|
|
1974
2022
|
* @param to - Address of the owner.
|
1975
2023
|
* @param assetId - Asset ID of coin.
|
1976
2024
|
*/
|
1977
|
-
addChangeOutput(to, assetId) {
|
2025
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1978
2026
|
const changeOutput = this.getChangeOutputs().find(
|
1979
2027
|
(output) => hexlify7(output.assetId) === assetId
|
1980
2028
|
);
|
@@ -1982,7 +2030,7 @@ var BaseTransactionRequest = class {
|
|
1982
2030
|
this.pushOutput({
|
1983
2031
|
type: OutputType2.Change,
|
1984
2032
|
to: addressify(to).toB256(),
|
1985
|
-
assetId
|
2033
|
+
assetId
|
1986
2034
|
});
|
1987
2035
|
}
|
1988
2036
|
}
|
@@ -2014,7 +2062,7 @@ var BaseTransactionRequest = class {
|
|
2014
2062
|
}
|
2015
2063
|
calculateMaxGas(chainInfo, minGas) {
|
2016
2064
|
const { consensusParameters } = chainInfo;
|
2017
|
-
const { gasPerByte } = consensusParameters;
|
2065
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2018
2066
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2019
2067
|
(acc, wit) => acc + wit.dataLength,
|
2020
2068
|
0
|
@@ -2023,7 +2071,8 @@ var BaseTransactionRequest = class {
|
|
2023
2071
|
gasPerByte,
|
2024
2072
|
minGas,
|
2025
2073
|
witnessesLength,
|
2026
|
-
witnessLimit: this.witnessLimit
|
2074
|
+
witnessLimit: this.witnessLimit,
|
2075
|
+
maxGasPerTx
|
2027
2076
|
});
|
2028
2077
|
}
|
2029
2078
|
/**
|
@@ -2033,12 +2082,6 @@ var BaseTransactionRequest = class {
|
|
2033
2082
|
* @param quantities - CoinQuantity Array.
|
2034
2083
|
*/
|
2035
2084
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2036
|
-
let idCounter = 0;
|
2037
|
-
const generateId = () => {
|
2038
|
-
const counterString = String(idCounter++);
|
2039
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2040
|
-
return id;
|
2041
|
-
};
|
2042
2085
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2043
2086
|
if ("assetId" in input) {
|
2044
2087
|
return input.assetId === assetId;
|
@@ -2047,24 +2090,27 @@ var BaseTransactionRequest = class {
|
|
2047
2090
|
});
|
2048
2091
|
const updateAssetInput = (assetId, quantity) => {
|
2049
2092
|
const assetInput = findAssetInput(assetId);
|
2093
|
+
let usedQuantity = quantity;
|
2094
|
+
if (assetId === BaseAssetId2) {
|
2095
|
+
usedQuantity = bn7("1000000000000000000");
|
2096
|
+
}
|
2050
2097
|
if (assetInput && "assetId" in assetInput) {
|
2051
|
-
assetInput.id =
|
2052
|
-
assetInput.amount =
|
2098
|
+
assetInput.id = hexlify7(randomBytes(34));
|
2099
|
+
assetInput.amount = usedQuantity;
|
2053
2100
|
} else {
|
2054
2101
|
this.addResources([
|
2055
2102
|
{
|
2056
|
-
id:
|
2057
|
-
amount:
|
2103
|
+
id: hexlify7(randomBytes(34)),
|
2104
|
+
amount: usedQuantity,
|
2058
2105
|
assetId,
|
2059
2106
|
owner: resourcesOwner || Address.fromRandom(),
|
2060
|
-
maturity: 0,
|
2061
2107
|
blockCreated: bn7(1),
|
2062
2108
|
txCreatedIdx: bn7(1)
|
2063
2109
|
}
|
2064
2110
|
]);
|
2065
2111
|
}
|
2066
2112
|
};
|
2067
|
-
updateAssetInput(
|
2113
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2068
2114
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2069
2115
|
}
|
2070
2116
|
/**
|
@@ -2089,7 +2135,7 @@ var BaseTransactionRequest = class {
|
|
2089
2135
|
toJSON() {
|
2090
2136
|
return normalizeJSON(this);
|
2091
2137
|
}
|
2092
|
-
|
2138
|
+
updatePredicateGasUsed(inputs) {
|
2093
2139
|
this.inputs.forEach((i) => {
|
2094
2140
|
let correspondingInput;
|
2095
2141
|
switch (i.type) {
|
@@ -2111,6 +2157,15 @@ var BaseTransactionRequest = class {
|
|
2111
2157
|
}
|
2112
2158
|
});
|
2113
2159
|
}
|
2160
|
+
shiftPredicateData() {
|
2161
|
+
this.inputs.forEach((input) => {
|
2162
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2163
|
+
input.predicateData = input.paddPredicateData(
|
2164
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2165
|
+
);
|
2166
|
+
}
|
2167
|
+
});
|
2168
|
+
}
|
2114
2169
|
};
|
2115
2170
|
|
2116
2171
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2257,9 +2312,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2257
2312
|
return {
|
2258
2313
|
type: TransactionType3.Create,
|
2259
2314
|
...baseTransaction,
|
2260
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2261
2315
|
bytecodeWitnessIndex,
|
2262
|
-
storageSlotsCount: storageSlots.length,
|
2316
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2263
2317
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2264
2318
|
storageSlots
|
2265
2319
|
};
|
@@ -2382,8 +2436,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2382
2436
|
type: TransactionType4.Script,
|
2383
2437
|
scriptGasLimit: this.gasLimit,
|
2384
2438
|
...super.getBaseTransaction(),
|
2385
|
-
scriptLength: script.length,
|
2386
|
-
scriptDataLength: scriptData.length,
|
2439
|
+
scriptLength: bn10(script.length),
|
2440
|
+
scriptDataLength: bn10(scriptData.length),
|
2387
2441
|
receiptsRoot: ZeroBytes327,
|
2388
2442
|
script: hexlify10(script),
|
2389
2443
|
scriptData: hexlify10(scriptData)
|
@@ -2447,7 +2501,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2447
2501
|
}
|
2448
2502
|
calculateMaxGas(chainInfo, minGas) {
|
2449
2503
|
const { consensusParameters } = chainInfo;
|
2450
|
-
const { gasPerByte } = consensusParameters;
|
2504
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2451
2505
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2452
2506
|
(acc, wit) => acc + wit.dataLength,
|
2453
2507
|
0
|
@@ -2457,7 +2511,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2457
2511
|
minGas,
|
2458
2512
|
witnessesLength,
|
2459
2513
|
witnessLimit: this.witnessLimit,
|
2460
|
-
gasLimit: this.gasLimit
|
2514
|
+
gasLimit: this.gasLimit,
|
2515
|
+
maxGasPerTx
|
2461
2516
|
});
|
2462
2517
|
}
|
2463
2518
|
/**
|
@@ -2514,7 +2569,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2514
2569
|
|
2515
2570
|
// src/providers/transaction-request/utils.ts
|
2516
2571
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2517
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2572
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2518
2573
|
var transactionRequestify = (obj) => {
|
2519
2574
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2520
2575
|
return obj;
|
@@ -2532,14 +2587,31 @@ var transactionRequestify = (obj) => {
|
|
2532
2587
|
}
|
2533
2588
|
}
|
2534
2589
|
};
|
2590
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2591
|
+
(acc, input) => {
|
2592
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2593
|
+
acc.utxos.push(input.id);
|
2594
|
+
}
|
2595
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2596
|
+
acc.messages.push(input.nonce);
|
2597
|
+
}
|
2598
|
+
return acc;
|
2599
|
+
},
|
2600
|
+
{
|
2601
|
+
utxos: [],
|
2602
|
+
messages: []
|
2603
|
+
}
|
2604
|
+
);
|
2535
2605
|
|
2536
2606
|
// src/providers/transaction-response/transaction-response.ts
|
2537
2607
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2538
|
-
import { bn as
|
2608
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2539
2609
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2540
2610
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2541
2611
|
|
2542
2612
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2613
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2614
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2543
2615
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2544
2616
|
|
2545
2617
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2548,9 +2620,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2548
2620
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2549
2621
|
var calculateTransactionFee = (params) => {
|
2550
2622
|
const {
|
2551
|
-
|
2623
|
+
gasPrice,
|
2552
2624
|
rawPayload,
|
2553
|
-
|
2625
|
+
tip,
|
2626
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2554
2627
|
} = params;
|
2555
2628
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2556
2629
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2560,8 +2633,7 @@ var calculateTransactionFee = (params) => {
|
|
2560
2633
|
return {
|
2561
2634
|
fee: bn11(0),
|
2562
2635
|
minFee: bn11(0),
|
2563
|
-
maxFee: bn11(0)
|
2564
|
-
feeFromGasUsed: bn11(0)
|
2636
|
+
maxFee: bn11(0)
|
2565
2637
|
};
|
2566
2638
|
}
|
2567
2639
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2593,7 +2665,6 @@ var calculateTransactionFee = (params) => {
|
|
2593
2665
|
metadataGas,
|
2594
2666
|
txBytesSize: transactionBytes.length
|
2595
2667
|
});
|
2596
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2597
2668
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2598
2669
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2599
2670
|
const maxGas = getMaxGas({
|
@@ -2601,17 +2672,25 @@ var calculateTransactionFee = (params) => {
|
|
2601
2672
|
minGas,
|
2602
2673
|
witnessesLength,
|
2603
2674
|
gasLimit,
|
2604
|
-
witnessLimit
|
2675
|
+
witnessLimit,
|
2676
|
+
maxGasPerTx
|
2677
|
+
});
|
2678
|
+
const minFee = calculateGasFee({
|
2679
|
+
gasPrice,
|
2680
|
+
gas: minGas,
|
2681
|
+
priceFactor: gasPriceFactor,
|
2682
|
+
tip
|
2683
|
+
});
|
2684
|
+
const maxFee = calculateGasFee({
|
2685
|
+
gasPrice,
|
2686
|
+
gas: maxGas,
|
2687
|
+
priceFactor: gasPriceFactor,
|
2688
|
+
tip
|
2605
2689
|
});
|
2606
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2607
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2608
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2609
|
-
const fee = minFee.add(feeFromGasUsed);
|
2610
2690
|
return {
|
2611
|
-
fee,
|
2612
2691
|
minFee,
|
2613
2692
|
maxFee,
|
2614
|
-
|
2693
|
+
fee: maxFee
|
2615
2694
|
};
|
2616
2695
|
};
|
2617
2696
|
|
@@ -2667,7 +2746,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2667
2746
|
|
2668
2747
|
// src/providers/transaction-summary/input.ts
|
2669
2748
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2670
|
-
import { InputType as
|
2749
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2671
2750
|
function getInputsByTypes(inputs, types) {
|
2672
2751
|
return inputs.filter((i) => types.includes(i.type));
|
2673
2752
|
}
|
@@ -2675,16 +2754,16 @@ function getInputsByType(inputs, type) {
|
|
2675
2754
|
return inputs.filter((i) => i.type === type);
|
2676
2755
|
}
|
2677
2756
|
function getInputsCoin(inputs) {
|
2678
|
-
return getInputsByType(inputs,
|
2757
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2679
2758
|
}
|
2680
2759
|
function getInputsMessage(inputs) {
|
2681
|
-
return getInputsByType(inputs,
|
2760
|
+
return getInputsByType(inputs, InputType6.Message);
|
2682
2761
|
}
|
2683
2762
|
function getInputsCoinAndMessage(inputs) {
|
2684
|
-
return getInputsByTypes(inputs, [
|
2763
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2685
2764
|
}
|
2686
2765
|
function getInputsContract(inputs) {
|
2687
|
-
return getInputsByType(inputs,
|
2766
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2688
2767
|
}
|
2689
2768
|
function getInputFromAssetId(inputs, assetId) {
|
2690
2769
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2703,7 +2782,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2703
2782
|
if (!contractInput) {
|
2704
2783
|
return void 0;
|
2705
2784
|
}
|
2706
|
-
if (contractInput.type !==
|
2785
|
+
if (contractInput.type !== InputType6.Contract) {
|
2707
2786
|
throw new FuelError9(
|
2708
2787
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2709
2788
|
`Contract input should be of type 'contract'.`
|
@@ -2712,10 +2791,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2712
2791
|
return contractInput;
|
2713
2792
|
}
|
2714
2793
|
function getInputAccountAddress(input) {
|
2715
|
-
if (input.type ===
|
2794
|
+
if (input.type === InputType6.Coin) {
|
2716
2795
|
return input.owner.toString();
|
2717
2796
|
}
|
2718
|
-
if (input.type ===
|
2797
|
+
if (input.type === InputType6.Message) {
|
2719
2798
|
return input.recipient.toString();
|
2720
2799
|
}
|
2721
2800
|
return "";
|
@@ -3178,7 +3257,9 @@ function assembleTransactionSummary(params) {
|
|
3178
3257
|
gqlTransactionStatus,
|
3179
3258
|
abiMap = {},
|
3180
3259
|
maxInputs,
|
3181
|
-
gasCosts
|
3260
|
+
gasCosts,
|
3261
|
+
maxGasPerTx,
|
3262
|
+
gasPrice
|
3182
3263
|
} = params;
|
3183
3264
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3184
3265
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3192,11 +3273,14 @@ function assembleTransactionSummary(params) {
|
|
3192
3273
|
maxInputs
|
3193
3274
|
});
|
3194
3275
|
const typeName = getTransactionTypeName(transaction.type);
|
3276
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3195
3277
|
const { fee } = calculateTransactionFee({
|
3196
|
-
|
3278
|
+
gasPrice,
|
3197
3279
|
rawPayload,
|
3280
|
+
tip,
|
3198
3281
|
consensusParameters: {
|
3199
3282
|
gasCosts,
|
3283
|
+
maxGasPerTx,
|
3200
3284
|
feeParams: {
|
3201
3285
|
gasPerByte,
|
3202
3286
|
gasPriceFactor
|
@@ -3256,7 +3340,7 @@ var TransactionResponse = class {
|
|
3256
3340
|
/** Current provider */
|
3257
3341
|
provider;
|
3258
3342
|
/** Gas used on the transaction */
|
3259
|
-
gasUsed =
|
3343
|
+
gasUsed = bn15(0);
|
3260
3344
|
/** The graphql Transaction with receipts object. */
|
3261
3345
|
gqlTransaction;
|
3262
3346
|
abis;
|
@@ -3334,8 +3418,13 @@ var TransactionResponse = class {
|
|
3334
3418
|
const decodedTransaction = this.decodeTransaction(
|
3335
3419
|
transaction
|
3336
3420
|
);
|
3337
|
-
|
3338
|
-
|
3421
|
+
let txReceipts = [];
|
3422
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3423
|
+
txReceipts = transaction.status.receipts;
|
3424
|
+
}
|
3425
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3426
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3427
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3339
3428
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3340
3429
|
const transactionSummary = assembleTransactionSummary({
|
3341
3430
|
id: this.id,
|
@@ -3347,7 +3436,9 @@ var TransactionResponse = class {
|
|
3347
3436
|
gasPriceFactor,
|
3348
3437
|
abiMap: contractsAbiMap,
|
3349
3438
|
maxInputs,
|
3350
|
-
gasCosts
|
3439
|
+
gasCosts,
|
3440
|
+
maxGasPerTx,
|
3441
|
+
gasPrice
|
3351
3442
|
});
|
3352
3443
|
return transactionSummary;
|
3353
3444
|
}
|
@@ -3474,30 +3565,29 @@ var processGqlChain = (chain) => {
|
|
3474
3565
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3475
3566
|
return {
|
3476
3567
|
name,
|
3477
|
-
baseChainHeight:
|
3568
|
+
baseChainHeight: bn16(daHeight),
|
3478
3569
|
consensusParameters: {
|
3479
|
-
contractMaxSize:
|
3480
|
-
maxInputs:
|
3481
|
-
maxOutputs:
|
3482
|
-
maxWitnesses:
|
3483
|
-
maxGasPerTx:
|
3484
|
-
maxScriptLength:
|
3485
|
-
maxScriptDataLength:
|
3486
|
-
maxStorageSlots:
|
3487
|
-
maxPredicateLength:
|
3488
|
-
maxPredicateDataLength:
|
3489
|
-
maxGasPerPredicate:
|
3490
|
-
gasPriceFactor:
|
3491
|
-
gasPerByte:
|
3492
|
-
maxMessageDataLength:
|
3493
|
-
chainId:
|
3494
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3570
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3571
|
+
maxInputs: bn16(txParams.maxInputs),
|
3572
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3573
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3574
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3575
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3576
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3577
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3578
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3579
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3580
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3581
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3582
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3583
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3584
|
+
chainId: bn16(consensusParameters.chainId),
|
3495
3585
|
gasCosts
|
3496
3586
|
},
|
3497
3587
|
gasCosts,
|
3498
3588
|
latestBlock: {
|
3499
3589
|
id: latestBlock.id,
|
3500
|
-
height:
|
3590
|
+
height: bn16(latestBlock.height),
|
3501
3591
|
time: latestBlock.header.time,
|
3502
3592
|
transactions: latestBlock.transactions.map((i) => ({
|
3503
3593
|
id: i.id
|
@@ -3591,10 +3681,8 @@ var _Provider = class {
|
|
3591
3681
|
* Returns some helpful parameters related to gas fees.
|
3592
3682
|
*/
|
3593
3683
|
getGasConfig() {
|
3594
|
-
const { minGasPrice } = this.getNode();
|
3595
3684
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3596
3685
|
return {
|
3597
|
-
minGasPrice,
|
3598
3686
|
maxGasPerTx,
|
3599
3687
|
maxGasPerPredicate,
|
3600
3688
|
gasPriceFactor,
|
@@ -3692,7 +3780,7 @@ var _Provider = class {
|
|
3692
3780
|
*/
|
3693
3781
|
async getBlockNumber() {
|
3694
3782
|
const { chain } = await this.operations.getChain();
|
3695
|
-
return
|
3783
|
+
return bn16(chain.latestBlock.height, 10);
|
3696
3784
|
}
|
3697
3785
|
/**
|
3698
3786
|
* Returns the chain information.
|
@@ -3702,13 +3790,11 @@ var _Provider = class {
|
|
3702
3790
|
async fetchNode() {
|
3703
3791
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3704
3792
|
const processedNodeInfo = {
|
3705
|
-
maxDepth:
|
3706
|
-
maxTx:
|
3707
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3793
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3794
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3708
3795
|
nodeVersion: nodeInfo.nodeVersion,
|
3709
3796
|
utxoValidation: nodeInfo.utxoValidation,
|
3710
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3711
|
-
peers: nodeInfo.peers
|
3797
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3712
3798
|
};
|
3713
3799
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3714
3800
|
return processedNodeInfo;
|
@@ -3734,17 +3820,6 @@ var _Provider = class {
|
|
3734
3820
|
} = this.getChain();
|
3735
3821
|
return chainId.toNumber();
|
3736
3822
|
}
|
3737
|
-
/**
|
3738
|
-
* Returns the base asset ID
|
3739
|
-
*
|
3740
|
-
* @returns A promise that resolves to the base asset ID
|
3741
|
-
*/
|
3742
|
-
getBaseAssetId() {
|
3743
|
-
const {
|
3744
|
-
consensusParameters: { baseAssetId }
|
3745
|
-
} = this.getChain();
|
3746
|
-
return baseAssetId;
|
3747
|
-
}
|
3748
3823
|
/**
|
3749
3824
|
* Submits a transaction to the chain to be executed.
|
3750
3825
|
*
|
@@ -3805,14 +3880,13 @@ var _Provider = class {
|
|
3805
3880
|
return this.estimateTxDependencies(transactionRequest);
|
3806
3881
|
}
|
3807
3882
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3808
|
-
const { dryRun:
|
3809
|
-
encodedTransaction,
|
3883
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3884
|
+
encodedTransactions: encodedTransaction,
|
3810
3885
|
utxoValidation: utxoValidation || false
|
3811
3886
|
});
|
3812
|
-
const receipts =
|
3813
|
-
|
3814
|
-
|
3815
|
-
};
|
3887
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3888
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3889
|
+
return { receipts, dryrunStatus: status };
|
3816
3890
|
}
|
3817
3891
|
/**
|
3818
3892
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3838,7 +3912,7 @@ var _Provider = class {
|
|
3838
3912
|
} = response;
|
3839
3913
|
if (inputs) {
|
3840
3914
|
inputs.forEach((input, index) => {
|
3841
|
-
if ("predicateGasUsed" in input &&
|
3915
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3842
3916
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3843
3917
|
}
|
3844
3918
|
});
|
@@ -3851,9 +3925,6 @@ var _Provider = class {
|
|
3851
3925
|
* If there are missing variable outputs,
|
3852
3926
|
* `addVariableOutputs` is called on the transaction.
|
3853
3927
|
*
|
3854
|
-
* @privateRemarks
|
3855
|
-
* TODO: Investigate support for missing contract IDs
|
3856
|
-
* TODO: Add support for missing output messages
|
3857
3928
|
*
|
3858
3929
|
* @param transactionRequest - The transaction request object.
|
3859
3930
|
* @returns A promise.
|
@@ -3866,16 +3937,19 @@ var _Provider = class {
|
|
3866
3937
|
missingContractIds: []
|
3867
3938
|
};
|
3868
3939
|
}
|
3869
|
-
await this.estimatePredicates(transactionRequest);
|
3870
3940
|
let receipts = [];
|
3871
3941
|
const missingContractIds = [];
|
3872
3942
|
let outputVariables = 0;
|
3943
|
+
let dryrunStatus;
|
3873
3944
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3874
|
-
const {
|
3875
|
-
|
3945
|
+
const {
|
3946
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3947
|
+
} = await this.operations.dryRun({
|
3948
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3876
3949
|
utxoValidation: false
|
3877
3950
|
});
|
3878
|
-
receipts =
|
3951
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3952
|
+
dryrunStatus = status;
|
3879
3953
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3880
3954
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3881
3955
|
if (hasMissingOutputs) {
|
@@ -3885,6 +3959,11 @@ var _Provider = class {
|
|
3885
3959
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3886
3960
|
missingContractIds.push(contractId);
|
3887
3961
|
});
|
3962
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3963
|
+
transactionRequest,
|
3964
|
+
optimizeGas: false
|
3965
|
+
});
|
3966
|
+
transactionRequest.maxFee = maxFee;
|
3888
3967
|
} else {
|
3889
3968
|
break;
|
3890
3969
|
}
|
@@ -3892,7 +3971,133 @@ var _Provider = class {
|
|
3892
3971
|
return {
|
3893
3972
|
receipts,
|
3894
3973
|
outputVariables,
|
3895
|
-
missingContractIds
|
3974
|
+
missingContractIds,
|
3975
|
+
dryrunStatus
|
3976
|
+
};
|
3977
|
+
}
|
3978
|
+
/**
|
3979
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3980
|
+
*
|
3981
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3982
|
+
* further modifications are identified. The method iteratively updates these transactions
|
3983
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3984
|
+
*
|
3985
|
+
* @param transactionRequests - Array of transaction request objects.
|
3986
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
3987
|
+
*/
|
3988
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
3989
|
+
const results = transactionRequests.map(() => ({
|
3990
|
+
receipts: [],
|
3991
|
+
outputVariables: 0,
|
3992
|
+
missingContractIds: [],
|
3993
|
+
dryrunStatus: void 0
|
3994
|
+
}));
|
3995
|
+
const allRequests = clone3(transactionRequests);
|
3996
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
3997
|
+
allRequests.forEach((req, index) => {
|
3998
|
+
if (req.type === TransactionType8.Script) {
|
3999
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4000
|
+
}
|
4001
|
+
});
|
4002
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4003
|
+
let attempt = 0;
|
4004
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4005
|
+
const encodedTransactions = transactionsToProcess.map(
|
4006
|
+
(index) => serializedTransactionsMap.get(index)
|
4007
|
+
);
|
4008
|
+
const dryRunResults = await this.operations.dryRun({
|
4009
|
+
encodedTransactions,
|
4010
|
+
utxoValidation: false
|
4011
|
+
});
|
4012
|
+
const nextRoundTransactions = [];
|
4013
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4014
|
+
const currentResultIndex = transactionsToProcess[i];
|
4015
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4016
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4017
|
+
results[currentResultIndex].dryrunStatus = status;
|
4018
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4019
|
+
results[currentResultIndex].receipts
|
4020
|
+
);
|
4021
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4022
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4023
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4024
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4025
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4026
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4027
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4028
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4029
|
+
});
|
4030
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4031
|
+
transactionRequest: requestToProcess,
|
4032
|
+
optimizeGas: false
|
4033
|
+
});
|
4034
|
+
requestToProcess.maxFee = maxFee;
|
4035
|
+
serializedTransactionsMap.set(
|
4036
|
+
currentResultIndex,
|
4037
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4038
|
+
);
|
4039
|
+
nextRoundTransactions.push(currentResultIndex);
|
4040
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4041
|
+
}
|
4042
|
+
}
|
4043
|
+
transactionsToProcess = nextRoundTransactions;
|
4044
|
+
attempt += 1;
|
4045
|
+
}
|
4046
|
+
return results;
|
4047
|
+
}
|
4048
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4049
|
+
if (estimateTxDependencies) {
|
4050
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4051
|
+
}
|
4052
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4053
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4054
|
+
encodedTransactions,
|
4055
|
+
utxoValidation: utxoValidation || false
|
4056
|
+
});
|
4057
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4058
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4059
|
+
return { receipts, dryrunStatus: status };
|
4060
|
+
});
|
4061
|
+
return results;
|
4062
|
+
}
|
4063
|
+
async estimateTxGasAndFee(params) {
|
4064
|
+
const { transactionRequest, optimizeGas = true } = params;
|
4065
|
+
let { gasPrice } = params;
|
4066
|
+
const chainInfo = this.getChain();
|
4067
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4068
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4069
|
+
if (!gasPrice) {
|
4070
|
+
gasPrice = await this.estimateGasPrice(10);
|
4071
|
+
}
|
4072
|
+
const minFee = calculateGasFee({
|
4073
|
+
gasPrice: bn16(gasPrice),
|
4074
|
+
gas: minGas,
|
4075
|
+
priceFactor: gasPriceFactor,
|
4076
|
+
tip: transactionRequest.tip
|
4077
|
+
}).add(1);
|
4078
|
+
let gasLimit = bn16(0);
|
4079
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
4080
|
+
gasLimit = transactionRequest.gasLimit;
|
4081
|
+
if (!optimizeGas) {
|
4082
|
+
transactionRequest.gasLimit = minGas;
|
4083
|
+
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4084
|
+
transactionRequest.gasLimit = gasLimit;
|
4085
|
+
}
|
4086
|
+
}
|
4087
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4088
|
+
const maxFee = calculateGasFee({
|
4089
|
+
gasPrice: bn16(gasPrice),
|
4090
|
+
gas: maxGas,
|
4091
|
+
priceFactor: gasPriceFactor,
|
4092
|
+
tip: transactionRequest.tip
|
4093
|
+
}).add(1);
|
4094
|
+
return {
|
4095
|
+
minGas,
|
4096
|
+
minFee,
|
4097
|
+
maxGas,
|
4098
|
+
maxFee,
|
4099
|
+
gasPrice,
|
4100
|
+
gasLimit
|
3896
4101
|
};
|
3897
4102
|
}
|
3898
4103
|
/**
|
@@ -3910,15 +4115,17 @@ var _Provider = class {
|
|
3910
4115
|
if (estimateTxDependencies) {
|
3911
4116
|
return this.estimateTxDependencies(transactionRequest);
|
3912
4117
|
}
|
3913
|
-
const
|
3914
|
-
const { dryRun:
|
3915
|
-
|
4118
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4119
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4120
|
+
encodedTransactions,
|
3916
4121
|
utxoValidation: true
|
3917
4122
|
});
|
3918
|
-
const
|
3919
|
-
|
3920
|
-
receipts
|
3921
|
-
|
4123
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4124
|
+
const { id, receipts, status } = dryRunStatus;
|
4125
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4126
|
+
return { id, receipts: processedReceipts, status };
|
4127
|
+
});
|
4128
|
+
return { receipts: callResult[0].receipts };
|
3922
4129
|
}
|
3923
4130
|
/**
|
3924
4131
|
* Returns a transaction cost to enable user
|
@@ -3935,80 +4142,80 @@ var _Provider = class {
|
|
3935
4142
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3936
4143
|
* @returns A promise that resolves to the transaction cost object.
|
3937
4144
|
*/
|
3938
|
-
async getTransactionCost(transactionRequestLike,
|
3939
|
-
estimateTxDependencies = true,
|
3940
|
-
estimatePredicates = true,
|
3941
|
-
resourcesOwner,
|
3942
|
-
signatureCallback
|
3943
|
-
} = {}) {
|
4145
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3944
4146
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3945
|
-
const chainInfo = this.getChain();
|
3946
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3947
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3948
4147
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3949
4148
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3950
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4149
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3951
4150
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3952
|
-
|
3953
|
-
|
3954
|
-
|
3955
|
-
}
|
3956
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3957
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3958
|
-
}
|
3959
|
-
await this.estimatePredicates(txRequestClone);
|
4151
|
+
txRequestClone.maxFee = bn16(0);
|
4152
|
+
if (isScriptTransaction) {
|
4153
|
+
txRequestClone.gasLimit = bn16(0);
|
3960
4154
|
}
|
3961
|
-
if (
|
3962
|
-
|
4155
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4156
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3963
4157
|
}
|
3964
|
-
const
|
3965
|
-
|
4158
|
+
const signedRequest = clone3(txRequestClone);
|
4159
|
+
let addedSignatures = 0;
|
4160
|
+
if (signatureCallback && isScriptTransaction) {
|
4161
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4162
|
+
await signatureCallback(signedRequest);
|
4163
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4164
|
+
}
|
4165
|
+
await this.estimatePredicates(signedRequest);
|
4166
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4167
|
+
transactionRequest: signedRequest,
|
4168
|
+
optimizeGas: false
|
4169
|
+
});
|
4170
|
+
txRequestClone.maxFee = maxFee;
|
3966
4171
|
let receipts = [];
|
3967
4172
|
let missingContractIds = [];
|
3968
4173
|
let outputVariables = 0;
|
3969
|
-
|
3970
|
-
|
3971
|
-
|
4174
|
+
let gasUsed = bn16(0);
|
4175
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4176
|
+
if (isScriptTransaction) {
|
4177
|
+
if (signatureCallback) {
|
4178
|
+
await signatureCallback(txRequestClone);
|
4179
|
+
}
|
4180
|
+
txRequestClone.gasLimit = gasLimit;
|
3972
4181
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3973
4182
|
receipts = result.receipts;
|
3974
4183
|
outputVariables = result.outputVariables;
|
3975
4184
|
missingContractIds = result.missingContractIds;
|
4185
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4186
|
+
txRequestClone.gasLimit = gasUsed;
|
4187
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4188
|
+
transactionRequest: txRequestClone,
|
4189
|
+
gasPrice
|
4190
|
+
}));
|
3976
4191
|
}
|
3977
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3978
|
-
const usedFee = calculatePriceWithFactor(
|
3979
|
-
gasUsed,
|
3980
|
-
gasPrice,
|
3981
|
-
gasPriceFactor
|
3982
|
-
).normalizeZeroToOne();
|
3983
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3984
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3985
4192
|
return {
|
3986
4193
|
requiredQuantities: allQuantities,
|
3987
4194
|
receipts,
|
3988
4195
|
gasUsed,
|
3989
|
-
minGasPrice,
|
3990
4196
|
gasPrice,
|
3991
4197
|
minGas,
|
3992
4198
|
maxGas,
|
3993
|
-
usedFee,
|
3994
4199
|
minFee,
|
3995
4200
|
maxFee,
|
3996
|
-
estimatedInputs: txRequestClone.inputs,
|
3997
4201
|
outputVariables,
|
3998
|
-
missingContractIds
|
4202
|
+
missingContractIds,
|
4203
|
+
addedSignatures,
|
4204
|
+
estimatedPredicates: txRequestClone.inputs
|
3999
4205
|
};
|
4000
4206
|
}
|
4001
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4207
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4002
4208
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4003
4209
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4004
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4210
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4211
|
+
quantitiesToContract
|
4212
|
+
});
|
4005
4213
|
transactionRequest.addResources(
|
4006
4214
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4007
4215
|
);
|
4008
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4009
|
-
|
4010
|
-
|
4011
|
-
);
|
4216
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4217
|
+
quantitiesToContract
|
4218
|
+
});
|
4012
4219
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4013
4220
|
return {
|
4014
4221
|
resources,
|
@@ -4030,11 +4237,10 @@ var _Provider = class {
|
|
4030
4237
|
return coins.map((coin) => ({
|
4031
4238
|
id: coin.utxoId,
|
4032
4239
|
assetId: coin.assetId,
|
4033
|
-
amount:
|
4240
|
+
amount: bn16(coin.amount),
|
4034
4241
|
owner: Address2.fromAddressOrString(coin.owner),
|
4035
|
-
|
4036
|
-
|
4037
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4242
|
+
blockCreated: bn16(coin.blockCreated),
|
4243
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4038
4244
|
}));
|
4039
4245
|
}
|
4040
4246
|
/**
|
@@ -4071,9 +4277,9 @@ var _Provider = class {
|
|
4071
4277
|
switch (coin.__typename) {
|
4072
4278
|
case "MessageCoin":
|
4073
4279
|
return {
|
4074
|
-
amount:
|
4280
|
+
amount: bn16(coin.amount),
|
4075
4281
|
assetId: coin.assetId,
|
4076
|
-
daHeight:
|
4282
|
+
daHeight: bn16(coin.daHeight),
|
4077
4283
|
sender: Address2.fromAddressOrString(coin.sender),
|
4078
4284
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4079
4285
|
nonce: coin.nonce
|
@@ -4081,12 +4287,11 @@ var _Provider = class {
|
|
4081
4287
|
case "Coin":
|
4082
4288
|
return {
|
4083
4289
|
id: coin.utxoId,
|
4084
|
-
amount:
|
4290
|
+
amount: bn16(coin.amount),
|
4085
4291
|
assetId: coin.assetId,
|
4086
4292
|
owner: Address2.fromAddressOrString(coin.owner),
|
4087
|
-
|
4088
|
-
|
4089
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4293
|
+
blockCreated: bn16(coin.blockCreated),
|
4294
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4090
4295
|
};
|
4091
4296
|
default:
|
4092
4297
|
return null;
|
@@ -4103,13 +4308,13 @@ var _Provider = class {
|
|
4103
4308
|
async getBlock(idOrHeight) {
|
4104
4309
|
let variables;
|
4105
4310
|
if (typeof idOrHeight === "number") {
|
4106
|
-
variables = { height:
|
4311
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4107
4312
|
} else if (idOrHeight === "latest") {
|
4108
4313
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4109
4314
|
} else if (idOrHeight.length === 66) {
|
4110
4315
|
variables = { blockId: idOrHeight };
|
4111
4316
|
} else {
|
4112
|
-
variables = { blockId:
|
4317
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4113
4318
|
}
|
4114
4319
|
const { block } = await this.operations.getBlock(variables);
|
4115
4320
|
if (!block) {
|
@@ -4117,7 +4322,7 @@ var _Provider = class {
|
|
4117
4322
|
}
|
4118
4323
|
return {
|
4119
4324
|
id: block.id,
|
4120
|
-
height:
|
4325
|
+
height: bn16(block.height),
|
4121
4326
|
time: block.header.time,
|
4122
4327
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4123
4328
|
};
|
@@ -4132,7 +4337,7 @@ var _Provider = class {
|
|
4132
4337
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4133
4338
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4134
4339
|
id: block.id,
|
4135
|
-
height:
|
4340
|
+
height: bn16(block.height),
|
4136
4341
|
time: block.header.time,
|
4137
4342
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4138
4343
|
}));
|
@@ -4147,7 +4352,7 @@ var _Provider = class {
|
|
4147
4352
|
async getBlockWithTransactions(idOrHeight) {
|
4148
4353
|
let variables;
|
4149
4354
|
if (typeof idOrHeight === "number") {
|
4150
|
-
variables = { blockHeight:
|
4355
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4151
4356
|
} else if (idOrHeight === "latest") {
|
4152
4357
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4153
4358
|
} else {
|
@@ -4159,7 +4364,7 @@ var _Provider = class {
|
|
4159
4364
|
}
|
4160
4365
|
return {
|
4161
4366
|
id: block.id,
|
4162
|
-
height:
|
4367
|
+
height: bn16(block.height, 10),
|
4163
4368
|
time: block.header.time,
|
4164
4369
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4165
4370
|
transactions: block.transactions.map(
|
@@ -4208,7 +4413,7 @@ var _Provider = class {
|
|
4208
4413
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4209
4414
|
asset: hexlify12(assetId)
|
4210
4415
|
});
|
4211
|
-
return
|
4416
|
+
return bn16(contractBalance.amount, 10);
|
4212
4417
|
}
|
4213
4418
|
/**
|
4214
4419
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4222,7 +4427,7 @@ var _Provider = class {
|
|
4222
4427
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4223
4428
|
assetId: hexlify12(assetId)
|
4224
4429
|
});
|
4225
|
-
return
|
4430
|
+
return bn16(balance.amount, 10);
|
4226
4431
|
}
|
4227
4432
|
/**
|
4228
4433
|
* Returns balances for the given owner.
|
@@ -4240,7 +4445,7 @@ var _Provider = class {
|
|
4240
4445
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4241
4446
|
return balances.map((balance) => ({
|
4242
4447
|
assetId: balance.assetId,
|
4243
|
-
amount:
|
4448
|
+
amount: bn16(balance.amount)
|
4244
4449
|
}));
|
4245
4450
|
}
|
4246
4451
|
/**
|
@@ -4262,15 +4467,15 @@ var _Provider = class {
|
|
4262
4467
|
sender: message.sender,
|
4263
4468
|
recipient: message.recipient,
|
4264
4469
|
nonce: message.nonce,
|
4265
|
-
amount:
|
4470
|
+
amount: bn16(message.amount),
|
4266
4471
|
data: message.data
|
4267
4472
|
}),
|
4268
4473
|
sender: Address2.fromAddressOrString(message.sender),
|
4269
4474
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4270
4475
|
nonce: message.nonce,
|
4271
|
-
amount:
|
4476
|
+
amount: bn16(message.amount),
|
4272
4477
|
data: InputMessageCoder.decodeData(message.data),
|
4273
|
-
daHeight:
|
4478
|
+
daHeight: bn16(message.daHeight)
|
4274
4479
|
}));
|
4275
4480
|
}
|
4276
4481
|
/**
|
@@ -4323,44 +4528,52 @@ var _Provider = class {
|
|
4323
4528
|
} = result.messageProof;
|
4324
4529
|
return {
|
4325
4530
|
messageProof: {
|
4326
|
-
proofIndex:
|
4531
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4327
4532
|
proofSet: messageProof.proofSet
|
4328
4533
|
},
|
4329
4534
|
blockProof: {
|
4330
|
-
proofIndex:
|
4535
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4331
4536
|
proofSet: blockProof.proofSet
|
4332
4537
|
},
|
4333
4538
|
messageBlockHeader: {
|
4334
4539
|
id: messageBlockHeader.id,
|
4335
|
-
daHeight:
|
4336
|
-
transactionsCount:
|
4540
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4541
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4337
4542
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4338
|
-
height:
|
4543
|
+
height: bn16(messageBlockHeader.height),
|
4339
4544
|
prevRoot: messageBlockHeader.prevRoot,
|
4340
4545
|
time: messageBlockHeader.time,
|
4341
4546
|
applicationHash: messageBlockHeader.applicationHash,
|
4342
|
-
|
4343
|
-
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4547
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount)
|
4344
4548
|
},
|
4345
4549
|
commitBlockHeader: {
|
4346
4550
|
id: commitBlockHeader.id,
|
4347
|
-
daHeight:
|
4348
|
-
transactionsCount:
|
4551
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4552
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4349
4553
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4350
|
-
height:
|
4554
|
+
height: bn16(commitBlockHeader.height),
|
4351
4555
|
prevRoot: commitBlockHeader.prevRoot,
|
4352
4556
|
time: commitBlockHeader.time,
|
4353
4557
|
applicationHash: commitBlockHeader.applicationHash,
|
4354
|
-
|
4355
|
-
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4558
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount)
|
4356
4559
|
},
|
4357
4560
|
sender: Address2.fromAddressOrString(sender),
|
4358
4561
|
recipient: Address2.fromAddressOrString(recipient),
|
4359
4562
|
nonce,
|
4360
|
-
amount:
|
4563
|
+
amount: bn16(amount),
|
4361
4564
|
data
|
4362
4565
|
};
|
4363
4566
|
}
|
4567
|
+
async getLatestGasPrice() {
|
4568
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4569
|
+
return bn16(latestGasPrice.gasPrice);
|
4570
|
+
}
|
4571
|
+
async estimateGasPrice(blockHorizon) {
|
4572
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4573
|
+
blockHorizon: String(blockHorizon)
|
4574
|
+
});
|
4575
|
+
return bn16(estimateGasPrice.gasPrice);
|
4576
|
+
}
|
4364
4577
|
/**
|
4365
4578
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4366
4579
|
*
|
@@ -4380,10 +4593,10 @@ var _Provider = class {
|
|
4380
4593
|
*/
|
4381
4594
|
async produceBlocks(amount, startTime) {
|
4382
4595
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4383
|
-
blocksToProduce:
|
4596
|
+
blocksToProduce: bn16(amount).toString(10),
|
4384
4597
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4385
4598
|
});
|
4386
|
-
return
|
4599
|
+
return bn16(latestBlockHeight);
|
4387
4600
|
}
|
4388
4601
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4389
4602
|
async getTransactionResponse(transactionId) {
|
@@ -4397,7 +4610,7 @@ cacheInputs_fn = function(inputs) {
|
|
4397
4610
|
return;
|
4398
4611
|
}
|
4399
4612
|
inputs.forEach((input) => {
|
4400
|
-
if (input.type ===
|
4613
|
+
if (input.type === InputType7.Coin) {
|
4401
4614
|
this.cache?.set(input.id);
|
4402
4615
|
}
|
4403
4616
|
});
|
@@ -4407,7 +4620,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4407
4620
|
|
4408
4621
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4409
4622
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4410
|
-
import { bn as
|
4623
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4411
4624
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4412
4625
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4413
4626
|
|
@@ -4615,9 +4828,8 @@ var Account = class extends AbstractAccount {
|
|
4615
4828
|
* @param assetId - The asset ID to check the balance for.
|
4616
4829
|
* @returns A promise that resolves to the balance amount.
|
4617
4830
|
*/
|
4618
|
-
async getBalance(assetId) {
|
4619
|
-
const
|
4620
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4831
|
+
async getBalance(assetId = BaseAssetId3) {
|
4832
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4621
4833
|
return amount;
|
4622
4834
|
}
|
4623
4835
|
/**
|
@@ -4654,37 +4866,33 @@ var Account = class extends AbstractAccount {
|
|
4654
4866
|
* @param fee - The estimated transaction fee.
|
4655
4867
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4656
4868
|
*/
|
4657
|
-
async fund(request,
|
4658
|
-
const
|
4659
|
-
const
|
4660
|
-
|
4661
|
-
|
4662
|
-
|
4869
|
+
async fund(request, params) {
|
4870
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4871
|
+
const txRequest = request;
|
4872
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4873
|
+
amount: bn18(fee),
|
4874
|
+
assetId: BaseAssetId3,
|
4875
|
+
coinQuantities: requiredQuantities
|
4663
4876
|
});
|
4664
4877
|
const quantitiesDict = {};
|
4665
|
-
|
4878
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4666
4879
|
quantitiesDict[assetId] = {
|
4667
4880
|
required: amount,
|
4668
|
-
owned:
|
4881
|
+
owned: bn18(0)
|
4669
4882
|
};
|
4670
4883
|
});
|
4671
|
-
|
4672
|
-
const cachedMessages = [];
|
4673
|
-
const owner = this.address.toB256();
|
4674
|
-
request.inputs.forEach((input) => {
|
4884
|
+
txRequest.inputs.forEach((input) => {
|
4675
4885
|
const isResource = "amount" in input;
|
4676
4886
|
if (isResource) {
|
4677
4887
|
const isCoin2 = "owner" in input;
|
4678
4888
|
if (isCoin2) {
|
4679
4889
|
const assetId = String(input.assetId);
|
4680
|
-
if (
|
4681
|
-
const amount =
|
4890
|
+
if (quantitiesDict[assetId]) {
|
4891
|
+
const amount = bn18(input.amount);
|
4682
4892
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4683
|
-
cachedUtxos.push(input.id);
|
4684
4893
|
}
|
4685
|
-
} else if (input.
|
4686
|
-
quantitiesDict[
|
4687
|
-
cachedMessages.push(input.nonce);
|
4894
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4895
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4688
4896
|
}
|
4689
4897
|
}
|
4690
4898
|
});
|
@@ -4699,12 +4907,23 @@ var Account = class extends AbstractAccount {
|
|
4699
4907
|
});
|
4700
4908
|
const needsToBeFunded = missingQuantities.length;
|
4701
4909
|
if (needsToBeFunded) {
|
4702
|
-
const
|
4703
|
-
|
4704
|
-
|
4705
|
-
|
4706
|
-
|
4910
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4911
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4912
|
+
txRequest.addResources(resources);
|
4913
|
+
}
|
4914
|
+
txRequest.shiftPredicateData();
|
4915
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4916
|
+
const requestToBeReEstimate = clone4(txRequest);
|
4917
|
+
if (addedSignatures) {
|
4918
|
+
Array.from({ length: addedSignatures }).forEach(
|
4919
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4920
|
+
);
|
4707
4921
|
}
|
4922
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4923
|
+
transactionRequest: requestToBeReEstimate
|
4924
|
+
});
|
4925
|
+
txRequest.maxFee = maxFee;
|
4926
|
+
return txRequest;
|
4708
4927
|
}
|
4709
4928
|
/**
|
4710
4929
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4712,29 +4931,25 @@ var Account = class extends AbstractAccount {
|
|
4712
4931
|
* @param destination - The address of the destination.
|
4713
4932
|
* @param amount - The amount of coins to transfer.
|
4714
4933
|
* @param assetId - The asset ID of the coins to transfer.
|
4715
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4934
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4716
4935
|
* @returns A promise that resolves to the prepared transaction request.
|
4717
4936
|
*/
|
4718
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4719
|
-
const
|
4720
|
-
|
4721
|
-
const
|
4722
|
-
const request = new ScriptTransactionRequest(params);
|
4723
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4724
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4937
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4938
|
+
const request = new ScriptTransactionRequest(txParams);
|
4939
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4940
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4725
4941
|
estimateTxDependencies: true,
|
4726
4942
|
resourcesOwner: this
|
4727
4943
|
});
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
4736
|
-
await this.fund(request,
|
4737
|
-
request.updatePredicateInputs(estimatedInputs);
|
4944
|
+
if ("gasLimit" in txParams) {
|
4945
|
+
this.validateGas({
|
4946
|
+
gasUsed: txCost.gasUsed,
|
4947
|
+
gasLimit: request.gasLimit
|
4948
|
+
});
|
4949
|
+
}
|
4950
|
+
request.gasLimit = txCost.gasUsed;
|
4951
|
+
request.maxFee = txCost.maxFee;
|
4952
|
+
await this.fund(request, txCost);
|
4738
4953
|
return request;
|
4739
4954
|
}
|
4740
4955
|
/**
|
@@ -4746,15 +4961,14 @@ var Account = class extends AbstractAccount {
|
|
4746
4961
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4747
4962
|
* @returns A promise that resolves to the transaction response.
|
4748
4963
|
*/
|
4749
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4750
|
-
if (
|
4964
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4965
|
+
if (bn18(amount).lte(0)) {
|
4751
4966
|
throw new FuelError15(
|
4752
4967
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4753
4968
|
"Transfer amount must be a positive number."
|
4754
4969
|
);
|
4755
4970
|
}
|
4756
|
-
const
|
4757
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4971
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4758
4972
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4759
4973
|
}
|
4760
4974
|
/**
|
@@ -4766,40 +4980,38 @@ var Account = class extends AbstractAccount {
|
|
4766
4980
|
* @param txParams - The optional transaction parameters.
|
4767
4981
|
* @returns A promise that resolves to the transaction response.
|
4768
4982
|
*/
|
4769
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4770
|
-
if (
|
4983
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4984
|
+
if (bn18(amount).lte(0)) {
|
4771
4985
|
throw new FuelError15(
|
4772
4986
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4773
4987
|
"Transfer amount must be a positive number."
|
4774
4988
|
);
|
4775
4989
|
}
|
4776
4990
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4777
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4778
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4779
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4780
4991
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4781
4992
|
hexlifiedContractId: contractAddress.toB256(),
|
4782
|
-
amountToTransfer:
|
4783
|
-
assetId
|
4993
|
+
amountToTransfer: bn18(amount),
|
4994
|
+
assetId
|
4784
4995
|
});
|
4785
4996
|
const request = new ScriptTransactionRequest({
|
4786
|
-
...
|
4997
|
+
...txParams,
|
4787
4998
|
script,
|
4788
4999
|
scriptData
|
4789
5000
|
});
|
4790
5001
|
request.addContractInputAndOutput(contractAddress);
|
4791
|
-
const
|
4792
|
-
|
4793
|
-
[{ amount:
|
4794
|
-
);
|
4795
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4796
|
-
this.validateGas({
|
4797
|
-
gasUsed,
|
4798
|
-
gasPrice: request.gasPrice,
|
4799
|
-
gasLimit: request.gasLimit,
|
4800
|
-
minGasPrice
|
5002
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5003
|
+
resourcesOwner: this,
|
5004
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
4801
5005
|
});
|
4802
|
-
|
5006
|
+
if (txParams.gasLimit) {
|
5007
|
+
this.validateGas({
|
5008
|
+
gasUsed: txCost.gasUsed,
|
5009
|
+
gasLimit: request.gasLimit
|
5010
|
+
});
|
5011
|
+
}
|
5012
|
+
request.gasLimit = txCost.gasUsed;
|
5013
|
+
request.maxFee = txCost.maxFee;
|
5014
|
+
await this.fund(request, txCost);
|
4803
5015
|
return this.sendTransaction(request);
|
4804
5016
|
}
|
4805
5017
|
/**
|
@@ -4811,35 +5023,31 @@ var Account = class extends AbstractAccount {
|
|
4811
5023
|
* @returns A promise that resolves to the transaction response.
|
4812
5024
|
*/
|
4813
5025
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4814
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4815
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4816
5026
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4817
5027
|
const recipientDataArray = arrayify14(
|
4818
5028
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4819
5029
|
);
|
4820
5030
|
const amountDataArray = arrayify14(
|
4821
|
-
"0x".concat(
|
5031
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4822
5032
|
);
|
4823
5033
|
const script = new Uint8Array([
|
4824
5034
|
...arrayify14(withdrawScript.bytes),
|
4825
5035
|
...recipientDataArray,
|
4826
5036
|
...amountDataArray
|
4827
5037
|
]);
|
4828
|
-
const params = { script,
|
5038
|
+
const params = { script, ...txParams };
|
4829
5039
|
const request = new ScriptTransactionRequest(params);
|
4830
|
-
const
|
4831
|
-
const
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
});
|
4842
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5040
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5041
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5042
|
+
if (txParams.gasLimit) {
|
5043
|
+
this.validateGas({
|
5044
|
+
gasUsed: txCost.gasUsed,
|
5045
|
+
gasLimit: request.gasLimit
|
5046
|
+
});
|
5047
|
+
}
|
5048
|
+
request.maxFee = txCost.maxFee;
|
5049
|
+
request.gasLimit = txCost.gasUsed;
|
5050
|
+
await this.fund(request, txCost);
|
4843
5051
|
return this.sendTransaction(request);
|
4844
5052
|
}
|
4845
5053
|
async signMessage(message) {
|
@@ -4897,18 +5105,7 @@ var Account = class extends AbstractAccount {
|
|
4897
5105
|
}
|
4898
5106
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4899
5107
|
}
|
4900
|
-
validateGas({
|
4901
|
-
gasUsed,
|
4902
|
-
gasPrice,
|
4903
|
-
gasLimit,
|
4904
|
-
minGasPrice
|
4905
|
-
}) {
|
4906
|
-
if (minGasPrice.gt(gasPrice)) {
|
4907
|
-
throw new FuelError15(
|
4908
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4909
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4910
|
-
);
|
4911
|
-
}
|
5108
|
+
validateGas({ gasUsed, gasLimit }) {
|
4912
5109
|
if (gasUsed.gt(gasLimit)) {
|
4913
5110
|
throw new FuelError15(
|
4914
5111
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -4920,7 +5117,7 @@ var Account = class extends AbstractAccount {
|
|
4920
5117
|
|
4921
5118
|
// src/signer/signer.ts
|
4922
5119
|
import { Address as Address4 } from "@fuel-ts/address";
|
4923
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5120
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
4924
5121
|
import { hash } from "@fuel-ts/hasher";
|
4925
5122
|
import { toBytes } from "@fuel-ts/math";
|
4926
5123
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5013,7 +5210,7 @@ var Signer = class {
|
|
5013
5210
|
* @returns random 32-byte hashed
|
5014
5211
|
*/
|
5015
5212
|
static generatePrivateKey(entropy) {
|
5016
|
-
return entropy ? hash(concat3([
|
5213
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5017
5214
|
}
|
5018
5215
|
/**
|
5019
5216
|
* Extended publicKey from a compact publicKey
|
@@ -5032,7 +5229,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5032
5229
|
import {
|
5033
5230
|
bufferFromString,
|
5034
5231
|
keccak256,
|
5035
|
-
randomBytes as
|
5232
|
+
randomBytes as randomBytes3,
|
5036
5233
|
scrypt,
|
5037
5234
|
stringFromBuffer,
|
5038
5235
|
decryptJsonWalletData,
|
@@ -5055,7 +5252,7 @@ var removeHexPrefix = (hexString) => {
|
|
5055
5252
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5056
5253
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5057
5254
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5058
|
-
const salt =
|
5255
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5059
5256
|
const key = scrypt({
|
5060
5257
|
password: bufferFromString(password),
|
5061
5258
|
salt,
|
@@ -5064,7 +5261,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5064
5261
|
r: DEFAULT_KDF_PARAMS_R,
|
5065
5262
|
p: DEFAULT_KDF_PARAMS_P
|
5066
5263
|
});
|
5067
|
-
const iv =
|
5264
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5068
5265
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5069
5266
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5070
5267
|
const macHashUint8Array = keccak256(data);
|
@@ -5200,7 +5397,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5200
5397
|
* @param transactionRequestLike - The transaction request to send.
|
5201
5398
|
* @returns A promise that resolves to the TransactionResponse object.
|
5202
5399
|
*/
|
5203
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5400
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5204
5401
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5205
5402
|
if (estimateTxDependencies) {
|
5206
5403
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5241,12 +5438,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5241
5438
|
// src/hdwallet/hdwallet.ts
|
5242
5439
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5243
5440
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5244
|
-
import { bn as
|
5441
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5245
5442
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5246
5443
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5247
5444
|
|
5248
5445
|
// src/mnemonic/mnemonic.ts
|
5249
|
-
import { randomBytes as
|
5446
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5250
5447
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5251
5448
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5252
5449
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7601,7 +7798,7 @@ var Mnemonic = class {
|
|
7601
7798
|
* @returns A randomly generated mnemonic
|
7602
7799
|
*/
|
7603
7800
|
static generate(size = 32, extraEntropy = "") {
|
7604
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7801
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7605
7802
|
return Mnemonic.entropyToMnemonic(entropy);
|
7606
7803
|
}
|
7607
7804
|
};
|
@@ -7707,7 +7904,7 @@ var HDWallet = class {
|
|
7707
7904
|
const IR = bytes.slice(32);
|
7708
7905
|
if (privateKey) {
|
7709
7906
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7710
|
-
const ki =
|
7907
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7711
7908
|
return new HDWallet({
|
7712
7909
|
privateKey: ki,
|
7713
7910
|
chainCode: IR,
|
@@ -7972,20 +8169,21 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7972
8169
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7973
8170
|
|
7974
8171
|
// src/test-utils/seedTestWallet.ts
|
7975
|
-
import { randomBytes as
|
8172
|
+
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7976
8173
|
var seedTestWallet = async (wallet, quantities) => {
|
7977
8174
|
const genesisWallet = new WalletUnlocked(
|
7978
|
-
process.env.GENESIS_SECRET ||
|
8175
|
+
process.env.GENESIS_SECRET || randomBytes5(32),
|
7979
8176
|
wallet.provider
|
7980
8177
|
);
|
7981
|
-
const
|
7982
|
-
|
7983
|
-
|
7984
|
-
|
7985
|
-
gasPrice: minGasPrice
|
8178
|
+
const request = new ScriptTransactionRequest();
|
8179
|
+
quantities.forEach((quantity) => {
|
8180
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8181
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7986
8182
|
});
|
7987
|
-
|
7988
|
-
|
8183
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8184
|
+
request.gasLimit = txCost.gasUsed;
|
8185
|
+
request.maxFee = txCost.maxFee;
|
8186
|
+
await genesisWallet.fund(request, txCost);
|
7989
8187
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
7990
8188
|
};
|
7991
8189
|
|
@@ -7999,12 +8197,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7999
8197
|
};
|
8000
8198
|
|
8001
8199
|
// src/test-utils/launchNode.ts
|
8002
|
-
import {
|
8003
|
-
import {
|
8004
|
-
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8200
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8201
|
+
import { defaultChainConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8005
8202
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8006
8203
|
import { spawn } from "child_process";
|
8007
8204
|
import { randomUUID } from "crypto";
|
8205
|
+
import { randomBytes as randomBytes6 } from "ethers";
|
8008
8206
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8009
8207
|
import os from "os";
|
8010
8208
|
import path from "path";
|
@@ -8053,12 +8251,12 @@ var launchNode = async ({
|
|
8053
8251
|
// eslint-disable-next-line no-async-promise-executor
|
8054
8252
|
new Promise(async (resolve, reject) => {
|
8055
8253
|
const remainingArgs = extractRemainingArgs(args, [
|
8056
|
-
"--
|
8254
|
+
"--snapshot",
|
8057
8255
|
"--consensus-key",
|
8058
8256
|
"--db-type",
|
8059
8257
|
"--poa-instant"
|
8060
8258
|
]);
|
8061
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8259
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8062
8260
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8063
8261
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8064
8262
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8077,36 +8275,54 @@ var launchNode = async ({
|
|
8077
8275
|
let chainConfigPathToUse;
|
8078
8276
|
const prefix = basePath || os.tmpdir();
|
8079
8277
|
const suffix = basePath ? "" : randomUUID();
|
8080
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8278
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "chainConfigs");
|
8081
8279
|
if (chainConfigPath) {
|
8082
8280
|
chainConfigPathToUse = chainConfigPath;
|
8083
8281
|
} else {
|
8084
8282
|
if (!existsSync(tempDirPath)) {
|
8085
8283
|
mkdirSync(tempDirPath, { recursive: true });
|
8086
8284
|
}
|
8087
|
-
|
8088
|
-
|
8285
|
+
let { stateConfigJson } = defaultChainConfigs;
|
8286
|
+
const { chainConfigJson, metadataJson } = defaultChainConfigs;
|
8287
|
+
stateConfigJson = {
|
8288
|
+
...stateConfigJson,
|
8289
|
+
coins: [
|
8290
|
+
...stateConfigJson.coins.map((coin) => ({
|
8291
|
+
...coin,
|
8292
|
+
amount: "18446744073709551615"
|
8293
|
+
}))
|
8294
|
+
],
|
8295
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8296
|
+
...message,
|
8297
|
+
amount: "18446744073709551615"
|
8298
|
+
}))
|
8299
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8300
|
+
};
|
8089
8301
|
if (!process.env.GENESIS_SECRET) {
|
8090
8302
|
const pk = Signer.generatePrivateKey();
|
8091
8303
|
const signer = new Signer(pk);
|
8092
8304
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8093
|
-
|
8094
|
-
|
8095
|
-
|
8096
|
-
|
8097
|
-
|
8098
|
-
|
8099
|
-
|
8100
|
-
|
8101
|
-
|
8102
|
-
|
8103
|
-
}
|
8104
|
-
]
|
8105
|
-
}
|
8106
|
-
};
|
8305
|
+
stateConfigJson.coins.push({
|
8306
|
+
tx_id: hexlify18(randomBytes6(34)),
|
8307
|
+
owner: signer.address.toHexString(),
|
8308
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8309
|
+
amount: "18446744073709551615",
|
8310
|
+
asset_id: BaseAssetId4,
|
8311
|
+
output_index: 0,
|
8312
|
+
tx_pointer_block_height: 0,
|
8313
|
+
tx_pointer_tx_idx: 0
|
8314
|
+
});
|
8107
8315
|
}
|
8108
|
-
|
8109
|
-
|
8316
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8317
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8318
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8319
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8320
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8321
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8322
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8323
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8324
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8325
|
+
chainConfigPathToUse = tempDirPath;
|
8110
8326
|
}
|
8111
8327
|
const child = spawn(
|
8112
8328
|
command,
|
@@ -8115,10 +8331,10 @@ var launchNode = async ({
|
|
8115
8331
|
["--ip", ipToUse],
|
8116
8332
|
["--port", portToUse],
|
8117
8333
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8118
|
-
["--min-gas-price", "
|
8334
|
+
["--min-gas-price", "1"],
|
8119
8335
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8120
8336
|
["--consensus-key", consensusKey],
|
8121
|
-
["--
|
8337
|
+
["--snapshot", chainConfigPathToUse],
|
8122
8338
|
"--vm-backtrace",
|
8123
8339
|
"--utxo-validation",
|
8124
8340
|
"--debug",
|
@@ -8165,10 +8381,9 @@ var launchNode = async ({
|
|
8165
8381
|
})
|
8166
8382
|
);
|
8167
8383
|
var generateWallets = async (count, provider) => {
|
8168
|
-
const baseAssetId = provider.getBaseAssetId();
|
8169
8384
|
const wallets = [];
|
8170
8385
|
for (let i = 0; i < count; i += 1) {
|
8171
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8386
|
+
const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
|
8172
8387
|
wallets.push(wallet);
|
8173
8388
|
}
|
8174
8389
|
return wallets;
|
@@ -8178,7 +8393,7 @@ var launchNodeAndGetWallets = async ({
|
|
8178
8393
|
walletCount = 10
|
8179
8394
|
} = {}) => {
|
8180
8395
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8181
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8396
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8182
8397
|
const wallets = await generateWallets(walletCount, provider);
|
8183
8398
|
const cleanup = () => {
|
8184
8399
|
closeNode();
|