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