@fuel-ts/account 0.0.0-rc-2021-20240410132122 → 0.0.0-rc-1976-20240410141707
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +615 -871
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +609 -851
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +452 -693
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -11
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +328 -894
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -45
- 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 +29 -9
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1116 -1585
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +606 -826
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +464 -684
- 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.js
CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
|
|
95
95
|
WalletLocked: () => WalletLocked,
|
96
96
|
WalletManager: () => WalletManager,
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
|
-
|
98
|
+
addAmountToAsset: () => addAmountToAsset,
|
99
99
|
addOperation: () => addOperation,
|
100
100
|
assemblePanicError: () => assemblePanicError,
|
101
101
|
assembleReceiptByType: () => assembleReceiptByType,
|
@@ -104,10 +104,9 @@ __export(src_exports, {
|
|
104
104
|
assets: () => assets,
|
105
105
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
106
106
|
cacheFor: () => cacheFor,
|
107
|
-
cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
|
108
|
-
calculateGasFee: () => calculateGasFee,
|
109
107
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
110
108
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
109
|
+
calculatePriceWithFactor: () => calculatePriceWithFactor,
|
111
110
|
calculateTransactionFee: () => calculateTransactionFee,
|
112
111
|
coinQuantityfy: () => coinQuantityfy,
|
113
112
|
deferPromise: () => deferPromise,
|
@@ -185,38 +184,35 @@ module.exports = __toCommonJS(src_exports);
|
|
185
184
|
|
186
185
|
// src/account.ts
|
187
186
|
var import_address4 = require("@fuel-ts/address");
|
188
|
-
var import_configs12 = require("@fuel-ts/address/configs");
|
189
187
|
var import_errors16 = require("@fuel-ts/errors");
|
190
188
|
var import_interfaces = require("@fuel-ts/interfaces");
|
191
|
-
var
|
192
|
-
var
|
193
|
-
var import_ramda4 = require("ramda");
|
189
|
+
var import_math18 = require("@fuel-ts/math");
|
190
|
+
var import_utils28 = require("@fuel-ts/utils");
|
194
191
|
|
195
192
|
// src/providers/coin-quantity.ts
|
196
|
-
var import_configs = require("@fuel-ts/address/configs");
|
197
193
|
var import_math = require("@fuel-ts/math");
|
198
194
|
var import_utils = require("@fuel-ts/utils");
|
199
195
|
var coinQuantityfy = (coinQuantityLike) => {
|
200
196
|
let assetId;
|
201
197
|
let amount;
|
202
|
-
let
|
198
|
+
let max2;
|
203
199
|
if (Array.isArray(coinQuantityLike)) {
|
204
200
|
amount = coinQuantityLike[0];
|
205
|
-
assetId = coinQuantityLike[1]
|
206
|
-
|
201
|
+
assetId = coinQuantityLike[1];
|
202
|
+
max2 = coinQuantityLike[2];
|
207
203
|
} else {
|
208
204
|
amount = coinQuantityLike.amount;
|
209
|
-
assetId = coinQuantityLike.assetId
|
210
|
-
|
205
|
+
assetId = coinQuantityLike.assetId;
|
206
|
+
max2 = coinQuantityLike.max ?? void 0;
|
211
207
|
}
|
212
208
|
const bnAmount = (0, import_math.bn)(amount);
|
213
209
|
return {
|
214
210
|
assetId: (0, import_utils.hexlify)(assetId),
|
215
211
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
216
|
-
max:
|
212
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
217
213
|
};
|
218
214
|
};
|
219
|
-
var
|
215
|
+
var addAmountToAsset = (params) => {
|
220
216
|
const { amount, assetId } = params;
|
221
217
|
const coinQuantities = [...params.coinQuantities];
|
222
218
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -231,12 +227,12 @@ var addAmountToCoinQuantities = (params) => {
|
|
231
227
|
// src/providers/provider.ts
|
232
228
|
var import_address3 = require("@fuel-ts/address");
|
233
229
|
var import_errors14 = require("@fuel-ts/errors");
|
234
|
-
var
|
235
|
-
var
|
236
|
-
var
|
230
|
+
var import_math15 = require("@fuel-ts/math");
|
231
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
232
|
+
var import_utils23 = require("@fuel-ts/utils");
|
237
233
|
var import_versions = require("@fuel-ts/versions");
|
238
|
-
var
|
239
|
-
var
|
234
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
235
|
+
var import_ethers = require("ethers");
|
240
236
|
var import_graphql_request = require("graphql-request");
|
241
237
|
var import_ramda3 = require("ramda");
|
242
238
|
|
@@ -244,10 +240,14 @@ var import_ramda3 = require("ramda");
|
|
244
240
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
245
241
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
246
242
|
fragment receiptFragment on Receipt {
|
247
|
-
|
243
|
+
contract {
|
244
|
+
id
|
245
|
+
}
|
248
246
|
pc
|
249
247
|
is
|
250
|
-
to
|
248
|
+
to {
|
249
|
+
id
|
250
|
+
}
|
251
251
|
toAddress
|
252
252
|
amount
|
253
253
|
assetId
|
@@ -285,16 +285,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
285
285
|
id
|
286
286
|
}
|
287
287
|
time
|
288
|
-
receipts {
|
289
|
-
...receiptFragment
|
290
|
-
}
|
291
288
|
programState {
|
292
289
|
returnType
|
293
290
|
data
|
294
291
|
}
|
295
|
-
receipts {
|
296
|
-
...receiptFragment
|
297
|
-
}
|
298
292
|
}
|
299
293
|
... on FailureStatus {
|
300
294
|
block {
|
@@ -302,24 +296,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
302
296
|
}
|
303
297
|
time
|
304
298
|
reason
|
305
|
-
receipts {
|
306
|
-
...receiptFragment
|
307
|
-
}
|
308
299
|
}
|
309
300
|
... on SqueezedOutStatus {
|
310
301
|
reason
|
311
302
|
}
|
312
303
|
}
|
313
|
-
|
304
|
+
`;
|
314
305
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
315
306
|
fragment transactionFragment on Transaction {
|
316
307
|
id
|
317
308
|
rawPayload
|
309
|
+
gasPrice
|
310
|
+
receipts {
|
311
|
+
...receiptFragment
|
312
|
+
}
|
318
313
|
status {
|
319
314
|
...transactionStatusFragment
|
320
315
|
}
|
321
316
|
}
|
322
|
-
${
|
317
|
+
${ReceiptFragmentFragmentDoc}
|
318
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
323
319
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
324
320
|
fragment inputEstimatePredicatesFragment on Input {
|
325
321
|
... on InputCoin {
|
@@ -337,46 +333,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
337
333
|
}
|
338
334
|
}
|
339
335
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
340
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
341
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
342
|
-
reason
|
343
|
-
programState {
|
344
|
-
returnType
|
345
|
-
data
|
346
|
-
}
|
347
|
-
}
|
348
|
-
`;
|
349
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
350
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
351
|
-
programState {
|
352
|
-
returnType
|
353
|
-
data
|
354
|
-
}
|
355
|
-
}
|
356
|
-
`;
|
357
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
358
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
359
|
-
... on DryRunFailureStatus {
|
360
|
-
...dryRunFailureStatusFragment
|
361
|
-
}
|
362
|
-
... on DryRunSuccessStatus {
|
363
|
-
...dryRunSuccessStatusFragment
|
364
|
-
}
|
365
|
-
}
|
366
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
367
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
368
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
370
|
-
id
|
371
|
-
status {
|
372
|
-
...dryRunTransactionStatusFragment
|
373
|
-
}
|
374
|
-
receipts {
|
375
|
-
...receiptFragment
|
376
|
-
}
|
377
|
-
}
|
378
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
379
|
-
${ReceiptFragmentFragmentDoc}`;
|
380
336
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
381
337
|
fragment coinFragment on Coin {
|
382
338
|
__typename
|
@@ -384,6 +340,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
384
340
|
owner
|
385
341
|
amount
|
386
342
|
assetId
|
343
|
+
maturity
|
387
344
|
blockCreated
|
388
345
|
txCreatedIdx
|
389
346
|
}
|
@@ -428,6 +385,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
428
385
|
prevRoot
|
429
386
|
time
|
430
387
|
applicationHash
|
388
|
+
messageReceiptRoot
|
431
389
|
messageReceiptCount
|
432
390
|
}
|
433
391
|
commitBlockHeader {
|
@@ -439,6 +397,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
439
397
|
prevRoot
|
440
398
|
time
|
441
399
|
applicationHash
|
400
|
+
messageReceiptRoot
|
442
401
|
messageReceiptCount
|
443
402
|
}
|
444
403
|
sender
|
@@ -458,8 +417,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
458
417
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
459
418
|
fragment blockFragment on Block {
|
460
419
|
id
|
461
|
-
height
|
462
420
|
header {
|
421
|
+
height
|
463
422
|
time
|
464
423
|
}
|
465
424
|
transactions {
|
@@ -517,11 +476,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
517
476
|
`;
|
518
477
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
519
478
|
fragment GasCostsFragment on GasCosts {
|
520
|
-
version {
|
521
|
-
... on Version {
|
522
|
-
value
|
523
|
-
}
|
524
|
-
}
|
525
479
|
add
|
526
480
|
addi
|
527
481
|
aloc
|
@@ -534,6 +488,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
534
488
|
cb
|
535
489
|
cfei
|
536
490
|
cfsi
|
491
|
+
croo
|
537
492
|
div
|
538
493
|
divi
|
539
494
|
ecr1
|
@@ -616,9 +571,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
616
571
|
ccp {
|
617
572
|
...DependentCostFragment
|
618
573
|
}
|
619
|
-
croo {
|
620
|
-
...DependentCostFragment
|
621
|
-
}
|
622
574
|
csiz {
|
623
575
|
...DependentCostFragment
|
624
576
|
}
|
@@ -678,11 +630,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
678
630
|
${DependentCostFragmentFragmentDoc}`;
|
679
631
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
680
632
|
fragment consensusParametersFragment on ConsensusParameters {
|
681
|
-
version {
|
682
|
-
... on Version {
|
683
|
-
value
|
684
|
-
}
|
685
|
-
}
|
686
633
|
txParams {
|
687
634
|
...TxParametersFragment
|
688
635
|
}
|
@@ -742,9 +689,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
742
689
|
fragment nodeInfoFragment on NodeInfo {
|
743
690
|
utxoValidation
|
744
691
|
vmBacktrace
|
692
|
+
minGasPrice
|
745
693
|
maxTx
|
746
694
|
maxDepth
|
747
695
|
nodeVersion
|
696
|
+
peers {
|
697
|
+
id
|
698
|
+
addresses
|
699
|
+
clientVersion
|
700
|
+
blockHeight
|
701
|
+
lastHeartbeatMs
|
702
|
+
appScore
|
703
|
+
}
|
748
704
|
}
|
749
705
|
`;
|
750
706
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -779,9 +735,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
779
735
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
780
736
|
transaction(id: $transactionId) {
|
781
737
|
...transactionFragment
|
738
|
+
receipts {
|
739
|
+
...receiptFragment
|
740
|
+
}
|
782
741
|
}
|
783
742
|
}
|
784
|
-
${TransactionFragmentFragmentDoc}
|
743
|
+
${TransactionFragmentFragmentDoc}
|
744
|
+
${ReceiptFragmentFragmentDoc}`;
|
785
745
|
var GetTransactionsDocument = import_graphql_tag.default`
|
786
746
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
787
747
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -909,20 +869,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
909
869
|
}
|
910
870
|
}
|
911
871
|
${BalanceFragmentFragmentDoc}`;
|
912
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
913
|
-
query getLatestGasPrice {
|
914
|
-
latestGasPrice {
|
915
|
-
gasPrice
|
916
|
-
}
|
917
|
-
}
|
918
|
-
`;
|
919
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
920
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
921
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
922
|
-
gasPrice
|
923
|
-
}
|
924
|
-
}
|
925
|
-
`;
|
926
872
|
var GetBalancesDocument = import_graphql_tag.default`
|
927
873
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
928
874
|
balances(
|
@@ -977,12 +923,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
977
923
|
}
|
978
924
|
`;
|
979
925
|
var DryRunDocument = import_graphql_tag.default`
|
980
|
-
mutation dryRun($
|
981
|
-
dryRun(
|
982
|
-
...
|
926
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
927
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
928
|
+
...receiptFragment
|
983
929
|
}
|
984
930
|
}
|
985
|
-
${
|
931
|
+
${ReceiptFragmentFragmentDoc}`;
|
986
932
|
var SubmitDocument = import_graphql_tag.default`
|
987
933
|
mutation submit($encodedTransaction: HexString!) {
|
988
934
|
submit(tx: $encodedTransaction) {
|
@@ -1065,12 +1011,6 @@ function getSdk(requester) {
|
|
1065
1011
|
getBalance(variables, options) {
|
1066
1012
|
return requester(GetBalanceDocument, variables, options);
|
1067
1013
|
},
|
1068
|
-
getLatestGasPrice(variables, options) {
|
1069
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
1070
|
-
},
|
1071
|
-
estimateGasPrice(variables, options) {
|
1072
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
1073
|
-
},
|
1074
1014
|
getBalances(variables, options) {
|
1075
1015
|
return requester(GetBalancesDocument, variables, options);
|
1076
1016
|
},
|
@@ -1140,14 +1080,11 @@ var _FuelGraphqlSubscriber = class {
|
|
1140
1080
|
let data;
|
1141
1081
|
let errors;
|
1142
1082
|
try {
|
1143
|
-
|
1144
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
1083
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
1145
1084
|
} catch (e) {
|
1146
1085
|
throw new import_errors.FuelError(
|
1147
1086
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
1148
|
-
`Error while parsing stream data response: ${text}
|
1149
|
-
|
1150
|
-
Thrown error: ${e}`
|
1087
|
+
`Error while parsing stream data response: ${text}`
|
1151
1088
|
);
|
1152
1089
|
}
|
1153
1090
|
if (Array.isArray(errors)) {
|
@@ -1234,7 +1171,7 @@ var MemoryCache = class {
|
|
1234
1171
|
};
|
1235
1172
|
|
1236
1173
|
// src/providers/transaction-request/input.ts
|
1237
|
-
var
|
1174
|
+
var import_configs = require("@fuel-ts/address/configs");
|
1238
1175
|
var import_errors3 = require("@fuel-ts/errors");
|
1239
1176
|
var import_math2 = require("@fuel-ts/math");
|
1240
1177
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1248,7 +1185,7 @@ var inputify = (value) => {
|
|
1248
1185
|
return {
|
1249
1186
|
type: import_transactions.InputType.Coin,
|
1250
1187
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1251
|
-
outputIndex: (0,
|
1188
|
+
outputIndex: (0, import_utils3.arrayify)(value.id)[32],
|
1252
1189
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1253
1190
|
amount: (0, import_math2.bn)(value.amount),
|
1254
1191
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1257,9 +1194,10 @@ var inputify = (value) => {
|
|
1257
1194
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1258
1195
|
},
|
1259
1196
|
witnessIndex: value.witnessIndex,
|
1197
|
+
maturity: value.maturity ?? 0,
|
1260
1198
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1261
|
-
predicateLength:
|
1262
|
-
predicateDataLength:
|
1199
|
+
predicateLength: predicate.length,
|
1200
|
+
predicateDataLength: predicateData.length,
|
1263
1201
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1264
1202
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1265
1203
|
};
|
@@ -1267,10 +1205,10 @@ var inputify = (value) => {
|
|
1267
1205
|
case import_transactions.InputType.Contract: {
|
1268
1206
|
return {
|
1269
1207
|
type: import_transactions.InputType.Contract,
|
1270
|
-
txID:
|
1208
|
+
txID: import_configs.ZeroBytes32,
|
1271
1209
|
outputIndex: 0,
|
1272
|
-
balanceRoot:
|
1273
|
-
stateRoot:
|
1210
|
+
balanceRoot: import_configs.ZeroBytes32,
|
1211
|
+
stateRoot: import_configs.ZeroBytes32,
|
1274
1212
|
txPointer: {
|
1275
1213
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1276
1214
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1290,8 +1228,8 @@ var inputify = (value) => {
|
|
1290
1228
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1291
1229
|
witnessIndex: value.witnessIndex,
|
1292
1230
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1293
|
-
predicateLength:
|
1294
|
-
predicateDataLength:
|
1231
|
+
predicateLength: predicate.length,
|
1232
|
+
predicateDataLength: predicateData.length,
|
1295
1233
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1296
1234
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1297
1235
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1308,7 +1246,7 @@ var inputify = (value) => {
|
|
1308
1246
|
};
|
1309
1247
|
|
1310
1248
|
// src/providers/transaction-request/output.ts
|
1311
|
-
var
|
1249
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1312
1250
|
var import_errors4 = require("@fuel-ts/errors");
|
1313
1251
|
var import_math3 = require("@fuel-ts/math");
|
1314
1252
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1328,8 +1266,8 @@ var outputify = (value) => {
|
|
1328
1266
|
return {
|
1329
1267
|
type: import_transactions2.OutputType.Contract,
|
1330
1268
|
inputIndex: value.inputIndex,
|
1331
|
-
balanceRoot:
|
1332
|
-
stateRoot:
|
1269
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1270
|
+
stateRoot: import_configs2.ZeroBytes32
|
1333
1271
|
};
|
1334
1272
|
}
|
1335
1273
|
case import_transactions2.OutputType.Change: {
|
@@ -1343,9 +1281,9 @@ var outputify = (value) => {
|
|
1343
1281
|
case import_transactions2.OutputType.Variable: {
|
1344
1282
|
return {
|
1345
1283
|
type: import_transactions2.OutputType.Variable,
|
1346
|
-
to:
|
1284
|
+
to: import_configs2.ZeroBytes32,
|
1347
1285
|
amount: (0, import_math3.bn)(0),
|
1348
|
-
assetId:
|
1286
|
+
assetId: import_configs2.ZeroBytes32
|
1349
1287
|
};
|
1350
1288
|
}
|
1351
1289
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1366,11 +1304,10 @@ var outputify = (value) => {
|
|
1366
1304
|
|
1367
1305
|
// src/providers/transaction-request/transaction-request.ts
|
1368
1306
|
var import_address = require("@fuel-ts/address");
|
1369
|
-
var
|
1307
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1370
1308
|
var import_math7 = require("@fuel-ts/math");
|
1371
1309
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1372
1310
|
var import_utils9 = require("@fuel-ts/utils");
|
1373
|
-
var import_ethers = require("ethers");
|
1374
1311
|
|
1375
1312
|
// src/providers/resource.ts
|
1376
1313
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1379,13 +1316,13 @@ var isCoin = (resource) => "id" in resource;
|
|
1379
1316
|
var isMessage = (resource) => "recipient" in resource;
|
1380
1317
|
|
1381
1318
|
// src/providers/utils/receipts.ts
|
1382
|
-
var
|
1319
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1383
1320
|
var import_errors5 = require("@fuel-ts/errors");
|
1384
1321
|
var import_math4 = require("@fuel-ts/math");
|
1385
1322
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1386
|
-
var
|
1323
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
1387
1324
|
var import_utils5 = require("@fuel-ts/utils");
|
1388
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1325
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1389
1326
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1390
1327
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1391
1328
|
(memo, receipt) => {
|
@@ -1402,15 +1339,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1402
1339
|
missingOutputContractIds: []
|
1403
1340
|
}
|
1404
1341
|
);
|
1405
|
-
var hexOrZero = (hex) => hex ||
|
1342
|
+
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
1406
1343
|
function assembleReceiptByType(receipt) {
|
1407
1344
|
const { receiptType } = receipt;
|
1408
1345
|
switch (receiptType) {
|
1409
1346
|
case "CALL" /* Call */: {
|
1410
1347
|
const callReceipt = {
|
1411
1348
|
type: import_transactions3.ReceiptType.Call,
|
1412
|
-
from: hexOrZero(receipt.id
|
1413
|
-
to: hexOrZero(receipt?.to),
|
1349
|
+
from: hexOrZero(receipt.contract?.id),
|
1350
|
+
to: hexOrZero(receipt?.to?.id),
|
1414
1351
|
amount: (0, import_math4.bn)(receipt.amount),
|
1415
1352
|
assetId: hexOrZero(receipt.assetId),
|
1416
1353
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1424,7 +1361,7 @@ function assembleReceiptByType(receipt) {
|
|
1424
1361
|
case "RETURN" /* Return */: {
|
1425
1362
|
const returnReceipt = {
|
1426
1363
|
type: import_transactions3.ReceiptType.Return,
|
1427
|
-
id: hexOrZero(receipt.id
|
1364
|
+
id: hexOrZero(receipt.contract?.id),
|
1428
1365
|
val: (0, import_math4.bn)(receipt.val),
|
1429
1366
|
pc: (0, import_math4.bn)(receipt.pc),
|
1430
1367
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1434,7 +1371,7 @@ function assembleReceiptByType(receipt) {
|
|
1434
1371
|
case "RETURN_DATA" /* ReturnData */: {
|
1435
1372
|
const returnDataReceipt = {
|
1436
1373
|
type: import_transactions3.ReceiptType.ReturnData,
|
1437
|
-
id: hexOrZero(receipt.id
|
1374
|
+
id: hexOrZero(receipt.contract?.id),
|
1438
1375
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1439
1376
|
len: (0, import_math4.bn)(receipt.len),
|
1440
1377
|
digest: hexOrZero(receipt.digest),
|
@@ -1446,7 +1383,7 @@ function assembleReceiptByType(receipt) {
|
|
1446
1383
|
case "PANIC" /* Panic */: {
|
1447
1384
|
const panicReceipt = {
|
1448
1385
|
type: import_transactions3.ReceiptType.Panic,
|
1449
|
-
id: hexOrZero(receipt.id),
|
1386
|
+
id: hexOrZero(receipt.contract?.id),
|
1450
1387
|
reason: (0, import_math4.bn)(receipt.reason),
|
1451
1388
|
pc: (0, import_math4.bn)(receipt.pc),
|
1452
1389
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1457,7 +1394,7 @@ function assembleReceiptByType(receipt) {
|
|
1457
1394
|
case "REVERT" /* Revert */: {
|
1458
1395
|
const revertReceipt = {
|
1459
1396
|
type: import_transactions3.ReceiptType.Revert,
|
1460
|
-
id: hexOrZero(receipt.id
|
1397
|
+
id: hexOrZero(receipt.contract?.id),
|
1461
1398
|
val: (0, import_math4.bn)(receipt.ra),
|
1462
1399
|
pc: (0, import_math4.bn)(receipt.pc),
|
1463
1400
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1467,7 +1404,7 @@ function assembleReceiptByType(receipt) {
|
|
1467
1404
|
case "LOG" /* Log */: {
|
1468
1405
|
const logReceipt = {
|
1469
1406
|
type: import_transactions3.ReceiptType.Log,
|
1470
|
-
id: hexOrZero(receipt.id
|
1407
|
+
id: hexOrZero(receipt.contract?.id),
|
1471
1408
|
val0: (0, import_math4.bn)(receipt.ra),
|
1472
1409
|
val1: (0, import_math4.bn)(receipt.rb),
|
1473
1410
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1480,7 +1417,7 @@ function assembleReceiptByType(receipt) {
|
|
1480
1417
|
case "LOG_DATA" /* LogData */: {
|
1481
1418
|
const logDataReceipt = {
|
1482
1419
|
type: import_transactions3.ReceiptType.LogData,
|
1483
|
-
id: hexOrZero(receipt.id
|
1420
|
+
id: hexOrZero(receipt.contract?.id),
|
1484
1421
|
val0: (0, import_math4.bn)(receipt.ra),
|
1485
1422
|
val1: (0, import_math4.bn)(receipt.rb),
|
1486
1423
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1494,8 +1431,8 @@ function assembleReceiptByType(receipt) {
|
|
1494
1431
|
case "TRANSFER" /* Transfer */: {
|
1495
1432
|
const transferReceipt = {
|
1496
1433
|
type: import_transactions3.ReceiptType.Transfer,
|
1497
|
-
from: hexOrZero(receipt.id
|
1498
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1434
|
+
from: hexOrZero(receipt.contract?.id),
|
1435
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1499
1436
|
amount: (0, import_math4.bn)(receipt.amount),
|
1500
1437
|
assetId: hexOrZero(receipt.assetId),
|
1501
1438
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1506,8 +1443,8 @@ function assembleReceiptByType(receipt) {
|
|
1506
1443
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1507
1444
|
const transferOutReceipt = {
|
1508
1445
|
type: import_transactions3.ReceiptType.TransferOut,
|
1509
|
-
from: hexOrZero(receipt.id
|
1510
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1446
|
+
from: hexOrZero(receipt.contract?.id),
|
1447
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1511
1448
|
amount: (0, import_math4.bn)(receipt.amount),
|
1512
1449
|
assetId: hexOrZero(receipt.assetId),
|
1513
1450
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1550,7 +1487,7 @@ function assembleReceiptByType(receipt) {
|
|
1550
1487
|
return receiptMessageOut;
|
1551
1488
|
}
|
1552
1489
|
case "MINT" /* Mint */: {
|
1553
|
-
const contractId = hexOrZero(receipt.id
|
1490
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1554
1491
|
const subId = hexOrZero(receipt.subId);
|
1555
1492
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1556
1493
|
const mintReceipt = {
|
@@ -1565,7 +1502,7 @@ function assembleReceiptByType(receipt) {
|
|
1565
1502
|
return mintReceipt;
|
1566
1503
|
}
|
1567
1504
|
case "BURN" /* Burn */: {
|
1568
|
-
const contractId = hexOrZero(receipt.id
|
1505
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1569
1506
|
const subId = hexOrZero(receipt.subId);
|
1570
1507
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1571
1508
|
const burnReceipt = {
|
@@ -1650,6 +1587,7 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1650
1587
|
var import_math5 = require("@fuel-ts/math");
|
1651
1588
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1652
1589
|
var import_utils6 = require("@fuel-ts/utils");
|
1590
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1653
1591
|
var getGasUsedFromReceipts = (receipts) => {
|
1654
1592
|
const scriptResult = receipts.filter(
|
1655
1593
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1670,28 +1608,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1670
1608
|
}
|
1671
1609
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1672
1610
|
const witnessCache = [];
|
1673
|
-
const
|
1674
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1675
|
-
if (isCoinOrMessage) {
|
1676
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1677
|
-
return true;
|
1678
|
-
}
|
1679
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1680
|
-
witnessCache.push(input.witnessIndex);
|
1681
|
-
return true;
|
1682
|
-
}
|
1683
|
-
}
|
1684
|
-
return false;
|
1685
|
-
});
|
1686
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1687
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1611
|
+
const totalGas = inputs.reduce((total, input) => {
|
1688
1612
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1689
1613
|
return total.add(
|
1690
|
-
|
1614
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1691
1615
|
);
|
1692
1616
|
}
|
1693
|
-
|
1694
|
-
|
1617
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1618
|
+
witnessCache.push(input.witnessIndex);
|
1619
|
+
return total.add(gasCosts.ecr1);
|
1620
|
+
}
|
1621
|
+
return total;
|
1622
|
+
}, (0, import_math5.bn)());
|
1695
1623
|
return totalGas;
|
1696
1624
|
}
|
1697
1625
|
function getMinGas(params) {
|
@@ -1703,20 +1631,12 @@ function getMinGas(params) {
|
|
1703
1631
|
return minGas;
|
1704
1632
|
}
|
1705
1633
|
function getMaxGas(params) {
|
1706
|
-
const {
|
1707
|
-
gasPerByte,
|
1708
|
-
witnessesLength,
|
1709
|
-
witnessLimit,
|
1710
|
-
minGas,
|
1711
|
-
gasLimit = (0, import_math5.bn)(0),
|
1712
|
-
maxGasPerTx
|
1713
|
-
} = params;
|
1634
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1714
1635
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1715
1636
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1716
1637
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1717
1638
|
}
|
1718
|
-
|
1719
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1639
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1720
1640
|
}
|
1721
1641
|
function calculateMetadataGasForTxCreate({
|
1722
1642
|
gasCosts,
|
@@ -1738,10 +1658,6 @@ function calculateMetadataGasForTxScript({
|
|
1738
1658
|
}) {
|
1739
1659
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1740
1660
|
}
|
1741
|
-
var calculateGasFee = (params) => {
|
1742
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1743
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1744
|
-
};
|
1745
1661
|
|
1746
1662
|
// src/providers/utils/json.ts
|
1747
1663
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1787,16 +1703,16 @@ function sleep(time) {
|
|
1787
1703
|
var import_errors7 = require("@fuel-ts/errors");
|
1788
1704
|
var import_math6 = require("@fuel-ts/math");
|
1789
1705
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1790
|
-
var
|
1706
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1791
1707
|
var assemblePanicError = (status) => {
|
1792
1708
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1793
1709
|
const reason = status.reason;
|
1794
|
-
if (
|
1710
|
+
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1795
1711
|
errorMessage = `${errorMessage}
|
1796
1712
|
|
1797
1713
|
You can read more about this error at:
|
1798
1714
|
|
1799
|
-
${
|
1715
|
+
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1800
1716
|
}
|
1801
1717
|
return { errorMessage, reason };
|
1802
1718
|
};
|
@@ -1808,28 +1724,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1808
1724
|
if (revertReceipt) {
|
1809
1725
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1810
1726
|
switch (reasonHex) {
|
1811
|
-
case
|
1727
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1812
1728
|
reason = "require";
|
1813
1729
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1814
1730
|
break;
|
1815
1731
|
}
|
1816
|
-
case
|
1732
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1817
1733
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1818
1734
|
reason = "assert_eq";
|
1819
1735
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1820
1736
|
break;
|
1821
1737
|
}
|
1822
|
-
case
|
1738
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1823
1739
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1824
1740
|
reason = "assert_ne";
|
1825
1741
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1826
1742
|
break;
|
1827
1743
|
}
|
1828
|
-
case
|
1744
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1829
1745
|
reason = "assert";
|
1830
1746
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1831
1747
|
break;
|
1832
|
-
case
|
1748
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1833
1749
|
reason = "MissingOutputChange";
|
1834
1750
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1835
1751
|
break;
|
@@ -1890,7 +1806,7 @@ var witnessify = (value) => {
|
|
1890
1806
|
// src/providers/transaction-request/transaction-request.ts
|
1891
1807
|
var BaseTransactionRequest = class {
|
1892
1808
|
/** Gas price for transaction */
|
1893
|
-
|
1809
|
+
gasPrice;
|
1894
1810
|
/** Block until which tx cannot be included */
|
1895
1811
|
maturity;
|
1896
1812
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1903,34 +1819,38 @@ var BaseTransactionRequest = class {
|
|
1903
1819
|
outputs = [];
|
1904
1820
|
/** List of witnesses */
|
1905
1821
|
witnesses = [];
|
1822
|
+
/** Base asset ID - should be fetched from the chain */
|
1823
|
+
baseAssetId = import_configs6.ZeroBytes32;
|
1906
1824
|
/**
|
1907
1825
|
* Constructor for initializing a base transaction request.
|
1908
1826
|
*
|
1909
1827
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1910
1828
|
*/
|
1911
1829
|
constructor({
|
1912
|
-
|
1830
|
+
gasPrice,
|
1913
1831
|
maturity,
|
1914
1832
|
maxFee,
|
1915
1833
|
witnessLimit,
|
1916
1834
|
inputs,
|
1917
1835
|
outputs,
|
1918
|
-
witnesses
|
1836
|
+
witnesses,
|
1837
|
+
baseAssetId
|
1919
1838
|
} = {}) {
|
1920
|
-
this.
|
1839
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1921
1840
|
this.maturity = maturity ?? 0;
|
1922
1841
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1923
1842
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1924
1843
|
this.inputs = inputs ?? [];
|
1925
1844
|
this.outputs = outputs ?? [];
|
1926
1845
|
this.witnesses = witnesses ?? [];
|
1846
|
+
this.baseAssetId = baseAssetId ?? import_configs6.ZeroBytes32;
|
1927
1847
|
}
|
1928
1848
|
static getPolicyMeta(req) {
|
1929
1849
|
let policyTypes = 0;
|
1930
1850
|
const policies = [];
|
1931
|
-
if (req.
|
1932
|
-
policyTypes += import_transactions6.PolicyType.
|
1933
|
-
policies.push({ data: req.
|
1851
|
+
if (req.gasPrice) {
|
1852
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1853
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1934
1854
|
}
|
1935
1855
|
if (req.witnessLimit) {
|
1936
1856
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -2016,7 +1936,7 @@ var BaseTransactionRequest = class {
|
|
2016
1936
|
* @returns The index of the created witness.
|
2017
1937
|
*/
|
2018
1938
|
addEmptyWitness() {
|
2019
|
-
this.addWitness((0, import_utils9.concat)([
|
1939
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
2020
1940
|
return this.witnesses.length - 1;
|
2021
1941
|
}
|
2022
1942
|
/**
|
@@ -2117,10 +2037,10 @@ var BaseTransactionRequest = class {
|
|
2117
2037
|
* @param predicate - Predicate bytes.
|
2118
2038
|
* @param predicateData - Predicate data bytes.
|
2119
2039
|
*/
|
2120
|
-
addCoinInput(coin) {
|
2040
|
+
addCoinInput(coin, predicate) {
|
2121
2041
|
const { assetId, owner, amount } = coin;
|
2122
2042
|
let witnessIndex;
|
2123
|
-
if (
|
2043
|
+
if (predicate) {
|
2124
2044
|
witnessIndex = 0;
|
2125
2045
|
} else {
|
2126
2046
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2135,7 +2055,8 @@ var BaseTransactionRequest = class {
|
|
2135
2055
|
amount,
|
2136
2056
|
assetId,
|
2137
2057
|
txPointer: "0x00000000000000000000000000000000",
|
2138
|
-
witnessIndex
|
2058
|
+
witnessIndex,
|
2059
|
+
predicate: predicate?.bytes
|
2139
2060
|
};
|
2140
2061
|
this.pushInput(input);
|
2141
2062
|
this.addChangeOutput(owner, assetId);
|
@@ -2146,13 +2067,11 @@ var BaseTransactionRequest = class {
|
|
2146
2067
|
*
|
2147
2068
|
* @param message - Message resource.
|
2148
2069
|
* @param predicate - Predicate bytes.
|
2149
|
-
* @param predicateData - Predicate data bytes.
|
2150
2070
|
*/
|
2151
|
-
addMessageInput(message) {
|
2071
|
+
addMessageInput(message, predicate) {
|
2152
2072
|
const { recipient, sender, amount } = message;
|
2153
|
-
const assetId = import_configs7.BaseAssetId;
|
2154
2073
|
let witnessIndex;
|
2155
|
-
if (
|
2074
|
+
if (predicate) {
|
2156
2075
|
witnessIndex = 0;
|
2157
2076
|
} else {
|
2158
2077
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2166,10 +2085,11 @@ var BaseTransactionRequest = class {
|
|
2166
2085
|
sender: sender.toB256(),
|
2167
2086
|
recipient: recipient.toB256(),
|
2168
2087
|
amount,
|
2169
|
-
witnessIndex
|
2088
|
+
witnessIndex,
|
2089
|
+
predicate: predicate?.bytes
|
2170
2090
|
};
|
2171
2091
|
this.pushInput(input);
|
2172
|
-
this.addChangeOutput(recipient,
|
2092
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
2173
2093
|
}
|
2174
2094
|
/**
|
2175
2095
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2197,6 +2117,32 @@ var BaseTransactionRequest = class {
|
|
2197
2117
|
resources.forEach((resource) => this.addResource(resource));
|
2198
2118
|
return this;
|
2199
2119
|
}
|
2120
|
+
/**
|
2121
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2122
|
+
* outputs from the related assetIds.
|
2123
|
+
*
|
2124
|
+
* @param resources - The resources to add.
|
2125
|
+
* @returns This transaction.
|
2126
|
+
*/
|
2127
|
+
addPredicateResource(resource, predicate) {
|
2128
|
+
if (isCoin(resource)) {
|
2129
|
+
this.addCoinInput(resource, predicate);
|
2130
|
+
} else {
|
2131
|
+
this.addMessageInput(resource, predicate);
|
2132
|
+
}
|
2133
|
+
return this;
|
2134
|
+
}
|
2135
|
+
/**
|
2136
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2137
|
+
* from the related assetIds.
|
2138
|
+
*
|
2139
|
+
* @param resources - The resources to add.
|
2140
|
+
* @returns This transaction.
|
2141
|
+
*/
|
2142
|
+
addPredicateResources(resources, predicate) {
|
2143
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2144
|
+
return this;
|
2145
|
+
}
|
2200
2146
|
/**
|
2201
2147
|
* Adds a coin output to the transaction.
|
2202
2148
|
*
|
@@ -2204,12 +2150,12 @@ var BaseTransactionRequest = class {
|
|
2204
2150
|
* @param amount - Amount of coin.
|
2205
2151
|
* @param assetId - Asset ID of coin.
|
2206
2152
|
*/
|
2207
|
-
addCoinOutput(to, amount, assetId
|
2153
|
+
addCoinOutput(to, amount, assetId) {
|
2208
2154
|
this.pushOutput({
|
2209
2155
|
type: import_transactions6.OutputType.Coin,
|
2210
2156
|
to: (0, import_address.addressify)(to).toB256(),
|
2211
2157
|
amount,
|
2212
|
-
assetId
|
2158
|
+
assetId: assetId ?? this.baseAssetId
|
2213
2159
|
});
|
2214
2160
|
return this;
|
2215
2161
|
}
|
@@ -2236,7 +2182,7 @@ var BaseTransactionRequest = class {
|
|
2236
2182
|
* @param to - Address of the owner.
|
2237
2183
|
* @param assetId - Asset ID of coin.
|
2238
2184
|
*/
|
2239
|
-
addChangeOutput(to, assetId
|
2185
|
+
addChangeOutput(to, assetId) {
|
2240
2186
|
const changeOutput = this.getChangeOutputs().find(
|
2241
2187
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2242
2188
|
);
|
@@ -2244,7 +2190,7 @@ var BaseTransactionRequest = class {
|
|
2244
2190
|
this.pushOutput({
|
2245
2191
|
type: import_transactions6.OutputType.Change,
|
2246
2192
|
to: (0, import_address.addressify)(to).toB256(),
|
2247
|
-
assetId
|
2193
|
+
assetId: assetId ?? this.baseAssetId
|
2248
2194
|
});
|
2249
2195
|
}
|
2250
2196
|
}
|
@@ -2276,7 +2222,7 @@ var BaseTransactionRequest = class {
|
|
2276
2222
|
}
|
2277
2223
|
calculateMaxGas(chainInfo, minGas) {
|
2278
2224
|
const { consensusParameters } = chainInfo;
|
2279
|
-
const { gasPerByte
|
2225
|
+
const { gasPerByte } = consensusParameters;
|
2280
2226
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2281
2227
|
(acc, wit) => acc + wit.dataLength,
|
2282
2228
|
0
|
@@ -2285,8 +2231,7 @@ var BaseTransactionRequest = class {
|
|
2285
2231
|
gasPerByte,
|
2286
2232
|
minGas,
|
2287
2233
|
witnessesLength,
|
2288
|
-
witnessLimit: this.witnessLimit
|
2289
|
-
maxGasPerTx
|
2234
|
+
witnessLimit: this.witnessLimit
|
2290
2235
|
});
|
2291
2236
|
}
|
2292
2237
|
/**
|
@@ -2296,6 +2241,12 @@ var BaseTransactionRequest = class {
|
|
2296
2241
|
* @param quantities - CoinQuantity Array.
|
2297
2242
|
*/
|
2298
2243
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2244
|
+
let idCounter = 0;
|
2245
|
+
const generateId = () => {
|
2246
|
+
const counterString = String(idCounter++);
|
2247
|
+
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2248
|
+
return id;
|
2249
|
+
};
|
2299
2250
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2300
2251
|
if ("assetId" in input) {
|
2301
2252
|
return input.assetId === assetId;
|
@@ -2304,27 +2255,24 @@ var BaseTransactionRequest = class {
|
|
2304
2255
|
});
|
2305
2256
|
const updateAssetInput = (assetId, quantity) => {
|
2306
2257
|
const assetInput = findAssetInput(assetId);
|
2307
|
-
let usedQuantity = quantity;
|
2308
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2309
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2310
|
-
}
|
2311
2258
|
if (assetInput && "assetId" in assetInput) {
|
2312
|
-
assetInput.id = (
|
2313
|
-
assetInput.amount =
|
2259
|
+
assetInput.id = generateId();
|
2260
|
+
assetInput.amount = quantity;
|
2314
2261
|
} else {
|
2315
2262
|
this.addResources([
|
2316
2263
|
{
|
2317
|
-
id: (
|
2318
|
-
amount:
|
2264
|
+
id: generateId(),
|
2265
|
+
amount: quantity,
|
2319
2266
|
assetId,
|
2320
2267
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2268
|
+
maturity: 0,
|
2321
2269
|
blockCreated: (0, import_math7.bn)(1),
|
2322
2270
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2323
2271
|
}
|
2324
2272
|
]);
|
2325
2273
|
}
|
2326
2274
|
};
|
2327
|
-
updateAssetInput(
|
2275
|
+
updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
|
2328
2276
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2329
2277
|
}
|
2330
2278
|
/**
|
@@ -2349,7 +2297,7 @@ var BaseTransactionRequest = class {
|
|
2349
2297
|
toJSON() {
|
2350
2298
|
return normalizeJSON(this);
|
2351
2299
|
}
|
2352
|
-
|
2300
|
+
updatePredicateInputs(inputs) {
|
2353
2301
|
this.inputs.forEach((i) => {
|
2354
2302
|
let correspondingInput;
|
2355
2303
|
switch (i.type) {
|
@@ -2371,25 +2319,16 @@ var BaseTransactionRequest = class {
|
|
2371
2319
|
}
|
2372
2320
|
});
|
2373
2321
|
}
|
2374
|
-
shiftPredicateData() {
|
2375
|
-
this.inputs.forEach((input) => {
|
2376
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2377
|
-
input.predicateData = input.paddPredicateData(
|
2378
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2379
|
-
);
|
2380
|
-
}
|
2381
|
-
});
|
2382
|
-
}
|
2383
2322
|
};
|
2384
2323
|
|
2385
2324
|
// src/providers/transaction-request/create-transaction-request.ts
|
2386
|
-
var
|
2325
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2387
2326
|
var import_math9 = require("@fuel-ts/math");
|
2388
2327
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2389
2328
|
var import_utils13 = require("@fuel-ts/utils");
|
2390
2329
|
|
2391
2330
|
// src/providers/transaction-request/hash-transaction.ts
|
2392
|
-
var
|
2331
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2393
2332
|
var import_hasher = require("@fuel-ts/hasher");
|
2394
2333
|
var import_math8 = require("@fuel-ts/math");
|
2395
2334
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2398,7 +2337,7 @@ var import_ramda2 = require("ramda");
|
|
2398
2337
|
function hashTransaction(transactionRequest, chainId) {
|
2399
2338
|
const transaction = transactionRequest.toTransaction();
|
2400
2339
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2401
|
-
transaction.receiptsRoot =
|
2340
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2402
2341
|
}
|
2403
2342
|
transaction.inputs = transaction.inputs.map((input) => {
|
2404
2343
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2420,10 +2359,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2420
2359
|
blockHeight: 0,
|
2421
2360
|
txIndex: 0
|
2422
2361
|
};
|
2423
|
-
inputClone.txID =
|
2362
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2424
2363
|
inputClone.outputIndex = 0;
|
2425
|
-
inputClone.balanceRoot =
|
2426
|
-
inputClone.stateRoot =
|
2364
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2365
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2427
2366
|
return inputClone;
|
2428
2367
|
}
|
2429
2368
|
default:
|
@@ -2434,8 +2373,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2434
2373
|
const outputClone = (0, import_ramda2.clone)(output);
|
2435
2374
|
switch (outputClone.type) {
|
2436
2375
|
case import_transactions7.OutputType.Contract: {
|
2437
|
-
outputClone.balanceRoot =
|
2438
|
-
outputClone.stateRoot =
|
2376
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2377
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2439
2378
|
return outputClone;
|
2440
2379
|
}
|
2441
2380
|
case import_transactions7.OutputType.Change: {
|
@@ -2443,9 +2382,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2443
2382
|
return outputClone;
|
2444
2383
|
}
|
2445
2384
|
case import_transactions7.OutputType.Variable: {
|
2446
|
-
outputClone.to =
|
2385
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2447
2386
|
outputClone.amount = (0, import_math8.bn)(0);
|
2448
|
-
outputClone.assetId =
|
2387
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2449
2388
|
return outputClone;
|
2450
2389
|
}
|
2451
2390
|
default:
|
@@ -2511,7 +2450,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2511
2450
|
} = {}) {
|
2512
2451
|
super(rest);
|
2513
2452
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2514
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2453
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2515
2454
|
this.storageSlots = [...storageSlots ?? []];
|
2516
2455
|
}
|
2517
2456
|
/**
|
@@ -2526,9 +2465,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2526
2465
|
return {
|
2527
2466
|
type: import_transactions8.TransactionType.Create,
|
2528
2467
|
...baseTransaction,
|
2468
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2529
2469
|
bytecodeWitnessIndex,
|
2530
|
-
storageSlotsCount:
|
2531
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2470
|
+
storageSlotsCount: storageSlots.length,
|
2471
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2532
2472
|
storageSlots
|
2533
2473
|
};
|
2534
2474
|
}
|
@@ -2578,7 +2518,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2578
2518
|
// src/providers/transaction-request/script-transaction-request.ts
|
2579
2519
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2580
2520
|
var import_address2 = require("@fuel-ts/address");
|
2581
|
-
var
|
2521
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2582
2522
|
var import_math10 = require("@fuel-ts/math");
|
2583
2523
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2584
2524
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2650,9 +2590,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2650
2590
|
type: import_transactions9.TransactionType.Script,
|
2651
2591
|
scriptGasLimit: this.gasLimit,
|
2652
2592
|
...super.getBaseTransaction(),
|
2653
|
-
scriptLength:
|
2654
|
-
scriptDataLength:
|
2655
|
-
receiptsRoot:
|
2593
|
+
scriptLength: script.length,
|
2594
|
+
scriptDataLength: scriptData.length,
|
2595
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2656
2596
|
script: (0, import_utils15.hexlify)(script),
|
2657
2597
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2658
2598
|
};
|
@@ -2715,7 +2655,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2715
2655
|
}
|
2716
2656
|
calculateMaxGas(chainInfo, minGas) {
|
2717
2657
|
const { consensusParameters } = chainInfo;
|
2718
|
-
const { gasPerByte
|
2658
|
+
const { gasPerByte } = consensusParameters;
|
2719
2659
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2720
2660
|
(acc, wit) => acc + wit.dataLength,
|
2721
2661
|
0
|
@@ -2725,8 +2665,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2725
2665
|
minGas,
|
2726
2666
|
witnessesLength,
|
2727
2667
|
witnessLimit: this.witnessLimit,
|
2728
|
-
gasLimit: this.gasLimit
|
2729
|
-
maxGasPerTx
|
2668
|
+
gasLimit: this.gasLimit
|
2730
2669
|
});
|
2731
2670
|
}
|
2732
2671
|
/**
|
@@ -2801,32 +2740,15 @@ var transactionRequestify = (obj) => {
|
|
2801
2740
|
}
|
2802
2741
|
}
|
2803
2742
|
};
|
2804
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2805
|
-
(acc, input) => {
|
2806
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2807
|
-
acc.utxos.push(input.id);
|
2808
|
-
}
|
2809
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2810
|
-
acc.messages.push(input.nonce);
|
2811
|
-
}
|
2812
|
-
return acc;
|
2813
|
-
},
|
2814
|
-
{
|
2815
|
-
utxos: [],
|
2816
|
-
messages: []
|
2817
|
-
}
|
2818
|
-
);
|
2819
2743
|
|
2820
2744
|
// src/providers/transaction-response/transaction-response.ts
|
2821
2745
|
var import_errors13 = require("@fuel-ts/errors");
|
2822
|
-
var
|
2823
|
-
var
|
2824
|
-
var
|
2746
|
+
var import_math14 = require("@fuel-ts/math");
|
2747
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2748
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2825
2749
|
|
2826
2750
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2827
|
-
var
|
2828
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2829
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2751
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2830
2752
|
|
2831
2753
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2832
2754
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2834,10 +2756,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2834
2756
|
var import_utils16 = require("@fuel-ts/utils");
|
2835
2757
|
var calculateTransactionFee = (params) => {
|
2836
2758
|
const {
|
2837
|
-
|
2759
|
+
gasUsed,
|
2838
2760
|
rawPayload,
|
2839
|
-
|
2840
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2761
|
+
consensusParameters: { gasCosts, feeParams }
|
2841
2762
|
} = params;
|
2842
2763
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2843
2764
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2847,7 +2768,8 @@ var calculateTransactionFee = (params) => {
|
|
2847
2768
|
return {
|
2848
2769
|
fee: (0, import_math11.bn)(0),
|
2849
2770
|
minFee: (0, import_math11.bn)(0),
|
2850
|
-
maxFee: (0, import_math11.bn)(0)
|
2771
|
+
maxFee: (0, import_math11.bn)(0),
|
2772
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2851
2773
|
};
|
2852
2774
|
}
|
2853
2775
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2879,6 +2801,7 @@ var calculateTransactionFee = (params) => {
|
|
2879
2801
|
metadataGas,
|
2880
2802
|
txBytesSize: transactionBytes.length
|
2881
2803
|
});
|
2804
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2882
2805
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2883
2806
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2884
2807
|
const maxGas = getMaxGas({
|
@@ -2886,30 +2809,22 @@ var calculateTransactionFee = (params) => {
|
|
2886
2809
|
minGas,
|
2887
2810
|
witnessesLength,
|
2888
2811
|
gasLimit,
|
2889
|
-
witnessLimit
|
2890
|
-
maxGasPerTx
|
2891
|
-
});
|
2892
|
-
const minFee = calculateGasFee({
|
2893
|
-
gasPrice,
|
2894
|
-
gas: minGas,
|
2895
|
-
priceFactor: gasPriceFactor,
|
2896
|
-
tip
|
2897
|
-
});
|
2898
|
-
const maxFee = calculateGasFee({
|
2899
|
-
gasPrice,
|
2900
|
-
gas: maxGas,
|
2901
|
-
priceFactor: gasPriceFactor,
|
2902
|
-
tip
|
2812
|
+
witnessLimit
|
2903
2813
|
});
|
2814
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2815
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2816
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2817
|
+
const fee = minFee.add(feeFromGasUsed);
|
2904
2818
|
return {
|
2819
|
+
fee,
|
2905
2820
|
minFee,
|
2906
2821
|
maxFee,
|
2907
|
-
|
2822
|
+
feeFromGasUsed
|
2908
2823
|
};
|
2909
2824
|
};
|
2910
2825
|
|
2911
2826
|
// src/providers/transaction-summary/operations.ts
|
2912
|
-
var
|
2827
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2913
2828
|
var import_errors11 = require("@fuel-ts/errors");
|
2914
2829
|
var import_math13 = require("@fuel-ts/math");
|
2915
2830
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3254,7 +3169,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3254
3169
|
const { to: toAddress, assetId, amount } = receipt;
|
3255
3170
|
let { from: fromAddress } = receipt;
|
3256
3171
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3257
|
-
if (
|
3172
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3258
3173
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3259
3174
|
fromAddress = change?.to || fromAddress;
|
3260
3175
|
}
|
@@ -3518,12 +3433,10 @@ function assembleTransactionSummary(params) {
|
|
3518
3433
|
gqlTransactionStatus,
|
3519
3434
|
abiMap = {},
|
3520
3435
|
maxInputs,
|
3521
|
-
gasCosts
|
3522
|
-
maxGasPerTx,
|
3523
|
-
gasPrice
|
3436
|
+
gasCosts
|
3524
3437
|
} = params;
|
3525
3438
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3526
|
-
const rawPayload = (0,
|
3439
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3527
3440
|
const operations = getOperations({
|
3528
3441
|
transactionType: transaction.type,
|
3529
3442
|
inputs: transaction.inputs || [],
|
@@ -3534,14 +3447,11 @@ function assembleTransactionSummary(params) {
|
|
3534
3447
|
maxInputs
|
3535
3448
|
});
|
3536
3449
|
const typeName = getTransactionTypeName(transaction.type);
|
3537
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3538
3450
|
const { fee } = calculateTransactionFee({
|
3539
|
-
|
3451
|
+
gasUsed,
|
3540
3452
|
rawPayload,
|
3541
|
-
tip,
|
3542
3453
|
consensusParameters: {
|
3543
3454
|
gasCosts,
|
3544
|
-
maxGasPerTx,
|
3545
3455
|
feeParams: {
|
3546
3456
|
gasPerByte,
|
3547
3457
|
gasPriceFactor
|
@@ -3553,7 +3463,7 @@ function assembleTransactionSummary(params) {
|
|
3553
3463
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3554
3464
|
let date;
|
3555
3465
|
if (time) {
|
3556
|
-
date =
|
3466
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3557
3467
|
}
|
3558
3468
|
const transactionSummary = {
|
3559
3469
|
id,
|
@@ -3581,12 +3491,12 @@ function assembleTransactionSummary(params) {
|
|
3581
3491
|
|
3582
3492
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3583
3493
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3584
|
-
var
|
3494
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3585
3495
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3586
3496
|
return receipts.reduce((logs, receipt) => {
|
3587
|
-
if (receipt.type ===
|
3497
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3588
3498
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3589
|
-
const data = receipt.type ===
|
3499
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3590
3500
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3591
3501
|
logs.push(decodedLog);
|
3592
3502
|
}
|
@@ -3601,7 +3511,7 @@ var TransactionResponse = class {
|
|
3601
3511
|
/** Current provider */
|
3602
3512
|
provider;
|
3603
3513
|
/** Gas used on the transaction */
|
3604
|
-
gasUsed = (0,
|
3514
|
+
gasUsed = (0, import_math14.bn)(0);
|
3605
3515
|
/** The graphql Transaction with receipts object. */
|
3606
3516
|
gqlTransaction;
|
3607
3517
|
abis;
|
@@ -3659,8 +3569,8 @@ var TransactionResponse = class {
|
|
3659
3569
|
* @returns The decoded transaction.
|
3660
3570
|
*/
|
3661
3571
|
decodeTransaction(transactionWithReceipts) {
|
3662
|
-
return new
|
3663
|
-
(0,
|
3572
|
+
return new import_transactions17.TransactionCoder().decode(
|
3573
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3664
3574
|
0
|
3665
3575
|
)?.[0];
|
3666
3576
|
}
|
@@ -3679,27 +3589,20 @@ var TransactionResponse = class {
|
|
3679
3589
|
const decodedTransaction = this.decodeTransaction(
|
3680
3590
|
transaction
|
3681
3591
|
);
|
3682
|
-
|
3683
|
-
|
3684
|
-
txReceipts = transaction.status.receipts;
|
3685
|
-
}
|
3686
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3687
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3688
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3592
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3593
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3689
3594
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3690
3595
|
const transactionSummary = assembleTransactionSummary({
|
3691
3596
|
id: this.id,
|
3692
3597
|
receipts,
|
3693
3598
|
transaction: decodedTransaction,
|
3694
|
-
transactionBytes: (0,
|
3599
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3695
3600
|
gqlTransactionStatus: transaction.status,
|
3696
3601
|
gasPerByte,
|
3697
3602
|
gasPriceFactor,
|
3698
3603
|
abiMap: contractsAbiMap,
|
3699
3604
|
maxInputs,
|
3700
|
-
gasCosts
|
3701
|
-
maxGasPerTx,
|
3702
|
-
gasPrice
|
3605
|
+
gasCosts
|
3703
3606
|
});
|
3704
3607
|
return transactionSummary;
|
3705
3608
|
}
|
@@ -3826,29 +3729,30 @@ var processGqlChain = (chain) => {
|
|
3826
3729
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3827
3730
|
return {
|
3828
3731
|
name,
|
3829
|
-
baseChainHeight: (0,
|
3732
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3830
3733
|
consensusParameters: {
|
3831
|
-
contractMaxSize: (0,
|
3832
|
-
maxInputs: (0,
|
3833
|
-
maxOutputs: (0,
|
3834
|
-
maxWitnesses: (0,
|
3835
|
-
maxGasPerTx: (0,
|
3836
|
-
maxScriptLength: (0,
|
3837
|
-
maxScriptDataLength: (0,
|
3838
|
-
maxStorageSlots: (0,
|
3839
|
-
maxPredicateLength: (0,
|
3840
|
-
maxPredicateDataLength: (0,
|
3841
|
-
maxGasPerPredicate: (0,
|
3842
|
-
gasPriceFactor: (0,
|
3843
|
-
gasPerByte: (0,
|
3844
|
-
maxMessageDataLength: (0,
|
3845
|
-
chainId: (0,
|
3734
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3735
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3736
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3737
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3738
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3739
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3740
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3741
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3742
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3743
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3744
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3745
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3746
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3747
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3748
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3749
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3846
3750
|
gasCosts
|
3847
3751
|
},
|
3848
3752
|
gasCosts,
|
3849
3753
|
latestBlock: {
|
3850
3754
|
id: latestBlock.id,
|
3851
|
-
height: (0,
|
3755
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3852
3756
|
time: latestBlock.header.time,
|
3853
3757
|
transactions: latestBlock.transactions.map((i) => ({
|
3854
3758
|
id: i.id
|
@@ -3942,8 +3846,10 @@ var _Provider = class {
|
|
3942
3846
|
* Returns some helpful parameters related to gas fees.
|
3943
3847
|
*/
|
3944
3848
|
getGasConfig() {
|
3849
|
+
const { minGasPrice } = this.getNode();
|
3945
3850
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3946
3851
|
return {
|
3852
|
+
minGasPrice,
|
3947
3853
|
maxGasPerTx,
|
3948
3854
|
maxGasPerPredicate,
|
3949
3855
|
gasPriceFactor,
|
@@ -4031,7 +3937,7 @@ var _Provider = class {
|
|
4031
3937
|
name,
|
4032
3938
|
consensusParameters: { chainId }
|
4033
3939
|
} = await this.getChain();
|
4034
|
-
const network = new
|
3940
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
4035
3941
|
return Promise.resolve(network);
|
4036
3942
|
}
|
4037
3943
|
/**
|
@@ -4041,7 +3947,7 @@ var _Provider = class {
|
|
4041
3947
|
*/
|
4042
3948
|
async getBlockNumber() {
|
4043
3949
|
const { chain } = await this.operations.getChain();
|
4044
|
-
return (0,
|
3950
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
4045
3951
|
}
|
4046
3952
|
/**
|
4047
3953
|
* Returns the chain information.
|
@@ -4051,11 +3957,13 @@ var _Provider = class {
|
|
4051
3957
|
async fetchNode() {
|
4052
3958
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
4053
3959
|
const processedNodeInfo = {
|
4054
|
-
maxDepth: (0,
|
4055
|
-
maxTx: (0,
|
3960
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3961
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3962
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4056
3963
|
nodeVersion: nodeInfo.nodeVersion,
|
4057
3964
|
utxoValidation: nodeInfo.utxoValidation,
|
4058
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3965
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3966
|
+
peers: nodeInfo.peers
|
4059
3967
|
};
|
4060
3968
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
4061
3969
|
return processedNodeInfo;
|
@@ -4081,6 +3989,17 @@ var _Provider = class {
|
|
4081
3989
|
} = this.getChain();
|
4082
3990
|
return chainId.toNumber();
|
4083
3991
|
}
|
3992
|
+
/**
|
3993
|
+
* Returns the base asset ID
|
3994
|
+
*
|
3995
|
+
* @returns A promise that resolves to the base asset ID
|
3996
|
+
*/
|
3997
|
+
getBaseAssetId() {
|
3998
|
+
const {
|
3999
|
+
consensusParameters: { baseAssetId }
|
4000
|
+
} = this.getChain();
|
4001
|
+
return baseAssetId;
|
4002
|
+
}
|
4084
4003
|
/**
|
4085
4004
|
* Submits a transaction to the chain to be executed.
|
4086
4005
|
*
|
@@ -4097,9 +4016,9 @@ var _Provider = class {
|
|
4097
4016
|
if (estimateTxDependencies) {
|
4098
4017
|
await this.estimateTxDependencies(transactionRequest);
|
4099
4018
|
}
|
4100
|
-
const encodedTransaction = (0,
|
4019
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4101
4020
|
let abis;
|
4102
|
-
if (transactionRequest.type ===
|
4021
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4103
4022
|
abis = transactionRequest.abis;
|
4104
4023
|
}
|
4105
4024
|
if (awaitExecution) {
|
@@ -4140,14 +4059,15 @@ var _Provider = class {
|
|
4140
4059
|
if (estimateTxDependencies) {
|
4141
4060
|
return this.estimateTxDependencies(transactionRequest);
|
4142
4061
|
}
|
4143
|
-
const encodedTransaction = (0,
|
4144
|
-
const { dryRun:
|
4145
|
-
|
4062
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4063
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4064
|
+
encodedTransaction,
|
4146
4065
|
utxoValidation: utxoValidation || false
|
4147
4066
|
});
|
4148
|
-
const
|
4149
|
-
|
4150
|
-
|
4067
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4068
|
+
return {
|
4069
|
+
receipts
|
4070
|
+
};
|
4151
4071
|
}
|
4152
4072
|
/**
|
4153
4073
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4158,13 +4078,13 @@ var _Provider = class {
|
|
4158
4078
|
async estimatePredicates(transactionRequest) {
|
4159
4079
|
const shouldEstimatePredicates = Boolean(
|
4160
4080
|
transactionRequest.inputs.find(
|
4161
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4081
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
|
4162
4082
|
)
|
4163
4083
|
);
|
4164
4084
|
if (!shouldEstimatePredicates) {
|
4165
4085
|
return transactionRequest;
|
4166
4086
|
}
|
4167
|
-
const encodedTransaction = (0,
|
4087
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4168
4088
|
const response = await this.operations.estimatePredicates({
|
4169
4089
|
encodedTransaction
|
4170
4090
|
});
|
@@ -4173,7 +4093,7 @@ var _Provider = class {
|
|
4173
4093
|
} = response;
|
4174
4094
|
if (inputs) {
|
4175
4095
|
inputs.forEach((input, index) => {
|
4176
|
-
if ("predicateGasUsed" in input && (0,
|
4096
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
4177
4097
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4178
4098
|
}
|
4179
4099
|
});
|
@@ -4186,31 +4106,31 @@ var _Provider = class {
|
|
4186
4106
|
* If there are missing variable outputs,
|
4187
4107
|
* `addVariableOutputs` is called on the transaction.
|
4188
4108
|
*
|
4109
|
+
* @privateRemarks
|
4110
|
+
* TODO: Investigate support for missing contract IDs
|
4111
|
+
* TODO: Add support for missing output messages
|
4189
4112
|
*
|
4190
4113
|
* @param transactionRequest - The transaction request object.
|
4191
4114
|
* @returns A promise.
|
4192
4115
|
*/
|
4193
4116
|
async estimateTxDependencies(transactionRequest) {
|
4194
|
-
if (transactionRequest.type ===
|
4117
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
4195
4118
|
return {
|
4196
4119
|
receipts: [],
|
4197
4120
|
outputVariables: 0,
|
4198
4121
|
missingContractIds: []
|
4199
4122
|
};
|
4200
4123
|
}
|
4124
|
+
await this.estimatePredicates(transactionRequest);
|
4201
4125
|
let receipts = [];
|
4202
4126
|
const missingContractIds = [];
|
4203
4127
|
let outputVariables = 0;
|
4204
|
-
let dryrunStatus;
|
4205
4128
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4206
|
-
const {
|
4207
|
-
|
4208
|
-
} = await this.operations.dryRun({
|
4209
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4129
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4130
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
4210
4131
|
utxoValidation: false
|
4211
4132
|
});
|
4212
|
-
receipts =
|
4213
|
-
dryrunStatus = status;
|
4133
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4214
4134
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4215
4135
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4216
4136
|
if (hasMissingOutputs) {
|
@@ -4220,11 +4140,6 @@ var _Provider = class {
|
|
4220
4140
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4221
4141
|
missingContractIds.push(contractId);
|
4222
4142
|
});
|
4223
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4224
|
-
transactionRequest,
|
4225
|
-
optimizeGas: false
|
4226
|
-
});
|
4227
|
-
transactionRequest.maxFee = maxFee;
|
4228
4143
|
} else {
|
4229
4144
|
break;
|
4230
4145
|
}
|
@@ -4232,133 +4147,7 @@ var _Provider = class {
|
|
4232
4147
|
return {
|
4233
4148
|
receipts,
|
4234
4149
|
outputVariables,
|
4235
|
-
missingContractIds
|
4236
|
-
dryrunStatus
|
4237
|
-
};
|
4238
|
-
}
|
4239
|
-
/**
|
4240
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4241
|
-
*
|
4242
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4243
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4244
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4245
|
-
*
|
4246
|
-
* @param transactionRequests - Array of transaction request objects.
|
4247
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4248
|
-
*/
|
4249
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4250
|
-
const results = transactionRequests.map(() => ({
|
4251
|
-
receipts: [],
|
4252
|
-
outputVariables: 0,
|
4253
|
-
missingContractIds: [],
|
4254
|
-
dryrunStatus: void 0
|
4255
|
-
}));
|
4256
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4257
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4258
|
-
allRequests.forEach((req, index) => {
|
4259
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4260
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4261
|
-
}
|
4262
|
-
});
|
4263
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4264
|
-
let attempt = 0;
|
4265
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4266
|
-
const encodedTransactions = transactionsToProcess.map(
|
4267
|
-
(index) => serializedTransactionsMap.get(index)
|
4268
|
-
);
|
4269
|
-
const dryRunResults = await this.operations.dryRun({
|
4270
|
-
encodedTransactions,
|
4271
|
-
utxoValidation: false
|
4272
|
-
});
|
4273
|
-
const nextRoundTransactions = [];
|
4274
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4275
|
-
const currentResultIndex = transactionsToProcess[i];
|
4276
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4277
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4278
|
-
results[currentResultIndex].dryrunStatus = status;
|
4279
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4280
|
-
results[currentResultIndex].receipts
|
4281
|
-
);
|
4282
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4283
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4284
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4285
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4286
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4287
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4288
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4289
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4290
|
-
});
|
4291
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4292
|
-
transactionRequest: requestToProcess,
|
4293
|
-
optimizeGas: false
|
4294
|
-
});
|
4295
|
-
requestToProcess.maxFee = maxFee;
|
4296
|
-
serializedTransactionsMap.set(
|
4297
|
-
currentResultIndex,
|
4298
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4299
|
-
);
|
4300
|
-
nextRoundTransactions.push(currentResultIndex);
|
4301
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4302
|
-
}
|
4303
|
-
}
|
4304
|
-
transactionsToProcess = nextRoundTransactions;
|
4305
|
-
attempt += 1;
|
4306
|
-
}
|
4307
|
-
return results;
|
4308
|
-
}
|
4309
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4310
|
-
if (estimateTxDependencies) {
|
4311
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4312
|
-
}
|
4313
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4314
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4315
|
-
encodedTransactions,
|
4316
|
-
utxoValidation: utxoValidation || false
|
4317
|
-
});
|
4318
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4319
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4320
|
-
return { receipts, dryrunStatus: status };
|
4321
|
-
});
|
4322
|
-
return results;
|
4323
|
-
}
|
4324
|
-
async estimateTxGasAndFee(params) {
|
4325
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4326
|
-
let { gasPrice } = params;
|
4327
|
-
const chainInfo = this.getChain();
|
4328
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4329
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4330
|
-
if (!gasPrice) {
|
4331
|
-
gasPrice = await this.estimateGasPrice(10);
|
4332
|
-
}
|
4333
|
-
const minFee = calculateGasFee({
|
4334
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4335
|
-
gas: minGas,
|
4336
|
-
priceFactor: gasPriceFactor,
|
4337
|
-
tip: transactionRequest.tip
|
4338
|
-
}).add(1);
|
4339
|
-
let gasLimit = (0, import_math16.bn)(0);
|
4340
|
-
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4341
|
-
gasLimit = transactionRequest.gasLimit;
|
4342
|
-
if (!optimizeGas) {
|
4343
|
-
transactionRequest.gasLimit = minGas;
|
4344
|
-
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4345
|
-
transactionRequest.gasLimit = gasLimit;
|
4346
|
-
}
|
4347
|
-
}
|
4348
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4349
|
-
const maxFee = calculateGasFee({
|
4350
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4351
|
-
gas: maxGas,
|
4352
|
-
priceFactor: gasPriceFactor,
|
4353
|
-
tip: transactionRequest.tip
|
4354
|
-
}).add(1);
|
4355
|
-
return {
|
4356
|
-
minGas,
|
4357
|
-
minFee,
|
4358
|
-
maxGas,
|
4359
|
-
maxFee,
|
4360
|
-
gasPrice,
|
4361
|
-
gasLimit
|
4150
|
+
missingContractIds
|
4362
4151
|
};
|
4363
4152
|
}
|
4364
4153
|
/**
|
@@ -4376,17 +4165,15 @@ var _Provider = class {
|
|
4376
4165
|
if (estimateTxDependencies) {
|
4377
4166
|
return this.estimateTxDependencies(transactionRequest);
|
4378
4167
|
}
|
4379
|
-
const
|
4380
|
-
const { dryRun:
|
4381
|
-
|
4168
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4169
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4170
|
+
encodedTransaction,
|
4382
4171
|
utxoValidation: true
|
4383
4172
|
});
|
4384
|
-
const
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
});
|
4389
|
-
return { receipts: callResult[0].receipts };
|
4173
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4174
|
+
return {
|
4175
|
+
receipts
|
4176
|
+
};
|
4390
4177
|
}
|
4391
4178
|
/**
|
4392
4179
|
* Returns a transaction cost to enable user
|
@@ -4403,80 +4190,80 @@ var _Provider = class {
|
|
4403
4190
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4404
4191
|
* @returns A promise that resolves to the transaction cost object.
|
4405
4192
|
*/
|
4406
|
-
async getTransactionCost(transactionRequestLike,
|
4193
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4194
|
+
estimateTxDependencies = true,
|
4195
|
+
estimatePredicates = true,
|
4196
|
+
resourcesOwner,
|
4197
|
+
signatureCallback
|
4198
|
+
} = {}) {
|
4407
4199
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4408
|
-
const
|
4200
|
+
const chainInfo = this.getChain();
|
4201
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4202
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4203
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4409
4204
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4410
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4205
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4411
4206
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4207
|
+
if (estimatePredicates) {
|
4208
|
+
if (isScriptTransaction) {
|
4209
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4210
|
+
}
|
4211
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4212
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4213
|
+
}
|
4214
|
+
await this.estimatePredicates(txRequestClone);
|
4418
4215
|
}
|
4419
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4420
|
-
let addedSignatures = 0;
|
4421
4216
|
if (signatureCallback && isScriptTransaction) {
|
4422
|
-
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4426
|
-
await this.estimatePredicates(signedRequest);
|
4427
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4428
|
-
transactionRequest: signedRequest,
|
4429
|
-
optimizeGas: false
|
4430
|
-
});
|
4431
|
-
txRequestClone.maxFee = maxFee;
|
4217
|
+
await signatureCallback(txRequestClone);
|
4218
|
+
}
|
4219
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4220
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4432
4221
|
let receipts = [];
|
4433
4222
|
let missingContractIds = [];
|
4434
4223
|
let outputVariables = 0;
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
if (signatureCallback) {
|
4439
|
-
await signatureCallback(txRequestClone);
|
4440
|
-
}
|
4441
|
-
txRequestClone.gasLimit = gasLimit;
|
4224
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4225
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4226
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4442
4227
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4443
4228
|
receipts = result.receipts;
|
4444
4229
|
outputVariables = result.outputVariables;
|
4445
4230
|
missingContractIds = result.missingContractIds;
|
4446
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4447
|
-
txRequestClone.gasLimit = gasUsed;
|
4448
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4449
|
-
transactionRequest: txRequestClone,
|
4450
|
-
gasPrice
|
4451
|
-
}));
|
4452
4231
|
}
|
4232
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4233
|
+
const usedFee = calculatePriceWithFactor(
|
4234
|
+
gasUsed,
|
4235
|
+
gasPrice,
|
4236
|
+
gasPriceFactor
|
4237
|
+
).normalizeZeroToOne();
|
4238
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4239
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4453
4240
|
return {
|
4454
4241
|
requiredQuantities: allQuantities,
|
4455
4242
|
receipts,
|
4456
4243
|
gasUsed,
|
4244
|
+
minGasPrice,
|
4457
4245
|
gasPrice,
|
4458
4246
|
minGas,
|
4459
4247
|
maxGas,
|
4248
|
+
usedFee,
|
4460
4249
|
minFee,
|
4461
4250
|
maxFee,
|
4251
|
+
estimatedInputs: txRequestClone.inputs,
|
4462
4252
|
outputVariables,
|
4463
|
-
missingContractIds
|
4464
|
-
addedSignatures,
|
4465
|
-
estimatedPredicates: txRequestClone.inputs
|
4253
|
+
missingContractIds
|
4466
4254
|
};
|
4467
4255
|
}
|
4468
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4256
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4469
4257
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4470
4258
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4471
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4472
|
-
quantitiesToContract
|
4473
|
-
});
|
4259
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4474
4260
|
transactionRequest.addResources(
|
4475
4261
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4476
4262
|
);
|
4477
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4478
|
-
|
4479
|
-
|
4263
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4264
|
+
transactionRequest,
|
4265
|
+
forwardingQuantities
|
4266
|
+
);
|
4480
4267
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4481
4268
|
return {
|
4482
4269
|
resources,
|
@@ -4492,16 +4279,17 @@ var _Provider = class {
|
|
4492
4279
|
const result = await this.operations.getCoins({
|
4493
4280
|
first: 10,
|
4494
4281
|
...paginationArgs,
|
4495
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4282
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4496
4283
|
});
|
4497
4284
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4498
4285
|
return coins.map((coin) => ({
|
4499
4286
|
id: coin.utxoId,
|
4500
4287
|
assetId: coin.assetId,
|
4501
|
-
amount: (0,
|
4288
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4502
4289
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4503
|
-
|
4504
|
-
|
4290
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4291
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4292
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4505
4293
|
}));
|
4506
4294
|
}
|
4507
4295
|
/**
|
@@ -4515,19 +4303,19 @@ var _Provider = class {
|
|
4515
4303
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4516
4304
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4517
4305
|
const excludeInput = {
|
4518
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4519
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4306
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4307
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4520
4308
|
};
|
4521
4309
|
if (this.cache) {
|
4522
4310
|
const uniqueUtxos = new Set(
|
4523
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4311
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4524
4312
|
);
|
4525
4313
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4526
4314
|
}
|
4527
4315
|
const coinsQuery = {
|
4528
4316
|
owner: ownerAddress.toB256(),
|
4529
4317
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4530
|
-
assetId: (0,
|
4318
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4531
4319
|
amount: amount.toString(10),
|
4532
4320
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4533
4321
|
})),
|
@@ -4538,9 +4326,9 @@ var _Provider = class {
|
|
4538
4326
|
switch (coin.__typename) {
|
4539
4327
|
case "MessageCoin":
|
4540
4328
|
return {
|
4541
|
-
amount: (0,
|
4329
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4542
4330
|
assetId: coin.assetId,
|
4543
|
-
daHeight: (0,
|
4331
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4544
4332
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4545
4333
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4546
4334
|
nonce: coin.nonce
|
@@ -4548,11 +4336,12 @@ var _Provider = class {
|
|
4548
4336
|
case "Coin":
|
4549
4337
|
return {
|
4550
4338
|
id: coin.utxoId,
|
4551
|
-
amount: (0,
|
4339
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4552
4340
|
assetId: coin.assetId,
|
4553
4341
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4554
|
-
|
4555
|
-
|
4342
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4343
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4344
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4556
4345
|
};
|
4557
4346
|
default:
|
4558
4347
|
return null;
|
@@ -4569,13 +4358,13 @@ var _Provider = class {
|
|
4569
4358
|
async getBlock(idOrHeight) {
|
4570
4359
|
let variables;
|
4571
4360
|
if (typeof idOrHeight === "number") {
|
4572
|
-
variables = { height: (0,
|
4361
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4573
4362
|
} else if (idOrHeight === "latest") {
|
4574
4363
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4575
4364
|
} else if (idOrHeight.length === 66) {
|
4576
4365
|
variables = { blockId: idOrHeight };
|
4577
4366
|
} else {
|
4578
|
-
variables = { blockId: (0,
|
4367
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4579
4368
|
}
|
4580
4369
|
const { block } = await this.operations.getBlock(variables);
|
4581
4370
|
if (!block) {
|
@@ -4583,7 +4372,7 @@ var _Provider = class {
|
|
4583
4372
|
}
|
4584
4373
|
return {
|
4585
4374
|
id: block.id,
|
4586
|
-
height: (0,
|
4375
|
+
height: (0, import_math15.bn)(block.header.height),
|
4587
4376
|
time: block.header.time,
|
4588
4377
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4589
4378
|
};
|
@@ -4598,7 +4387,7 @@ var _Provider = class {
|
|
4598
4387
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4599
4388
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4600
4389
|
id: block.id,
|
4601
|
-
height: (0,
|
4390
|
+
height: (0, import_math15.bn)(block.header.height),
|
4602
4391
|
time: block.header.time,
|
4603
4392
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4604
4393
|
}));
|
@@ -4613,7 +4402,7 @@ var _Provider = class {
|
|
4613
4402
|
async getBlockWithTransactions(idOrHeight) {
|
4614
4403
|
let variables;
|
4615
4404
|
if (typeof idOrHeight === "number") {
|
4616
|
-
variables = { blockHeight: (0,
|
4405
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4617
4406
|
} else if (idOrHeight === "latest") {
|
4618
4407
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4619
4408
|
} else {
|
@@ -4625,11 +4414,11 @@ var _Provider = class {
|
|
4625
4414
|
}
|
4626
4415
|
return {
|
4627
4416
|
id: block.id,
|
4628
|
-
height: (0,
|
4417
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4629
4418
|
time: block.header.time,
|
4630
4419
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4631
4420
|
transactions: block.transactions.map(
|
4632
|
-
(tx) => new
|
4421
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4633
4422
|
)
|
4634
4423
|
};
|
4635
4424
|
}
|
@@ -4644,8 +4433,8 @@ var _Provider = class {
|
|
4644
4433
|
if (!transaction) {
|
4645
4434
|
return null;
|
4646
4435
|
}
|
4647
|
-
return new
|
4648
|
-
(0,
|
4436
|
+
return new import_transactions18.TransactionCoder().decode(
|
4437
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4649
4438
|
0
|
4650
4439
|
)?.[0];
|
4651
4440
|
}
|
@@ -4672,9 +4461,9 @@ var _Provider = class {
|
|
4672
4461
|
async getContractBalance(contractId, assetId) {
|
4673
4462
|
const { contractBalance } = await this.operations.getContractBalance({
|
4674
4463
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4675
|
-
asset: (0,
|
4464
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4676
4465
|
});
|
4677
|
-
return (0,
|
4466
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4678
4467
|
}
|
4679
4468
|
/**
|
4680
4469
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4686,9 +4475,9 @@ var _Provider = class {
|
|
4686
4475
|
async getBalance(owner, assetId) {
|
4687
4476
|
const { balance } = await this.operations.getBalance({
|
4688
4477
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4689
|
-
assetId: (0,
|
4478
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4690
4479
|
});
|
4691
|
-
return (0,
|
4480
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4692
4481
|
}
|
4693
4482
|
/**
|
4694
4483
|
* Returns balances for the given owner.
|
@@ -4706,7 +4495,7 @@ var _Provider = class {
|
|
4706
4495
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4707
4496
|
return balances.map((balance) => ({
|
4708
4497
|
assetId: balance.assetId,
|
4709
|
-
amount: (0,
|
4498
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4710
4499
|
}));
|
4711
4500
|
}
|
4712
4501
|
/**
|
@@ -4724,19 +4513,19 @@ var _Provider = class {
|
|
4724
4513
|
});
|
4725
4514
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4726
4515
|
return messages.map((message) => ({
|
4727
|
-
messageId:
|
4516
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4728
4517
|
sender: message.sender,
|
4729
4518
|
recipient: message.recipient,
|
4730
4519
|
nonce: message.nonce,
|
4731
|
-
amount: (0,
|
4520
|
+
amount: (0, import_math15.bn)(message.amount),
|
4732
4521
|
data: message.data
|
4733
4522
|
}),
|
4734
4523
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4735
4524
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4736
4525
|
nonce: message.nonce,
|
4737
|
-
amount: (0,
|
4738
|
-
data:
|
4739
|
-
daHeight: (0,
|
4526
|
+
amount: (0, import_math15.bn)(message.amount),
|
4527
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4528
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4740
4529
|
}));
|
4741
4530
|
}
|
4742
4531
|
/**
|
@@ -4789,52 +4578,44 @@ var _Provider = class {
|
|
4789
4578
|
} = result.messageProof;
|
4790
4579
|
return {
|
4791
4580
|
messageProof: {
|
4792
|
-
proofIndex: (0,
|
4581
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4793
4582
|
proofSet: messageProof.proofSet
|
4794
4583
|
},
|
4795
4584
|
blockProof: {
|
4796
|
-
proofIndex: (0,
|
4585
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4797
4586
|
proofSet: blockProof.proofSet
|
4798
4587
|
},
|
4799
4588
|
messageBlockHeader: {
|
4800
4589
|
id: messageBlockHeader.id,
|
4801
|
-
daHeight: (0,
|
4802
|
-
transactionsCount: (0,
|
4590
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4591
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4803
4592
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4804
|
-
height: (0,
|
4593
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4805
4594
|
prevRoot: messageBlockHeader.prevRoot,
|
4806
4595
|
time: messageBlockHeader.time,
|
4807
4596
|
applicationHash: messageBlockHeader.applicationHash,
|
4808
|
-
|
4597
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4598
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4809
4599
|
},
|
4810
4600
|
commitBlockHeader: {
|
4811
4601
|
id: commitBlockHeader.id,
|
4812
|
-
daHeight: (0,
|
4813
|
-
transactionsCount: (0,
|
4602
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4603
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4814
4604
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4815
|
-
height: (0,
|
4605
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4816
4606
|
prevRoot: commitBlockHeader.prevRoot,
|
4817
4607
|
time: commitBlockHeader.time,
|
4818
4608
|
applicationHash: commitBlockHeader.applicationHash,
|
4819
|
-
|
4609
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4610
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4820
4611
|
},
|
4821
4612
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4822
4613
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4823
4614
|
nonce,
|
4824
|
-
amount: (0,
|
4615
|
+
amount: (0, import_math15.bn)(amount),
|
4825
4616
|
data
|
4826
4617
|
};
|
4827
4618
|
}
|
4828
|
-
async getLatestGasPrice() {
|
4829
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4830
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4831
|
-
}
|
4832
|
-
async estimateGasPrice(blockHorizon) {
|
4833
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4834
|
-
blockHorizon: String(blockHorizon)
|
4835
|
-
});
|
4836
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4837
|
-
}
|
4838
4619
|
/**
|
4839
4620
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4840
4621
|
*
|
@@ -4854,10 +4635,10 @@ var _Provider = class {
|
|
4854
4635
|
*/
|
4855
4636
|
async produceBlocks(amount, startTime) {
|
4856
4637
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4857
|
-
blocksToProduce: (0,
|
4858
|
-
startTimestamp: startTime ?
|
4638
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4639
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4859
4640
|
});
|
4860
|
-
return (0,
|
4641
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4861
4642
|
}
|
4862
4643
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4863
4644
|
async getTransactionResponse(transactionId) {
|
@@ -4871,7 +4652,7 @@ cacheInputs_fn = function(inputs) {
|
|
4871
4652
|
return;
|
4872
4653
|
}
|
4873
4654
|
inputs.forEach((input) => {
|
4874
|
-
if (input.type ===
|
4655
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4875
4656
|
this.cache?.set(input.id);
|
4876
4657
|
}
|
4877
4658
|
});
|
@@ -4881,9 +4662,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4881
4662
|
|
4882
4663
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4883
4664
|
var import_errors15 = require("@fuel-ts/errors");
|
4884
|
-
var
|
4885
|
-
var
|
4886
|
-
var
|
4665
|
+
var import_math16 = require("@fuel-ts/math");
|
4666
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4667
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4887
4668
|
async function getTransactionSummary(params) {
|
4888
4669
|
const { id, provider, abiMap } = params;
|
4889
4670
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4895,32 +4676,25 @@ async function getTransactionSummary(params) {
|
|
4895
4676
|
`Transaction not found for given id: ${id}.`
|
4896
4677
|
);
|
4897
4678
|
}
|
4898
|
-
const [decodedTransaction] = new
|
4899
|
-
(0,
|
4679
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
|
4680
|
+
(0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4900
4681
|
0
|
4901
4682
|
);
|
4902
|
-
|
4903
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4904
|
-
txReceipts = gqlTransaction.status.receipts;
|
4905
|
-
}
|
4906
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4683
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4907
4684
|
const {
|
4908
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4685
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4909
4686
|
} = provider.getChain();
|
4910
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4911
4687
|
const transactionInfo = assembleTransactionSummary({
|
4912
4688
|
id: gqlTransaction.id,
|
4913
4689
|
receipts,
|
4914
4690
|
transaction: decodedTransaction,
|
4915
|
-
transactionBytes: (0,
|
4691
|
+
transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4916
4692
|
gqlTransactionStatus: gqlTransaction.status,
|
4917
|
-
gasPerByte: (0,
|
4918
|
-
gasPriceFactor: (0,
|
4693
|
+
gasPerByte: (0, import_math16.bn)(gasPerByte),
|
4694
|
+
gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
|
4919
4695
|
abiMap,
|
4920
4696
|
maxInputs,
|
4921
|
-
gasCosts
|
4922
|
-
maxGasPerTx,
|
4923
|
-
gasPrice
|
4697
|
+
gasCosts
|
4924
4698
|
});
|
4925
4699
|
return {
|
4926
4700
|
gqlTransaction,
|
@@ -4930,11 +4704,10 @@ async function getTransactionSummary(params) {
|
|
4930
4704
|
async function getTransactionSummaryFromRequest(params) {
|
4931
4705
|
const { provider, transactionRequest, abiMap } = params;
|
4932
4706
|
const { receipts } = await provider.call(transactionRequest);
|
4933
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4707
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4934
4708
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4935
4709
|
const transaction = transactionRequest.toTransaction();
|
4936
4710
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4937
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4938
4711
|
const transactionSummary = assembleTransactionSummary({
|
4939
4712
|
receipts,
|
4940
4713
|
transaction,
|
@@ -4943,9 +4716,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4943
4716
|
gasPerByte,
|
4944
4717
|
gasPriceFactor,
|
4945
4718
|
maxInputs,
|
4946
|
-
gasCosts
|
4947
|
-
maxGasPerTx,
|
4948
|
-
gasPrice
|
4719
|
+
gasCosts
|
4949
4720
|
});
|
4950
4721
|
return transactionSummary;
|
4951
4722
|
}
|
@@ -4954,31 +4725,24 @@ async function getTransactionsSummaries(params) {
|
|
4954
4725
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4955
4726
|
const { edges, pageInfo } = transactionsByOwner;
|
4956
4727
|
const {
|
4957
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4728
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4958
4729
|
} = provider.getChain();
|
4959
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4960
4730
|
const transactions = edges.map((edge) => {
|
4961
4731
|
const { node: gqlTransaction } = edge;
|
4962
|
-
const { id, rawPayload, status } = gqlTransaction;
|
4963
|
-
const [decodedTransaction] = new
|
4964
|
-
|
4965
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4966
|
-
txReceipts = gqlTransaction.status.receipts;
|
4967
|
-
}
|
4968
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4732
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4733
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
|
4734
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4969
4735
|
const transactionSummary = assembleTransactionSummary({
|
4970
4736
|
id,
|
4971
4737
|
receipts,
|
4972
4738
|
transaction: decodedTransaction,
|
4973
|
-
transactionBytes: (0,
|
4739
|
+
transactionBytes: (0, import_utils26.arrayify)(rawPayload),
|
4974
4740
|
gqlTransactionStatus: status,
|
4975
4741
|
abiMap,
|
4976
4742
|
gasPerByte,
|
4977
4743
|
gasPriceFactor,
|
4978
4744
|
maxInputs,
|
4979
|
-
gasCosts
|
4980
|
-
maxGasPerTx,
|
4981
|
-
gasPrice
|
4745
|
+
gasCosts
|
4982
4746
|
});
|
4983
4747
|
const output = {
|
4984
4748
|
gqlTransaction,
|
@@ -5115,17 +4879,17 @@ var assets = [
|
|
5115
4879
|
|
5116
4880
|
// src/utils/formatTransferToContractScriptData.ts
|
5117
4881
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5118
|
-
var
|
5119
|
-
var
|
4882
|
+
var import_math17 = require("@fuel-ts/math");
|
4883
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5120
4884
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5121
4885
|
var formatTransferToContractScriptData = (params) => {
|
5122
4886
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5123
4887
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
5124
|
-
const encoded = numberCoder.encode(new
|
4888
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
5125
4889
|
const scriptData = Uint8Array.from([
|
5126
|
-
...(0,
|
4890
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
5127
4891
|
...encoded,
|
5128
|
-
...(0,
|
4892
|
+
...(0, import_utils27.arrayify)(assetId)
|
5129
4893
|
]);
|
5130
4894
|
return scriptData;
|
5131
4895
|
};
|
@@ -5272,8 +5036,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5272
5036
|
* @param assetId - The asset ID to check the balance for.
|
5273
5037
|
* @returns A promise that resolves to the balance amount.
|
5274
5038
|
*/
|
5275
|
-
async getBalance(assetId
|
5276
|
-
const
|
5039
|
+
async getBalance(assetId) {
|
5040
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
5041
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5277
5042
|
return amount;
|
5278
5043
|
}
|
5279
5044
|
/**
|
@@ -5310,33 +5075,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5310
5075
|
* @param fee - The estimated transaction fee.
|
5311
5076
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5312
5077
|
*/
|
5313
|
-
async fund(request,
|
5314
|
-
const
|
5315
|
-
const
|
5316
|
-
|
5317
|
-
|
5318
|
-
|
5319
|
-
coinQuantities: requiredQuantities
|
5078
|
+
async fund(request, coinQuantities, fee) {
|
5079
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5080
|
+
const updatedQuantities = addAmountToAsset({
|
5081
|
+
amount: (0, import_math18.bn)(fee),
|
5082
|
+
assetId: baseAssetId,
|
5083
|
+
coinQuantities
|
5320
5084
|
});
|
5321
5085
|
const quantitiesDict = {};
|
5322
|
-
|
5086
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5323
5087
|
quantitiesDict[assetId] = {
|
5324
5088
|
required: amount,
|
5325
|
-
owned: (0,
|
5089
|
+
owned: (0, import_math18.bn)(0)
|
5326
5090
|
};
|
5327
5091
|
});
|
5328
|
-
|
5092
|
+
const cachedUtxos = [];
|
5093
|
+
const cachedMessages = [];
|
5094
|
+
const owner = this.address.toB256();
|
5095
|
+
request.inputs.forEach((input) => {
|
5329
5096
|
const isResource = "amount" in input;
|
5330
5097
|
if (isResource) {
|
5331
5098
|
const isCoin2 = "owner" in input;
|
5332
5099
|
if (isCoin2) {
|
5333
5100
|
const assetId = String(input.assetId);
|
5334
|
-
if (quantitiesDict[assetId]) {
|
5335
|
-
const amount = (0,
|
5101
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
5102
|
+
const amount = (0, import_math18.bn)(input.amount);
|
5336
5103
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5104
|
+
cachedUtxos.push(input.id);
|
5337
5105
|
}
|
5338
|
-
} else if (input.amount && quantitiesDict[
|
5339
|
-
quantitiesDict[
|
5106
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
5107
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
5108
|
+
cachedMessages.push(input.nonce);
|
5340
5109
|
}
|
5341
5110
|
}
|
5342
5111
|
});
|
@@ -5351,23 +5120,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5351
5120
|
});
|
5352
5121
|
const needsToBeFunded = missingQuantities.length;
|
5353
5122
|
if (needsToBeFunded) {
|
5354
|
-
const
|
5355
|
-
|
5356
|
-
|
5357
|
-
|
5358
|
-
|
5359
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5360
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5361
|
-
if (addedSignatures) {
|
5362
|
-
Array.from({ length: addedSignatures }).forEach(
|
5363
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
5364
|
-
);
|
5123
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5124
|
+
messages: cachedMessages,
|
5125
|
+
utxos: cachedUtxos
|
5126
|
+
});
|
5127
|
+
request.addResources(resources);
|
5365
5128
|
}
|
5366
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5367
|
-
transactionRequest: requestToBeReEstimate
|
5368
|
-
});
|
5369
|
-
txRequest.maxFee = maxFee;
|
5370
|
-
return txRequest;
|
5371
5129
|
}
|
5372
5130
|
/**
|
5373
5131
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5375,25 +5133,29 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5375
5133
|
* @param destination - The address of the destination.
|
5376
5134
|
* @param amount - The amount of coins to transfer.
|
5377
5135
|
* @param assetId - The asset ID of the coins to transfer.
|
5378
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5136
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5379
5137
|
* @returns A promise that resolves to the prepared transaction request.
|
5380
5138
|
*/
|
5381
|
-
async createTransfer(destination, amount, assetId
|
5382
|
-
const
|
5383
|
-
|
5384
|
-
const
|
5139
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5140
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5141
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5142
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5143
|
+
const request = new ScriptTransactionRequest(params);
|
5144
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5145
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5385
5146
|
estimateTxDependencies: true,
|
5386
5147
|
resourcesOwner: this
|
5387
5148
|
});
|
5388
|
-
|
5389
|
-
|
5390
|
-
|
5391
|
-
|
5392
|
-
|
5393
|
-
|
5394
|
-
|
5395
|
-
|
5396
|
-
await this.fund(request,
|
5149
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
5150
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
5151
|
+
this.validateGas({
|
5152
|
+
gasUsed,
|
5153
|
+
gasPrice: request.gasPrice,
|
5154
|
+
gasLimit: request.gasLimit,
|
5155
|
+
minGasPrice
|
5156
|
+
});
|
5157
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5158
|
+
request.updatePredicateInputs(estimatedInputs);
|
5397
5159
|
return request;
|
5398
5160
|
}
|
5399
5161
|
/**
|
@@ -5405,14 +5167,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5405
5167
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5406
5168
|
* @returns A promise that resolves to the transaction response.
|
5407
5169
|
*/
|
5408
|
-
async transfer(destination, amount, assetId
|
5409
|
-
if ((0,
|
5170
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5171
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5410
5172
|
throw new import_errors16.FuelError(
|
5411
5173
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5412
5174
|
"Transfer amount must be a positive number."
|
5413
5175
|
);
|
5414
5176
|
}
|
5415
|
-
const
|
5177
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5178
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5416
5179
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5417
5180
|
}
|
5418
5181
|
/**
|
@@ -5424,38 +5187,40 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5424
5187
|
* @param txParams - The optional transaction parameters.
|
5425
5188
|
* @returns A promise that resolves to the transaction response.
|
5426
5189
|
*/
|
5427
|
-
async transferToContract(contractId, amount, assetId
|
5428
|
-
if ((0,
|
5190
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5191
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5429
5192
|
throw new import_errors16.FuelError(
|
5430
5193
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5431
5194
|
"Transfer amount must be a positive number."
|
5432
5195
|
);
|
5433
5196
|
}
|
5434
5197
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5198
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5199
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5200
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5435
5201
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5436
5202
|
hexlifiedContractId: contractAddress.toB256(),
|
5437
|
-
amountToTransfer: (0,
|
5438
|
-
assetId
|
5203
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5204
|
+
assetId: assetIdToTransfer
|
5439
5205
|
});
|
5440
5206
|
const request = new ScriptTransactionRequest({
|
5441
|
-
...
|
5207
|
+
...params,
|
5442
5208
|
script,
|
5443
5209
|
scriptData
|
5444
5210
|
});
|
5445
5211
|
request.addContractInputAndOutput(contractAddress);
|
5446
|
-
const
|
5447
|
-
|
5448
|
-
|
5212
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5213
|
+
request,
|
5214
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5215
|
+
);
|
5216
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5217
|
+
this.validateGas({
|
5218
|
+
gasUsed,
|
5219
|
+
gasPrice: request.gasPrice,
|
5220
|
+
gasLimit: request.gasLimit,
|
5221
|
+
minGasPrice
|
5449
5222
|
});
|
5450
|
-
|
5451
|
-
this.validateGas({
|
5452
|
-
gasUsed: txCost.gasUsed,
|
5453
|
-
gasLimit: request.gasLimit
|
5454
|
-
});
|
5455
|
-
}
|
5456
|
-
request.gasLimit = txCost.gasUsed;
|
5457
|
-
request.maxFee = txCost.maxFee;
|
5458
|
-
await this.fund(request, txCost);
|
5223
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5459
5224
|
return this.sendTransaction(request);
|
5460
5225
|
}
|
5461
5226
|
/**
|
@@ -5467,31 +5232,35 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5467
5232
|
* @returns A promise that resolves to the transaction response.
|
5468
5233
|
*/
|
5469
5234
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5235
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5236
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5470
5237
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5471
|
-
const recipientDataArray = (0,
|
5238
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5472
5239
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5473
5240
|
);
|
5474
|
-
const amountDataArray = (0,
|
5475
|
-
"0x".concat((0,
|
5241
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5242
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5476
5243
|
);
|
5477
5244
|
const script = new Uint8Array([
|
5478
|
-
...(0,
|
5245
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5479
5246
|
...recipientDataArray,
|
5480
5247
|
...amountDataArray
|
5481
5248
|
]);
|
5482
|
-
const params = { script, ...txParams };
|
5249
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5483
5250
|
const request = new ScriptTransactionRequest(params);
|
5484
|
-
const
|
5485
|
-
const
|
5486
|
-
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5492
|
-
|
5493
|
-
|
5494
|
-
|
5251
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
|
5252
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5253
|
+
request,
|
5254
|
+
forwardingQuantities
|
5255
|
+
);
|
5256
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5257
|
+
this.validateGas({
|
5258
|
+
gasUsed,
|
5259
|
+
gasPrice: request.gasPrice,
|
5260
|
+
gasLimit: request.gasLimit,
|
5261
|
+
minGasPrice
|
5262
|
+
});
|
5263
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5495
5264
|
return this.sendTransaction(request);
|
5496
5265
|
}
|
5497
5266
|
async signMessage(message) {
|
@@ -5549,7 +5318,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5549
5318
|
}
|
5550
5319
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5551
5320
|
}
|
5552
|
-
validateGas({
|
5321
|
+
validateGas({
|
5322
|
+
gasUsed,
|
5323
|
+
gasPrice,
|
5324
|
+
gasLimit,
|
5325
|
+
minGasPrice
|
5326
|
+
}) {
|
5327
|
+
if (minGasPrice.gt(gasPrice)) {
|
5328
|
+
throw new import_errors16.FuelError(
|
5329
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5330
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5331
|
+
);
|
5332
|
+
}
|
5553
5333
|
if (gasUsed.gt(gasLimit)) {
|
5554
5334
|
throw new import_errors16.FuelError(
|
5555
5335
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5561,14 +5341,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5561
5341
|
|
5562
5342
|
// src/wallet/base-wallet-unlocked.ts
|
5563
5343
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5564
|
-
var
|
5344
|
+
var import_utils31 = require("@fuel-ts/utils");
|
5565
5345
|
|
5566
5346
|
// src/signer/signer.ts
|
5567
5347
|
var import_address5 = require("@fuel-ts/address");
|
5568
5348
|
var import_crypto = require("@fuel-ts/crypto");
|
5569
5349
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5570
|
-
var
|
5571
|
-
var
|
5350
|
+
var import_math19 = require("@fuel-ts/math");
|
5351
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5572
5352
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5573
5353
|
var Signer = class {
|
5574
5354
|
address;
|
@@ -5587,10 +5367,10 @@ var Signer = class {
|
|
5587
5367
|
privateKey = `0x${privateKey}`;
|
5588
5368
|
}
|
5589
5369
|
}
|
5590
|
-
const privateKeyBytes = (0,
|
5591
|
-
this.privateKey = (0,
|
5592
|
-
this.publicKey = (0,
|
5593
|
-
this.compressedPublicKey = (0,
|
5370
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
5371
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
5372
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5373
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5594
5374
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5595
5375
|
}
|
5596
5376
|
/**
|
@@ -5604,11 +5384,11 @@ var Signer = class {
|
|
5604
5384
|
* @returns hashed signature
|
5605
5385
|
*/
|
5606
5386
|
sign(data) {
|
5607
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5608
|
-
const r = (0,
|
5609
|
-
const s = (0,
|
5387
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5388
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5389
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5610
5390
|
s[0] |= (signature.recovery || 0) << 7;
|
5611
|
-
return (0,
|
5391
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5612
5392
|
}
|
5613
5393
|
/**
|
5614
5394
|
* Add point on the current elliptic curve
|
@@ -5617,8 +5397,8 @@ var Signer = class {
|
|
5617
5397
|
* @returns compressed point on the curve
|
5618
5398
|
*/
|
5619
5399
|
addPoint(point) {
|
5620
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5621
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5400
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5401
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5622
5402
|
const result = p0.add(p1);
|
5623
5403
|
return `0x${result.toHex(true)}`;
|
5624
5404
|
}
|
@@ -5630,16 +5410,16 @@ var Signer = class {
|
|
5630
5410
|
* @returns public key from signature from the
|
5631
5411
|
*/
|
5632
5412
|
static recoverPublicKey(data, signature) {
|
5633
|
-
const signedMessageBytes = (0,
|
5413
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5634
5414
|
const r = signedMessageBytes.slice(0, 32);
|
5635
5415
|
const s = signedMessageBytes.slice(32, 64);
|
5636
5416
|
const recoveryParam = (s[0] & 128) >> 7;
|
5637
5417
|
s[0] &= 127;
|
5638
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5418
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5639
5419
|
recoveryParam
|
5640
5420
|
);
|
5641
|
-
const publicKey = sig.recoverPublicKey((0,
|
5642
|
-
return (0,
|
5421
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5422
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5643
5423
|
}
|
5644
5424
|
/**
|
5645
5425
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5658,7 +5438,7 @@ var Signer = class {
|
|
5658
5438
|
* @returns random 32-byte hashed
|
5659
5439
|
*/
|
5660
5440
|
static generatePrivateKey(entropy) {
|
5661
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5441
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5662
5442
|
}
|
5663
5443
|
/**
|
5664
5444
|
* Extended publicKey from a compact publicKey
|
@@ -5667,8 +5447,8 @@ var Signer = class {
|
|
5667
5447
|
* @returns extended publicKey
|
5668
5448
|
*/
|
5669
5449
|
static extendPublicKey(publicKey) {
|
5670
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5671
|
-
return (0,
|
5450
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5451
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5672
5452
|
}
|
5673
5453
|
};
|
5674
5454
|
|
@@ -5676,7 +5456,7 @@ var Signer = class {
|
|
5676
5456
|
var import_address6 = require("@fuel-ts/address");
|
5677
5457
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5678
5458
|
var import_errors17 = require("@fuel-ts/errors");
|
5679
|
-
var
|
5459
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5680
5460
|
var import_uuid = require("uuid");
|
5681
5461
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5682
5462
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5759,7 +5539,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5759
5539
|
);
|
5760
5540
|
}
|
5761
5541
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5762
|
-
const privateKey = (0,
|
5542
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5763
5543
|
return privateKey;
|
5764
5544
|
}
|
5765
5545
|
|
@@ -5804,7 +5584,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5804
5584
|
*/
|
5805
5585
|
async signMessage(message) {
|
5806
5586
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5807
|
-
return (0,
|
5587
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5808
5588
|
}
|
5809
5589
|
/**
|
5810
5590
|
* Signs a transaction with the wallet's private key.
|
@@ -5817,7 +5597,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5817
5597
|
const chainId = this.provider.getChainId();
|
5818
5598
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5819
5599
|
const signature = await this.signer().sign(hashedTransaction);
|
5820
|
-
return (0,
|
5600
|
+
return (0, import_utils31.hexlify)(signature);
|
5821
5601
|
}
|
5822
5602
|
/**
|
5823
5603
|
* Populates a transaction with the witnesses signature.
|
@@ -5837,7 +5617,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5837
5617
|
* @param transactionRequestLike - The transaction request to send.
|
5838
5618
|
* @returns A promise that resolves to the TransactionResponse object.
|
5839
5619
|
*/
|
5840
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5620
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5841
5621
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5842
5622
|
if (estimateTxDependencies) {
|
5843
5623
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5878,16 +5658,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5878
5658
|
// src/hdwallet/hdwallet.ts
|
5879
5659
|
var import_errors20 = require("@fuel-ts/errors");
|
5880
5660
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5881
|
-
var
|
5882
|
-
var
|
5883
|
-
var
|
5661
|
+
var import_math20 = require("@fuel-ts/math");
|
5662
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5663
|
+
var import_ethers3 = require("ethers");
|
5884
5664
|
|
5885
5665
|
// src/mnemonic/mnemonic.ts
|
5886
5666
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5887
5667
|
var import_errors19 = require("@fuel-ts/errors");
|
5888
5668
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5889
|
-
var
|
5890
|
-
var
|
5669
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5670
|
+
var import_ethers2 = require("ethers");
|
5891
5671
|
|
5892
5672
|
// src/wordlists/words/english.ts
|
5893
5673
|
var english = [
|
@@ -7950,7 +7730,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7950
7730
|
// src/mnemonic/utils.ts
|
7951
7731
|
var import_errors18 = require("@fuel-ts/errors");
|
7952
7732
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7953
|
-
var
|
7733
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7954
7734
|
function toUtf8Bytes(stri) {
|
7955
7735
|
const str = stri.normalize("NFKD");
|
7956
7736
|
const result = [];
|
@@ -8017,14 +7797,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
8017
7797
|
}
|
8018
7798
|
}
|
8019
7799
|
const checksumBits = entropy.length / 4;
|
8020
|
-
const checksum = (0,
|
7800
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
8021
7801
|
indices[indices.length - 1] <<= checksumBits;
|
8022
7802
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
8023
7803
|
return indices;
|
8024
7804
|
}
|
8025
7805
|
function mnemonicWordsToEntropy(words, wordlist) {
|
8026
7806
|
const size = Math.ceil(11 * words.length / 8);
|
8027
|
-
const entropy = (0,
|
7807
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
8028
7808
|
let offset = 0;
|
8029
7809
|
for (let i = 0; i < words.length; i += 1) {
|
8030
7810
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -8044,7 +7824,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8044
7824
|
const entropyBits = 32 * words.length / 3;
|
8045
7825
|
const checksumBits = words.length / 3;
|
8046
7826
|
const checksumMask = getUpperMask(checksumBits);
|
8047
|
-
const checksum = (0,
|
7827
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8048
7828
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8049
7829
|
throw new import_errors18.FuelError(
|
8050
7830
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -8119,7 +7899,7 @@ var Mnemonic = class {
|
|
8119
7899
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8120
7900
|
const words = getWords(phrase);
|
8121
7901
|
assertMnemonic(words);
|
8122
|
-
return (0,
|
7902
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8123
7903
|
}
|
8124
7904
|
/**
|
8125
7905
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8127,7 +7907,7 @@ var Mnemonic = class {
|
|
8127
7907
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8128
7908
|
*/
|
8129
7909
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8130
|
-
const entropyBytes = (0,
|
7910
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
8131
7911
|
assertWordList(wordlist);
|
8132
7912
|
assertEntropy(entropyBytes);
|
8133
7913
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8141,7 +7921,7 @@ var Mnemonic = class {
|
|
8141
7921
|
assertMnemonic(getWords(phrase));
|
8142
7922
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
8143
7923
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
8144
|
-
return (0,
|
7924
|
+
return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
8145
7925
|
}
|
8146
7926
|
/**
|
8147
7927
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -8196,14 +7976,14 @@ var Mnemonic = class {
|
|
8196
7976
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8197
7977
|
*/
|
8198
7978
|
static masterKeysFromSeed(seed) {
|
8199
|
-
const seedArray = (0,
|
7979
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
8200
7980
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8201
7981
|
throw new import_errors19.FuelError(
|
8202
7982
|
import_errors19.ErrorCode.INVALID_SEED,
|
8203
7983
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8204
7984
|
);
|
8205
7985
|
}
|
8206
|
-
return (0,
|
7986
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
8207
7987
|
}
|
8208
7988
|
/**
|
8209
7989
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8214,22 +7994,22 @@ var Mnemonic = class {
|
|
8214
7994
|
*/
|
8215
7995
|
static seedToExtendedKey(seed, testnet = false) {
|
8216
7996
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8217
|
-
const prefix = (0,
|
7997
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8218
7998
|
const depth = "0x00";
|
8219
7999
|
const fingerprint = "0x00000000";
|
8220
8000
|
const index = "0x00000000";
|
8221
8001
|
const chainCode = masterKey.slice(32);
|
8222
8002
|
const privateKey = masterKey.slice(0, 32);
|
8223
|
-
const extendedKey = (0,
|
8003
|
+
const extendedKey = (0, import_utils33.concat)([
|
8224
8004
|
prefix,
|
8225
8005
|
depth,
|
8226
8006
|
fingerprint,
|
8227
8007
|
index,
|
8228
8008
|
chainCode,
|
8229
|
-
(0,
|
8009
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
8230
8010
|
]);
|
8231
|
-
const checksum = (0,
|
8232
|
-
return (0,
|
8011
|
+
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8012
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
8233
8013
|
}
|
8234
8014
|
/**
|
8235
8015
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8244,7 +8024,7 @@ var Mnemonic = class {
|
|
8244
8024
|
* @returns A randomly generated mnemonic
|
8245
8025
|
*/
|
8246
8026
|
static generate(size = 32, extraEntropy = "") {
|
8247
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8027
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
8248
8028
|
return Mnemonic.entropyToMnemonic(entropy);
|
8249
8029
|
}
|
8250
8030
|
};
|
@@ -8252,12 +8032,12 @@ var mnemonic_default = Mnemonic;
|
|
8252
8032
|
|
8253
8033
|
// src/hdwallet/hdwallet.ts
|
8254
8034
|
var HARDENED_INDEX = 2147483648;
|
8255
|
-
var MainnetPRV2 = (0,
|
8256
|
-
var MainnetPUB = (0,
|
8257
|
-
var TestnetPRV2 = (0,
|
8258
|
-
var TestnetPUB = (0,
|
8035
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
8036
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
8037
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
8038
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
8259
8039
|
function base58check(data) {
|
8260
|
-
return (0,
|
8040
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8261
8041
|
}
|
8262
8042
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8263
8043
|
if (isPublic) {
|
@@ -8266,11 +8046,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8266
8046
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8267
8047
|
}
|
8268
8048
|
function isPublicExtendedKey(extendedKey) {
|
8269
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8049
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
8270
8050
|
}
|
8271
8051
|
function isValidExtendedKey(extendedKey) {
|
8272
8052
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8273
|
-
(0,
|
8053
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
8274
8054
|
);
|
8275
8055
|
}
|
8276
8056
|
function parsePath(path, depth = 0) {
|
@@ -8288,8 +8068,8 @@ function parsePath(path, depth = 0) {
|
|
8288
8068
|
var HDWallet = class {
|
8289
8069
|
depth = 0;
|
8290
8070
|
index = 0;
|
8291
|
-
fingerprint = (0,
|
8292
|
-
parentFingerprint = (0,
|
8071
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8072
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8293
8073
|
privateKey;
|
8294
8074
|
publicKey;
|
8295
8075
|
chainCode;
|
@@ -8301,8 +8081,8 @@ var HDWallet = class {
|
|
8301
8081
|
constructor(config) {
|
8302
8082
|
if (config.privateKey) {
|
8303
8083
|
const signer = new Signer(config.privateKey);
|
8304
|
-
this.publicKey = (0,
|
8305
|
-
this.privateKey = (0,
|
8084
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
8085
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
8306
8086
|
} else {
|
8307
8087
|
if (!config.publicKey) {
|
8308
8088
|
throw new import_errors20.FuelError(
|
@@ -8310,10 +8090,10 @@ var HDWallet = class {
|
|
8310
8090
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8311
8091
|
);
|
8312
8092
|
}
|
8313
|
-
this.publicKey = (0,
|
8093
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
8314
8094
|
}
|
8315
8095
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8316
|
-
this.fingerprint = (0,
|
8096
|
+
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8317
8097
|
this.depth = config.depth || this.depth;
|
8318
8098
|
this.index = config.index || this.index;
|
8319
8099
|
this.chainCode = config.chainCode;
|
@@ -8329,9 +8109,9 @@ var HDWallet = class {
|
|
8329
8109
|
* @returns A new instance of HDWallet on the derived index
|
8330
8110
|
*/
|
8331
8111
|
deriveIndex(index) {
|
8332
|
-
const privateKey = this.privateKey && (0,
|
8333
|
-
const publicKey = (0,
|
8334
|
-
const chainCode = (0,
|
8112
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
8113
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
8114
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
8335
8115
|
const data = new Uint8Array(37);
|
8336
8116
|
if (index & HARDENED_INDEX) {
|
8337
8117
|
if (!privateKey) {
|
@@ -8342,15 +8122,15 @@ var HDWallet = class {
|
|
8342
8122
|
}
|
8343
8123
|
data.set(privateKey, 1);
|
8344
8124
|
} else {
|
8345
|
-
data.set((0,
|
8125
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
8346
8126
|
}
|
8347
|
-
data.set((0,
|
8348
|
-
const bytes = (0,
|
8127
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
8128
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8349
8129
|
const IL = bytes.slice(0, 32);
|
8350
8130
|
const IR = bytes.slice(32);
|
8351
8131
|
if (privateKey) {
|
8352
8132
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8353
|
-
const ki = (0,
|
8133
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8354
8134
|
return new HDWallet({
|
8355
8135
|
privateKey: ki,
|
8356
8136
|
chainCode: IR,
|
@@ -8359,7 +8139,7 @@ var HDWallet = class {
|
|
8359
8139
|
parentFingerprint: this.fingerprint
|
8360
8140
|
});
|
8361
8141
|
}
|
8362
|
-
const signer = new Signer((0,
|
8142
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
8363
8143
|
const Ki = signer.addPoint(publicKey);
|
8364
8144
|
return new HDWallet({
|
8365
8145
|
publicKey: Ki,
|
@@ -8394,12 +8174,12 @@ var HDWallet = class {
|
|
8394
8174
|
);
|
8395
8175
|
}
|
8396
8176
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8397
|
-
const depth = (0,
|
8177
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
8398
8178
|
const parentFingerprint = this.parentFingerprint;
|
8399
|
-
const index = (0,
|
8179
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
8400
8180
|
const chainCode = this.chainCode;
|
8401
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8402
|
-
const extendedKey = (0,
|
8181
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8182
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8403
8183
|
return base58check(extendedKey);
|
8404
8184
|
}
|
8405
8185
|
/**
|
@@ -8411,13 +8191,13 @@ var HDWallet = class {
|
|
8411
8191
|
static fromSeed(seed) {
|
8412
8192
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8413
8193
|
return new HDWallet({
|
8414
|
-
chainCode: (0,
|
8415
|
-
privateKey: (0,
|
8194
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
8195
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8416
8196
|
});
|
8417
8197
|
}
|
8418
8198
|
static fromExtendedKey(extendedKey) {
|
8419
|
-
const decoded = (0,
|
8420
|
-
const bytes = (0,
|
8199
|
+
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8200
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8421
8201
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8422
8202
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8423
8203
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8426,9 +8206,9 @@ var HDWallet = class {
|
|
8426
8206
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8427
8207
|
}
|
8428
8208
|
const depth = bytes[4];
|
8429
|
-
const parentFingerprint = (0,
|
8430
|
-
const index = parseInt((0,
|
8431
|
-
const chainCode = (0,
|
8209
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
8210
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8211
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8432
8212
|
const key = bytes.slice(45, 78);
|
8433
8213
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8434
8214
|
throw new import_errors20.FuelError(
|
@@ -9031,28 +8811,26 @@ var StorageAbstract = class {
|
|
9031
8811
|
// src/predicate/predicate.ts
|
9032
8812
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
9033
8813
|
var import_address10 = require("@fuel-ts/address");
|
9034
|
-
var import_configs13 = require("@fuel-ts/address/configs");
|
9035
8814
|
var import_errors25 = require("@fuel-ts/errors");
|
9036
|
-
var
|
9037
|
-
var
|
8815
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
8816
|
+
var import_utils37 = require("@fuel-ts/utils");
|
9038
8817
|
|
9039
8818
|
// src/predicate/utils/getPredicateRoot.ts
|
9040
8819
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9041
8820
|
var import_merkle = require("@fuel-ts/merkle");
|
9042
|
-
var
|
8821
|
+
var import_utils36 = require("@fuel-ts/utils");
|
9043
8822
|
var getPredicateRoot = (bytecode) => {
|
9044
8823
|
const chunkSize = 16 * 1024;
|
9045
|
-
const bytes = (0,
|
9046
|
-
const chunks = (0,
|
9047
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
9048
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
8824
|
+
const bytes = (0, import_utils36.arrayify)(bytecode);
|
8825
|
+
const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
|
8826
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
|
8827
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
|
9049
8828
|
return predicateRoot;
|
9050
8829
|
};
|
9051
8830
|
|
9052
8831
|
// src/predicate/predicate.ts
|
9053
8832
|
var Predicate = class extends Account {
|
9054
8833
|
bytes;
|
9055
|
-
predicateDataBytes = Uint8Array.from([]);
|
9056
8834
|
predicateData = [];
|
9057
8835
|
interface;
|
9058
8836
|
/**
|
@@ -9082,7 +8860,6 @@ var Predicate = class extends Account {
|
|
9082
8860
|
this.interface = predicateInterface;
|
9083
8861
|
if (inputData !== void 0 && inputData.length > 0) {
|
9084
8862
|
this.predicateData = inputData;
|
9085
|
-
this.predicateDataBytes = this.getPredicateData(0);
|
9086
8863
|
}
|
9087
8864
|
}
|
9088
8865
|
/**
|
@@ -9095,9 +8872,9 @@ var Predicate = class extends Account {
|
|
9095
8872
|
const request = transactionRequestify(transactionRequestLike);
|
9096
8873
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9097
8874
|
request.inputs?.forEach((input) => {
|
9098
|
-
if (input.type ===
|
9099
|
-
input.predicate =
|
9100
|
-
input.predicateData =
|
8875
|
+
if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
|
8876
|
+
input.predicate = this.bytes;
|
8877
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9101
8878
|
}
|
9102
8879
|
});
|
9103
8880
|
return request;
|
@@ -9111,8 +8888,10 @@ var Predicate = class extends Account {
|
|
9111
8888
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
9112
8889
|
* @returns A promise that resolves to the prepared transaction request.
|
9113
8890
|
*/
|
9114
|
-
async createTransfer(destination, amount, assetId
|
9115
|
-
|
8891
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8892
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8893
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8894
|
+
return this.populateTransactionPredicateData(request);
|
9116
8895
|
}
|
9117
8896
|
/**
|
9118
8897
|
* Sends a transaction with the populated predicate data.
|
@@ -9120,9 +8899,9 @@ var Predicate = class extends Account {
|
|
9120
8899
|
* @param transactionRequestLike - The transaction request-like object.
|
9121
8900
|
* @returns A promise that resolves to the transaction response.
|
9122
8901
|
*/
|
9123
|
-
sendTransaction(transactionRequestLike) {
|
9124
|
-
const transactionRequest =
|
9125
|
-
return super.sendTransaction(transactionRequest,
|
8902
|
+
sendTransaction(transactionRequestLike, options) {
|
8903
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8904
|
+
return super.sendTransaction(transactionRequest, options);
|
9126
8905
|
}
|
9127
8906
|
/**
|
9128
8907
|
* Simulates a transaction with the populated predicate data.
|
@@ -9131,15 +8910,15 @@ var Predicate = class extends Account {
|
|
9131
8910
|
* @returns A promise that resolves to the call result.
|
9132
8911
|
*/
|
9133
8912
|
simulateTransaction(transactionRequestLike) {
|
9134
|
-
const transactionRequest =
|
9135
|
-
return super.simulateTransaction(transactionRequest
|
8913
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8914
|
+
return super.simulateTransaction(transactionRequest);
|
9136
8915
|
}
|
9137
8916
|
getPredicateData(policiesLength) {
|
9138
8917
|
if (!this.predicateData.length) {
|
9139
8918
|
return new Uint8Array();
|
9140
8919
|
}
|
9141
8920
|
const mainFn = this.interface?.functions.main;
|
9142
|
-
const paddedCode = new
|
8921
|
+
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
9143
8922
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
9144
8923
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
9145
8924
|
});
|
@@ -9155,7 +8934,7 @@ var Predicate = class extends Account {
|
|
9155
8934
|
* @returns An object containing the new predicate bytes and interface.
|
9156
8935
|
*/
|
9157
8936
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9158
|
-
let predicateBytes = (0,
|
8937
|
+
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
9159
8938
|
let abiInterface;
|
9160
8939
|
if (jsonAbi) {
|
9161
8940
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
@@ -9178,26 +8957,6 @@ var Predicate = class extends Account {
|
|
9178
8957
|
predicateInterface: abiInterface
|
9179
8958
|
};
|
9180
8959
|
}
|
9181
|
-
/**
|
9182
|
-
* Retrieves resources satisfying the spend query for the account.
|
9183
|
-
*
|
9184
|
-
* @param quantities - IDs of coins to exclude.
|
9185
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9186
|
-
* @returns A promise that resolves to an array of Resources.
|
9187
|
-
*/
|
9188
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9189
|
-
const resources = await this.provider.getResourcesToSpend(
|
9190
|
-
this.address,
|
9191
|
-
quantities,
|
9192
|
-
excludedIds
|
9193
|
-
);
|
9194
|
-
return resources.map((resource) => ({
|
9195
|
-
...resource,
|
9196
|
-
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9197
|
-
predicateData: (0, import_utils36.hexlify)(this.predicateDataBytes),
|
9198
|
-
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9199
|
-
}));
|
9200
|
-
}
|
9201
8960
|
/**
|
9202
8961
|
* Sets the configurable constants for the predicate.
|
9203
8962
|
*
|
@@ -9947,7 +9706,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9947
9706
|
WalletLocked,
|
9948
9707
|
WalletManager,
|
9949
9708
|
WalletUnlocked,
|
9950
|
-
|
9709
|
+
addAmountToAsset,
|
9951
9710
|
addOperation,
|
9952
9711
|
assemblePanicError,
|
9953
9712
|
assembleReceiptByType,
|
@@ -9956,10 +9715,9 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9956
9715
|
assets,
|
9957
9716
|
buildBlockExplorerUrl,
|
9958
9717
|
cacheFor,
|
9959
|
-
cacheTxInputsFromOwner,
|
9960
|
-
calculateGasFee,
|
9961
9718
|
calculateMetadataGasForTxCreate,
|
9962
9719
|
calculateMetadataGasForTxScript,
|
9720
|
+
calculatePriceWithFactor,
|
9963
9721
|
calculateTransactionFee,
|
9964
9722
|
coinQuantityfy,
|
9965
9723
|
deferPromise,
|