@fuel-ts/account 0.0.0-rc-1976-20240406124842 → 0.0.0-rc-2021-20240408141516
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +865 -615
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +845 -609
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +687 -452
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +888 -322
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +3 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +45 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1580 -1116
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +821 -606
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +679 -464
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/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
|
},
|
@@ -1171,7 +1231,7 @@ var MemoryCache = class {
|
|
1171
1231
|
};
|
1172
1232
|
|
1173
1233
|
// src/providers/transaction-request/input.ts
|
1174
|
-
var
|
1234
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1175
1235
|
var import_errors3 = require("@fuel-ts/errors");
|
1176
1236
|
var import_math2 = require("@fuel-ts/math");
|
1177
1237
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1185,7 +1245,7 @@ var inputify = (value) => {
|
|
1185
1245
|
return {
|
1186
1246
|
type: import_transactions.InputType.Coin,
|
1187
1247
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1188
|
-
outputIndex: (0, import_utils3.arrayify)(value.id)
|
1248
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 34)),
|
1189
1249
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1190
1250
|
amount: (0, import_math2.bn)(value.amount),
|
1191
1251
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1194,10 +1254,9 @@ var inputify = (value) => {
|
|
1194
1254
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1195
1255
|
},
|
1196
1256
|
witnessIndex: value.witnessIndex,
|
1197
|
-
maturity: value.maturity ?? 0,
|
1198
1257
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1199
|
-
predicateLength: predicate.length,
|
1200
|
-
predicateDataLength: predicateData.length,
|
1258
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1259
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1201
1260
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1202
1261
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1203
1262
|
};
|
@@ -1205,10 +1264,10 @@ var inputify = (value) => {
|
|
1205
1264
|
case import_transactions.InputType.Contract: {
|
1206
1265
|
return {
|
1207
1266
|
type: import_transactions.InputType.Contract,
|
1208
|
-
txID:
|
1267
|
+
txID: import_configs2.ZeroBytes32,
|
1209
1268
|
outputIndex: 0,
|
1210
|
-
balanceRoot:
|
1211
|
-
stateRoot:
|
1269
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1270
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1212
1271
|
txPointer: {
|
1213
1272
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1214
1273
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1228,8 +1287,8 @@ var inputify = (value) => {
|
|
1228
1287
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1229
1288
|
witnessIndex: value.witnessIndex,
|
1230
1289
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1231
|
-
predicateLength: predicate.length,
|
1232
|
-
predicateDataLength: predicateData.length,
|
1290
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1291
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1233
1292
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1234
1293
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1235
1294
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1246,7 +1305,7 @@ var inputify = (value) => {
|
|
1246
1305
|
};
|
1247
1306
|
|
1248
1307
|
// src/providers/transaction-request/output.ts
|
1249
|
-
var
|
1308
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1250
1309
|
var import_errors4 = require("@fuel-ts/errors");
|
1251
1310
|
var import_math3 = require("@fuel-ts/math");
|
1252
1311
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1266,8 +1325,8 @@ var outputify = (value) => {
|
|
1266
1325
|
return {
|
1267
1326
|
type: import_transactions2.OutputType.Contract,
|
1268
1327
|
inputIndex: value.inputIndex,
|
1269
|
-
balanceRoot:
|
1270
|
-
stateRoot:
|
1328
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1329
|
+
stateRoot: import_configs3.ZeroBytes32
|
1271
1330
|
};
|
1272
1331
|
}
|
1273
1332
|
case import_transactions2.OutputType.Change: {
|
@@ -1281,9 +1340,9 @@ var outputify = (value) => {
|
|
1281
1340
|
case import_transactions2.OutputType.Variable: {
|
1282
1341
|
return {
|
1283
1342
|
type: import_transactions2.OutputType.Variable,
|
1284
|
-
to:
|
1343
|
+
to: import_configs3.ZeroBytes32,
|
1285
1344
|
amount: (0, import_math3.bn)(0),
|
1286
|
-
assetId:
|
1345
|
+
assetId: import_configs3.ZeroBytes32
|
1287
1346
|
};
|
1288
1347
|
}
|
1289
1348
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1304,10 +1363,11 @@ var outputify = (value) => {
|
|
1304
1363
|
|
1305
1364
|
// src/providers/transaction-request/transaction-request.ts
|
1306
1365
|
var import_address = require("@fuel-ts/address");
|
1307
|
-
var
|
1366
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1308
1367
|
var import_math7 = require("@fuel-ts/math");
|
1309
1368
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1310
1369
|
var import_utils9 = require("@fuel-ts/utils");
|
1370
|
+
var import_ethers = require("ethers");
|
1311
1371
|
|
1312
1372
|
// src/providers/resource.ts
|
1313
1373
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1316,13 +1376,13 @@ var isCoin = (resource) => "id" in resource;
|
|
1316
1376
|
var isMessage = (resource) => "recipient" in resource;
|
1317
1377
|
|
1318
1378
|
// src/providers/utils/receipts.ts
|
1319
|
-
var
|
1379
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1320
1380
|
var import_errors5 = require("@fuel-ts/errors");
|
1321
1381
|
var import_math4 = require("@fuel-ts/math");
|
1322
1382
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1323
|
-
var
|
1383
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1324
1384
|
var import_utils5 = require("@fuel-ts/utils");
|
1325
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1385
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1326
1386
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1327
1387
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1328
1388
|
(memo, receipt) => {
|
@@ -1339,15 +1399,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1339
1399
|
missingOutputContractIds: []
|
1340
1400
|
}
|
1341
1401
|
);
|
1342
|
-
var hexOrZero = (hex) => hex ||
|
1402
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1343
1403
|
function assembleReceiptByType(receipt) {
|
1344
1404
|
const { receiptType } = receipt;
|
1345
1405
|
switch (receiptType) {
|
1346
1406
|
case "CALL" /* Call */: {
|
1347
1407
|
const callReceipt = {
|
1348
1408
|
type: import_transactions3.ReceiptType.Call,
|
1349
|
-
from: hexOrZero(receipt.
|
1350
|
-
to: hexOrZero(receipt?.to
|
1409
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1410
|
+
to: hexOrZero(receipt?.to),
|
1351
1411
|
amount: (0, import_math4.bn)(receipt.amount),
|
1352
1412
|
assetId: hexOrZero(receipt.assetId),
|
1353
1413
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1361,7 +1421,7 @@ function assembleReceiptByType(receipt) {
|
|
1361
1421
|
case "RETURN" /* Return */: {
|
1362
1422
|
const returnReceipt = {
|
1363
1423
|
type: import_transactions3.ReceiptType.Return,
|
1364
|
-
id: hexOrZero(receipt.
|
1424
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1365
1425
|
val: (0, import_math4.bn)(receipt.val),
|
1366
1426
|
pc: (0, import_math4.bn)(receipt.pc),
|
1367
1427
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1371,7 +1431,7 @@ function assembleReceiptByType(receipt) {
|
|
1371
1431
|
case "RETURN_DATA" /* ReturnData */: {
|
1372
1432
|
const returnDataReceipt = {
|
1373
1433
|
type: import_transactions3.ReceiptType.ReturnData,
|
1374
|
-
id: hexOrZero(receipt.
|
1434
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1375
1435
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1376
1436
|
len: (0, import_math4.bn)(receipt.len),
|
1377
1437
|
digest: hexOrZero(receipt.digest),
|
@@ -1383,7 +1443,7 @@ function assembleReceiptByType(receipt) {
|
|
1383
1443
|
case "PANIC" /* Panic */: {
|
1384
1444
|
const panicReceipt = {
|
1385
1445
|
type: import_transactions3.ReceiptType.Panic,
|
1386
|
-
id: hexOrZero(receipt.
|
1446
|
+
id: hexOrZero(receipt.id),
|
1387
1447
|
reason: (0, import_math4.bn)(receipt.reason),
|
1388
1448
|
pc: (0, import_math4.bn)(receipt.pc),
|
1389
1449
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1394,7 +1454,7 @@ function assembleReceiptByType(receipt) {
|
|
1394
1454
|
case "REVERT" /* Revert */: {
|
1395
1455
|
const revertReceipt = {
|
1396
1456
|
type: import_transactions3.ReceiptType.Revert,
|
1397
|
-
id: hexOrZero(receipt.
|
1457
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1398
1458
|
val: (0, import_math4.bn)(receipt.ra),
|
1399
1459
|
pc: (0, import_math4.bn)(receipt.pc),
|
1400
1460
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1404,7 +1464,7 @@ function assembleReceiptByType(receipt) {
|
|
1404
1464
|
case "LOG" /* Log */: {
|
1405
1465
|
const logReceipt = {
|
1406
1466
|
type: import_transactions3.ReceiptType.Log,
|
1407
|
-
id: hexOrZero(receipt.
|
1467
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1408
1468
|
val0: (0, import_math4.bn)(receipt.ra),
|
1409
1469
|
val1: (0, import_math4.bn)(receipt.rb),
|
1410
1470
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1417,7 +1477,7 @@ function assembleReceiptByType(receipt) {
|
|
1417
1477
|
case "LOG_DATA" /* LogData */: {
|
1418
1478
|
const logDataReceipt = {
|
1419
1479
|
type: import_transactions3.ReceiptType.LogData,
|
1420
|
-
id: hexOrZero(receipt.
|
1480
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1421
1481
|
val0: (0, import_math4.bn)(receipt.ra),
|
1422
1482
|
val1: (0, import_math4.bn)(receipt.rb),
|
1423
1483
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1431,8 +1491,8 @@ function assembleReceiptByType(receipt) {
|
|
1431
1491
|
case "TRANSFER" /* Transfer */: {
|
1432
1492
|
const transferReceipt = {
|
1433
1493
|
type: import_transactions3.ReceiptType.Transfer,
|
1434
|
-
from: hexOrZero(receipt.
|
1435
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1494
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1495
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1436
1496
|
amount: (0, import_math4.bn)(receipt.amount),
|
1437
1497
|
assetId: hexOrZero(receipt.assetId),
|
1438
1498
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1443,8 +1503,8 @@ function assembleReceiptByType(receipt) {
|
|
1443
1503
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1444
1504
|
const transferOutReceipt = {
|
1445
1505
|
type: import_transactions3.ReceiptType.TransferOut,
|
1446
|
-
from: hexOrZero(receipt.
|
1447
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1506
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1507
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1448
1508
|
amount: (0, import_math4.bn)(receipt.amount),
|
1449
1509
|
assetId: hexOrZero(receipt.assetId),
|
1450
1510
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1487,7 +1547,7 @@ function assembleReceiptByType(receipt) {
|
|
1487
1547
|
return receiptMessageOut;
|
1488
1548
|
}
|
1489
1549
|
case "MINT" /* Mint */: {
|
1490
|
-
const contractId = hexOrZero(receipt.
|
1550
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1491
1551
|
const subId = hexOrZero(receipt.subId);
|
1492
1552
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1493
1553
|
const mintReceipt = {
|
@@ -1502,7 +1562,7 @@ function assembleReceiptByType(receipt) {
|
|
1502
1562
|
return mintReceipt;
|
1503
1563
|
}
|
1504
1564
|
case "BURN" /* Burn */: {
|
1505
|
-
const contractId = hexOrZero(receipt.
|
1565
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1506
1566
|
const subId = hexOrZero(receipt.subId);
|
1507
1567
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1508
1568
|
const burnReceipt = {
|
@@ -1587,7 +1647,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1587
1647
|
var import_math5 = require("@fuel-ts/math");
|
1588
1648
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1589
1649
|
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
1650
|
var getGasUsedFromReceipts = (receipts) => {
|
1592
1651
|
const scriptResult = receipts.filter(
|
1593
1652
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1608,18 +1667,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1608
1667
|
}
|
1609
1668
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1610
1669
|
const witnessCache = [];
|
1611
|
-
const
|
1670
|
+
const chargeableInputs = inputs.filter((input) => {
|
1671
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1672
|
+
if (isCoinOrMessage) {
|
1673
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1674
|
+
return true;
|
1675
|
+
}
|
1676
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1677
|
+
witnessCache.push(input.witnessIndex);
|
1678
|
+
return true;
|
1679
|
+
}
|
1680
|
+
}
|
1681
|
+
return false;
|
1682
|
+
});
|
1683
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1684
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1612
1685
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1613
1686
|
return total.add(
|
1614
|
-
|
1687
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1615
1688
|
);
|
1616
1689
|
}
|
1617
|
-
|
1618
|
-
|
1619
|
-
return total.add(gasCosts.ecr1);
|
1620
|
-
}
|
1621
|
-
return total;
|
1622
|
-
}, (0, import_math5.bn)());
|
1690
|
+
return total.add(gasCosts.ecr1);
|
1691
|
+
}, (0, import_math5.bn)(0));
|
1623
1692
|
return totalGas;
|
1624
1693
|
}
|
1625
1694
|
function getMinGas(params) {
|
@@ -1631,12 +1700,20 @@ function getMinGas(params) {
|
|
1631
1700
|
return minGas;
|
1632
1701
|
}
|
1633
1702
|
function getMaxGas(params) {
|
1634
|
-
const {
|
1703
|
+
const {
|
1704
|
+
gasPerByte,
|
1705
|
+
witnessesLength,
|
1706
|
+
witnessLimit,
|
1707
|
+
minGas,
|
1708
|
+
gasLimit = (0, import_math5.bn)(0),
|
1709
|
+
maxGasPerTx
|
1710
|
+
} = params;
|
1635
1711
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1636
1712
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1637
1713
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1638
1714
|
}
|
1639
|
-
|
1715
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1716
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1640
1717
|
}
|
1641
1718
|
function calculateMetadataGasForTxCreate({
|
1642
1719
|
gasCosts,
|
@@ -1658,6 +1735,10 @@ function calculateMetadataGasForTxScript({
|
|
1658
1735
|
}) {
|
1659
1736
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1660
1737
|
}
|
1738
|
+
var calculateGasFee = (params) => {
|
1739
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1740
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1741
|
+
};
|
1661
1742
|
|
1662
1743
|
// src/providers/utils/json.ts
|
1663
1744
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1703,16 +1784,16 @@ function sleep(time) {
|
|
1703
1784
|
var import_errors7 = require("@fuel-ts/errors");
|
1704
1785
|
var import_math6 = require("@fuel-ts/math");
|
1705
1786
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1706
|
-
var
|
1787
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1707
1788
|
var assemblePanicError = (status) => {
|
1708
1789
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1709
1790
|
const reason = status.reason;
|
1710
|
-
if (
|
1791
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1711
1792
|
errorMessage = `${errorMessage}
|
1712
1793
|
|
1713
1794
|
You can read more about this error at:
|
1714
1795
|
|
1715
|
-
${
|
1796
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1716
1797
|
}
|
1717
1798
|
return { errorMessage, reason };
|
1718
1799
|
};
|
@@ -1724,28 +1805,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1724
1805
|
if (revertReceipt) {
|
1725
1806
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1726
1807
|
switch (reasonHex) {
|
1727
|
-
case
|
1808
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1728
1809
|
reason = "require";
|
1729
1810
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1730
1811
|
break;
|
1731
1812
|
}
|
1732
|
-
case
|
1813
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1733
1814
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1734
1815
|
reason = "assert_eq";
|
1735
1816
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1736
1817
|
break;
|
1737
1818
|
}
|
1738
|
-
case
|
1819
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1739
1820
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1740
1821
|
reason = "assert_ne";
|
1741
1822
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1742
1823
|
break;
|
1743
1824
|
}
|
1744
|
-
case
|
1825
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1745
1826
|
reason = "assert";
|
1746
1827
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1747
1828
|
break;
|
1748
|
-
case
|
1829
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1749
1830
|
reason = "MissingOutputChange";
|
1750
1831
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1751
1832
|
break;
|
@@ -1806,7 +1887,7 @@ var witnessify = (value) => {
|
|
1806
1887
|
// src/providers/transaction-request/transaction-request.ts
|
1807
1888
|
var BaseTransactionRequest = class {
|
1808
1889
|
/** Gas price for transaction */
|
1809
|
-
|
1890
|
+
tip;
|
1810
1891
|
/** Block until which tx cannot be included */
|
1811
1892
|
maturity;
|
1812
1893
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1819,38 +1900,34 @@ var BaseTransactionRequest = class {
|
|
1819
1900
|
outputs = [];
|
1820
1901
|
/** List of witnesses */
|
1821
1902
|
witnesses = [];
|
1822
|
-
/** Base asset ID - should be fetched from the chain */
|
1823
|
-
baseAssetId = import_configs6.ZeroBytes32;
|
1824
1903
|
/**
|
1825
1904
|
* Constructor for initializing a base transaction request.
|
1826
1905
|
*
|
1827
1906
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1828
1907
|
*/
|
1829
1908
|
constructor({
|
1830
|
-
|
1909
|
+
tip,
|
1831
1910
|
maturity,
|
1832
1911
|
maxFee,
|
1833
1912
|
witnessLimit,
|
1834
1913
|
inputs,
|
1835
1914
|
outputs,
|
1836
|
-
witnesses
|
1837
|
-
baseAssetId
|
1915
|
+
witnesses
|
1838
1916
|
} = {}) {
|
1839
|
-
this.
|
1917
|
+
this.tip = (0, import_math7.bn)(tip);
|
1840
1918
|
this.maturity = maturity ?? 0;
|
1841
1919
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1842
1920
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1843
1921
|
this.inputs = inputs ?? [];
|
1844
1922
|
this.outputs = outputs ?? [];
|
1845
1923
|
this.witnesses = witnesses ?? [];
|
1846
|
-
this.baseAssetId = baseAssetId ?? import_configs6.ZeroBytes32;
|
1847
1924
|
}
|
1848
1925
|
static getPolicyMeta(req) {
|
1849
1926
|
let policyTypes = 0;
|
1850
1927
|
const policies = [];
|
1851
|
-
if (req.
|
1852
|
-
policyTypes += import_transactions6.PolicyType.
|
1853
|
-
policies.push({ data: req.
|
1928
|
+
if (req.tip) {
|
1929
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1930
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1854
1931
|
}
|
1855
1932
|
if (req.witnessLimit) {
|
1856
1933
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1936,7 +2013,7 @@ var BaseTransactionRequest = class {
|
|
1936
2013
|
* @returns The index of the created witness.
|
1937
2014
|
*/
|
1938
2015
|
addEmptyWitness() {
|
1939
|
-
this.addWitness((0, import_utils9.concat)([
|
2016
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1940
2017
|
return this.witnesses.length - 1;
|
1941
2018
|
}
|
1942
2019
|
/**
|
@@ -2037,10 +2114,10 @@ var BaseTransactionRequest = class {
|
|
2037
2114
|
* @param predicate - Predicate bytes.
|
2038
2115
|
* @param predicateData - Predicate data bytes.
|
2039
2116
|
*/
|
2040
|
-
addCoinInput(coin
|
2117
|
+
addCoinInput(coin) {
|
2041
2118
|
const { assetId, owner, amount } = coin;
|
2042
2119
|
let witnessIndex;
|
2043
|
-
if (predicate) {
|
2120
|
+
if (coin.predicate) {
|
2044
2121
|
witnessIndex = 0;
|
2045
2122
|
} else {
|
2046
2123
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2055,9 +2132,7 @@ var BaseTransactionRequest = class {
|
|
2055
2132
|
amount,
|
2056
2133
|
assetId,
|
2057
2134
|
txPointer: "0x00000000000000000000000000000000",
|
2058
|
-
witnessIndex
|
2059
|
-
predicate: predicate?.bytes,
|
2060
|
-
predicateData: predicate?.predicateDataBytes
|
2135
|
+
witnessIndex
|
2061
2136
|
};
|
2062
2137
|
this.pushInput(input);
|
2063
2138
|
this.addChangeOutput(owner, assetId);
|
@@ -2068,11 +2143,13 @@ var BaseTransactionRequest = class {
|
|
2068
2143
|
*
|
2069
2144
|
* @param message - Message resource.
|
2070
2145
|
* @param predicate - Predicate bytes.
|
2146
|
+
* @param predicateData - Predicate data bytes.
|
2071
2147
|
*/
|
2072
|
-
addMessageInput(message
|
2148
|
+
addMessageInput(message) {
|
2073
2149
|
const { recipient, sender, amount } = message;
|
2150
|
+
const assetId = import_configs7.BaseAssetId;
|
2074
2151
|
let witnessIndex;
|
2075
|
-
if (predicate) {
|
2152
|
+
if (message.predicate) {
|
2076
2153
|
witnessIndex = 0;
|
2077
2154
|
} else {
|
2078
2155
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2086,12 +2163,10 @@ var BaseTransactionRequest = class {
|
|
2086
2163
|
sender: sender.toB256(),
|
2087
2164
|
recipient: recipient.toB256(),
|
2088
2165
|
amount,
|
2089
|
-
witnessIndex
|
2090
|
-
predicate: predicate?.bytes,
|
2091
|
-
predicateData: predicate?.predicateDataBytes
|
2166
|
+
witnessIndex
|
2092
2167
|
};
|
2093
2168
|
this.pushInput(input);
|
2094
|
-
this.addChangeOutput(recipient,
|
2169
|
+
this.addChangeOutput(recipient, assetId);
|
2095
2170
|
}
|
2096
2171
|
/**
|
2097
2172
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2119,32 +2194,6 @@ var BaseTransactionRequest = class {
|
|
2119
2194
|
resources.forEach((resource) => this.addResource(resource));
|
2120
2195
|
return this;
|
2121
2196
|
}
|
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
2197
|
/**
|
2149
2198
|
* Adds a coin output to the transaction.
|
2150
2199
|
*
|
@@ -2152,12 +2201,12 @@ var BaseTransactionRequest = class {
|
|
2152
2201
|
* @param amount - Amount of coin.
|
2153
2202
|
* @param assetId - Asset ID of coin.
|
2154
2203
|
*/
|
2155
|
-
addCoinOutput(to, amount, assetId) {
|
2204
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
2156
2205
|
this.pushOutput({
|
2157
2206
|
type: import_transactions6.OutputType.Coin,
|
2158
2207
|
to: (0, import_address.addressify)(to).toB256(),
|
2159
2208
|
amount,
|
2160
|
-
assetId
|
2209
|
+
assetId
|
2161
2210
|
});
|
2162
2211
|
return this;
|
2163
2212
|
}
|
@@ -2184,7 +2233,7 @@ var BaseTransactionRequest = class {
|
|
2184
2233
|
* @param to - Address of the owner.
|
2185
2234
|
* @param assetId - Asset ID of coin.
|
2186
2235
|
*/
|
2187
|
-
addChangeOutput(to, assetId) {
|
2236
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
2188
2237
|
const changeOutput = this.getChangeOutputs().find(
|
2189
2238
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2190
2239
|
);
|
@@ -2192,7 +2241,7 @@ var BaseTransactionRequest = class {
|
|
2192
2241
|
this.pushOutput({
|
2193
2242
|
type: import_transactions6.OutputType.Change,
|
2194
2243
|
to: (0, import_address.addressify)(to).toB256(),
|
2195
|
-
assetId
|
2244
|
+
assetId
|
2196
2245
|
});
|
2197
2246
|
}
|
2198
2247
|
}
|
@@ -2224,7 +2273,7 @@ var BaseTransactionRequest = class {
|
|
2224
2273
|
}
|
2225
2274
|
calculateMaxGas(chainInfo, minGas) {
|
2226
2275
|
const { consensusParameters } = chainInfo;
|
2227
|
-
const { gasPerByte } = consensusParameters;
|
2276
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2228
2277
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2229
2278
|
(acc, wit) => acc + wit.dataLength,
|
2230
2279
|
0
|
@@ -2233,7 +2282,8 @@ var BaseTransactionRequest = class {
|
|
2233
2282
|
gasPerByte,
|
2234
2283
|
minGas,
|
2235
2284
|
witnessesLength,
|
2236
|
-
witnessLimit: this.witnessLimit
|
2285
|
+
witnessLimit: this.witnessLimit,
|
2286
|
+
maxGasPerTx
|
2237
2287
|
});
|
2238
2288
|
}
|
2239
2289
|
/**
|
@@ -2243,12 +2293,6 @@ var BaseTransactionRequest = class {
|
|
2243
2293
|
* @param quantities - CoinQuantity Array.
|
2244
2294
|
*/
|
2245
2295
|
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
2296
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2253
2297
|
if ("assetId" in input) {
|
2254
2298
|
return input.assetId === assetId;
|
@@ -2257,24 +2301,27 @@ var BaseTransactionRequest = class {
|
|
2257
2301
|
});
|
2258
2302
|
const updateAssetInput = (assetId, quantity) => {
|
2259
2303
|
const assetInput = findAssetInput(assetId);
|
2304
|
+
let usedQuantity = quantity;
|
2305
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2306
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2307
|
+
}
|
2260
2308
|
if (assetInput && "assetId" in assetInput) {
|
2261
|
-
assetInput.id =
|
2262
|
-
assetInput.amount =
|
2309
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34));
|
2310
|
+
assetInput.amount = usedQuantity;
|
2263
2311
|
} else {
|
2264
2312
|
this.addResources([
|
2265
2313
|
{
|
2266
|
-
id:
|
2267
|
-
amount:
|
2314
|
+
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34)),
|
2315
|
+
amount: usedQuantity,
|
2268
2316
|
assetId,
|
2269
2317
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2270
|
-
maturity: 0,
|
2271
2318
|
blockCreated: (0, import_math7.bn)(1),
|
2272
2319
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2273
2320
|
}
|
2274
2321
|
]);
|
2275
2322
|
}
|
2276
2323
|
};
|
2277
|
-
updateAssetInput(
|
2324
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2278
2325
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2279
2326
|
}
|
2280
2327
|
/**
|
@@ -2299,7 +2346,7 @@ var BaseTransactionRequest = class {
|
|
2299
2346
|
toJSON() {
|
2300
2347
|
return normalizeJSON(this);
|
2301
2348
|
}
|
2302
|
-
|
2349
|
+
updatePredicateGasUsed(inputs) {
|
2303
2350
|
this.inputs.forEach((i) => {
|
2304
2351
|
let correspondingInput;
|
2305
2352
|
switch (i.type) {
|
@@ -2321,16 +2368,25 @@ var BaseTransactionRequest = class {
|
|
2321
2368
|
}
|
2322
2369
|
});
|
2323
2370
|
}
|
2371
|
+
shiftPredicateData() {
|
2372
|
+
this.inputs.forEach((input) => {
|
2373
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2374
|
+
input.predicateData = input.paddPredicateData(
|
2375
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2376
|
+
);
|
2377
|
+
}
|
2378
|
+
});
|
2379
|
+
}
|
2324
2380
|
};
|
2325
2381
|
|
2326
2382
|
// src/providers/transaction-request/create-transaction-request.ts
|
2327
|
-
var
|
2383
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2328
2384
|
var import_math9 = require("@fuel-ts/math");
|
2329
2385
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2330
2386
|
var import_utils13 = require("@fuel-ts/utils");
|
2331
2387
|
|
2332
2388
|
// src/providers/transaction-request/hash-transaction.ts
|
2333
|
-
var
|
2389
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2334
2390
|
var import_hasher = require("@fuel-ts/hasher");
|
2335
2391
|
var import_math8 = require("@fuel-ts/math");
|
2336
2392
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2339,7 +2395,7 @@ var import_ramda2 = require("ramda");
|
|
2339
2395
|
function hashTransaction(transactionRequest, chainId) {
|
2340
2396
|
const transaction = transactionRequest.toTransaction();
|
2341
2397
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2342
|
-
transaction.receiptsRoot =
|
2398
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2343
2399
|
}
|
2344
2400
|
transaction.inputs = transaction.inputs.map((input) => {
|
2345
2401
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2361,10 +2417,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2361
2417
|
blockHeight: 0,
|
2362
2418
|
txIndex: 0
|
2363
2419
|
};
|
2364
|
-
inputClone.txID =
|
2420
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2365
2421
|
inputClone.outputIndex = 0;
|
2366
|
-
inputClone.balanceRoot =
|
2367
|
-
inputClone.stateRoot =
|
2422
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2423
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2368
2424
|
return inputClone;
|
2369
2425
|
}
|
2370
2426
|
default:
|
@@ -2375,8 +2431,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2375
2431
|
const outputClone = (0, import_ramda2.clone)(output);
|
2376
2432
|
switch (outputClone.type) {
|
2377
2433
|
case import_transactions7.OutputType.Contract: {
|
2378
|
-
outputClone.balanceRoot =
|
2379
|
-
outputClone.stateRoot =
|
2434
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2435
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2380
2436
|
return outputClone;
|
2381
2437
|
}
|
2382
2438
|
case import_transactions7.OutputType.Change: {
|
@@ -2384,9 +2440,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2384
2440
|
return outputClone;
|
2385
2441
|
}
|
2386
2442
|
case import_transactions7.OutputType.Variable: {
|
2387
|
-
outputClone.to =
|
2443
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2388
2444
|
outputClone.amount = (0, import_math8.bn)(0);
|
2389
|
-
outputClone.assetId =
|
2445
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2390
2446
|
return outputClone;
|
2391
2447
|
}
|
2392
2448
|
default:
|
@@ -2452,7 +2508,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2452
2508
|
} = {}) {
|
2453
2509
|
super(rest);
|
2454
2510
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2455
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2511
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2456
2512
|
this.storageSlots = [...storageSlots ?? []];
|
2457
2513
|
}
|
2458
2514
|
/**
|
@@ -2467,10 +2523,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2467
2523
|
return {
|
2468
2524
|
type: import_transactions8.TransactionType.Create,
|
2469
2525
|
...baseTransaction,
|
2470
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2471
2526
|
bytecodeWitnessIndex,
|
2472
|
-
storageSlotsCount: storageSlots.length,
|
2473
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2527
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2528
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2474
2529
|
storageSlots
|
2475
2530
|
};
|
2476
2531
|
}
|
@@ -2520,7 +2575,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2520
2575
|
// src/providers/transaction-request/script-transaction-request.ts
|
2521
2576
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2522
2577
|
var import_address2 = require("@fuel-ts/address");
|
2523
|
-
var
|
2578
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2524
2579
|
var import_math10 = require("@fuel-ts/math");
|
2525
2580
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2526
2581
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2592,9 +2647,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2592
2647
|
type: import_transactions9.TransactionType.Script,
|
2593
2648
|
scriptGasLimit: this.gasLimit,
|
2594
2649
|
...super.getBaseTransaction(),
|
2595
|
-
scriptLength: script.length,
|
2596
|
-
scriptDataLength: scriptData.length,
|
2597
|
-
receiptsRoot:
|
2650
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2651
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2652
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2598
2653
|
script: (0, import_utils15.hexlify)(script),
|
2599
2654
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2600
2655
|
};
|
@@ -2657,7 +2712,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2657
2712
|
}
|
2658
2713
|
calculateMaxGas(chainInfo, minGas) {
|
2659
2714
|
const { consensusParameters } = chainInfo;
|
2660
|
-
const { gasPerByte } = consensusParameters;
|
2715
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2661
2716
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2662
2717
|
(acc, wit) => acc + wit.dataLength,
|
2663
2718
|
0
|
@@ -2667,7 +2722,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2667
2722
|
minGas,
|
2668
2723
|
witnessesLength,
|
2669
2724
|
witnessLimit: this.witnessLimit,
|
2670
|
-
gasLimit: this.gasLimit
|
2725
|
+
gasLimit: this.gasLimit,
|
2726
|
+
maxGasPerTx
|
2671
2727
|
});
|
2672
2728
|
}
|
2673
2729
|
/**
|
@@ -2742,15 +2798,32 @@ var transactionRequestify = (obj) => {
|
|
2742
2798
|
}
|
2743
2799
|
}
|
2744
2800
|
};
|
2801
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2802
|
+
(acc, input) => {
|
2803
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2804
|
+
acc.utxos.push(input.id);
|
2805
|
+
}
|
2806
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2807
|
+
acc.messages.push(input.nonce);
|
2808
|
+
}
|
2809
|
+
return acc;
|
2810
|
+
},
|
2811
|
+
{
|
2812
|
+
utxos: [],
|
2813
|
+
messages: []
|
2814
|
+
}
|
2815
|
+
);
|
2745
2816
|
|
2746
2817
|
// src/providers/transaction-response/transaction-response.ts
|
2747
2818
|
var import_errors13 = require("@fuel-ts/errors");
|
2748
|
-
var
|
2749
|
-
var
|
2750
|
-
var
|
2819
|
+
var import_math15 = require("@fuel-ts/math");
|
2820
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2821
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2751
2822
|
|
2752
2823
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2753
|
-
var
|
2824
|
+
var import_math14 = require("@fuel-ts/math");
|
2825
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2826
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2754
2827
|
|
2755
2828
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2756
2829
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2758,9 +2831,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2758
2831
|
var import_utils16 = require("@fuel-ts/utils");
|
2759
2832
|
var calculateTransactionFee = (params) => {
|
2760
2833
|
const {
|
2761
|
-
|
2834
|
+
gasPrice,
|
2762
2835
|
rawPayload,
|
2763
|
-
|
2836
|
+
tip,
|
2837
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2764
2838
|
} = params;
|
2765
2839
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2766
2840
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2770,8 +2844,7 @@ var calculateTransactionFee = (params) => {
|
|
2770
2844
|
return {
|
2771
2845
|
fee: (0, import_math11.bn)(0),
|
2772
2846
|
minFee: (0, import_math11.bn)(0),
|
2773
|
-
maxFee: (0, import_math11.bn)(0)
|
2774
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2847
|
+
maxFee: (0, import_math11.bn)(0)
|
2775
2848
|
};
|
2776
2849
|
}
|
2777
2850
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2803,7 +2876,6 @@ var calculateTransactionFee = (params) => {
|
|
2803
2876
|
metadataGas,
|
2804
2877
|
txBytesSize: transactionBytes.length
|
2805
2878
|
});
|
2806
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2807
2879
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2808
2880
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2809
2881
|
const maxGas = getMaxGas({
|
@@ -2811,22 +2883,30 @@ var calculateTransactionFee = (params) => {
|
|
2811
2883
|
minGas,
|
2812
2884
|
witnessesLength,
|
2813
2885
|
gasLimit,
|
2814
|
-
witnessLimit
|
2886
|
+
witnessLimit,
|
2887
|
+
maxGasPerTx
|
2888
|
+
});
|
2889
|
+
const minFee = calculateGasFee({
|
2890
|
+
gasPrice,
|
2891
|
+
gas: minGas,
|
2892
|
+
priceFactor: gasPriceFactor,
|
2893
|
+
tip
|
2894
|
+
});
|
2895
|
+
const maxFee = calculateGasFee({
|
2896
|
+
gasPrice,
|
2897
|
+
gas: maxGas,
|
2898
|
+
priceFactor: gasPriceFactor,
|
2899
|
+
tip
|
2815
2900
|
});
|
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
2901
|
return {
|
2821
|
-
fee,
|
2822
2902
|
minFee,
|
2823
2903
|
maxFee,
|
2824
|
-
|
2904
|
+
fee: maxFee
|
2825
2905
|
};
|
2826
2906
|
};
|
2827
2907
|
|
2828
2908
|
// src/providers/transaction-summary/operations.ts
|
2829
|
-
var
|
2909
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2830
2910
|
var import_errors11 = require("@fuel-ts/errors");
|
2831
2911
|
var import_math13 = require("@fuel-ts/math");
|
2832
2912
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3171,7 +3251,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3171
3251
|
const { to: toAddress, assetId, amount } = receipt;
|
3172
3252
|
let { from: fromAddress } = receipt;
|
3173
3253
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3174
|
-
if (
|
3254
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
3175
3255
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3176
3256
|
fromAddress = change?.to || fromAddress;
|
3177
3257
|
}
|
@@ -3435,10 +3515,12 @@ function assembleTransactionSummary(params) {
|
|
3435
3515
|
gqlTransactionStatus,
|
3436
3516
|
abiMap = {},
|
3437
3517
|
maxInputs,
|
3438
|
-
gasCosts
|
3518
|
+
gasCosts,
|
3519
|
+
maxGasPerTx,
|
3520
|
+
gasPrice
|
3439
3521
|
} = params;
|
3440
3522
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3441
|
-
const rawPayload = (0,
|
3523
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3442
3524
|
const operations = getOperations({
|
3443
3525
|
transactionType: transaction.type,
|
3444
3526
|
inputs: transaction.inputs || [],
|
@@ -3449,11 +3531,14 @@ function assembleTransactionSummary(params) {
|
|
3449
3531
|
maxInputs
|
3450
3532
|
});
|
3451
3533
|
const typeName = getTransactionTypeName(transaction.type);
|
3534
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3452
3535
|
const { fee } = calculateTransactionFee({
|
3453
|
-
|
3536
|
+
gasPrice,
|
3454
3537
|
rawPayload,
|
3538
|
+
tip,
|
3455
3539
|
consensusParameters: {
|
3456
3540
|
gasCosts,
|
3541
|
+
maxGasPerTx,
|
3457
3542
|
feeParams: {
|
3458
3543
|
gasPerByte,
|
3459
3544
|
gasPriceFactor
|
@@ -3465,7 +3550,7 @@ function assembleTransactionSummary(params) {
|
|
3465
3550
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3466
3551
|
let date;
|
3467
3552
|
if (time) {
|
3468
|
-
date =
|
3553
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3469
3554
|
}
|
3470
3555
|
const transactionSummary = {
|
3471
3556
|
id,
|
@@ -3493,12 +3578,12 @@ function assembleTransactionSummary(params) {
|
|
3493
3578
|
|
3494
3579
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3495
3580
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3496
|
-
var
|
3581
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3497
3582
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3498
3583
|
return receipts.reduce((logs, receipt) => {
|
3499
|
-
if (receipt.type ===
|
3584
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3500
3585
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3501
|
-
const data = receipt.type ===
|
3586
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3502
3587
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3503
3588
|
logs.push(decodedLog);
|
3504
3589
|
}
|
@@ -3513,7 +3598,7 @@ var TransactionResponse = class {
|
|
3513
3598
|
/** Current provider */
|
3514
3599
|
provider;
|
3515
3600
|
/** Gas used on the transaction */
|
3516
|
-
gasUsed = (0,
|
3601
|
+
gasUsed = (0, import_math15.bn)(0);
|
3517
3602
|
/** The graphql Transaction with receipts object. */
|
3518
3603
|
gqlTransaction;
|
3519
3604
|
abis;
|
@@ -3571,8 +3656,8 @@ var TransactionResponse = class {
|
|
3571
3656
|
* @returns The decoded transaction.
|
3572
3657
|
*/
|
3573
3658
|
decodeTransaction(transactionWithReceipts) {
|
3574
|
-
return new
|
3575
|
-
(0,
|
3659
|
+
return new import_transactions18.TransactionCoder().decode(
|
3660
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3576
3661
|
0
|
3577
3662
|
)?.[0];
|
3578
3663
|
}
|
@@ -3591,20 +3676,27 @@ var TransactionResponse = class {
|
|
3591
3676
|
const decodedTransaction = this.decodeTransaction(
|
3592
3677
|
transaction
|
3593
3678
|
);
|
3594
|
-
|
3595
|
-
|
3679
|
+
let txReceipts = [];
|
3680
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3681
|
+
txReceipts = transaction.status.receipts;
|
3682
|
+
}
|
3683
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3684
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3685
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3596
3686
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3597
3687
|
const transactionSummary = assembleTransactionSummary({
|
3598
3688
|
id: this.id,
|
3599
3689
|
receipts,
|
3600
3690
|
transaction: decodedTransaction,
|
3601
|
-
transactionBytes: (0,
|
3691
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3602
3692
|
gqlTransactionStatus: transaction.status,
|
3603
3693
|
gasPerByte,
|
3604
3694
|
gasPriceFactor,
|
3605
3695
|
abiMap: contractsAbiMap,
|
3606
3696
|
maxInputs,
|
3607
|
-
gasCosts
|
3697
|
+
gasCosts,
|
3698
|
+
maxGasPerTx,
|
3699
|
+
gasPrice
|
3608
3700
|
});
|
3609
3701
|
return transactionSummary;
|
3610
3702
|
}
|
@@ -3731,30 +3823,29 @@ var processGqlChain = (chain) => {
|
|
3731
3823
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3732
3824
|
return {
|
3733
3825
|
name,
|
3734
|
-
baseChainHeight: (0,
|
3826
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3735
3827
|
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,
|
3828
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3829
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3830
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3831
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3832
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3833
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3834
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3835
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3836
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3837
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3838
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3839
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3840
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3841
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3842
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3752
3843
|
gasCosts
|
3753
3844
|
},
|
3754
3845
|
gasCosts,
|
3755
3846
|
latestBlock: {
|
3756
3847
|
id: latestBlock.id,
|
3757
|
-
height: (0,
|
3848
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3758
3849
|
time: latestBlock.header.time,
|
3759
3850
|
transactions: latestBlock.transactions.map((i) => ({
|
3760
3851
|
id: i.id
|
@@ -3848,10 +3939,8 @@ var _Provider = class {
|
|
3848
3939
|
* Returns some helpful parameters related to gas fees.
|
3849
3940
|
*/
|
3850
3941
|
getGasConfig() {
|
3851
|
-
const { minGasPrice } = this.getNode();
|
3852
3942
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3853
3943
|
return {
|
3854
|
-
minGasPrice,
|
3855
3944
|
maxGasPerTx,
|
3856
3945
|
maxGasPerPredicate,
|
3857
3946
|
gasPriceFactor,
|
@@ -3939,7 +4028,7 @@ var _Provider = class {
|
|
3939
4028
|
name,
|
3940
4029
|
consensusParameters: { chainId }
|
3941
4030
|
} = await this.getChain();
|
3942
|
-
const network = new
|
4031
|
+
const network = new import_ethers2.Network(name, chainId.toNumber());
|
3943
4032
|
return Promise.resolve(network);
|
3944
4033
|
}
|
3945
4034
|
/**
|
@@ -3949,7 +4038,7 @@ var _Provider = class {
|
|
3949
4038
|
*/
|
3950
4039
|
async getBlockNumber() {
|
3951
4040
|
const { chain } = await this.operations.getChain();
|
3952
|
-
return (0,
|
4041
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3953
4042
|
}
|
3954
4043
|
/**
|
3955
4044
|
* Returns the chain information.
|
@@ -3959,13 +4048,11 @@ var _Provider = class {
|
|
3959
4048
|
async fetchNode() {
|
3960
4049
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3961
4050
|
const processedNodeInfo = {
|
3962
|
-
maxDepth: (0,
|
3963
|
-
maxTx: (0,
|
3964
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4051
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
4052
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3965
4053
|
nodeVersion: nodeInfo.nodeVersion,
|
3966
4054
|
utxoValidation: nodeInfo.utxoValidation,
|
3967
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3968
|
-
peers: nodeInfo.peers
|
4055
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3969
4056
|
};
|
3970
4057
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3971
4058
|
return processedNodeInfo;
|
@@ -3991,17 +4078,6 @@ var _Provider = class {
|
|
3991
4078
|
} = this.getChain();
|
3992
4079
|
return chainId.toNumber();
|
3993
4080
|
}
|
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
4081
|
/**
|
4006
4082
|
* Submits a transaction to the chain to be executed.
|
4007
4083
|
*
|
@@ -4018,9 +4094,9 @@ var _Provider = class {
|
|
4018
4094
|
if (estimateTxDependencies) {
|
4019
4095
|
await this.estimateTxDependencies(transactionRequest);
|
4020
4096
|
}
|
4021
|
-
const encodedTransaction = (0,
|
4097
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4022
4098
|
let abis;
|
4023
|
-
if (transactionRequest.type ===
|
4099
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4024
4100
|
abis = transactionRequest.abis;
|
4025
4101
|
}
|
4026
4102
|
if (awaitExecution) {
|
@@ -4061,15 +4137,14 @@ var _Provider = class {
|
|
4061
4137
|
if (estimateTxDependencies) {
|
4062
4138
|
return this.estimateTxDependencies(transactionRequest);
|
4063
4139
|
}
|
4064
|
-
const encodedTransaction = (0,
|
4065
|
-
const { dryRun:
|
4066
|
-
encodedTransaction,
|
4140
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4141
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4142
|
+
encodedTransactions: encodedTransaction,
|
4067
4143
|
utxoValidation: utxoValidation || false
|
4068
4144
|
});
|
4069
|
-
const receipts =
|
4070
|
-
|
4071
|
-
|
4072
|
-
};
|
4145
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4146
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4147
|
+
return { receipts, dryrunStatus: status };
|
4073
4148
|
}
|
4074
4149
|
/**
|
4075
4150
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4080,13 +4155,13 @@ var _Provider = class {
|
|
4080
4155
|
async estimatePredicates(transactionRequest) {
|
4081
4156
|
const shouldEstimatePredicates = Boolean(
|
4082
4157
|
transactionRequest.inputs.find(
|
4083
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4158
|
+
(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
4159
|
)
|
4085
4160
|
);
|
4086
4161
|
if (!shouldEstimatePredicates) {
|
4087
4162
|
return transactionRequest;
|
4088
4163
|
}
|
4089
|
-
const encodedTransaction = (0,
|
4164
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4090
4165
|
const response = await this.operations.estimatePredicates({
|
4091
4166
|
encodedTransaction
|
4092
4167
|
});
|
@@ -4095,7 +4170,7 @@ var _Provider = class {
|
|
4095
4170
|
} = response;
|
4096
4171
|
if (inputs) {
|
4097
4172
|
inputs.forEach((input, index) => {
|
4098
|
-
if ("predicateGasUsed" in input && (0,
|
4173
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
4099
4174
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4100
4175
|
}
|
4101
4176
|
});
|
@@ -4108,31 +4183,31 @@ var _Provider = class {
|
|
4108
4183
|
* If there are missing variable outputs,
|
4109
4184
|
* `addVariableOutputs` is called on the transaction.
|
4110
4185
|
*
|
4111
|
-
* @privateRemarks
|
4112
|
-
* TODO: Investigate support for missing contract IDs
|
4113
|
-
* TODO: Add support for missing output messages
|
4114
4186
|
*
|
4115
4187
|
* @param transactionRequest - The transaction request object.
|
4116
4188
|
* @returns A promise.
|
4117
4189
|
*/
|
4118
4190
|
async estimateTxDependencies(transactionRequest) {
|
4119
|
-
if (transactionRequest.type ===
|
4191
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
4120
4192
|
return {
|
4121
4193
|
receipts: [],
|
4122
4194
|
outputVariables: 0,
|
4123
4195
|
missingContractIds: []
|
4124
4196
|
};
|
4125
4197
|
}
|
4126
|
-
await this.estimatePredicates(transactionRequest);
|
4127
4198
|
let receipts = [];
|
4128
4199
|
const missingContractIds = [];
|
4129
4200
|
let outputVariables = 0;
|
4201
|
+
let dryrunStatus;
|
4130
4202
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4131
|
-
const {
|
4132
|
-
|
4203
|
+
const {
|
4204
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4205
|
+
} = await this.operations.dryRun({
|
4206
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4133
4207
|
utxoValidation: false
|
4134
4208
|
});
|
4135
|
-
receipts =
|
4209
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4210
|
+
dryrunStatus = status;
|
4136
4211
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4137
4212
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4138
4213
|
if (hasMissingOutputs) {
|
@@ -4142,6 +4217,11 @@ var _Provider = class {
|
|
4142
4217
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4143
4218
|
missingContractIds.push(contractId);
|
4144
4219
|
});
|
4220
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4221
|
+
transactionRequest,
|
4222
|
+
optimizeGas: false
|
4223
|
+
});
|
4224
|
+
transactionRequest.maxFee = maxFee;
|
4145
4225
|
} else {
|
4146
4226
|
break;
|
4147
4227
|
}
|
@@ -4149,7 +4229,133 @@ var _Provider = class {
|
|
4149
4229
|
return {
|
4150
4230
|
receipts,
|
4151
4231
|
outputVariables,
|
4152
|
-
missingContractIds
|
4232
|
+
missingContractIds,
|
4233
|
+
dryrunStatus
|
4234
|
+
};
|
4235
|
+
}
|
4236
|
+
/**
|
4237
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4238
|
+
*
|
4239
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4240
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4241
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4242
|
+
*
|
4243
|
+
* @param transactionRequests - Array of transaction request objects.
|
4244
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4245
|
+
*/
|
4246
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4247
|
+
const results = transactionRequests.map(() => ({
|
4248
|
+
receipts: [],
|
4249
|
+
outputVariables: 0,
|
4250
|
+
missingContractIds: [],
|
4251
|
+
dryrunStatus: void 0
|
4252
|
+
}));
|
4253
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4254
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4255
|
+
allRequests.forEach((req, index) => {
|
4256
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4257
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4258
|
+
}
|
4259
|
+
});
|
4260
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4261
|
+
let attempt = 0;
|
4262
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4263
|
+
const encodedTransactions = transactionsToProcess.map(
|
4264
|
+
(index) => serializedTransactionsMap.get(index)
|
4265
|
+
);
|
4266
|
+
const dryRunResults = await this.operations.dryRun({
|
4267
|
+
encodedTransactions,
|
4268
|
+
utxoValidation: false
|
4269
|
+
});
|
4270
|
+
const nextRoundTransactions = [];
|
4271
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4272
|
+
const currentResultIndex = transactionsToProcess[i];
|
4273
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4274
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4275
|
+
results[currentResultIndex].dryrunStatus = status;
|
4276
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4277
|
+
results[currentResultIndex].receipts
|
4278
|
+
);
|
4279
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4280
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4281
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4282
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4283
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4284
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4285
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4286
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4287
|
+
});
|
4288
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4289
|
+
transactionRequest: requestToProcess,
|
4290
|
+
optimizeGas: false
|
4291
|
+
});
|
4292
|
+
requestToProcess.maxFee = maxFee;
|
4293
|
+
serializedTransactionsMap.set(
|
4294
|
+
currentResultIndex,
|
4295
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4296
|
+
);
|
4297
|
+
nextRoundTransactions.push(currentResultIndex);
|
4298
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4299
|
+
}
|
4300
|
+
}
|
4301
|
+
transactionsToProcess = nextRoundTransactions;
|
4302
|
+
attempt += 1;
|
4303
|
+
}
|
4304
|
+
return results;
|
4305
|
+
}
|
4306
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4307
|
+
if (estimateTxDependencies) {
|
4308
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4309
|
+
}
|
4310
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4311
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4312
|
+
encodedTransactions,
|
4313
|
+
utxoValidation: utxoValidation || false
|
4314
|
+
});
|
4315
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4316
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4317
|
+
return { receipts, dryrunStatus: status };
|
4318
|
+
});
|
4319
|
+
return results;
|
4320
|
+
}
|
4321
|
+
async estimateTxGasAndFee(params) {
|
4322
|
+
const { transactionRequest, optimizeGas = true } = params;
|
4323
|
+
let { gasPrice } = params;
|
4324
|
+
const chainInfo = this.getChain();
|
4325
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4326
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4327
|
+
if (!gasPrice) {
|
4328
|
+
gasPrice = await this.estimateGasPrice(10);
|
4329
|
+
}
|
4330
|
+
const minFee = calculateGasFee({
|
4331
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4332
|
+
gas: minGas,
|
4333
|
+
priceFactor: gasPriceFactor,
|
4334
|
+
tip: transactionRequest.tip
|
4335
|
+
}).add(1);
|
4336
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4337
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4338
|
+
gasLimit = transactionRequest.gasLimit;
|
4339
|
+
if (!optimizeGas) {
|
4340
|
+
transactionRequest.gasLimit = minGas;
|
4341
|
+
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4342
|
+
transactionRequest.gasLimit = gasLimit;
|
4343
|
+
}
|
4344
|
+
}
|
4345
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4346
|
+
const maxFee = calculateGasFee({
|
4347
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4348
|
+
gas: maxGas,
|
4349
|
+
priceFactor: gasPriceFactor,
|
4350
|
+
tip: transactionRequest.tip
|
4351
|
+
}).add(1);
|
4352
|
+
return {
|
4353
|
+
minGas,
|
4354
|
+
minFee,
|
4355
|
+
maxGas,
|
4356
|
+
maxFee,
|
4357
|
+
gasPrice,
|
4358
|
+
gasLimit
|
4153
4359
|
};
|
4154
4360
|
}
|
4155
4361
|
/**
|
@@ -4167,15 +4373,17 @@ var _Provider = class {
|
|
4167
4373
|
if (estimateTxDependencies) {
|
4168
4374
|
return this.estimateTxDependencies(transactionRequest);
|
4169
4375
|
}
|
4170
|
-
const
|
4171
|
-
const { dryRun:
|
4172
|
-
|
4376
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4377
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4378
|
+
encodedTransactions,
|
4173
4379
|
utxoValidation: true
|
4174
4380
|
});
|
4175
|
-
const
|
4176
|
-
|
4177
|
-
receipts
|
4178
|
-
|
4381
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4382
|
+
const { id, receipts, status } = dryRunStatus;
|
4383
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4384
|
+
return { id, receipts: processedReceipts, status };
|
4385
|
+
});
|
4386
|
+
return { receipts: callResult[0].receipts };
|
4179
4387
|
}
|
4180
4388
|
/**
|
4181
4389
|
* Returns a transaction cost to enable user
|
@@ -4192,80 +4400,80 @@ var _Provider = class {
|
|
4192
4400
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4193
4401
|
* @returns A promise that resolves to the transaction cost object.
|
4194
4402
|
*/
|
4195
|
-
async getTransactionCost(transactionRequestLike,
|
4196
|
-
estimateTxDependencies = true,
|
4197
|
-
estimatePredicates = true,
|
4198
|
-
resourcesOwner,
|
4199
|
-
signatureCallback
|
4200
|
-
} = {}) {
|
4403
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4201
4404
|
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;
|
4405
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4206
4406
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4207
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4407
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4208
4408
|
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);
|
4409
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4410
|
+
if (isScriptTransaction) {
|
4411
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
4217
4412
|
}
|
4218
|
-
if (
|
4219
|
-
|
4413
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4414
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4220
4415
|
}
|
4221
|
-
const
|
4222
|
-
|
4416
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4417
|
+
let addedSignatures = 0;
|
4418
|
+
if (signatureCallback && isScriptTransaction) {
|
4419
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4420
|
+
await signatureCallback(signedRequest);
|
4421
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4422
|
+
}
|
4423
|
+
await this.estimatePredicates(signedRequest);
|
4424
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4425
|
+
transactionRequest: signedRequest,
|
4426
|
+
optimizeGas: false
|
4427
|
+
});
|
4428
|
+
txRequestClone.maxFee = maxFee;
|
4223
4429
|
let receipts = [];
|
4224
4430
|
let missingContractIds = [];
|
4225
4431
|
let outputVariables = 0;
|
4226
|
-
|
4227
|
-
|
4228
|
-
|
4432
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4433
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4434
|
+
if (isScriptTransaction) {
|
4435
|
+
if (signatureCallback) {
|
4436
|
+
await signatureCallback(txRequestClone);
|
4437
|
+
}
|
4438
|
+
txRequestClone.gasLimit = gasLimit;
|
4229
4439
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4230
4440
|
receipts = result.receipts;
|
4231
4441
|
outputVariables = result.outputVariables;
|
4232
4442
|
missingContractIds = result.missingContractIds;
|
4443
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4444
|
+
txRequestClone.gasLimit = gasUsed;
|
4445
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4446
|
+
transactionRequest: txRequestClone,
|
4447
|
+
gasPrice
|
4448
|
+
}));
|
4233
4449
|
}
|
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
4450
|
return {
|
4243
4451
|
requiredQuantities: allQuantities,
|
4244
4452
|
receipts,
|
4245
4453
|
gasUsed,
|
4246
|
-
minGasPrice,
|
4247
4454
|
gasPrice,
|
4248
4455
|
minGas,
|
4249
4456
|
maxGas,
|
4250
|
-
usedFee,
|
4251
4457
|
minFee,
|
4252
4458
|
maxFee,
|
4253
|
-
estimatedInputs: txRequestClone.inputs,
|
4254
4459
|
outputVariables,
|
4255
|
-
missingContractIds
|
4460
|
+
missingContractIds,
|
4461
|
+
addedSignatures,
|
4462
|
+
estimatedPredicates: txRequestClone.inputs
|
4256
4463
|
};
|
4257
4464
|
}
|
4258
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4465
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4259
4466
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4260
4467
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4261
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4468
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4469
|
+
quantitiesToContract
|
4470
|
+
});
|
4262
4471
|
transactionRequest.addResources(
|
4263
4472
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4264
4473
|
);
|
4265
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4266
|
-
|
4267
|
-
|
4268
|
-
);
|
4474
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4475
|
+
quantitiesToContract
|
4476
|
+
});
|
4269
4477
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4270
4478
|
return {
|
4271
4479
|
resources,
|
@@ -4281,17 +4489,16 @@ var _Provider = class {
|
|
4281
4489
|
const result = await this.operations.getCoins({
|
4282
4490
|
first: 10,
|
4283
4491
|
...paginationArgs,
|
4284
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4492
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4285
4493
|
});
|
4286
4494
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4287
4495
|
return coins.map((coin) => ({
|
4288
4496
|
id: coin.utxoId,
|
4289
4497
|
assetId: coin.assetId,
|
4290
|
-
amount: (0,
|
4498
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4291
4499
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4292
|
-
|
4293
|
-
|
4294
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4500
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4501
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4295
4502
|
}));
|
4296
4503
|
}
|
4297
4504
|
/**
|
@@ -4305,19 +4512,19 @@ var _Provider = class {
|
|
4305
4512
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4306
4513
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4307
4514
|
const excludeInput = {
|
4308
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4309
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4515
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4516
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4310
4517
|
};
|
4311
4518
|
if (this.cache) {
|
4312
4519
|
const uniqueUtxos = new Set(
|
4313
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4520
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4314
4521
|
);
|
4315
4522
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4316
4523
|
}
|
4317
4524
|
const coinsQuery = {
|
4318
4525
|
owner: ownerAddress.toB256(),
|
4319
4526
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4320
|
-
assetId: (0,
|
4527
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4321
4528
|
amount: amount.toString(10),
|
4322
4529
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4323
4530
|
})),
|
@@ -4328,9 +4535,9 @@ var _Provider = class {
|
|
4328
4535
|
switch (coin.__typename) {
|
4329
4536
|
case "MessageCoin":
|
4330
4537
|
return {
|
4331
|
-
amount: (0,
|
4538
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4332
4539
|
assetId: coin.assetId,
|
4333
|
-
daHeight: (0,
|
4540
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4334
4541
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4335
4542
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4336
4543
|
nonce: coin.nonce
|
@@ -4338,12 +4545,11 @@ var _Provider = class {
|
|
4338
4545
|
case "Coin":
|
4339
4546
|
return {
|
4340
4547
|
id: coin.utxoId,
|
4341
|
-
amount: (0,
|
4548
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4342
4549
|
assetId: coin.assetId,
|
4343
4550
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4344
|
-
|
4345
|
-
|
4346
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4551
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4552
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4347
4553
|
};
|
4348
4554
|
default:
|
4349
4555
|
return null;
|
@@ -4360,13 +4566,13 @@ var _Provider = class {
|
|
4360
4566
|
async getBlock(idOrHeight) {
|
4361
4567
|
let variables;
|
4362
4568
|
if (typeof idOrHeight === "number") {
|
4363
|
-
variables = { height: (0,
|
4569
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4364
4570
|
} else if (idOrHeight === "latest") {
|
4365
4571
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4366
4572
|
} else if (idOrHeight.length === 66) {
|
4367
4573
|
variables = { blockId: idOrHeight };
|
4368
4574
|
} else {
|
4369
|
-
variables = { blockId: (0,
|
4575
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4370
4576
|
}
|
4371
4577
|
const { block } = await this.operations.getBlock(variables);
|
4372
4578
|
if (!block) {
|
@@ -4374,7 +4580,7 @@ var _Provider = class {
|
|
4374
4580
|
}
|
4375
4581
|
return {
|
4376
4582
|
id: block.id,
|
4377
|
-
height: (0,
|
4583
|
+
height: (0, import_math16.bn)(block.height),
|
4378
4584
|
time: block.header.time,
|
4379
4585
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4380
4586
|
};
|
@@ -4389,7 +4595,7 @@ var _Provider = class {
|
|
4389
4595
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4390
4596
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4391
4597
|
id: block.id,
|
4392
|
-
height: (0,
|
4598
|
+
height: (0, import_math16.bn)(block.height),
|
4393
4599
|
time: block.header.time,
|
4394
4600
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4395
4601
|
}));
|
@@ -4404,7 +4610,7 @@ var _Provider = class {
|
|
4404
4610
|
async getBlockWithTransactions(idOrHeight) {
|
4405
4611
|
let variables;
|
4406
4612
|
if (typeof idOrHeight === "number") {
|
4407
|
-
variables = { blockHeight: (0,
|
4613
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4408
4614
|
} else if (idOrHeight === "latest") {
|
4409
4615
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4410
4616
|
} else {
|
@@ -4416,11 +4622,11 @@ var _Provider = class {
|
|
4416
4622
|
}
|
4417
4623
|
return {
|
4418
4624
|
id: block.id,
|
4419
|
-
height: (0,
|
4625
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4420
4626
|
time: block.header.time,
|
4421
4627
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4422
4628
|
transactions: block.transactions.map(
|
4423
|
-
(tx) => new
|
4629
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4424
4630
|
)
|
4425
4631
|
};
|
4426
4632
|
}
|
@@ -4435,8 +4641,8 @@ var _Provider = class {
|
|
4435
4641
|
if (!transaction) {
|
4436
4642
|
return null;
|
4437
4643
|
}
|
4438
|
-
return new
|
4439
|
-
(0,
|
4644
|
+
return new import_transactions19.TransactionCoder().decode(
|
4645
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4440
4646
|
0
|
4441
4647
|
)?.[0];
|
4442
4648
|
}
|
@@ -4463,9 +4669,9 @@ var _Provider = class {
|
|
4463
4669
|
async getContractBalance(contractId, assetId) {
|
4464
4670
|
const { contractBalance } = await this.operations.getContractBalance({
|
4465
4671
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4466
|
-
asset: (0,
|
4672
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4467
4673
|
});
|
4468
|
-
return (0,
|
4674
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4469
4675
|
}
|
4470
4676
|
/**
|
4471
4677
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4477,9 +4683,9 @@ var _Provider = class {
|
|
4477
4683
|
async getBalance(owner, assetId) {
|
4478
4684
|
const { balance } = await this.operations.getBalance({
|
4479
4685
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4480
|
-
assetId: (0,
|
4686
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4481
4687
|
});
|
4482
|
-
return (0,
|
4688
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4483
4689
|
}
|
4484
4690
|
/**
|
4485
4691
|
* Returns balances for the given owner.
|
@@ -4497,7 +4703,7 @@ var _Provider = class {
|
|
4497
4703
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4498
4704
|
return balances.map((balance) => ({
|
4499
4705
|
assetId: balance.assetId,
|
4500
|
-
amount: (0,
|
4706
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4501
4707
|
}));
|
4502
4708
|
}
|
4503
4709
|
/**
|
@@ -4515,19 +4721,19 @@ var _Provider = class {
|
|
4515
4721
|
});
|
4516
4722
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4517
4723
|
return messages.map((message) => ({
|
4518
|
-
messageId:
|
4724
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4519
4725
|
sender: message.sender,
|
4520
4726
|
recipient: message.recipient,
|
4521
4727
|
nonce: message.nonce,
|
4522
|
-
amount: (0,
|
4728
|
+
amount: (0, import_math16.bn)(message.amount),
|
4523
4729
|
data: message.data
|
4524
4730
|
}),
|
4525
4731
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4526
4732
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4527
4733
|
nonce: message.nonce,
|
4528
|
-
amount: (0,
|
4529
|
-
data:
|
4530
|
-
daHeight: (0,
|
4734
|
+
amount: (0, import_math16.bn)(message.amount),
|
4735
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4736
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4531
4737
|
}));
|
4532
4738
|
}
|
4533
4739
|
/**
|
@@ -4580,44 +4786,52 @@ var _Provider = class {
|
|
4580
4786
|
} = result.messageProof;
|
4581
4787
|
return {
|
4582
4788
|
messageProof: {
|
4583
|
-
proofIndex: (0,
|
4789
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4584
4790
|
proofSet: messageProof.proofSet
|
4585
4791
|
},
|
4586
4792
|
blockProof: {
|
4587
|
-
proofIndex: (0,
|
4793
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4588
4794
|
proofSet: blockProof.proofSet
|
4589
4795
|
},
|
4590
4796
|
messageBlockHeader: {
|
4591
4797
|
id: messageBlockHeader.id,
|
4592
|
-
daHeight: (0,
|
4593
|
-
transactionsCount: (0,
|
4798
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4799
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4594
4800
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4595
|
-
height: (0,
|
4801
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4596
4802
|
prevRoot: messageBlockHeader.prevRoot,
|
4597
4803
|
time: messageBlockHeader.time,
|
4598
4804
|
applicationHash: messageBlockHeader.applicationHash,
|
4599
|
-
|
4600
|
-
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4805
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount)
|
4601
4806
|
},
|
4602
4807
|
commitBlockHeader: {
|
4603
4808
|
id: commitBlockHeader.id,
|
4604
|
-
daHeight: (0,
|
4605
|
-
transactionsCount: (0,
|
4809
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4810
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4606
4811
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4607
|
-
height: (0,
|
4812
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4608
4813
|
prevRoot: commitBlockHeader.prevRoot,
|
4609
4814
|
time: commitBlockHeader.time,
|
4610
4815
|
applicationHash: commitBlockHeader.applicationHash,
|
4611
|
-
|
4612
|
-
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4816
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount)
|
4613
4817
|
},
|
4614
4818
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4615
4819
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4616
4820
|
nonce,
|
4617
|
-
amount: (0,
|
4821
|
+
amount: (0, import_math16.bn)(amount),
|
4618
4822
|
data
|
4619
4823
|
};
|
4620
4824
|
}
|
4825
|
+
async getLatestGasPrice() {
|
4826
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4827
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4828
|
+
}
|
4829
|
+
async estimateGasPrice(blockHorizon) {
|
4830
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4831
|
+
blockHorizon: String(blockHorizon)
|
4832
|
+
});
|
4833
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4834
|
+
}
|
4621
4835
|
/**
|
4622
4836
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4623
4837
|
*
|
@@ -4637,10 +4851,10 @@ var _Provider = class {
|
|
4637
4851
|
*/
|
4638
4852
|
async produceBlocks(amount, startTime) {
|
4639
4853
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4640
|
-
blocksToProduce: (0,
|
4641
|
-
startTimestamp: startTime ?
|
4854
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4855
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4642
4856
|
});
|
4643
|
-
return (0,
|
4857
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4644
4858
|
}
|
4645
4859
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4646
4860
|
async getTransactionResponse(transactionId) {
|
@@ -4654,7 +4868,7 @@ cacheInputs_fn = function(inputs) {
|
|
4654
4868
|
return;
|
4655
4869
|
}
|
4656
4870
|
inputs.forEach((input) => {
|
4657
|
-
if (input.type ===
|
4871
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4658
4872
|
this.cache?.set(input.id);
|
4659
4873
|
}
|
4660
4874
|
});
|
@@ -4664,9 +4878,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4664
4878
|
|
4665
4879
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4666
4880
|
var import_errors15 = require("@fuel-ts/errors");
|
4667
|
-
var
|
4668
|
-
var
|
4669
|
-
var
|
4881
|
+
var import_math17 = require("@fuel-ts/math");
|
4882
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4883
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4670
4884
|
async function getTransactionSummary(params) {
|
4671
4885
|
const { id, provider, abiMap } = params;
|
4672
4886
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4678,25 +4892,32 @@ async function getTransactionSummary(params) {
|
|
4678
4892
|
`Transaction not found for given id: ${id}.`
|
4679
4893
|
);
|
4680
4894
|
}
|
4681
|
-
const [decodedTransaction] = new
|
4682
|
-
(0,
|
4895
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
|
4896
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4683
4897
|
0
|
4684
4898
|
);
|
4685
|
-
|
4899
|
+
let txReceipts = [];
|
4900
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4901
|
+
txReceipts = gqlTransaction.status.receipts;
|
4902
|
+
}
|
4903
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4686
4904
|
const {
|
4687
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4905
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4688
4906
|
} = provider.getChain();
|
4907
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4689
4908
|
const transactionInfo = assembleTransactionSummary({
|
4690
4909
|
id: gqlTransaction.id,
|
4691
4910
|
receipts,
|
4692
4911
|
transaction: decodedTransaction,
|
4693
|
-
transactionBytes: (0,
|
4912
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4694
4913
|
gqlTransactionStatus: gqlTransaction.status,
|
4695
|
-
gasPerByte: (0,
|
4696
|
-
gasPriceFactor: (0,
|
4914
|
+
gasPerByte: (0, import_math17.bn)(gasPerByte),
|
4915
|
+
gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
|
4697
4916
|
abiMap,
|
4698
4917
|
maxInputs,
|
4699
|
-
gasCosts
|
4918
|
+
gasCosts,
|
4919
|
+
maxGasPerTx,
|
4920
|
+
gasPrice
|
4700
4921
|
});
|
4701
4922
|
return {
|
4702
4923
|
gqlTransaction,
|
@@ -4706,10 +4927,11 @@ async function getTransactionSummary(params) {
|
|
4706
4927
|
async function getTransactionSummaryFromRequest(params) {
|
4707
4928
|
const { provider, transactionRequest, abiMap } = params;
|
4708
4929
|
const { receipts } = await provider.call(transactionRequest);
|
4709
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4930
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4710
4931
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4711
4932
|
const transaction = transactionRequest.toTransaction();
|
4712
4933
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4934
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4713
4935
|
const transactionSummary = assembleTransactionSummary({
|
4714
4936
|
receipts,
|
4715
4937
|
transaction,
|
@@ -4718,7 +4940,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4718
4940
|
gasPerByte,
|
4719
4941
|
gasPriceFactor,
|
4720
4942
|
maxInputs,
|
4721
|
-
gasCosts
|
4943
|
+
gasCosts,
|
4944
|
+
maxGasPerTx,
|
4945
|
+
gasPrice
|
4722
4946
|
});
|
4723
4947
|
return transactionSummary;
|
4724
4948
|
}
|
@@ -4727,24 +4951,31 @@ async function getTransactionsSummaries(params) {
|
|
4727
4951
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4728
4952
|
const { edges, pageInfo } = transactionsByOwner;
|
4729
4953
|
const {
|
4730
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4954
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4731
4955
|
} = provider.getChain();
|
4956
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4732
4957
|
const transactions = edges.map((edge) => {
|
4733
4958
|
const { node: gqlTransaction } = edge;
|
4734
|
-
const { id, rawPayload,
|
4735
|
-
const [decodedTransaction] = new
|
4736
|
-
|
4959
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4960
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
4961
|
+
let txReceipts = [];
|
4962
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4963
|
+
txReceipts = gqlTransaction.status.receipts;
|
4964
|
+
}
|
4965
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4737
4966
|
const transactionSummary = assembleTransactionSummary({
|
4738
4967
|
id,
|
4739
4968
|
receipts,
|
4740
4969
|
transaction: decodedTransaction,
|
4741
|
-
transactionBytes: (0,
|
4970
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4742
4971
|
gqlTransactionStatus: status,
|
4743
4972
|
abiMap,
|
4744
4973
|
gasPerByte,
|
4745
4974
|
gasPriceFactor,
|
4746
4975
|
maxInputs,
|
4747
|
-
gasCosts
|
4976
|
+
gasCosts,
|
4977
|
+
maxGasPerTx,
|
4978
|
+
gasPrice
|
4748
4979
|
});
|
4749
4980
|
const output = {
|
4750
4981
|
gqlTransaction,
|
@@ -4881,17 +5112,17 @@ var assets = [
|
|
4881
5112
|
|
4882
5113
|
// src/utils/formatTransferToContractScriptData.ts
|
4883
5114
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4884
|
-
var
|
4885
|
-
var
|
5115
|
+
var import_math18 = require("@fuel-ts/math");
|
5116
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4886
5117
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4887
5118
|
var formatTransferToContractScriptData = (params) => {
|
4888
5119
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4889
5120
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4890
|
-
const encoded = numberCoder.encode(new
|
5121
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4891
5122
|
const scriptData = Uint8Array.from([
|
4892
|
-
...(0,
|
5123
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4893
5124
|
...encoded,
|
4894
|
-
...(0,
|
5125
|
+
...(0, import_utils26.arrayify)(assetId)
|
4895
5126
|
]);
|
4896
5127
|
return scriptData;
|
4897
5128
|
};
|
@@ -5038,9 +5269,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5038
5269
|
* @param assetId - The asset ID to check the balance for.
|
5039
5270
|
* @returns A promise that resolves to the balance amount.
|
5040
5271
|
*/
|
5041
|
-
async getBalance(assetId) {
|
5042
|
-
const
|
5043
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5272
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
5273
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
5044
5274
|
return amount;
|
5045
5275
|
}
|
5046
5276
|
/**
|
@@ -5077,37 +5307,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5077
5307
|
* @param fee - The estimated transaction fee.
|
5078
5308
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5079
5309
|
*/
|
5080
|
-
async fund(request,
|
5081
|
-
const
|
5082
|
-
const
|
5083
|
-
|
5084
|
-
|
5085
|
-
|
5310
|
+
async fund(request, params) {
|
5311
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5312
|
+
const txRequest = request;
|
5313
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5314
|
+
amount: (0, import_math19.bn)(fee),
|
5315
|
+
assetId: import_configs12.BaseAssetId,
|
5316
|
+
coinQuantities: requiredQuantities
|
5086
5317
|
});
|
5087
5318
|
const quantitiesDict = {};
|
5088
|
-
|
5319
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5089
5320
|
quantitiesDict[assetId] = {
|
5090
5321
|
required: amount,
|
5091
|
-
owned: (0,
|
5322
|
+
owned: (0, import_math19.bn)(0)
|
5092
5323
|
};
|
5093
5324
|
});
|
5094
|
-
|
5095
|
-
const cachedMessages = [];
|
5096
|
-
const owner = this.address.toB256();
|
5097
|
-
request.inputs.forEach((input) => {
|
5325
|
+
txRequest.inputs.forEach((input) => {
|
5098
5326
|
const isResource = "amount" in input;
|
5099
5327
|
if (isResource) {
|
5100
5328
|
const isCoin2 = "owner" in input;
|
5101
5329
|
if (isCoin2) {
|
5102
5330
|
const assetId = String(input.assetId);
|
5103
|
-
if (
|
5104
|
-
const amount = (0,
|
5331
|
+
if (quantitiesDict[assetId]) {
|
5332
|
+
const amount = (0, import_math19.bn)(input.amount);
|
5105
5333
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5106
|
-
cachedUtxos.push(input.id);
|
5107
5334
|
}
|
5108
|
-
} else if (input.
|
5109
|
-
quantitiesDict[
|
5110
|
-
cachedMessages.push(input.nonce);
|
5335
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5336
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5111
5337
|
}
|
5112
5338
|
}
|
5113
5339
|
});
|
@@ -5122,12 +5348,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5122
5348
|
});
|
5123
5349
|
const needsToBeFunded = missingQuantities.length;
|
5124
5350
|
if (needsToBeFunded) {
|
5125
|
-
const
|
5126
|
-
|
5127
|
-
|
5128
|
-
|
5129
|
-
|
5351
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5352
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5353
|
+
txRequest.addResources(resources);
|
5354
|
+
}
|
5355
|
+
txRequest.shiftPredicateData();
|
5356
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5357
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5358
|
+
if (addedSignatures) {
|
5359
|
+
Array.from({ length: addedSignatures }).forEach(
|
5360
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5361
|
+
);
|
5130
5362
|
}
|
5363
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5364
|
+
transactionRequest: requestToBeReEstimate
|
5365
|
+
});
|
5366
|
+
txRequest.maxFee = maxFee;
|
5367
|
+
return txRequest;
|
5131
5368
|
}
|
5132
5369
|
/**
|
5133
5370
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5135,29 +5372,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5135
5372
|
* @param destination - The address of the destination.
|
5136
5373
|
* @param amount - The amount of coins to transfer.
|
5137
5374
|
* @param assetId - The asset ID of the coins to transfer.
|
5138
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5375
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5139
5376
|
* @returns A promise that resolves to the prepared transaction request.
|
5140
5377
|
*/
|
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, [], {
|
5378
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5379
|
+
const request = new ScriptTransactionRequest(txParams);
|
5380
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5381
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5148
5382
|
estimateTxDependencies: true,
|
5149
5383
|
resourcesOwner: this
|
5150
5384
|
});
|
5151
|
-
|
5152
|
-
|
5153
|
-
|
5154
|
-
|
5155
|
-
|
5156
|
-
|
5157
|
-
|
5158
|
-
|
5159
|
-
await this.fund(request,
|
5160
|
-
request.updatePredicateInputs(estimatedInputs);
|
5385
|
+
if ("gasLimit" in txParams) {
|
5386
|
+
this.validateGas({
|
5387
|
+
gasUsed: txCost.gasUsed,
|
5388
|
+
gasLimit: request.gasLimit
|
5389
|
+
});
|
5390
|
+
}
|
5391
|
+
request.gasLimit = txCost.gasUsed;
|
5392
|
+
request.maxFee = txCost.maxFee;
|
5393
|
+
await this.fund(request, txCost);
|
5161
5394
|
return request;
|
5162
5395
|
}
|
5163
5396
|
/**
|
@@ -5169,15 +5402,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5169
5402
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5170
5403
|
* @returns A promise that resolves to the transaction response.
|
5171
5404
|
*/
|
5172
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5173
|
-
if ((0,
|
5405
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5406
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5174
5407
|
throw new import_errors16.FuelError(
|
5175
5408
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5176
5409
|
"Transfer amount must be a positive number."
|
5177
5410
|
);
|
5178
5411
|
}
|
5179
|
-
const
|
5180
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5412
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5181
5413
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5182
5414
|
}
|
5183
5415
|
/**
|
@@ -5189,40 +5421,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5189
5421
|
* @param txParams - The optional transaction parameters.
|
5190
5422
|
* @returns A promise that resolves to the transaction response.
|
5191
5423
|
*/
|
5192
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5193
|
-
if ((0,
|
5424
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5425
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5194
5426
|
throw new import_errors16.FuelError(
|
5195
5427
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5196
5428
|
"Transfer amount must be a positive number."
|
5197
5429
|
);
|
5198
5430
|
}
|
5199
5431
|
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
5432
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5204
5433
|
hexlifiedContractId: contractAddress.toB256(),
|
5205
|
-
amountToTransfer: (0,
|
5206
|
-
assetId
|
5434
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5435
|
+
assetId
|
5207
5436
|
});
|
5208
5437
|
const request = new ScriptTransactionRequest({
|
5209
|
-
...
|
5438
|
+
...txParams,
|
5210
5439
|
script,
|
5211
5440
|
scriptData
|
5212
5441
|
});
|
5213
5442
|
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
|
5443
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5444
|
+
resourcesOwner: this,
|
5445
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
5224
5446
|
});
|
5225
|
-
|
5447
|
+
if (txParams.gasLimit) {
|
5448
|
+
this.validateGas({
|
5449
|
+
gasUsed: txCost.gasUsed,
|
5450
|
+
gasLimit: request.gasLimit
|
5451
|
+
});
|
5452
|
+
}
|
5453
|
+
request.gasLimit = txCost.gasUsed;
|
5454
|
+
request.maxFee = txCost.maxFee;
|
5455
|
+
await this.fund(request, txCost);
|
5226
5456
|
return this.sendTransaction(request);
|
5227
5457
|
}
|
5228
5458
|
/**
|
@@ -5234,35 +5464,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5234
5464
|
* @returns A promise that resolves to the transaction response.
|
5235
5465
|
*/
|
5236
5466
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5237
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5238
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5239
5467
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5240
|
-
const recipientDataArray = (0,
|
5468
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5241
5469
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5242
5470
|
);
|
5243
|
-
const amountDataArray = (0,
|
5244
|
-
"0x".concat((0,
|
5471
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5472
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5245
5473
|
);
|
5246
5474
|
const script = new Uint8Array([
|
5247
|
-
...(0,
|
5475
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5248
5476
|
...recipientDataArray,
|
5249
5477
|
...amountDataArray
|
5250
5478
|
]);
|
5251
|
-
const params = { script,
|
5479
|
+
const params = { script, ...txParams };
|
5252
5480
|
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);
|
5481
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5482
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5483
|
+
if (txParams.gasLimit) {
|
5484
|
+
this.validateGas({
|
5485
|
+
gasUsed: txCost.gasUsed,
|
5486
|
+
gasLimit: request.gasLimit
|
5487
|
+
});
|
5488
|
+
}
|
5489
|
+
request.maxFee = txCost.maxFee;
|
5490
|
+
request.gasLimit = txCost.gasUsed;
|
5491
|
+
await this.fund(request, txCost);
|
5266
5492
|
return this.sendTransaction(request);
|
5267
5493
|
}
|
5268
5494
|
async signMessage(message) {
|
@@ -5320,18 +5546,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5320
5546
|
}
|
5321
5547
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5322
5548
|
}
|
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
|
-
}
|
5549
|
+
validateGas({ gasUsed, gasLimit }) {
|
5335
5550
|
if (gasUsed.gt(gasLimit)) {
|
5336
5551
|
throw new import_errors16.FuelError(
|
5337
5552
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5343,14 +5558,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5343
5558
|
|
5344
5559
|
// src/wallet/base-wallet-unlocked.ts
|
5345
5560
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5346
|
-
var
|
5561
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5347
5562
|
|
5348
5563
|
// src/signer/signer.ts
|
5349
5564
|
var import_address5 = require("@fuel-ts/address");
|
5350
5565
|
var import_crypto = require("@fuel-ts/crypto");
|
5351
5566
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5352
|
-
var
|
5353
|
-
var
|
5567
|
+
var import_math20 = require("@fuel-ts/math");
|
5568
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5354
5569
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5355
5570
|
var Signer = class {
|
5356
5571
|
address;
|
@@ -5369,10 +5584,10 @@ var Signer = class {
|
|
5369
5584
|
privateKey = `0x${privateKey}`;
|
5370
5585
|
}
|
5371
5586
|
}
|
5372
|
-
const privateKeyBytes = (0,
|
5373
|
-
this.privateKey = (0,
|
5374
|
-
this.publicKey = (0,
|
5375
|
-
this.compressedPublicKey = (0,
|
5587
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5588
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5589
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5590
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5376
5591
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5377
5592
|
}
|
5378
5593
|
/**
|
@@ -5386,11 +5601,11 @@ var Signer = class {
|
|
5386
5601
|
* @returns hashed signature
|
5387
5602
|
*/
|
5388
5603
|
sign(data) {
|
5389
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5390
|
-
const r = (0,
|
5391
|
-
const s = (0,
|
5604
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5605
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5606
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5392
5607
|
s[0] |= (signature.recovery || 0) << 7;
|
5393
|
-
return (0,
|
5608
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5394
5609
|
}
|
5395
5610
|
/**
|
5396
5611
|
* Add point on the current elliptic curve
|
@@ -5399,8 +5614,8 @@ var Signer = class {
|
|
5399
5614
|
* @returns compressed point on the curve
|
5400
5615
|
*/
|
5401
5616
|
addPoint(point) {
|
5402
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5403
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5617
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5618
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5404
5619
|
const result = p0.add(p1);
|
5405
5620
|
return `0x${result.toHex(true)}`;
|
5406
5621
|
}
|
@@ -5412,16 +5627,16 @@ var Signer = class {
|
|
5412
5627
|
* @returns public key from signature from the
|
5413
5628
|
*/
|
5414
5629
|
static recoverPublicKey(data, signature) {
|
5415
|
-
const signedMessageBytes = (0,
|
5630
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5416
5631
|
const r = signedMessageBytes.slice(0, 32);
|
5417
5632
|
const s = signedMessageBytes.slice(32, 64);
|
5418
5633
|
const recoveryParam = (s[0] & 128) >> 7;
|
5419
5634
|
s[0] &= 127;
|
5420
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5635
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5421
5636
|
recoveryParam
|
5422
5637
|
);
|
5423
|
-
const publicKey = sig.recoverPublicKey((0,
|
5424
|
-
return (0,
|
5638
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5639
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5425
5640
|
}
|
5426
5641
|
/**
|
5427
5642
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5440,7 +5655,7 @@ var Signer = class {
|
|
5440
5655
|
* @returns random 32-byte hashed
|
5441
5656
|
*/
|
5442
5657
|
static generatePrivateKey(entropy) {
|
5443
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5658
|
+
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
5659
|
}
|
5445
5660
|
/**
|
5446
5661
|
* Extended publicKey from a compact publicKey
|
@@ -5449,8 +5664,8 @@ var Signer = class {
|
|
5449
5664
|
* @returns extended publicKey
|
5450
5665
|
*/
|
5451
5666
|
static extendPublicKey(publicKey) {
|
5452
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5453
|
-
return (0,
|
5667
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5668
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5454
5669
|
}
|
5455
5670
|
};
|
5456
5671
|
|
@@ -5458,7 +5673,7 @@ var Signer = class {
|
|
5458
5673
|
var import_address6 = require("@fuel-ts/address");
|
5459
5674
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5460
5675
|
var import_errors17 = require("@fuel-ts/errors");
|
5461
|
-
var
|
5676
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5462
5677
|
var import_uuid = require("uuid");
|
5463
5678
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5464
5679
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5541,7 +5756,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5541
5756
|
);
|
5542
5757
|
}
|
5543
5758
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5544
|
-
const privateKey = (0,
|
5759
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5545
5760
|
return privateKey;
|
5546
5761
|
}
|
5547
5762
|
|
@@ -5586,7 +5801,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5586
5801
|
*/
|
5587
5802
|
async signMessage(message) {
|
5588
5803
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5589
|
-
return (0,
|
5804
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5590
5805
|
}
|
5591
5806
|
/**
|
5592
5807
|
* Signs a transaction with the wallet's private key.
|
@@ -5599,7 +5814,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5599
5814
|
const chainId = this.provider.getChainId();
|
5600
5815
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5601
5816
|
const signature = await this.signer().sign(hashedTransaction);
|
5602
|
-
return (0,
|
5817
|
+
return (0, import_utils30.hexlify)(signature);
|
5603
5818
|
}
|
5604
5819
|
/**
|
5605
5820
|
* Populates a transaction with the witnesses signature.
|
@@ -5619,7 +5834,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5619
5834
|
* @param transactionRequestLike - The transaction request to send.
|
5620
5835
|
* @returns A promise that resolves to the TransactionResponse object.
|
5621
5836
|
*/
|
5622
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5837
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5623
5838
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5624
5839
|
if (estimateTxDependencies) {
|
5625
5840
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5660,16 +5875,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5660
5875
|
// src/hdwallet/hdwallet.ts
|
5661
5876
|
var import_errors20 = require("@fuel-ts/errors");
|
5662
5877
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5663
|
-
var
|
5664
|
-
var
|
5665
|
-
var
|
5878
|
+
var import_math21 = require("@fuel-ts/math");
|
5879
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5880
|
+
var import_ethers4 = require("ethers");
|
5666
5881
|
|
5667
5882
|
// src/mnemonic/mnemonic.ts
|
5668
5883
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5669
5884
|
var import_errors19 = require("@fuel-ts/errors");
|
5670
5885
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5671
|
-
var
|
5672
|
-
var
|
5886
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5887
|
+
var import_ethers3 = require("ethers");
|
5673
5888
|
|
5674
5889
|
// src/wordlists/words/english.ts
|
5675
5890
|
var english = [
|
@@ -7732,7 +7947,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7732
7947
|
// src/mnemonic/utils.ts
|
7733
7948
|
var import_errors18 = require("@fuel-ts/errors");
|
7734
7949
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7735
|
-
var
|
7950
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7736
7951
|
function toUtf8Bytes(stri) {
|
7737
7952
|
const str = stri.normalize("NFKD");
|
7738
7953
|
const result = [];
|
@@ -7799,14 +8014,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7799
8014
|
}
|
7800
8015
|
}
|
7801
8016
|
const checksumBits = entropy.length / 4;
|
7802
|
-
const checksum = (0,
|
8017
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7803
8018
|
indices[indices.length - 1] <<= checksumBits;
|
7804
8019
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7805
8020
|
return indices;
|
7806
8021
|
}
|
7807
8022
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7808
8023
|
const size = Math.ceil(11 * words.length / 8);
|
7809
|
-
const entropy = (0,
|
8024
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7810
8025
|
let offset = 0;
|
7811
8026
|
for (let i = 0; i < words.length; i += 1) {
|
7812
8027
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7826,7 +8041,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7826
8041
|
const entropyBits = 32 * words.length / 3;
|
7827
8042
|
const checksumBits = words.length / 3;
|
7828
8043
|
const checksumMask = getUpperMask(checksumBits);
|
7829
|
-
const checksum = (0,
|
8044
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7830
8045
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7831
8046
|
throw new import_errors18.FuelError(
|
7832
8047
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7901,7 +8116,7 @@ var Mnemonic = class {
|
|
7901
8116
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7902
8117
|
const words = getWords(phrase);
|
7903
8118
|
assertMnemonic(words);
|
7904
|
-
return (0,
|
8119
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7905
8120
|
}
|
7906
8121
|
/**
|
7907
8122
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7909,7 +8124,7 @@ var Mnemonic = class {
|
|
7909
8124
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7910
8125
|
*/
|
7911
8126
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7912
|
-
const entropyBytes = (0,
|
8127
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7913
8128
|
assertWordList(wordlist);
|
7914
8129
|
assertEntropy(entropyBytes);
|
7915
8130
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7923,7 +8138,7 @@ var Mnemonic = class {
|
|
7923
8138
|
assertMnemonic(getWords(phrase));
|
7924
8139
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7925
8140
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7926
|
-
return (0,
|
8141
|
+
return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7927
8142
|
}
|
7928
8143
|
/**
|
7929
8144
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7978,14 +8193,14 @@ var Mnemonic = class {
|
|
7978
8193
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7979
8194
|
*/
|
7980
8195
|
static masterKeysFromSeed(seed) {
|
7981
|
-
const seedArray = (0,
|
8196
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7982
8197
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7983
8198
|
throw new import_errors19.FuelError(
|
7984
8199
|
import_errors19.ErrorCode.INVALID_SEED,
|
7985
8200
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7986
8201
|
);
|
7987
8202
|
}
|
7988
|
-
return (0,
|
8203
|
+
return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
|
7989
8204
|
}
|
7990
8205
|
/**
|
7991
8206
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7996,22 +8211,22 @@ var Mnemonic = class {
|
|
7996
8211
|
*/
|
7997
8212
|
static seedToExtendedKey(seed, testnet = false) {
|
7998
8213
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7999
|
-
const prefix = (0,
|
8214
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8000
8215
|
const depth = "0x00";
|
8001
8216
|
const fingerprint = "0x00000000";
|
8002
8217
|
const index = "0x00000000";
|
8003
8218
|
const chainCode = masterKey.slice(32);
|
8004
8219
|
const privateKey = masterKey.slice(0, 32);
|
8005
|
-
const extendedKey = (0,
|
8220
|
+
const extendedKey = (0, import_utils32.concat)([
|
8006
8221
|
prefix,
|
8007
8222
|
depth,
|
8008
8223
|
fingerprint,
|
8009
8224
|
index,
|
8010
8225
|
chainCode,
|
8011
|
-
(0,
|
8226
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
8012
8227
|
]);
|
8013
|
-
const checksum = (0,
|
8014
|
-
return (0,
|
8228
|
+
const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8229
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
8015
8230
|
}
|
8016
8231
|
/**
|
8017
8232
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8026,7 +8241,7 @@ var Mnemonic = class {
|
|
8026
8241
|
* @returns A randomly generated mnemonic
|
8027
8242
|
*/
|
8028
8243
|
static generate(size = 32, extraEntropy = "") {
|
8029
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8244
|
+
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
8245
|
return Mnemonic.entropyToMnemonic(entropy);
|
8031
8246
|
}
|
8032
8247
|
};
|
@@ -8034,12 +8249,12 @@ var mnemonic_default = Mnemonic;
|
|
8034
8249
|
|
8035
8250
|
// src/hdwallet/hdwallet.ts
|
8036
8251
|
var HARDENED_INDEX = 2147483648;
|
8037
|
-
var MainnetPRV2 = (0,
|
8038
|
-
var MainnetPUB = (0,
|
8039
|
-
var TestnetPRV2 = (0,
|
8040
|
-
var TestnetPUB = (0,
|
8252
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
8253
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
8254
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
8255
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8041
8256
|
function base58check(data) {
|
8042
|
-
return (0,
|
8257
|
+
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
8258
|
}
|
8044
8259
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8045
8260
|
if (isPublic) {
|
@@ -8048,11 +8263,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8048
8263
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8049
8264
|
}
|
8050
8265
|
function isPublicExtendedKey(extendedKey) {
|
8051
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8266
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8052
8267
|
}
|
8053
8268
|
function isValidExtendedKey(extendedKey) {
|
8054
8269
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8055
|
-
(0,
|
8270
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8056
8271
|
);
|
8057
8272
|
}
|
8058
8273
|
function parsePath(path, depth = 0) {
|
@@ -8070,8 +8285,8 @@ function parsePath(path, depth = 0) {
|
|
8070
8285
|
var HDWallet = class {
|
8071
8286
|
depth = 0;
|
8072
8287
|
index = 0;
|
8073
|
-
fingerprint = (0,
|
8074
|
-
parentFingerprint = (0,
|
8288
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8289
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8075
8290
|
privateKey;
|
8076
8291
|
publicKey;
|
8077
8292
|
chainCode;
|
@@ -8083,8 +8298,8 @@ var HDWallet = class {
|
|
8083
8298
|
constructor(config) {
|
8084
8299
|
if (config.privateKey) {
|
8085
8300
|
const signer = new Signer(config.privateKey);
|
8086
|
-
this.publicKey = (0,
|
8087
|
-
this.privateKey = (0,
|
8301
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
8302
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8088
8303
|
} else {
|
8089
8304
|
if (!config.publicKey) {
|
8090
8305
|
throw new import_errors20.FuelError(
|
@@ -8092,10 +8307,10 @@ var HDWallet = class {
|
|
8092
8307
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8093
8308
|
);
|
8094
8309
|
}
|
8095
|
-
this.publicKey = (0,
|
8310
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8096
8311
|
}
|
8097
8312
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8098
|
-
this.fingerprint = (0,
|
8313
|
+
this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8099
8314
|
this.depth = config.depth || this.depth;
|
8100
8315
|
this.index = config.index || this.index;
|
8101
8316
|
this.chainCode = config.chainCode;
|
@@ -8111,9 +8326,9 @@ var HDWallet = class {
|
|
8111
8326
|
* @returns A new instance of HDWallet on the derived index
|
8112
8327
|
*/
|
8113
8328
|
deriveIndex(index) {
|
8114
|
-
const privateKey = this.privateKey && (0,
|
8115
|
-
const publicKey = (0,
|
8116
|
-
const chainCode = (0,
|
8329
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8330
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8331
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8117
8332
|
const data = new Uint8Array(37);
|
8118
8333
|
if (index & HARDENED_INDEX) {
|
8119
8334
|
if (!privateKey) {
|
@@ -8124,15 +8339,15 @@ var HDWallet = class {
|
|
8124
8339
|
}
|
8125
8340
|
data.set(privateKey, 1);
|
8126
8341
|
} else {
|
8127
|
-
data.set((0,
|
8342
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8128
8343
|
}
|
8129
|
-
data.set((0,
|
8130
|
-
const bytes = (0,
|
8344
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
8345
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
|
8131
8346
|
const IL = bytes.slice(0, 32);
|
8132
8347
|
const IR = bytes.slice(32);
|
8133
8348
|
if (privateKey) {
|
8134
8349
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8135
|
-
const ki = (0,
|
8350
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8136
8351
|
return new HDWallet({
|
8137
8352
|
privateKey: ki,
|
8138
8353
|
chainCode: IR,
|
@@ -8141,7 +8356,7 @@ var HDWallet = class {
|
|
8141
8356
|
parentFingerprint: this.fingerprint
|
8142
8357
|
});
|
8143
8358
|
}
|
8144
|
-
const signer = new Signer((0,
|
8359
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8145
8360
|
const Ki = signer.addPoint(publicKey);
|
8146
8361
|
return new HDWallet({
|
8147
8362
|
publicKey: Ki,
|
@@ -8176,12 +8391,12 @@ var HDWallet = class {
|
|
8176
8391
|
);
|
8177
8392
|
}
|
8178
8393
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8179
|
-
const depth = (0,
|
8394
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8180
8395
|
const parentFingerprint = this.parentFingerprint;
|
8181
|
-
const index = (0,
|
8396
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
8182
8397
|
const chainCode = this.chainCode;
|
8183
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8184
|
-
const extendedKey = (0,
|
8398
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8399
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8185
8400
|
return base58check(extendedKey);
|
8186
8401
|
}
|
8187
8402
|
/**
|
@@ -8193,13 +8408,13 @@ var HDWallet = class {
|
|
8193
8408
|
static fromSeed(seed) {
|
8194
8409
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8195
8410
|
return new HDWallet({
|
8196
|
-
chainCode: (0,
|
8197
|
-
privateKey: (0,
|
8411
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8412
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8198
8413
|
});
|
8199
8414
|
}
|
8200
8415
|
static fromExtendedKey(extendedKey) {
|
8201
|
-
const decoded = (0,
|
8202
|
-
const bytes = (0,
|
8416
|
+
const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
|
8417
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8203
8418
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8204
8419
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8205
8420
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8208,9 +8423,9 @@ var HDWallet = class {
|
|
8208
8423
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8209
8424
|
}
|
8210
8425
|
const depth = bytes[4];
|
8211
|
-
const parentFingerprint = (0,
|
8212
|
-
const index = parseInt((0,
|
8213
|
-
const chainCode = (0,
|
8426
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8427
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8428
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8214
8429
|
const key = bytes.slice(45, 78);
|
8215
8430
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8216
8431
|
throw new import_errors20.FuelError(
|
@@ -8813,20 +9028,21 @@ var StorageAbstract = class {
|
|
8813
9028
|
// src/predicate/predicate.ts
|
8814
9029
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
8815
9030
|
var import_address10 = require("@fuel-ts/address");
|
9031
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8816
9032
|
var import_errors25 = require("@fuel-ts/errors");
|
8817
|
-
var
|
8818
|
-
var
|
9033
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
9034
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8819
9035
|
|
8820
9036
|
// src/predicate/utils/getPredicateRoot.ts
|
8821
9037
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8822
9038
|
var import_merkle = require("@fuel-ts/merkle");
|
8823
|
-
var
|
9039
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8824
9040
|
var getPredicateRoot = (bytecode) => {
|
8825
9041
|
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,
|
9042
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
9043
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
9044
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
9045
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8830
9046
|
return predicateRoot;
|
8831
9047
|
};
|
8832
9048
|
|
@@ -8863,6 +9079,7 @@ var Predicate = class extends Account {
|
|
8863
9079
|
this.interface = predicateInterface;
|
8864
9080
|
if (inputData !== void 0 && inputData.length > 0) {
|
8865
9081
|
this.predicateData = inputData;
|
9082
|
+
this.predicateDataBytes = this.getPredicateData(0);
|
8866
9083
|
}
|
8867
9084
|
}
|
8868
9085
|
/**
|
@@ -8875,9 +9092,9 @@ var Predicate = class extends Account {
|
|
8875
9092
|
const request = transactionRequestify(transactionRequestLike);
|
8876
9093
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8877
9094
|
request.inputs?.forEach((input) => {
|
8878
|
-
if (input.type ===
|
8879
|
-
input.predicate = this.bytes;
|
8880
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9095
|
+
if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
9096
|
+
input.predicate = (0, import_utils36.hexlify)(this.bytes);
|
9097
|
+
input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
|
8881
9098
|
}
|
8882
9099
|
});
|
8883
9100
|
return request;
|
@@ -8891,10 +9108,8 @@ var Predicate = class extends Account {
|
|
8891
9108
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8892
9109
|
* @returns A promise that resolves to the prepared transaction request.
|
8893
9110
|
*/
|
8894
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8895
|
-
|
8896
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8897
|
-
return this.populateTransactionPredicateData(request);
|
9111
|
+
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
9112
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8898
9113
|
}
|
8899
9114
|
/**
|
8900
9115
|
* Sends a transaction with the populated predicate data.
|
@@ -8902,9 +9117,9 @@ var Predicate = class extends Account {
|
|
8902
9117
|
* @param transactionRequestLike - The transaction request-like object.
|
8903
9118
|
* @returns A promise that resolves to the transaction response.
|
8904
9119
|
*/
|
8905
|
-
sendTransaction(transactionRequestLike
|
8906
|
-
const transactionRequest =
|
8907
|
-
return super.sendTransaction(transactionRequest,
|
9120
|
+
sendTransaction(transactionRequestLike) {
|
9121
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9122
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8908
9123
|
}
|
8909
9124
|
/**
|
8910
9125
|
* Simulates a transaction with the populated predicate data.
|
@@ -8913,15 +9128,15 @@ var Predicate = class extends Account {
|
|
8913
9128
|
* @returns A promise that resolves to the call result.
|
8914
9129
|
*/
|
8915
9130
|
simulateTransaction(transactionRequestLike) {
|
8916
|
-
const transactionRequest =
|
8917
|
-
return super.simulateTransaction(transactionRequest);
|
9131
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9132
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8918
9133
|
}
|
8919
9134
|
getPredicateData(policiesLength) {
|
8920
9135
|
if (!this.predicateData.length) {
|
8921
9136
|
return new Uint8Array();
|
8922
9137
|
}
|
8923
9138
|
const mainFn = this.interface?.functions.main;
|
8924
|
-
const paddedCode = new
|
9139
|
+
const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8925
9140
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
8926
9141
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8927
9142
|
});
|
@@ -8937,7 +9152,7 @@ var Predicate = class extends Account {
|
|
8937
9152
|
* @returns An object containing the new predicate bytes and interface.
|
8938
9153
|
*/
|
8939
9154
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8940
|
-
let predicateBytes = (0,
|
9155
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8941
9156
|
let abiInterface;
|
8942
9157
|
if (jsonAbi) {
|
8943
9158
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
@@ -8960,6 +9175,26 @@ var Predicate = class extends Account {
|
|
8960
9175
|
predicateInterface: abiInterface
|
8961
9176
|
};
|
8962
9177
|
}
|
9178
|
+
/**
|
9179
|
+
* Retrieves resources satisfying the spend query for the account.
|
9180
|
+
*
|
9181
|
+
* @param quantities - IDs of coins to exclude.
|
9182
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9183
|
+
* @returns A promise that resolves to an array of Resources.
|
9184
|
+
*/
|
9185
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9186
|
+
const resources = await this.provider.getResourcesToSpend(
|
9187
|
+
this.address,
|
9188
|
+
quantities,
|
9189
|
+
excludedIds
|
9190
|
+
);
|
9191
|
+
return resources.map((resource) => ({
|
9192
|
+
...resource,
|
9193
|
+
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9194
|
+
predicateData: (0, import_utils36.hexlify)(this.predicateDataBytes),
|
9195
|
+
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9196
|
+
}));
|
9197
|
+
}
|
8963
9198
|
/**
|
8964
9199
|
* Sets the configurable constants for the predicate.
|
8965
9200
|
*
|
@@ -9709,7 +9944,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9709
9944
|
WalletLocked,
|
9710
9945
|
WalletManager,
|
9711
9946
|
WalletUnlocked,
|
9712
|
-
|
9947
|
+
addAmountToCoinQuantities,
|
9713
9948
|
addOperation,
|
9714
9949
|
assemblePanicError,
|
9715
9950
|
assembleReceiptByType,
|
@@ -9718,9 +9953,10 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9718
9953
|
assets,
|
9719
9954
|
buildBlockExplorerUrl,
|
9720
9955
|
cacheFor,
|
9956
|
+
cacheTxInputsFromOwner,
|
9957
|
+
calculateGasFee,
|
9721
9958
|
calculateMetadataGasForTxCreate,
|
9722
9959
|
calculateMetadataGasForTxScript,
|
9723
|
-
calculatePriceWithFactor,
|
9724
9960
|
calculateTransactionFee,
|
9725
9961
|
coinQuantityfy,
|
9726
9962
|
deferPromise,
|