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