@fuel-ts/account 0.0.0-rc-2040-20240415161844 → 0.0.0-rc-2021-20240415193305
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 +833 -560
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +834 -555
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +684 -406
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +906 -324
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +48 -27
- 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 +8 -25
- 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 +1579 -1068
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +809 -548
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +678 -417
- 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/index.mjs
CHANGED
@@ -32,8 +32,9 @@ import { Address as Address3 } from "@fuel-ts/address";
|
|
32
32
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
33
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
34
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
|
-
import { bn as
|
35
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
36
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
|
+
import { clone as clone4 } from "ramda";
|
37
38
|
|
38
39
|
// src/providers/coin-quantity.ts
|
39
40
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
@@ -59,7 +60,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
59
60
|
max: max2 ? bn(max2) : void 0
|
60
61
|
};
|
61
62
|
};
|
62
|
-
var
|
63
|
+
var addAmountToCoinQuantities = (params) => {
|
63
64
|
const { amount, assetId } = params;
|
64
65
|
const coinQuantities = [...params.coinQuantities];
|
65
66
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -74,9 +75,9 @@ var addAmountToAsset = (params) => {
|
|
74
75
|
// src/providers/provider.ts
|
75
76
|
import { Address as Address2 } from "@fuel-ts/address";
|
76
77
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
77
|
-
import { BN, bn as
|
78
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
78
79
|
import {
|
79
|
-
InputType as
|
80
|
+
InputType as InputType7,
|
80
81
|
TransactionType as TransactionType8,
|
81
82
|
InputMessageCoder,
|
82
83
|
TransactionCoder as TransactionCoder5
|
@@ -92,14 +93,10 @@ import { clone as clone3 } from "ramda";
|
|
92
93
|
import gql from "graphql-tag";
|
93
94
|
var ReceiptFragmentFragmentDoc = gql`
|
94
95
|
fragment receiptFragment on Receipt {
|
95
|
-
|
96
|
-
id
|
97
|
-
}
|
96
|
+
id
|
98
97
|
pc
|
99
98
|
is
|
100
|
-
to
|
101
|
-
id
|
102
|
-
}
|
99
|
+
to
|
103
100
|
toAddress
|
104
101
|
amount
|
105
102
|
assetId
|
@@ -137,10 +134,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
137
134
|
id
|
138
135
|
}
|
139
136
|
time
|
137
|
+
receipts {
|
138
|
+
...receiptFragment
|
139
|
+
}
|
140
140
|
programState {
|
141
141
|
returnType
|
142
142
|
data
|
143
143
|
}
|
144
|
+
receipts {
|
145
|
+
...receiptFragment
|
146
|
+
}
|
144
147
|
}
|
145
148
|
... on FailureStatus {
|
146
149
|
block {
|
@@ -148,26 +151,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
148
151
|
}
|
149
152
|
time
|
150
153
|
reason
|
154
|
+
receipts {
|
155
|
+
...receiptFragment
|
156
|
+
}
|
151
157
|
}
|
152
158
|
... on SqueezedOutStatus {
|
153
159
|
reason
|
154
160
|
}
|
155
161
|
}
|
156
|
-
`;
|
162
|
+
${ReceiptFragmentFragmentDoc}`;
|
157
163
|
var TransactionFragmentFragmentDoc = gql`
|
158
164
|
fragment transactionFragment on Transaction {
|
159
165
|
id
|
160
166
|
rawPayload
|
161
|
-
gasPrice
|
162
|
-
receipts {
|
163
|
-
...receiptFragment
|
164
|
-
}
|
165
167
|
status {
|
166
168
|
...transactionStatusFragment
|
167
169
|
}
|
168
170
|
}
|
169
|
-
${
|
170
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
171
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
171
172
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
172
173
|
fragment inputEstimatePredicatesFragment on Input {
|
173
174
|
... on InputCoin {
|
@@ -185,6 +186,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
185
186
|
}
|
186
187
|
}
|
187
188
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
189
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
190
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
191
|
+
reason
|
192
|
+
programState {
|
193
|
+
returnType
|
194
|
+
data
|
195
|
+
}
|
196
|
+
}
|
197
|
+
`;
|
198
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
199
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
200
|
+
programState {
|
201
|
+
returnType
|
202
|
+
data
|
203
|
+
}
|
204
|
+
}
|
205
|
+
`;
|
206
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
207
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
208
|
+
... on DryRunFailureStatus {
|
209
|
+
...dryRunFailureStatusFragment
|
210
|
+
}
|
211
|
+
... on DryRunSuccessStatus {
|
212
|
+
...dryRunSuccessStatusFragment
|
213
|
+
}
|
214
|
+
}
|
215
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
216
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
217
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
218
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
219
|
+
id
|
220
|
+
status {
|
221
|
+
...dryRunTransactionStatusFragment
|
222
|
+
}
|
223
|
+
receipts {
|
224
|
+
...receiptFragment
|
225
|
+
}
|
226
|
+
}
|
227
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
228
|
+
${ReceiptFragmentFragmentDoc}`;
|
188
229
|
var CoinFragmentFragmentDoc = gql`
|
189
230
|
fragment coinFragment on Coin {
|
190
231
|
__typename
|
@@ -192,7 +233,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
192
233
|
owner
|
193
234
|
amount
|
194
235
|
assetId
|
195
|
-
maturity
|
196
236
|
blockCreated
|
197
237
|
txCreatedIdx
|
198
238
|
}
|
@@ -231,26 +271,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
231
271
|
messageBlockHeader {
|
232
272
|
id
|
233
273
|
daHeight
|
274
|
+
consensusParametersVersion
|
275
|
+
stateTransitionBytecodeVersion
|
234
276
|
transactionsCount
|
277
|
+
messageReceiptCount
|
235
278
|
transactionsRoot
|
279
|
+
messageOutboxRoot
|
280
|
+
eventInboxRoot
|
236
281
|
height
|
237
282
|
prevRoot
|
238
283
|
time
|
239
284
|
applicationHash
|
240
|
-
messageReceiptRoot
|
241
|
-
messageReceiptCount
|
242
285
|
}
|
243
286
|
commitBlockHeader {
|
244
287
|
id
|
245
288
|
daHeight
|
289
|
+
consensusParametersVersion
|
290
|
+
stateTransitionBytecodeVersion
|
246
291
|
transactionsCount
|
292
|
+
messageReceiptCount
|
247
293
|
transactionsRoot
|
294
|
+
messageOutboxRoot
|
295
|
+
eventInboxRoot
|
248
296
|
height
|
249
297
|
prevRoot
|
250
298
|
time
|
251
299
|
applicationHash
|
252
|
-
messageReceiptRoot
|
253
|
-
messageReceiptCount
|
254
300
|
}
|
255
301
|
sender
|
256
302
|
recipient
|
@@ -269,8 +315,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
269
315
|
var BlockFragmentFragmentDoc = gql`
|
270
316
|
fragment blockFragment on Block {
|
271
317
|
id
|
318
|
+
height
|
272
319
|
header {
|
273
|
-
height
|
274
320
|
time
|
275
321
|
}
|
276
322
|
transactions {
|
@@ -328,6 +374,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
328
374
|
`;
|
329
375
|
var GasCostsFragmentFragmentDoc = gql`
|
330
376
|
fragment GasCostsFragment on GasCosts {
|
377
|
+
version {
|
378
|
+
... on Version {
|
379
|
+
value
|
380
|
+
}
|
381
|
+
}
|
331
382
|
add
|
332
383
|
addi
|
333
384
|
aloc
|
@@ -340,7 +391,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
340
391
|
cb
|
341
392
|
cfei
|
342
393
|
cfsi
|
343
|
-
croo
|
344
394
|
div
|
345
395
|
divi
|
346
396
|
ecr1
|
@@ -423,6 +473,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
423
473
|
ccp {
|
424
474
|
...DependentCostFragment
|
425
475
|
}
|
476
|
+
croo {
|
477
|
+
...DependentCostFragment
|
478
|
+
}
|
426
479
|
csiz {
|
427
480
|
...DependentCostFragment
|
428
481
|
}
|
@@ -482,6 +535,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
482
535
|
${DependentCostFragmentFragmentDoc}`;
|
483
536
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
484
537
|
fragment consensusParametersFragment on ConsensusParameters {
|
538
|
+
version {
|
539
|
+
... on Version {
|
540
|
+
value
|
541
|
+
}
|
542
|
+
}
|
485
543
|
txParams {
|
486
544
|
...TxParametersFragment
|
487
545
|
}
|
@@ -541,18 +599,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
541
599
|
fragment nodeInfoFragment on NodeInfo {
|
542
600
|
utxoValidation
|
543
601
|
vmBacktrace
|
544
|
-
minGasPrice
|
545
602
|
maxTx
|
546
603
|
maxDepth
|
547
604
|
nodeVersion
|
548
|
-
peers {
|
549
|
-
id
|
550
|
-
addresses
|
551
|
-
clientVersion
|
552
|
-
blockHeight
|
553
|
-
lastHeartbeatMs
|
554
|
-
appScore
|
555
|
-
}
|
556
605
|
}
|
557
606
|
`;
|
558
607
|
var GetVersionDocument = gql`
|
@@ -587,13 +636,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
587
636
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
588
637
|
transaction(id: $transactionId) {
|
589
638
|
...transactionFragment
|
590
|
-
receipts {
|
591
|
-
...receiptFragment
|
592
|
-
}
|
593
639
|
}
|
594
640
|
}
|
595
|
-
${TransactionFragmentFragmentDoc}
|
596
|
-
${ReceiptFragmentFragmentDoc}`;
|
641
|
+
${TransactionFragmentFragmentDoc}`;
|
597
642
|
var GetTransactionsDocument = gql`
|
598
643
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
599
644
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -721,6 +766,20 @@ var GetBalanceDocument = gql`
|
|
721
766
|
}
|
722
767
|
}
|
723
768
|
${BalanceFragmentFragmentDoc}`;
|
769
|
+
var GetLatestGasPriceDocument = gql`
|
770
|
+
query getLatestGasPrice {
|
771
|
+
latestGasPrice {
|
772
|
+
gasPrice
|
773
|
+
}
|
774
|
+
}
|
775
|
+
`;
|
776
|
+
var EstimateGasPriceDocument = gql`
|
777
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
778
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
779
|
+
gasPrice
|
780
|
+
}
|
781
|
+
}
|
782
|
+
`;
|
724
783
|
var GetBalancesDocument = gql`
|
725
784
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
726
785
|
balances(
|
@@ -775,12 +834,12 @@ var GetMessageStatusDocument = gql`
|
|
775
834
|
}
|
776
835
|
`;
|
777
836
|
var DryRunDocument = gql`
|
778
|
-
mutation dryRun($
|
779
|
-
dryRun(
|
780
|
-
...
|
837
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
838
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
839
|
+
...dryRunTransactionExecutionStatusFragment
|
781
840
|
}
|
782
841
|
}
|
783
|
-
${
|
842
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
784
843
|
var SubmitDocument = gql`
|
785
844
|
mutation submit($encodedTransaction: HexString!) {
|
786
845
|
submit(tx: $encodedTransaction) {
|
@@ -863,6 +922,12 @@ function getSdk(requester) {
|
|
863
922
|
getBalance(variables, options) {
|
864
923
|
return requester(GetBalanceDocument, variables, options);
|
865
924
|
},
|
925
|
+
getLatestGasPrice(variables, options) {
|
926
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
927
|
+
},
|
928
|
+
estimateGasPrice(variables, options) {
|
929
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
930
|
+
},
|
866
931
|
getBalances(variables, options) {
|
867
932
|
return requester(GetBalancesDocument, variables, options);
|
868
933
|
},
|
@@ -932,11 +997,14 @@ var _FuelGraphqlSubscriber = class {
|
|
932
997
|
let data;
|
933
998
|
let errors;
|
934
999
|
try {
|
935
|
-
|
1000
|
+
const sanitizedText = text.replace(/\s/g, "");
|
1001
|
+
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
936
1002
|
} catch (e) {
|
937
1003
|
throw new FuelError(
|
938
1004
|
ErrorCode.STREAM_PARSING_ERROR,
|
939
|
-
`Error while parsing stream data response: ${text}
|
1005
|
+
`Error while parsing stream data response: ${text}
|
1006
|
+
|
1007
|
+
Thrown error: ${e}`
|
940
1008
|
);
|
941
1009
|
}
|
942
1010
|
if (Array.isArray(errors)) {
|
@@ -1023,6 +1091,7 @@ var MemoryCache = class {
|
|
1023
1091
|
};
|
1024
1092
|
|
1025
1093
|
// src/providers/transaction-request/input.ts
|
1094
|
+
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1026
1095
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1027
1096
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1028
1097
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1036,8 +1105,8 @@ var inputify = (value) => {
|
|
1036
1105
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1037
1106
|
return {
|
1038
1107
|
type: InputType.Coin,
|
1039
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1040
|
-
outputIndex: arrayify(value.id)
|
1108
|
+
txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
|
1109
|
+
outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
1041
1110
|
owner: hexlify3(value.owner),
|
1042
1111
|
amount: bn2(value.amount),
|
1043
1112
|
assetId: hexlify3(value.assetId),
|
@@ -1046,10 +1115,9 @@ var inputify = (value) => {
|
|
1046
1115
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1047
1116
|
},
|
1048
1117
|
witnessIndex: value.witnessIndex,
|
1049
|
-
maturity: value.maturity ?? 0,
|
1050
1118
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1051
|
-
predicateLength: predicate.length,
|
1052
|
-
predicateDataLength: predicateData.length,
|
1119
|
+
predicateLength: bn2(predicate.length),
|
1120
|
+
predicateDataLength: bn2(predicateData.length),
|
1053
1121
|
predicate: hexlify3(predicate),
|
1054
1122
|
predicateData: hexlify3(predicateData)
|
1055
1123
|
};
|
@@ -1080,8 +1148,8 @@ var inputify = (value) => {
|
|
1080
1148
|
nonce: hexlify3(value.nonce),
|
1081
1149
|
witnessIndex: value.witnessIndex,
|
1082
1150
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1083
|
-
predicateLength: predicate.length,
|
1084
|
-
predicateDataLength: predicateData.length,
|
1151
|
+
predicateLength: bn2(predicate.length),
|
1152
|
+
predicateDataLength: bn2(predicateData.length),
|
1085
1153
|
predicate: hexlify3(predicate),
|
1086
1154
|
predicateData: hexlify3(predicateData),
|
1087
1155
|
data: hexlify3(data),
|
@@ -1155,8 +1223,10 @@ var outputify = (value) => {
|
|
1155
1223
|
};
|
1156
1224
|
|
1157
1225
|
// src/providers/transaction-request/transaction-request.ts
|
1226
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1158
1227
|
import { Address, addressify } from "@fuel-ts/address";
|
1159
1228
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1229
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
1160
1230
|
import { bn as bn7 } from "@fuel-ts/math";
|
1161
1231
|
import {
|
1162
1232
|
PolicyType,
|
@@ -1209,8 +1279,8 @@ function assembleReceiptByType(receipt) {
|
|
1209
1279
|
case "CALL" /* Call */: {
|
1210
1280
|
const callReceipt = {
|
1211
1281
|
type: ReceiptType.Call,
|
1212
|
-
from: hexOrZero(receipt.
|
1213
|
-
to: hexOrZero(receipt?.to
|
1282
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1283
|
+
to: hexOrZero(receipt?.to),
|
1214
1284
|
amount: bn4(receipt.amount),
|
1215
1285
|
assetId: hexOrZero(receipt.assetId),
|
1216
1286
|
gas: bn4(receipt.gas),
|
@@ -1224,7 +1294,7 @@ function assembleReceiptByType(receipt) {
|
|
1224
1294
|
case "RETURN" /* Return */: {
|
1225
1295
|
const returnReceipt = {
|
1226
1296
|
type: ReceiptType.Return,
|
1227
|
-
id: hexOrZero(receipt.
|
1297
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1228
1298
|
val: bn4(receipt.val),
|
1229
1299
|
pc: bn4(receipt.pc),
|
1230
1300
|
is: bn4(receipt.is)
|
@@ -1234,7 +1304,7 @@ function assembleReceiptByType(receipt) {
|
|
1234
1304
|
case "RETURN_DATA" /* ReturnData */: {
|
1235
1305
|
const returnDataReceipt = {
|
1236
1306
|
type: ReceiptType.ReturnData,
|
1237
|
-
id: hexOrZero(receipt.
|
1307
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1238
1308
|
ptr: bn4(receipt.ptr),
|
1239
1309
|
len: bn4(receipt.len),
|
1240
1310
|
digest: hexOrZero(receipt.digest),
|
@@ -1246,7 +1316,7 @@ function assembleReceiptByType(receipt) {
|
|
1246
1316
|
case "PANIC" /* Panic */: {
|
1247
1317
|
const panicReceipt = {
|
1248
1318
|
type: ReceiptType.Panic,
|
1249
|
-
id: hexOrZero(receipt.
|
1319
|
+
id: hexOrZero(receipt.id),
|
1250
1320
|
reason: bn4(receipt.reason),
|
1251
1321
|
pc: bn4(receipt.pc),
|
1252
1322
|
is: bn4(receipt.is),
|
@@ -1257,7 +1327,7 @@ function assembleReceiptByType(receipt) {
|
|
1257
1327
|
case "REVERT" /* Revert */: {
|
1258
1328
|
const revertReceipt = {
|
1259
1329
|
type: ReceiptType.Revert,
|
1260
|
-
id: hexOrZero(receipt.
|
1330
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1261
1331
|
val: bn4(receipt.ra),
|
1262
1332
|
pc: bn4(receipt.pc),
|
1263
1333
|
is: bn4(receipt.is)
|
@@ -1267,7 +1337,7 @@ function assembleReceiptByType(receipt) {
|
|
1267
1337
|
case "LOG" /* Log */: {
|
1268
1338
|
const logReceipt = {
|
1269
1339
|
type: ReceiptType.Log,
|
1270
|
-
id: hexOrZero(receipt.
|
1340
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1271
1341
|
val0: bn4(receipt.ra),
|
1272
1342
|
val1: bn4(receipt.rb),
|
1273
1343
|
val2: bn4(receipt.rc),
|
@@ -1280,7 +1350,7 @@ function assembleReceiptByType(receipt) {
|
|
1280
1350
|
case "LOG_DATA" /* LogData */: {
|
1281
1351
|
const logDataReceipt = {
|
1282
1352
|
type: ReceiptType.LogData,
|
1283
|
-
id: hexOrZero(receipt.
|
1353
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1284
1354
|
val0: bn4(receipt.ra),
|
1285
1355
|
val1: bn4(receipt.rb),
|
1286
1356
|
ptr: bn4(receipt.ptr),
|
@@ -1294,8 +1364,8 @@ function assembleReceiptByType(receipt) {
|
|
1294
1364
|
case "TRANSFER" /* Transfer */: {
|
1295
1365
|
const transferReceipt = {
|
1296
1366
|
type: ReceiptType.Transfer,
|
1297
|
-
from: hexOrZero(receipt.
|
1298
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1367
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1368
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1299
1369
|
amount: bn4(receipt.amount),
|
1300
1370
|
assetId: hexOrZero(receipt.assetId),
|
1301
1371
|
pc: bn4(receipt.pc),
|
@@ -1306,8 +1376,8 @@ function assembleReceiptByType(receipt) {
|
|
1306
1376
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1307
1377
|
const transferOutReceipt = {
|
1308
1378
|
type: ReceiptType.TransferOut,
|
1309
|
-
from: hexOrZero(receipt.
|
1310
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1379
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1380
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1311
1381
|
amount: bn4(receipt.amount),
|
1312
1382
|
assetId: hexOrZero(receipt.assetId),
|
1313
1383
|
pc: bn4(receipt.pc),
|
@@ -1350,7 +1420,7 @@ function assembleReceiptByType(receipt) {
|
|
1350
1420
|
return receiptMessageOut;
|
1351
1421
|
}
|
1352
1422
|
case "MINT" /* Mint */: {
|
1353
|
-
const contractId = hexOrZero(receipt.
|
1423
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1354
1424
|
const subId = hexOrZero(receipt.subId);
|
1355
1425
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1356
1426
|
const mintReceipt = {
|
@@ -1365,7 +1435,7 @@ function assembleReceiptByType(receipt) {
|
|
1365
1435
|
return mintReceipt;
|
1366
1436
|
}
|
1367
1437
|
case "BURN" /* Burn */: {
|
1368
|
-
const contractId = hexOrZero(receipt.
|
1438
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1369
1439
|
const subId = hexOrZero(receipt.subId);
|
1370
1440
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1371
1441
|
const burnReceipt = {
|
@@ -1450,7 +1520,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1450
1520
|
import { bn as bn5 } from "@fuel-ts/math";
|
1451
1521
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1452
1522
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1453
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1454
1523
|
var getGasUsedFromReceipts = (receipts) => {
|
1455
1524
|
const scriptResult = receipts.filter(
|
1456
1525
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1471,18 +1540,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1471
1540
|
}
|
1472
1541
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1473
1542
|
const witnessCache = [];
|
1474
|
-
const
|
1543
|
+
const chargeableInputs = inputs.filter((input) => {
|
1544
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1545
|
+
if (isCoinOrMessage) {
|
1546
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1547
|
+
return true;
|
1548
|
+
}
|
1549
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1550
|
+
witnessCache.push(input.witnessIndex);
|
1551
|
+
return true;
|
1552
|
+
}
|
1553
|
+
}
|
1554
|
+
return false;
|
1555
|
+
});
|
1556
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1557
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1475
1558
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1476
1559
|
return total.add(
|
1477
|
-
|
1560
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1478
1561
|
);
|
1479
1562
|
}
|
1480
|
-
|
1481
|
-
|
1482
|
-
return total.add(gasCosts.ecr1);
|
1483
|
-
}
|
1484
|
-
return total;
|
1485
|
-
}, bn5());
|
1563
|
+
return total.add(gasCosts.ecr1);
|
1564
|
+
}, bn5(0));
|
1486
1565
|
return totalGas;
|
1487
1566
|
}
|
1488
1567
|
function getMinGas(params) {
|
@@ -1494,12 +1573,20 @@ function getMinGas(params) {
|
|
1494
1573
|
return minGas;
|
1495
1574
|
}
|
1496
1575
|
function getMaxGas(params) {
|
1497
|
-
const {
|
1576
|
+
const {
|
1577
|
+
gasPerByte,
|
1578
|
+
witnessesLength,
|
1579
|
+
witnessLimit,
|
1580
|
+
minGas,
|
1581
|
+
gasLimit = bn5(0),
|
1582
|
+
maxGasPerTx
|
1583
|
+
} = params;
|
1498
1584
|
let remainingAllowedWitnessGas = bn5(0);
|
1499
1585
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1500
1586
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1501
1587
|
}
|
1502
|
-
|
1588
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1589
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1503
1590
|
}
|
1504
1591
|
function calculateMetadataGasForTxCreate({
|
1505
1592
|
gasCosts,
|
@@ -1521,6 +1608,10 @@ function calculateMetadataGasForTxScript({
|
|
1521
1608
|
}) {
|
1522
1609
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1523
1610
|
}
|
1611
|
+
var calculateGasFee = (params) => {
|
1612
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1613
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1614
|
+
};
|
1524
1615
|
|
1525
1616
|
// src/providers/utils/json.ts
|
1526
1617
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1677,7 +1768,7 @@ var witnessify = (value) => {
|
|
1677
1768
|
// src/providers/transaction-request/transaction-request.ts
|
1678
1769
|
var BaseTransactionRequest = class {
|
1679
1770
|
/** Gas price for transaction */
|
1680
|
-
|
1771
|
+
tip;
|
1681
1772
|
/** Block until which tx cannot be included */
|
1682
1773
|
maturity;
|
1683
1774
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1696,7 +1787,7 @@ var BaseTransactionRequest = class {
|
|
1696
1787
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1697
1788
|
*/
|
1698
1789
|
constructor({
|
1699
|
-
|
1790
|
+
tip,
|
1700
1791
|
maturity,
|
1701
1792
|
maxFee,
|
1702
1793
|
witnessLimit,
|
@@ -1704,7 +1795,7 @@ var BaseTransactionRequest = class {
|
|
1704
1795
|
outputs,
|
1705
1796
|
witnesses
|
1706
1797
|
} = {}) {
|
1707
|
-
this.
|
1798
|
+
this.tip = bn7(tip);
|
1708
1799
|
this.maturity = maturity ?? 0;
|
1709
1800
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1710
1801
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1715,9 +1806,9 @@ var BaseTransactionRequest = class {
|
|
1715
1806
|
static getPolicyMeta(req) {
|
1716
1807
|
let policyTypes = 0;
|
1717
1808
|
const policies = [];
|
1718
|
-
if (req.
|
1719
|
-
policyTypes += PolicyType.
|
1720
|
-
policies.push({ data: req.
|
1809
|
+
if (req.tip) {
|
1810
|
+
policyTypes += PolicyType.Tip;
|
1811
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1721
1812
|
}
|
1722
1813
|
if (req.witnessLimit) {
|
1723
1814
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1904,10 +1995,10 @@ var BaseTransactionRequest = class {
|
|
1904
1995
|
* @param predicate - Predicate bytes.
|
1905
1996
|
* @param predicateData - Predicate data bytes.
|
1906
1997
|
*/
|
1907
|
-
addCoinInput(coin
|
1998
|
+
addCoinInput(coin) {
|
1908
1999
|
const { assetId, owner, amount } = coin;
|
1909
2000
|
let witnessIndex;
|
1910
|
-
if (predicate) {
|
2001
|
+
if (coin.predicate) {
|
1911
2002
|
witnessIndex = 0;
|
1912
2003
|
} else {
|
1913
2004
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1922,8 +2013,7 @@ var BaseTransactionRequest = class {
|
|
1922
2013
|
amount,
|
1923
2014
|
assetId,
|
1924
2015
|
txPointer: "0x00000000000000000000000000000000",
|
1925
|
-
witnessIndex
|
1926
|
-
predicate: predicate?.bytes
|
2016
|
+
witnessIndex
|
1927
2017
|
};
|
1928
2018
|
this.pushInput(input);
|
1929
2019
|
this.addChangeOutput(owner, assetId);
|
@@ -1936,11 +2026,11 @@ var BaseTransactionRequest = class {
|
|
1936
2026
|
* @param predicate - Predicate bytes.
|
1937
2027
|
* @param predicateData - Predicate data bytes.
|
1938
2028
|
*/
|
1939
|
-
addMessageInput(message
|
2029
|
+
addMessageInput(message) {
|
1940
2030
|
const { recipient, sender, amount } = message;
|
1941
2031
|
const assetId = BaseAssetId2;
|
1942
2032
|
let witnessIndex;
|
1943
|
-
if (predicate) {
|
2033
|
+
if (message.predicate) {
|
1944
2034
|
witnessIndex = 0;
|
1945
2035
|
} else {
|
1946
2036
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1954,8 +2044,7 @@ var BaseTransactionRequest = class {
|
|
1954
2044
|
sender: sender.toB256(),
|
1955
2045
|
recipient: recipient.toB256(),
|
1956
2046
|
amount,
|
1957
|
-
witnessIndex
|
1958
|
-
predicate: predicate?.bytes
|
2047
|
+
witnessIndex
|
1959
2048
|
};
|
1960
2049
|
this.pushInput(input);
|
1961
2050
|
this.addChangeOutput(recipient, assetId);
|
@@ -1986,32 +2075,6 @@ var BaseTransactionRequest = class {
|
|
1986
2075
|
resources.forEach((resource) => this.addResource(resource));
|
1987
2076
|
return this;
|
1988
2077
|
}
|
1989
|
-
/**
|
1990
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1991
|
-
* outputs from the related assetIds.
|
1992
|
-
*
|
1993
|
-
* @param resources - The resources to add.
|
1994
|
-
* @returns This transaction.
|
1995
|
-
*/
|
1996
|
-
addPredicateResource(resource, predicate) {
|
1997
|
-
if (isCoin(resource)) {
|
1998
|
-
this.addCoinInput(resource, predicate);
|
1999
|
-
} else {
|
2000
|
-
this.addMessageInput(resource, predicate);
|
2001
|
-
}
|
2002
|
-
return this;
|
2003
|
-
}
|
2004
|
-
/**
|
2005
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2006
|
-
* from the related assetIds.
|
2007
|
-
*
|
2008
|
-
* @param resources - The resources to add.
|
2009
|
-
* @returns This transaction.
|
2010
|
-
*/
|
2011
|
-
addPredicateResources(resources, predicate) {
|
2012
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2013
|
-
return this;
|
2014
|
-
}
|
2015
2078
|
/**
|
2016
2079
|
* Adds a coin output to the transaction.
|
2017
2080
|
*
|
@@ -2091,7 +2154,7 @@ var BaseTransactionRequest = class {
|
|
2091
2154
|
}
|
2092
2155
|
calculateMaxGas(chainInfo, minGas) {
|
2093
2156
|
const { consensusParameters } = chainInfo;
|
2094
|
-
const { gasPerByte } = consensusParameters;
|
2157
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2095
2158
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2096
2159
|
(acc, wit) => acc + wit.dataLength,
|
2097
2160
|
0
|
@@ -2100,7 +2163,8 @@ var BaseTransactionRequest = class {
|
|
2100
2163
|
gasPerByte,
|
2101
2164
|
minGas,
|
2102
2165
|
witnessesLength,
|
2103
|
-
witnessLimit: this.witnessLimit
|
2166
|
+
witnessLimit: this.witnessLimit,
|
2167
|
+
maxGasPerTx
|
2104
2168
|
});
|
2105
2169
|
}
|
2106
2170
|
/**
|
@@ -2110,12 +2174,6 @@ var BaseTransactionRequest = class {
|
|
2110
2174
|
* @param quantities - CoinQuantity Array.
|
2111
2175
|
*/
|
2112
2176
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2113
|
-
let idCounter = 0;
|
2114
|
-
const generateId = () => {
|
2115
|
-
const counterString = String(idCounter++);
|
2116
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2117
|
-
return id;
|
2118
|
-
};
|
2119
2177
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2120
2178
|
if ("assetId" in input) {
|
2121
2179
|
return input.assetId === assetId;
|
@@ -2124,17 +2182,20 @@ var BaseTransactionRequest = class {
|
|
2124
2182
|
});
|
2125
2183
|
const updateAssetInput = (assetId, quantity) => {
|
2126
2184
|
const assetInput = findAssetInput(assetId);
|
2185
|
+
let usedQuantity = quantity;
|
2186
|
+
if (assetId === BaseAssetId2) {
|
2187
|
+
usedQuantity = bn7("1000000000000000000");
|
2188
|
+
}
|
2127
2189
|
if (assetInput && "assetId" in assetInput) {
|
2128
|
-
assetInput.id =
|
2129
|
-
assetInput.amount =
|
2190
|
+
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2191
|
+
assetInput.amount = usedQuantity;
|
2130
2192
|
} else {
|
2131
2193
|
this.addResources([
|
2132
2194
|
{
|
2133
|
-
id:
|
2134
|
-
amount:
|
2195
|
+
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2196
|
+
amount: usedQuantity,
|
2135
2197
|
assetId,
|
2136
2198
|
owner: resourcesOwner || Address.fromRandom(),
|
2137
|
-
maturity: 0,
|
2138
2199
|
blockCreated: bn7(1),
|
2139
2200
|
txCreatedIdx: bn7(1)
|
2140
2201
|
}
|
@@ -2166,7 +2227,7 @@ var BaseTransactionRequest = class {
|
|
2166
2227
|
toJSON() {
|
2167
2228
|
return normalizeJSON(this);
|
2168
2229
|
}
|
2169
|
-
|
2230
|
+
updatePredicateGasUsed(inputs) {
|
2170
2231
|
this.inputs.forEach((i) => {
|
2171
2232
|
let correspondingInput;
|
2172
2233
|
switch (i.type) {
|
@@ -2188,6 +2249,15 @@ var BaseTransactionRequest = class {
|
|
2188
2249
|
}
|
2189
2250
|
});
|
2190
2251
|
}
|
2252
|
+
shiftPredicateData() {
|
2253
|
+
this.inputs.forEach((input) => {
|
2254
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2255
|
+
input.predicateData = input.paddPredicateData(
|
2256
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2257
|
+
);
|
2258
|
+
}
|
2259
|
+
});
|
2260
|
+
}
|
2191
2261
|
};
|
2192
2262
|
|
2193
2263
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2334,9 +2404,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2334
2404
|
return {
|
2335
2405
|
type: TransactionType3.Create,
|
2336
2406
|
...baseTransaction,
|
2337
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2338
2407
|
bytecodeWitnessIndex,
|
2339
|
-
storageSlotsCount: storageSlots.length,
|
2408
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2340
2409
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2341
2410
|
storageSlots
|
2342
2411
|
};
|
@@ -2459,8 +2528,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2459
2528
|
type: TransactionType4.Script,
|
2460
2529
|
scriptGasLimit: this.gasLimit,
|
2461
2530
|
...super.getBaseTransaction(),
|
2462
|
-
scriptLength: script.length,
|
2463
|
-
scriptDataLength: scriptData.length,
|
2531
|
+
scriptLength: bn10(script.length),
|
2532
|
+
scriptDataLength: bn10(scriptData.length),
|
2464
2533
|
receiptsRoot: ZeroBytes327,
|
2465
2534
|
script: hexlify10(script),
|
2466
2535
|
scriptData: hexlify10(scriptData)
|
@@ -2524,7 +2593,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2524
2593
|
}
|
2525
2594
|
calculateMaxGas(chainInfo, minGas) {
|
2526
2595
|
const { consensusParameters } = chainInfo;
|
2527
|
-
const { gasPerByte } = consensusParameters;
|
2596
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2528
2597
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2529
2598
|
(acc, wit) => acc + wit.dataLength,
|
2530
2599
|
0
|
@@ -2534,7 +2603,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2534
2603
|
minGas,
|
2535
2604
|
witnessesLength,
|
2536
2605
|
witnessLimit: this.witnessLimit,
|
2537
|
-
gasLimit: this.gasLimit
|
2606
|
+
gasLimit: this.gasLimit,
|
2607
|
+
maxGasPerTx
|
2538
2608
|
});
|
2539
2609
|
}
|
2540
2610
|
/**
|
@@ -2591,7 +2661,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2591
2661
|
|
2592
2662
|
// src/providers/transaction-request/utils.ts
|
2593
2663
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2594
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2664
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2595
2665
|
var transactionRequestify = (obj) => {
|
2596
2666
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2597
2667
|
return obj;
|
@@ -2609,14 +2679,31 @@ var transactionRequestify = (obj) => {
|
|
2609
2679
|
}
|
2610
2680
|
}
|
2611
2681
|
};
|
2682
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2683
|
+
(acc, input) => {
|
2684
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2685
|
+
acc.utxos.push(input.id);
|
2686
|
+
}
|
2687
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2688
|
+
acc.messages.push(input.nonce);
|
2689
|
+
}
|
2690
|
+
return acc;
|
2691
|
+
},
|
2692
|
+
{
|
2693
|
+
utxos: [],
|
2694
|
+
messages: []
|
2695
|
+
}
|
2696
|
+
);
|
2612
2697
|
|
2613
2698
|
// src/providers/transaction-response/transaction-response.ts
|
2614
2699
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2615
|
-
import { bn as
|
2700
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2616
2701
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2617
2702
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2618
2703
|
|
2619
2704
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2705
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2706
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2620
2707
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2621
2708
|
|
2622
2709
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2625,9 +2712,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2625
2712
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2626
2713
|
var calculateTransactionFee = (params) => {
|
2627
2714
|
const {
|
2628
|
-
|
2715
|
+
gasPrice,
|
2629
2716
|
rawPayload,
|
2630
|
-
|
2717
|
+
tip,
|
2718
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2631
2719
|
} = params;
|
2632
2720
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2633
2721
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2637,8 +2725,7 @@ var calculateTransactionFee = (params) => {
|
|
2637
2725
|
return {
|
2638
2726
|
fee: bn11(0),
|
2639
2727
|
minFee: bn11(0),
|
2640
|
-
maxFee: bn11(0)
|
2641
|
-
feeFromGasUsed: bn11(0)
|
2728
|
+
maxFee: bn11(0)
|
2642
2729
|
};
|
2643
2730
|
}
|
2644
2731
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2670,7 +2757,6 @@ var calculateTransactionFee = (params) => {
|
|
2670
2757
|
metadataGas,
|
2671
2758
|
txBytesSize: transactionBytes.length
|
2672
2759
|
});
|
2673
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2674
2760
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2675
2761
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2676
2762
|
const maxGas = getMaxGas({
|
@@ -2678,17 +2764,25 @@ var calculateTransactionFee = (params) => {
|
|
2678
2764
|
minGas,
|
2679
2765
|
witnessesLength,
|
2680
2766
|
gasLimit,
|
2681
|
-
witnessLimit
|
2767
|
+
witnessLimit,
|
2768
|
+
maxGasPerTx
|
2769
|
+
});
|
2770
|
+
const minFee = calculateGasFee({
|
2771
|
+
gasPrice,
|
2772
|
+
gas: minGas,
|
2773
|
+
priceFactor: gasPriceFactor,
|
2774
|
+
tip
|
2775
|
+
});
|
2776
|
+
const maxFee = calculateGasFee({
|
2777
|
+
gasPrice,
|
2778
|
+
gas: maxGas,
|
2779
|
+
priceFactor: gasPriceFactor,
|
2780
|
+
tip
|
2682
2781
|
});
|
2683
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2684
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2685
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2686
|
-
const fee = minFee.add(feeFromGasUsed);
|
2687
2782
|
return {
|
2688
|
-
fee,
|
2689
2783
|
minFee,
|
2690
2784
|
maxFee,
|
2691
|
-
|
2785
|
+
fee: maxFee
|
2692
2786
|
};
|
2693
2787
|
};
|
2694
2788
|
|
@@ -2744,7 +2838,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2744
2838
|
|
2745
2839
|
// src/providers/transaction-summary/input.ts
|
2746
2840
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2747
|
-
import { InputType as
|
2841
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2748
2842
|
function getInputsByTypes(inputs, types) {
|
2749
2843
|
return inputs.filter((i) => types.includes(i.type));
|
2750
2844
|
}
|
@@ -2752,16 +2846,16 @@ function getInputsByType(inputs, type) {
|
|
2752
2846
|
return inputs.filter((i) => i.type === type);
|
2753
2847
|
}
|
2754
2848
|
function getInputsCoin(inputs) {
|
2755
|
-
return getInputsByType(inputs,
|
2849
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2756
2850
|
}
|
2757
2851
|
function getInputsMessage(inputs) {
|
2758
|
-
return getInputsByType(inputs,
|
2852
|
+
return getInputsByType(inputs, InputType6.Message);
|
2759
2853
|
}
|
2760
2854
|
function getInputsCoinAndMessage(inputs) {
|
2761
|
-
return getInputsByTypes(inputs, [
|
2855
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2762
2856
|
}
|
2763
2857
|
function getInputsContract(inputs) {
|
2764
|
-
return getInputsByType(inputs,
|
2858
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2765
2859
|
}
|
2766
2860
|
function getInputFromAssetId(inputs, assetId) {
|
2767
2861
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2780,7 +2874,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2780
2874
|
if (!contractInput) {
|
2781
2875
|
return void 0;
|
2782
2876
|
}
|
2783
|
-
if (contractInput.type !==
|
2877
|
+
if (contractInput.type !== InputType6.Contract) {
|
2784
2878
|
throw new FuelError9(
|
2785
2879
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2786
2880
|
`Contract input should be of type 'contract'.`
|
@@ -2789,10 +2883,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2789
2883
|
return contractInput;
|
2790
2884
|
}
|
2791
2885
|
function getInputAccountAddress(input) {
|
2792
|
-
if (input.type ===
|
2886
|
+
if (input.type === InputType6.Coin) {
|
2793
2887
|
return input.owner.toString();
|
2794
2888
|
}
|
2795
|
-
if (input.type ===
|
2889
|
+
if (input.type === InputType6.Message) {
|
2796
2890
|
return input.recipient.toString();
|
2797
2891
|
}
|
2798
2892
|
return "";
|
@@ -3302,7 +3396,9 @@ function assembleTransactionSummary(params) {
|
|
3302
3396
|
gqlTransactionStatus,
|
3303
3397
|
abiMap = {},
|
3304
3398
|
maxInputs,
|
3305
|
-
gasCosts
|
3399
|
+
gasCosts,
|
3400
|
+
maxGasPerTx,
|
3401
|
+
gasPrice
|
3306
3402
|
} = params;
|
3307
3403
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3308
3404
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3316,11 +3412,14 @@ function assembleTransactionSummary(params) {
|
|
3316
3412
|
maxInputs
|
3317
3413
|
});
|
3318
3414
|
const typeName = getTransactionTypeName(transaction.type);
|
3415
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3319
3416
|
const { fee } = calculateTransactionFee({
|
3320
|
-
|
3417
|
+
gasPrice,
|
3321
3418
|
rawPayload,
|
3419
|
+
tip,
|
3322
3420
|
consensusParameters: {
|
3323
3421
|
gasCosts,
|
3422
|
+
maxGasPerTx,
|
3324
3423
|
feeParams: {
|
3325
3424
|
gasPerByte,
|
3326
3425
|
gasPriceFactor
|
@@ -3380,7 +3479,7 @@ var TransactionResponse = class {
|
|
3380
3479
|
/** Current provider */
|
3381
3480
|
provider;
|
3382
3481
|
/** Gas used on the transaction */
|
3383
|
-
gasUsed =
|
3482
|
+
gasUsed = bn15(0);
|
3384
3483
|
/** The graphql Transaction with receipts object. */
|
3385
3484
|
gqlTransaction;
|
3386
3485
|
abis;
|
@@ -3458,8 +3557,13 @@ var TransactionResponse = class {
|
|
3458
3557
|
const decodedTransaction = this.decodeTransaction(
|
3459
3558
|
transaction
|
3460
3559
|
);
|
3461
|
-
|
3462
|
-
|
3560
|
+
let txReceipts = [];
|
3561
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3562
|
+
txReceipts = transaction.status.receipts;
|
3563
|
+
}
|
3564
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3565
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3566
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3463
3567
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3464
3568
|
const transactionSummary = assembleTransactionSummary({
|
3465
3569
|
id: this.id,
|
@@ -3471,7 +3575,9 @@ var TransactionResponse = class {
|
|
3471
3575
|
gasPriceFactor,
|
3472
3576
|
abiMap: contractsAbiMap,
|
3473
3577
|
maxInputs,
|
3474
|
-
gasCosts
|
3578
|
+
gasCosts,
|
3579
|
+
maxGasPerTx,
|
3580
|
+
gasPrice
|
3475
3581
|
});
|
3476
3582
|
return transactionSummary;
|
3477
3583
|
}
|
@@ -3598,29 +3704,29 @@ var processGqlChain = (chain) => {
|
|
3598
3704
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3599
3705
|
return {
|
3600
3706
|
name,
|
3601
|
-
baseChainHeight:
|
3707
|
+
baseChainHeight: bn16(daHeight),
|
3602
3708
|
consensusParameters: {
|
3603
|
-
contractMaxSize:
|
3604
|
-
maxInputs:
|
3605
|
-
maxOutputs:
|
3606
|
-
maxWitnesses:
|
3607
|
-
maxGasPerTx:
|
3608
|
-
maxScriptLength:
|
3609
|
-
maxScriptDataLength:
|
3610
|
-
maxStorageSlots:
|
3611
|
-
maxPredicateLength:
|
3612
|
-
maxPredicateDataLength:
|
3613
|
-
maxGasPerPredicate:
|
3614
|
-
gasPriceFactor:
|
3615
|
-
gasPerByte:
|
3616
|
-
maxMessageDataLength:
|
3617
|
-
chainId:
|
3709
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3710
|
+
maxInputs: bn16(txParams.maxInputs),
|
3711
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3712
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3713
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3714
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3715
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3716
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3717
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3718
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3719
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3720
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3721
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3722
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3723
|
+
chainId: bn16(consensusParameters.chainId),
|
3618
3724
|
gasCosts
|
3619
3725
|
},
|
3620
3726
|
gasCosts,
|
3621
3727
|
latestBlock: {
|
3622
3728
|
id: latestBlock.id,
|
3623
|
-
height:
|
3729
|
+
height: bn16(latestBlock.height),
|
3624
3730
|
time: latestBlock.header.time,
|
3625
3731
|
transactions: latestBlock.transactions.map((i) => ({
|
3626
3732
|
id: i.id
|
@@ -3714,10 +3820,8 @@ var _Provider = class {
|
|
3714
3820
|
* Returns some helpful parameters related to gas fees.
|
3715
3821
|
*/
|
3716
3822
|
getGasConfig() {
|
3717
|
-
const { minGasPrice } = this.getNode();
|
3718
3823
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3719
3824
|
return {
|
3720
|
-
minGasPrice,
|
3721
3825
|
maxGasPerTx,
|
3722
3826
|
maxGasPerPredicate,
|
3723
3827
|
gasPriceFactor,
|
@@ -3815,7 +3919,7 @@ var _Provider = class {
|
|
3815
3919
|
*/
|
3816
3920
|
async getBlockNumber() {
|
3817
3921
|
const { chain } = await this.operations.getChain();
|
3818
|
-
return
|
3922
|
+
return bn16(chain.latestBlock.height, 10);
|
3819
3923
|
}
|
3820
3924
|
/**
|
3821
3925
|
* Returns the chain information.
|
@@ -3825,13 +3929,11 @@ var _Provider = class {
|
|
3825
3929
|
async fetchNode() {
|
3826
3930
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3827
3931
|
const processedNodeInfo = {
|
3828
|
-
maxDepth:
|
3829
|
-
maxTx:
|
3830
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3932
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3933
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3831
3934
|
nodeVersion: nodeInfo.nodeVersion,
|
3832
3935
|
utxoValidation: nodeInfo.utxoValidation,
|
3833
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3834
|
-
peers: nodeInfo.peers
|
3936
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3835
3937
|
};
|
3836
3938
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3837
3939
|
return processedNodeInfo;
|
@@ -3917,14 +4019,13 @@ var _Provider = class {
|
|
3917
4019
|
return this.estimateTxDependencies(transactionRequest);
|
3918
4020
|
}
|
3919
4021
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3920
|
-
const { dryRun:
|
3921
|
-
encodedTransaction,
|
4022
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4023
|
+
encodedTransactions: encodedTransaction,
|
3922
4024
|
utxoValidation: utxoValidation || false
|
3923
4025
|
});
|
3924
|
-
const receipts =
|
3925
|
-
|
3926
|
-
|
3927
|
-
};
|
4026
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4027
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4028
|
+
return { receipts, dryrunStatus: status };
|
3928
4029
|
}
|
3929
4030
|
/**
|
3930
4031
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3950,7 +4051,7 @@ var _Provider = class {
|
|
3950
4051
|
} = response;
|
3951
4052
|
if (inputs) {
|
3952
4053
|
inputs.forEach((input, index) => {
|
3953
|
-
if ("predicateGasUsed" in input &&
|
4054
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3954
4055
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3955
4056
|
}
|
3956
4057
|
});
|
@@ -3963,9 +4064,6 @@ var _Provider = class {
|
|
3963
4064
|
* If there are missing variable outputs,
|
3964
4065
|
* `addVariableOutputs` is called on the transaction.
|
3965
4066
|
*
|
3966
|
-
* @privateRemarks
|
3967
|
-
* TODO: Investigate support for missing contract IDs
|
3968
|
-
* TODO: Add support for missing output messages
|
3969
4067
|
*
|
3970
4068
|
* @param transactionRequest - The transaction request object.
|
3971
4069
|
* @returns A promise.
|
@@ -3978,16 +4076,19 @@ var _Provider = class {
|
|
3978
4076
|
missingContractIds: []
|
3979
4077
|
};
|
3980
4078
|
}
|
3981
|
-
await this.estimatePredicates(transactionRequest);
|
3982
4079
|
let receipts = [];
|
3983
4080
|
const missingContractIds = [];
|
3984
4081
|
let outputVariables = 0;
|
4082
|
+
let dryrunStatus;
|
3985
4083
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3986
|
-
const {
|
3987
|
-
|
4084
|
+
const {
|
4085
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4086
|
+
} = await this.operations.dryRun({
|
4087
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3988
4088
|
utxoValidation: false
|
3989
4089
|
});
|
3990
|
-
receipts =
|
4090
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4091
|
+
dryrunStatus = status;
|
3991
4092
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3992
4093
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3993
4094
|
if (hasMissingOutputs) {
|
@@ -3997,6 +4098,10 @@ var _Provider = class {
|
|
3997
4098
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3998
4099
|
missingContractIds.push(contractId);
|
3999
4100
|
});
|
4101
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4102
|
+
transactionRequest
|
4103
|
+
});
|
4104
|
+
transactionRequest.maxFee = maxFee;
|
4000
4105
|
} else {
|
4001
4106
|
break;
|
4002
4107
|
}
|
@@ -4004,7 +4109,139 @@ var _Provider = class {
|
|
4004
4109
|
return {
|
4005
4110
|
receipts,
|
4006
4111
|
outputVariables,
|
4007
|
-
missingContractIds
|
4112
|
+
missingContractIds,
|
4113
|
+
dryrunStatus
|
4114
|
+
};
|
4115
|
+
}
|
4116
|
+
/**
|
4117
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4118
|
+
*
|
4119
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4120
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4121
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4122
|
+
*
|
4123
|
+
* @param transactionRequests - Array of transaction request objects.
|
4124
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4125
|
+
*/
|
4126
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4127
|
+
const results = transactionRequests.map(() => ({
|
4128
|
+
receipts: [],
|
4129
|
+
outputVariables: 0,
|
4130
|
+
missingContractIds: [],
|
4131
|
+
dryrunStatus: void 0
|
4132
|
+
}));
|
4133
|
+
const allRequests = clone3(transactionRequests);
|
4134
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4135
|
+
allRequests.forEach((req, index) => {
|
4136
|
+
if (req.type === TransactionType8.Script) {
|
4137
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4138
|
+
}
|
4139
|
+
});
|
4140
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4141
|
+
let attempt = 0;
|
4142
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4143
|
+
const encodedTransactions = transactionsToProcess.map(
|
4144
|
+
(index) => serializedTransactionsMap.get(index)
|
4145
|
+
);
|
4146
|
+
const dryRunResults = await this.operations.dryRun({
|
4147
|
+
encodedTransactions,
|
4148
|
+
utxoValidation: false
|
4149
|
+
});
|
4150
|
+
const nextRoundTransactions = [];
|
4151
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4152
|
+
const currentResultIndex = transactionsToProcess[i];
|
4153
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4154
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4155
|
+
results[currentResultIndex].dryrunStatus = status;
|
4156
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4157
|
+
results[currentResultIndex].receipts
|
4158
|
+
);
|
4159
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4160
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4161
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4162
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4163
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4164
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4165
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4166
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4167
|
+
});
|
4168
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4169
|
+
transactionRequest: requestToProcess
|
4170
|
+
});
|
4171
|
+
requestToProcess.maxFee = maxFee;
|
4172
|
+
serializedTransactionsMap.set(
|
4173
|
+
currentResultIndex,
|
4174
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4175
|
+
);
|
4176
|
+
nextRoundTransactions.push(currentResultIndex);
|
4177
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4178
|
+
}
|
4179
|
+
}
|
4180
|
+
transactionsToProcess = nextRoundTransactions;
|
4181
|
+
attempt += 1;
|
4182
|
+
}
|
4183
|
+
return results;
|
4184
|
+
}
|
4185
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4186
|
+
if (estimateTxDependencies) {
|
4187
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4188
|
+
}
|
4189
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4190
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4191
|
+
encodedTransactions,
|
4192
|
+
utxoValidation: utxoValidation || false
|
4193
|
+
});
|
4194
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4195
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4196
|
+
return { receipts, dryrunStatus: status };
|
4197
|
+
});
|
4198
|
+
return results;
|
4199
|
+
}
|
4200
|
+
/**
|
4201
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
4202
|
+
* @param transactionRequest - The transaction request object.
|
4203
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4204
|
+
*/
|
4205
|
+
async estimateTxGasAndFee(params) {
|
4206
|
+
const { transactionRequest } = params;
|
4207
|
+
let { gasPrice } = params;
|
4208
|
+
const chainInfo = this.getChain();
|
4209
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4210
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4211
|
+
if (!gasPrice) {
|
4212
|
+
gasPrice = await this.estimateGasPrice(10);
|
4213
|
+
}
|
4214
|
+
const minFee = calculateGasFee({
|
4215
|
+
gasPrice: bn16(gasPrice),
|
4216
|
+
gas: minGas,
|
4217
|
+
priceFactor: gasPriceFactor,
|
4218
|
+
tip: transactionRequest.tip
|
4219
|
+
}).add(1);
|
4220
|
+
let gasLimit = bn16(0);
|
4221
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
4222
|
+
gasLimit = transactionRequest.gasLimit;
|
4223
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4224
|
+
transactionRequest.gasLimit = minGas;
|
4225
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4226
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4227
|
+
);
|
4228
|
+
gasLimit = transactionRequest.gasLimit;
|
4229
|
+
}
|
4230
|
+
}
|
4231
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4232
|
+
const maxFee = calculateGasFee({
|
4233
|
+
gasPrice: bn16(gasPrice),
|
4234
|
+
gas: maxGas,
|
4235
|
+
priceFactor: gasPriceFactor,
|
4236
|
+
tip: transactionRequest.tip
|
4237
|
+
}).add(1);
|
4238
|
+
return {
|
4239
|
+
minGas,
|
4240
|
+
minFee,
|
4241
|
+
maxGas,
|
4242
|
+
maxFee,
|
4243
|
+
gasPrice,
|
4244
|
+
gasLimit
|
4008
4245
|
};
|
4009
4246
|
}
|
4010
4247
|
/**
|
@@ -4022,15 +4259,17 @@ var _Provider = class {
|
|
4022
4259
|
if (estimateTxDependencies) {
|
4023
4260
|
return this.estimateTxDependencies(transactionRequest);
|
4024
4261
|
}
|
4025
|
-
const
|
4026
|
-
const { dryRun:
|
4027
|
-
|
4262
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4263
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4264
|
+
encodedTransactions,
|
4028
4265
|
utxoValidation: true
|
4029
4266
|
});
|
4030
|
-
const
|
4031
|
-
|
4032
|
-
receipts
|
4033
|
-
|
4267
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4268
|
+
const { id, receipts, status } = dryRunStatus;
|
4269
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4270
|
+
return { id, receipts: processedReceipts, status };
|
4271
|
+
});
|
4272
|
+
return { receipts: callResult[0].receipts };
|
4034
4273
|
}
|
4035
4274
|
/**
|
4036
4275
|
* Returns a transaction cost to enable user
|
@@ -4047,80 +4286,79 @@ var _Provider = class {
|
|
4047
4286
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4048
4287
|
* @returns A promise that resolves to the transaction cost object.
|
4049
4288
|
*/
|
4050
|
-
async getTransactionCost(transactionRequestLike,
|
4051
|
-
estimateTxDependencies = true,
|
4052
|
-
estimatePredicates = true,
|
4053
|
-
resourcesOwner,
|
4054
|
-
signatureCallback
|
4055
|
-
} = {}) {
|
4289
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4056
4290
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4057
|
-
const chainInfo = this.getChain();
|
4058
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4059
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4060
4291
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4061
4292
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4062
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4293
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4063
4294
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4064
|
-
|
4065
|
-
|
4066
|
-
|
4067
|
-
|
4068
|
-
|
4069
|
-
|
4070
|
-
}
|
4071
|
-
await this.estimatePredicates(txRequestClone);
|
4295
|
+
txRequestClone.maxFee = bn16(0);
|
4296
|
+
if (isScriptTransaction) {
|
4297
|
+
txRequestClone.gasLimit = bn16(0);
|
4298
|
+
}
|
4299
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4300
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4072
4301
|
}
|
4302
|
+
const signedRequest = clone3(txRequestClone);
|
4303
|
+
let addedSignatures = 0;
|
4073
4304
|
if (signatureCallback && isScriptTransaction) {
|
4074
|
-
|
4305
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4306
|
+
await signatureCallback(signedRequest);
|
4307
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4075
4308
|
}
|
4076
|
-
|
4077
|
-
|
4309
|
+
await this.estimatePredicates(signedRequest);
|
4310
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4311
|
+
transactionRequest: signedRequest
|
4312
|
+
});
|
4078
4313
|
let receipts = [];
|
4079
4314
|
let missingContractIds = [];
|
4080
4315
|
let outputVariables = 0;
|
4081
|
-
|
4082
|
-
|
4083
|
-
|
4316
|
+
let gasUsed = bn16(0);
|
4317
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4318
|
+
txRequestClone.maxFee = maxFee;
|
4319
|
+
if (isScriptTransaction) {
|
4320
|
+
txRequestClone.gasLimit = gasLimit;
|
4321
|
+
if (signatureCallback) {
|
4322
|
+
await signatureCallback(txRequestClone);
|
4323
|
+
}
|
4084
4324
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4085
4325
|
receipts = result.receipts;
|
4086
4326
|
outputVariables = result.outputVariables;
|
4087
4327
|
missingContractIds = result.missingContractIds;
|
4328
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4329
|
+
txRequestClone.gasLimit = gasUsed;
|
4330
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4331
|
+
transactionRequest: txRequestClone,
|
4332
|
+
gasPrice
|
4333
|
+
}));
|
4088
4334
|
}
|
4089
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4090
|
-
const usedFee = calculatePriceWithFactor(
|
4091
|
-
gasUsed,
|
4092
|
-
gasPrice,
|
4093
|
-
gasPriceFactor
|
4094
|
-
).normalizeZeroToOne();
|
4095
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4096
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4097
4335
|
return {
|
4098
4336
|
requiredQuantities: allQuantities,
|
4099
4337
|
receipts,
|
4100
4338
|
gasUsed,
|
4101
|
-
minGasPrice,
|
4102
4339
|
gasPrice,
|
4103
4340
|
minGas,
|
4104
4341
|
maxGas,
|
4105
|
-
usedFee,
|
4106
4342
|
minFee,
|
4107
4343
|
maxFee,
|
4108
|
-
estimatedInputs: txRequestClone.inputs,
|
4109
4344
|
outputVariables,
|
4110
|
-
missingContractIds
|
4345
|
+
missingContractIds,
|
4346
|
+
addedSignatures,
|
4347
|
+
estimatedPredicates: txRequestClone.inputs
|
4111
4348
|
};
|
4112
4349
|
}
|
4113
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4350
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4114
4351
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4115
4352
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4116
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4353
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4354
|
+
quantitiesToContract
|
4355
|
+
});
|
4117
4356
|
transactionRequest.addResources(
|
4118
4357
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4119
4358
|
);
|
4120
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4121
|
-
|
4122
|
-
|
4123
|
-
);
|
4359
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4360
|
+
quantitiesToContract
|
4361
|
+
});
|
4124
4362
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4125
4363
|
return {
|
4126
4364
|
resources,
|
@@ -4142,11 +4380,10 @@ var _Provider = class {
|
|
4142
4380
|
return coins.map((coin) => ({
|
4143
4381
|
id: coin.utxoId,
|
4144
4382
|
assetId: coin.assetId,
|
4145
|
-
amount:
|
4383
|
+
amount: bn16(coin.amount),
|
4146
4384
|
owner: Address2.fromAddressOrString(coin.owner),
|
4147
|
-
|
4148
|
-
|
4149
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4385
|
+
blockCreated: bn16(coin.blockCreated),
|
4386
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4150
4387
|
}));
|
4151
4388
|
}
|
4152
4389
|
/**
|
@@ -4183,9 +4420,9 @@ var _Provider = class {
|
|
4183
4420
|
switch (coin.__typename) {
|
4184
4421
|
case "MessageCoin":
|
4185
4422
|
return {
|
4186
|
-
amount:
|
4423
|
+
amount: bn16(coin.amount),
|
4187
4424
|
assetId: coin.assetId,
|
4188
|
-
daHeight:
|
4425
|
+
daHeight: bn16(coin.daHeight),
|
4189
4426
|
sender: Address2.fromAddressOrString(coin.sender),
|
4190
4427
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4191
4428
|
nonce: coin.nonce
|
@@ -4193,12 +4430,11 @@ var _Provider = class {
|
|
4193
4430
|
case "Coin":
|
4194
4431
|
return {
|
4195
4432
|
id: coin.utxoId,
|
4196
|
-
amount:
|
4433
|
+
amount: bn16(coin.amount),
|
4197
4434
|
assetId: coin.assetId,
|
4198
4435
|
owner: Address2.fromAddressOrString(coin.owner),
|
4199
|
-
|
4200
|
-
|
4201
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4436
|
+
blockCreated: bn16(coin.blockCreated),
|
4437
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4202
4438
|
};
|
4203
4439
|
default:
|
4204
4440
|
return null;
|
@@ -4215,13 +4451,13 @@ var _Provider = class {
|
|
4215
4451
|
async getBlock(idOrHeight) {
|
4216
4452
|
let variables;
|
4217
4453
|
if (typeof idOrHeight === "number") {
|
4218
|
-
variables = { height:
|
4454
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4219
4455
|
} else if (idOrHeight === "latest") {
|
4220
4456
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4221
4457
|
} else if (idOrHeight.length === 66) {
|
4222
4458
|
variables = { blockId: idOrHeight };
|
4223
4459
|
} else {
|
4224
|
-
variables = { blockId:
|
4460
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4225
4461
|
}
|
4226
4462
|
const { block } = await this.operations.getBlock(variables);
|
4227
4463
|
if (!block) {
|
@@ -4229,7 +4465,7 @@ var _Provider = class {
|
|
4229
4465
|
}
|
4230
4466
|
return {
|
4231
4467
|
id: block.id,
|
4232
|
-
height:
|
4468
|
+
height: bn16(block.height),
|
4233
4469
|
time: block.header.time,
|
4234
4470
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4235
4471
|
};
|
@@ -4244,7 +4480,7 @@ var _Provider = class {
|
|
4244
4480
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4245
4481
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4246
4482
|
id: block.id,
|
4247
|
-
height:
|
4483
|
+
height: bn16(block.height),
|
4248
4484
|
time: block.header.time,
|
4249
4485
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4250
4486
|
}));
|
@@ -4259,7 +4495,7 @@ var _Provider = class {
|
|
4259
4495
|
async getBlockWithTransactions(idOrHeight) {
|
4260
4496
|
let variables;
|
4261
4497
|
if (typeof idOrHeight === "number") {
|
4262
|
-
variables = { blockHeight:
|
4498
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4263
4499
|
} else if (idOrHeight === "latest") {
|
4264
4500
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4265
4501
|
} else {
|
@@ -4271,7 +4507,7 @@ var _Provider = class {
|
|
4271
4507
|
}
|
4272
4508
|
return {
|
4273
4509
|
id: block.id,
|
4274
|
-
height:
|
4510
|
+
height: bn16(block.height, 10),
|
4275
4511
|
time: block.header.time,
|
4276
4512
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4277
4513
|
transactions: block.transactions.map(
|
@@ -4320,7 +4556,7 @@ var _Provider = class {
|
|
4320
4556
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4321
4557
|
asset: hexlify12(assetId)
|
4322
4558
|
});
|
4323
|
-
return
|
4559
|
+
return bn16(contractBalance.amount, 10);
|
4324
4560
|
}
|
4325
4561
|
/**
|
4326
4562
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4334,7 +4570,7 @@ var _Provider = class {
|
|
4334
4570
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4335
4571
|
assetId: hexlify12(assetId)
|
4336
4572
|
});
|
4337
|
-
return
|
4573
|
+
return bn16(balance.amount, 10);
|
4338
4574
|
}
|
4339
4575
|
/**
|
4340
4576
|
* Returns balances for the given owner.
|
@@ -4352,7 +4588,7 @@ var _Provider = class {
|
|
4352
4588
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4353
4589
|
return balances.map((balance) => ({
|
4354
4590
|
assetId: balance.assetId,
|
4355
|
-
amount:
|
4591
|
+
amount: bn16(balance.amount)
|
4356
4592
|
}));
|
4357
4593
|
}
|
4358
4594
|
/**
|
@@ -4374,15 +4610,15 @@ var _Provider = class {
|
|
4374
4610
|
sender: message.sender,
|
4375
4611
|
recipient: message.recipient,
|
4376
4612
|
nonce: message.nonce,
|
4377
|
-
amount:
|
4613
|
+
amount: bn16(message.amount),
|
4378
4614
|
data: message.data
|
4379
4615
|
}),
|
4380
4616
|
sender: Address2.fromAddressOrString(message.sender),
|
4381
4617
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4382
4618
|
nonce: message.nonce,
|
4383
|
-
amount:
|
4619
|
+
amount: bn16(message.amount),
|
4384
4620
|
data: InputMessageCoder.decodeData(message.data),
|
4385
|
-
daHeight:
|
4621
|
+
daHeight: bn16(message.daHeight)
|
4386
4622
|
}));
|
4387
4623
|
}
|
4388
4624
|
/**
|
@@ -4435,44 +4671,60 @@ var _Provider = class {
|
|
4435
4671
|
} = result.messageProof;
|
4436
4672
|
return {
|
4437
4673
|
messageProof: {
|
4438
|
-
proofIndex:
|
4674
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4439
4675
|
proofSet: messageProof.proofSet
|
4440
4676
|
},
|
4441
4677
|
blockProof: {
|
4442
|
-
proofIndex:
|
4678
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4443
4679
|
proofSet: blockProof.proofSet
|
4444
4680
|
},
|
4445
4681
|
messageBlockHeader: {
|
4446
4682
|
id: messageBlockHeader.id,
|
4447
|
-
daHeight:
|
4448
|
-
transactionsCount:
|
4683
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4684
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4449
4685
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4450
|
-
height:
|
4686
|
+
height: bn16(messageBlockHeader.height),
|
4451
4687
|
prevRoot: messageBlockHeader.prevRoot,
|
4452
4688
|
time: messageBlockHeader.time,
|
4453
4689
|
applicationHash: messageBlockHeader.applicationHash,
|
4454
|
-
|
4455
|
-
|
4690
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4691
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4692
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4693
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4694
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4456
4695
|
},
|
4457
4696
|
commitBlockHeader: {
|
4458
4697
|
id: commitBlockHeader.id,
|
4459
|
-
daHeight:
|
4460
|
-
transactionsCount:
|
4698
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4699
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4461
4700
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4462
|
-
height:
|
4701
|
+
height: bn16(commitBlockHeader.height),
|
4463
4702
|
prevRoot: commitBlockHeader.prevRoot,
|
4464
4703
|
time: commitBlockHeader.time,
|
4465
4704
|
applicationHash: commitBlockHeader.applicationHash,
|
4466
|
-
|
4467
|
-
|
4705
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4706
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4707
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4708
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4709
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4468
4710
|
},
|
4469
4711
|
sender: Address2.fromAddressOrString(sender),
|
4470
4712
|
recipient: Address2.fromAddressOrString(recipient),
|
4471
4713
|
nonce,
|
4472
|
-
amount:
|
4714
|
+
amount: bn16(amount),
|
4473
4715
|
data
|
4474
4716
|
};
|
4475
4717
|
}
|
4718
|
+
async getLatestGasPrice() {
|
4719
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4720
|
+
return bn16(latestGasPrice.gasPrice);
|
4721
|
+
}
|
4722
|
+
async estimateGasPrice(blockHorizon) {
|
4723
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4724
|
+
blockHorizon: String(blockHorizon)
|
4725
|
+
});
|
4726
|
+
return bn16(estimateGasPrice.gasPrice);
|
4727
|
+
}
|
4476
4728
|
/**
|
4477
4729
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4478
4730
|
*
|
@@ -4492,10 +4744,10 @@ var _Provider = class {
|
|
4492
4744
|
*/
|
4493
4745
|
async produceBlocks(amount, startTime) {
|
4494
4746
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4495
|
-
blocksToProduce:
|
4747
|
+
blocksToProduce: bn16(amount).toString(10),
|
4496
4748
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4497
4749
|
});
|
4498
|
-
return
|
4750
|
+
return bn16(latestBlockHeight);
|
4499
4751
|
}
|
4500
4752
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4501
4753
|
async getTransactionResponse(transactionId) {
|
@@ -4509,7 +4761,7 @@ cacheInputs_fn = function(inputs) {
|
|
4509
4761
|
return;
|
4510
4762
|
}
|
4511
4763
|
inputs.forEach((input) => {
|
4512
|
-
if (input.type ===
|
4764
|
+
if (input.type === InputType7.Coin) {
|
4513
4765
|
this.cache?.set(input.id);
|
4514
4766
|
}
|
4515
4767
|
});
|
@@ -4519,7 +4771,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4519
4771
|
|
4520
4772
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4521
4773
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4522
|
-
import { bn as
|
4774
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4523
4775
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4524
4776
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4525
4777
|
async function getTransactionSummary(params) {
|
@@ -4537,21 +4789,28 @@ async function getTransactionSummary(params) {
|
|
4537
4789
|
arrayify12(gqlTransaction.rawPayload),
|
4538
4790
|
0
|
4539
4791
|
);
|
4540
|
-
|
4792
|
+
let txReceipts = [];
|
4793
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4794
|
+
txReceipts = gqlTransaction.status.receipts;
|
4795
|
+
}
|
4796
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4541
4797
|
const {
|
4542
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4798
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4543
4799
|
} = provider.getChain();
|
4800
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4544
4801
|
const transactionInfo = assembleTransactionSummary({
|
4545
4802
|
id: gqlTransaction.id,
|
4546
4803
|
receipts,
|
4547
4804
|
transaction: decodedTransaction,
|
4548
4805
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4549
4806
|
gqlTransactionStatus: gqlTransaction.status,
|
4550
|
-
gasPerByte:
|
4551
|
-
gasPriceFactor:
|
4807
|
+
gasPerByte: bn17(gasPerByte),
|
4808
|
+
gasPriceFactor: bn17(gasPriceFactor),
|
4552
4809
|
abiMap,
|
4553
4810
|
maxInputs,
|
4554
|
-
gasCosts
|
4811
|
+
gasCosts,
|
4812
|
+
maxGasPerTx,
|
4813
|
+
gasPrice
|
4555
4814
|
});
|
4556
4815
|
return {
|
4557
4816
|
gqlTransaction,
|
@@ -4561,10 +4820,11 @@ async function getTransactionSummary(params) {
|
|
4561
4820
|
async function getTransactionSummaryFromRequest(params) {
|
4562
4821
|
const { provider, transactionRequest, abiMap } = params;
|
4563
4822
|
const { receipts } = await provider.call(transactionRequest);
|
4564
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4823
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4565
4824
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4566
4825
|
const transaction = transactionRequest.toTransaction();
|
4567
4826
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4827
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4568
4828
|
const transactionSummary = assembleTransactionSummary({
|
4569
4829
|
receipts,
|
4570
4830
|
transaction,
|
@@ -4573,7 +4833,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4573
4833
|
gasPerByte,
|
4574
4834
|
gasPriceFactor,
|
4575
4835
|
maxInputs,
|
4576
|
-
gasCosts
|
4836
|
+
gasCosts,
|
4837
|
+
maxGasPerTx,
|
4838
|
+
gasPrice
|
4577
4839
|
});
|
4578
4840
|
return transactionSummary;
|
4579
4841
|
}
|
@@ -4582,13 +4844,18 @@ async function getTransactionsSummaries(params) {
|
|
4582
4844
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4583
4845
|
const { edges, pageInfo } = transactionsByOwner;
|
4584
4846
|
const {
|
4585
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4847
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4586
4848
|
} = provider.getChain();
|
4849
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4587
4850
|
const transactions = edges.map((edge) => {
|
4588
4851
|
const { node: gqlTransaction } = edge;
|
4589
|
-
const { id, rawPayload,
|
4852
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4590
4853
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4591
|
-
|
4854
|
+
let txReceipts = [];
|
4855
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4856
|
+
txReceipts = gqlTransaction.status.receipts;
|
4857
|
+
}
|
4858
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4592
4859
|
const transactionSummary = assembleTransactionSummary({
|
4593
4860
|
id,
|
4594
4861
|
receipts,
|
@@ -4599,7 +4866,9 @@ async function getTransactionsSummaries(params) {
|
|
4599
4866
|
gasPerByte,
|
4600
4867
|
gasPriceFactor,
|
4601
4868
|
maxInputs,
|
4602
|
-
gasCosts
|
4869
|
+
gasCosts,
|
4870
|
+
maxGasPerTx,
|
4871
|
+
gasPrice
|
4603
4872
|
});
|
4604
4873
|
const output = {
|
4605
4874
|
gqlTransaction,
|
@@ -4931,36 +5200,33 @@ var Account = class extends AbstractAccount {
|
|
4931
5200
|
* @param fee - The estimated transaction fee.
|
4932
5201
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4933
5202
|
*/
|
4934
|
-
async fund(request,
|
4935
|
-
const
|
4936
|
-
|
5203
|
+
async fund(request, params) {
|
5204
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5205
|
+
const txRequest = request;
|
5206
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5207
|
+
amount: bn18(fee),
|
4937
5208
|
assetId: BaseAssetId3,
|
4938
|
-
coinQuantities
|
5209
|
+
coinQuantities: requiredQuantities
|
4939
5210
|
});
|
4940
5211
|
const quantitiesDict = {};
|
4941
|
-
|
5212
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4942
5213
|
quantitiesDict[assetId] = {
|
4943
5214
|
required: amount,
|
4944
|
-
owned:
|
5215
|
+
owned: bn18(0)
|
4945
5216
|
};
|
4946
5217
|
});
|
4947
|
-
|
4948
|
-
const cachedMessages = [];
|
4949
|
-
const owner = this.address.toB256();
|
4950
|
-
request.inputs.forEach((input) => {
|
5218
|
+
txRequest.inputs.forEach((input) => {
|
4951
5219
|
const isResource = "amount" in input;
|
4952
5220
|
if (isResource) {
|
4953
5221
|
const isCoin2 = "owner" in input;
|
4954
5222
|
if (isCoin2) {
|
4955
5223
|
const assetId = String(input.assetId);
|
4956
|
-
if (
|
4957
|
-
const amount =
|
5224
|
+
if (quantitiesDict[assetId]) {
|
5225
|
+
const amount = bn18(input.amount);
|
4958
5226
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4959
|
-
cachedUtxos.push(input.id);
|
4960
5227
|
}
|
4961
|
-
} else if (input.
|
5228
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4962
5229
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4963
|
-
cachedMessages.push(input.nonce);
|
4964
5230
|
}
|
4965
5231
|
}
|
4966
5232
|
});
|
@@ -4975,12 +5241,23 @@ var Account = class extends AbstractAccount {
|
|
4975
5241
|
});
|
4976
5242
|
const needsToBeFunded = missingQuantities.length;
|
4977
5243
|
if (needsToBeFunded) {
|
4978
|
-
const
|
4979
|
-
|
4980
|
-
|
4981
|
-
|
4982
|
-
|
5244
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5245
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5246
|
+
txRequest.addResources(resources);
|
5247
|
+
}
|
5248
|
+
txRequest.shiftPredicateData();
|
5249
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5250
|
+
const requestToBeReEstimate = clone4(txRequest);
|
5251
|
+
if (addedSignatures) {
|
5252
|
+
Array.from({ length: addedSignatures }).forEach(
|
5253
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5254
|
+
);
|
4983
5255
|
}
|
5256
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5257
|
+
transactionRequest: requestToBeReEstimate
|
5258
|
+
});
|
5259
|
+
txRequest.maxFee = maxFee;
|
5260
|
+
return txRequest;
|
4984
5261
|
}
|
4985
5262
|
/**
|
4986
5263
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4988,28 +5265,25 @@ var Account = class extends AbstractAccount {
|
|
4988
5265
|
* @param destination - The address of the destination.
|
4989
5266
|
* @param amount - The amount of coins to transfer.
|
4990
5267
|
* @param assetId - The asset ID of the coins to transfer.
|
4991
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5268
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4992
5269
|
* @returns A promise that resolves to the prepared transaction request.
|
4993
5270
|
*/
|
4994
5271
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4995
|
-
const
|
4996
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4997
|
-
const request = new ScriptTransactionRequest(params);
|
5272
|
+
const request = new ScriptTransactionRequest(txParams);
|
4998
5273
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4999
|
-
const
|
5274
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5000
5275
|
estimateTxDependencies: true,
|
5001
5276
|
resourcesOwner: this
|
5002
5277
|
});
|
5003
|
-
|
5004
|
-
|
5005
|
-
|
5006
|
-
|
5007
|
-
|
5008
|
-
|
5009
|
-
|
5010
|
-
|
5011
|
-
await this.fund(request,
|
5012
|
-
request.updatePredicateInputs(estimatedInputs);
|
5278
|
+
if ("gasLimit" in txParams) {
|
5279
|
+
this.validateGas({
|
5280
|
+
gasUsed: txCost.gasUsed,
|
5281
|
+
gasLimit: request.gasLimit
|
5282
|
+
});
|
5283
|
+
}
|
5284
|
+
request.gasLimit = txCost.gasUsed;
|
5285
|
+
request.maxFee = txCost.maxFee;
|
5286
|
+
await this.fund(request, txCost);
|
5013
5287
|
return request;
|
5014
5288
|
}
|
5015
5289
|
/**
|
@@ -5022,7 +5296,7 @@ var Account = class extends AbstractAccount {
|
|
5022
5296
|
* @returns A promise that resolves to the transaction response.
|
5023
5297
|
*/
|
5024
5298
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5025
|
-
if (
|
5299
|
+
if (bn18(amount).lte(0)) {
|
5026
5300
|
throw new FuelError15(
|
5027
5301
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5028
5302
|
"Transfer amount must be a positive number."
|
@@ -5041,38 +5315,37 @@ var Account = class extends AbstractAccount {
|
|
5041
5315
|
* @returns A promise that resolves to the transaction response.
|
5042
5316
|
*/
|
5043
5317
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5044
|
-
if (
|
5318
|
+
if (bn18(amount).lte(0)) {
|
5045
5319
|
throw new FuelError15(
|
5046
5320
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5047
5321
|
"Transfer amount must be a positive number."
|
5048
5322
|
);
|
5049
5323
|
}
|
5050
5324
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5051
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5052
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5053
5325
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5054
5326
|
hexlifiedContractId: contractAddress.toB256(),
|
5055
|
-
amountToTransfer:
|
5327
|
+
amountToTransfer: bn18(amount),
|
5056
5328
|
assetId
|
5057
5329
|
});
|
5058
5330
|
const request = new ScriptTransactionRequest({
|
5059
|
-
...
|
5331
|
+
...txParams,
|
5060
5332
|
script,
|
5061
5333
|
scriptData
|
5062
5334
|
});
|
5063
5335
|
request.addContractInputAndOutput(contractAddress);
|
5064
|
-
const
|
5065
|
-
|
5066
|
-
[{ amount:
|
5067
|
-
);
|
5068
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5069
|
-
this.validateGas({
|
5070
|
-
gasUsed,
|
5071
|
-
gasPrice: request.gasPrice,
|
5072
|
-
gasLimit: request.gasLimit,
|
5073
|
-
minGasPrice
|
5336
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5337
|
+
resourcesOwner: this,
|
5338
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
5074
5339
|
});
|
5075
|
-
|
5340
|
+
if (txParams.gasLimit) {
|
5341
|
+
this.validateGas({
|
5342
|
+
gasUsed: txCost.gasUsed,
|
5343
|
+
gasLimit: request.gasLimit
|
5344
|
+
});
|
5345
|
+
}
|
5346
|
+
request.gasLimit = txCost.gasUsed;
|
5347
|
+
request.maxFee = txCost.maxFee;
|
5348
|
+
await this.fund(request, txCost);
|
5076
5349
|
return this.sendTransaction(request);
|
5077
5350
|
}
|
5078
5351
|
/**
|
@@ -5084,34 +5357,31 @@ var Account = class extends AbstractAccount {
|
|
5084
5357
|
* @returns A promise that resolves to the transaction response.
|
5085
5358
|
*/
|
5086
5359
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5087
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5088
5360
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5089
5361
|
const recipientDataArray = arrayify14(
|
5090
5362
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5091
5363
|
);
|
5092
5364
|
const amountDataArray = arrayify14(
|
5093
|
-
"0x".concat(
|
5365
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
5094
5366
|
);
|
5095
5367
|
const script = new Uint8Array([
|
5096
5368
|
...arrayify14(withdrawScript.bytes),
|
5097
5369
|
...recipientDataArray,
|
5098
5370
|
...amountDataArray
|
5099
5371
|
]);
|
5100
|
-
const params = { script,
|
5372
|
+
const params = { script, ...txParams };
|
5101
5373
|
const request = new ScriptTransactionRequest(params);
|
5102
|
-
const
|
5103
|
-
const
|
5104
|
-
|
5105
|
-
|
5106
|
-
|
5107
|
-
|
5108
|
-
|
5109
|
-
|
5110
|
-
|
5111
|
-
|
5112
|
-
|
5113
|
-
});
|
5114
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5374
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5375
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5376
|
+
if (txParams.gasLimit) {
|
5377
|
+
this.validateGas({
|
5378
|
+
gasUsed: txCost.gasUsed,
|
5379
|
+
gasLimit: request.gasLimit
|
5380
|
+
});
|
5381
|
+
}
|
5382
|
+
request.maxFee = txCost.maxFee;
|
5383
|
+
request.gasLimit = txCost.gasUsed;
|
5384
|
+
await this.fund(request, txCost);
|
5115
5385
|
return this.sendTransaction(request);
|
5116
5386
|
}
|
5117
5387
|
async signMessage(message) {
|
@@ -5169,18 +5439,7 @@ var Account = class extends AbstractAccount {
|
|
5169
5439
|
}
|
5170
5440
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5171
5441
|
}
|
5172
|
-
validateGas({
|
5173
|
-
gasUsed,
|
5174
|
-
gasPrice,
|
5175
|
-
gasLimit,
|
5176
|
-
minGasPrice
|
5177
|
-
}) {
|
5178
|
-
if (minGasPrice.gt(gasPrice)) {
|
5179
|
-
throw new FuelError15(
|
5180
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5181
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5182
|
-
);
|
5183
|
-
}
|
5442
|
+
validateGas({ gasUsed, gasLimit }) {
|
5184
5443
|
if (gasUsed.gt(gasLimit)) {
|
5185
5444
|
throw new FuelError15(
|
5186
5445
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5196,7 +5455,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5196
5455
|
|
5197
5456
|
// src/signer/signer.ts
|
5198
5457
|
import { Address as Address4 } from "@fuel-ts/address";
|
5199
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5458
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
5200
5459
|
import { hash } from "@fuel-ts/hasher";
|
5201
5460
|
import { toBytes } from "@fuel-ts/math";
|
5202
5461
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5289,7 +5548,7 @@ var Signer = class {
|
|
5289
5548
|
* @returns random 32-byte hashed
|
5290
5549
|
*/
|
5291
5550
|
static generatePrivateKey(entropy) {
|
5292
|
-
return entropy ? hash(concat3([
|
5551
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5293
5552
|
}
|
5294
5553
|
/**
|
5295
5554
|
* Extended publicKey from a compact publicKey
|
@@ -5308,7 +5567,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5308
5567
|
import {
|
5309
5568
|
bufferFromString,
|
5310
5569
|
keccak256,
|
5311
|
-
randomBytes as
|
5570
|
+
randomBytes as randomBytes3,
|
5312
5571
|
scrypt,
|
5313
5572
|
stringFromBuffer,
|
5314
5573
|
decryptJsonWalletData,
|
@@ -5331,7 +5590,7 @@ var removeHexPrefix = (hexString) => {
|
|
5331
5590
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5332
5591
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5333
5592
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5334
|
-
const salt =
|
5593
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5335
5594
|
const key = scrypt({
|
5336
5595
|
password: bufferFromString(password),
|
5337
5596
|
salt,
|
@@ -5340,7 +5599,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5340
5599
|
r: DEFAULT_KDF_PARAMS_R,
|
5341
5600
|
p: DEFAULT_KDF_PARAMS_P
|
5342
5601
|
});
|
5343
|
-
const iv =
|
5602
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5344
5603
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5345
5604
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5346
5605
|
const macHashUint8Array = keccak256(data);
|
@@ -5476,7 +5735,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5476
5735
|
* @param transactionRequestLike - The transaction request to send.
|
5477
5736
|
* @returns A promise that resolves to the TransactionResponse object.
|
5478
5737
|
*/
|
5479
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5738
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5480
5739
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5481
5740
|
if (estimateTxDependencies) {
|
5482
5741
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5517,12 +5776,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5517
5776
|
// src/hdwallet/hdwallet.ts
|
5518
5777
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5519
5778
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5520
|
-
import { bn as
|
5779
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5521
5780
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5522
5781
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5523
5782
|
|
5524
5783
|
// src/mnemonic/mnemonic.ts
|
5525
|
-
import { randomBytes as
|
5784
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5526
5785
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5527
5786
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5528
5787
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7883,7 +8142,7 @@ var Mnemonic = class {
|
|
7883
8142
|
* @returns A randomly generated mnemonic
|
7884
8143
|
*/
|
7885
8144
|
static generate(size = 32, extraEntropy = "") {
|
7886
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
8145
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7887
8146
|
return Mnemonic.entropyToMnemonic(entropy);
|
7888
8147
|
}
|
7889
8148
|
};
|
@@ -7989,7 +8248,7 @@ var HDWallet = class {
|
|
7989
8248
|
const IR = bytes.slice(32);
|
7990
8249
|
if (privateKey) {
|
7991
8250
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7992
|
-
const ki =
|
8251
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7993
8252
|
return new HDWallet({
|
7994
8253
|
privateKey: ki,
|
7995
8254
|
chainCode: IR,
|
@@ -8678,7 +8937,7 @@ import {
|
|
8678
8937
|
import { Address as Address9 } from "@fuel-ts/address";
|
8679
8938
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8680
8939
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8681
|
-
import { ByteArrayCoder, InputType as
|
8940
|
+
import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
|
8682
8941
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8683
8942
|
|
8684
8943
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8738,9 +8997,9 @@ var Predicate = class extends Account {
|
|
8738
8997
|
const request = transactionRequestify(transactionRequestLike);
|
8739
8998
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8740
8999
|
request.inputs?.forEach((input) => {
|
8741
|
-
if (input.type ===
|
8742
|
-
input.predicate = this.bytes;
|
8743
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9000
|
+
if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
9001
|
+
input.predicate = hexlify19(this.bytes);
|
9002
|
+
input.predicateData = hexlify19(this.getPredicateData(policies.length));
|
8744
9003
|
}
|
8745
9004
|
});
|
8746
9005
|
return request;
|
@@ -8755,8 +9014,7 @@ var Predicate = class extends Account {
|
|
8755
9014
|
* @returns A promise that resolves to the prepared transaction request.
|
8756
9015
|
*/
|
8757
9016
|
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8758
|
-
|
8759
|
-
return this.populateTransactionPredicateData(request);
|
9017
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8760
9018
|
}
|
8761
9019
|
/**
|
8762
9020
|
* Sends a transaction with the populated predicate data.
|
@@ -8764,9 +9022,9 @@ var Predicate = class extends Account {
|
|
8764
9022
|
* @param transactionRequestLike - The transaction request-like object.
|
8765
9023
|
* @returns A promise that resolves to the transaction response.
|
8766
9024
|
*/
|
8767
|
-
sendTransaction(transactionRequestLike
|
8768
|
-
const transactionRequest =
|
8769
|
-
return super.sendTransaction(transactionRequest,
|
9025
|
+
sendTransaction(transactionRequestLike) {
|
9026
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9027
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8770
9028
|
}
|
8771
9029
|
/**
|
8772
9030
|
* Simulates a transaction with the populated predicate data.
|
@@ -8775,8 +9033,8 @@ var Predicate = class extends Account {
|
|
8775
9033
|
* @returns A promise that resolves to the call result.
|
8776
9034
|
*/
|
8777
9035
|
simulateTransaction(transactionRequestLike) {
|
8778
|
-
const transactionRequest =
|
8779
|
-
return super.simulateTransaction(transactionRequest);
|
9036
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9037
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8780
9038
|
}
|
8781
9039
|
getPredicateData(policiesLength) {
|
8782
9040
|
if (!this.predicateData.length) {
|
@@ -8822,6 +9080,25 @@ var Predicate = class extends Account {
|
|
8822
9080
|
predicateInterface: abiInterface
|
8823
9081
|
};
|
8824
9082
|
}
|
9083
|
+
/**
|
9084
|
+
* Retrieves resources satisfying the spend query for the account.
|
9085
|
+
*
|
9086
|
+
* @param quantities - IDs of coins to exclude.
|
9087
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9088
|
+
* @returns A promise that resolves to an array of Resources.
|
9089
|
+
*/
|
9090
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9091
|
+
const resources = await this.provider.getResourcesToSpend(
|
9092
|
+
this.address,
|
9093
|
+
quantities,
|
9094
|
+
excludedIds
|
9095
|
+
);
|
9096
|
+
return resources.map((resource) => ({
|
9097
|
+
...resource,
|
9098
|
+
predicate: hexlify19(this.bytes),
|
9099
|
+
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9100
|
+
}));
|
9101
|
+
}
|
8825
9102
|
/**
|
8826
9103
|
* Sets the configurable constants for the predicate.
|
8827
9104
|
*
|
@@ -9570,7 +9847,7 @@ export {
|
|
9570
9847
|
WalletLocked,
|
9571
9848
|
WalletManager,
|
9572
9849
|
WalletUnlocked,
|
9573
|
-
|
9850
|
+
addAmountToCoinQuantities,
|
9574
9851
|
addOperation,
|
9575
9852
|
assemblePanicError,
|
9576
9853
|
assembleReceiptByType,
|
@@ -9579,9 +9856,10 @@ export {
|
|
9579
9856
|
assets,
|
9580
9857
|
buildBlockExplorerUrl,
|
9581
9858
|
cacheFor,
|
9859
|
+
cacheTxInputsFromOwner,
|
9860
|
+
calculateGasFee,
|
9582
9861
|
calculateMetadataGasForTxCreate,
|
9583
9862
|
calculateMetadataGasForTxScript,
|
9584
|
-
calculatePriceWithFactor,
|
9585
9863
|
calculateTransactionFee,
|
9586
9864
|
coinQuantityfy,
|
9587
9865
|
deferPromise,
|