@fuel-ts/account 0.0.0-rc-2021-20240411141803 → 0.0.0-rc-1976-20240411153008
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 +625 -876
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +619 -856
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +462 -698
- 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 +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 +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/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1128 -1593
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +618 -834
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +476 -692
- 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;
|
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
|
1919
|
-
|
1920
|
-
|
1836
|
+
witnesses,
|
1837
|
+
baseAssetId
|
1838
|
+
}) {
|
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;
|
1927
1847
|
}
|
1928
1848
|
static getPolicyMeta(req) {
|
1929
1849
|
let policyTypes = 0;
|
1930
1850
|
const policies = [];
|
1931
|
-
if (req.
|
1932
|
-
policyTypes += import_transactions6.PolicyType.
|
1933
|
-
policies.push({ data: req.
|
1851
|
+
if (req.gasPrice) {
|
1852
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1853
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1934
1854
|
}
|
1935
1855
|
if (req.witnessLimit) {
|
1936
1856
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -2016,7 +1936,7 @@ var BaseTransactionRequest = class {
|
|
2016
1936
|
* @returns The index of the created witness.
|
2017
1937
|
*/
|
2018
1938
|
addEmptyWitness() {
|
2019
|
-
this.addWitness((0, import_utils9.concat)([
|
1939
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
2020
1940
|
return this.witnesses.length - 1;
|
2021
1941
|
}
|
2022
1942
|
/**
|
@@ -2117,10 +2037,10 @@ var BaseTransactionRequest = class {
|
|
2117
2037
|
* @param predicate - Predicate bytes.
|
2118
2038
|
* @param predicateData - Predicate data bytes.
|
2119
2039
|
*/
|
2120
|
-
addCoinInput(coin) {
|
2040
|
+
addCoinInput(coin, predicate) {
|
2121
2041
|
const { assetId, owner, amount } = coin;
|
2122
2042
|
let witnessIndex;
|
2123
|
-
if (
|
2043
|
+
if (predicate) {
|
2124
2044
|
witnessIndex = 0;
|
2125
2045
|
} else {
|
2126
2046
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2135,7 +2055,8 @@ var BaseTransactionRequest = class {
|
|
2135
2055
|
amount,
|
2136
2056
|
assetId,
|
2137
2057
|
txPointer: "0x00000000000000000000000000000000",
|
2138
|
-
witnessIndex
|
2058
|
+
witnessIndex,
|
2059
|
+
predicate: predicate?.bytes
|
2139
2060
|
};
|
2140
2061
|
this.pushInput(input);
|
2141
2062
|
this.addChangeOutput(owner, assetId);
|
@@ -2146,13 +2067,11 @@ var BaseTransactionRequest = class {
|
|
2146
2067
|
*
|
2147
2068
|
* @param message - Message resource.
|
2148
2069
|
* @param predicate - Predicate bytes.
|
2149
|
-
* @param predicateData - Predicate data bytes.
|
2150
2070
|
*/
|
2151
|
-
addMessageInput(message) {
|
2071
|
+
addMessageInput(message, predicate) {
|
2152
2072
|
const { recipient, sender, amount } = message;
|
2153
|
-
const assetId = import_configs7.BaseAssetId;
|
2154
2073
|
let witnessIndex;
|
2155
|
-
if (
|
2074
|
+
if (predicate) {
|
2156
2075
|
witnessIndex = 0;
|
2157
2076
|
} else {
|
2158
2077
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2166,10 +2085,11 @@ var BaseTransactionRequest = class {
|
|
2166
2085
|
sender: sender.toB256(),
|
2167
2086
|
recipient: recipient.toB256(),
|
2168
2087
|
amount,
|
2169
|
-
witnessIndex
|
2088
|
+
witnessIndex,
|
2089
|
+
predicate: predicate?.bytes
|
2170
2090
|
};
|
2171
2091
|
this.pushInput(input);
|
2172
|
-
this.addChangeOutput(recipient,
|
2092
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
2173
2093
|
}
|
2174
2094
|
/**
|
2175
2095
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2197,6 +2117,32 @@ var BaseTransactionRequest = class {
|
|
2197
2117
|
resources.forEach((resource) => this.addResource(resource));
|
2198
2118
|
return this;
|
2199
2119
|
}
|
2120
|
+
/**
|
2121
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2122
|
+
* outputs from the related assetIds.
|
2123
|
+
*
|
2124
|
+
* @param resources - The resources to add.
|
2125
|
+
* @returns This transaction.
|
2126
|
+
*/
|
2127
|
+
addPredicateResource(resource, predicate) {
|
2128
|
+
if (isCoin(resource)) {
|
2129
|
+
this.addCoinInput(resource, predicate);
|
2130
|
+
} else {
|
2131
|
+
this.addMessageInput(resource, predicate);
|
2132
|
+
}
|
2133
|
+
return this;
|
2134
|
+
}
|
2135
|
+
/**
|
2136
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2137
|
+
* from the related assetIds.
|
2138
|
+
*
|
2139
|
+
* @param resources - The resources to add.
|
2140
|
+
* @returns This transaction.
|
2141
|
+
*/
|
2142
|
+
addPredicateResources(resources, predicate) {
|
2143
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2144
|
+
return this;
|
2145
|
+
}
|
2200
2146
|
/**
|
2201
2147
|
* Adds a coin output to the transaction.
|
2202
2148
|
*
|
@@ -2204,12 +2150,12 @@ var BaseTransactionRequest = class {
|
|
2204
2150
|
* @param amount - Amount of coin.
|
2205
2151
|
* @param assetId - Asset ID of coin.
|
2206
2152
|
*/
|
2207
|
-
addCoinOutput(to, amount, assetId
|
2153
|
+
addCoinOutput(to, amount, assetId) {
|
2208
2154
|
this.pushOutput({
|
2209
2155
|
type: import_transactions6.OutputType.Coin,
|
2210
2156
|
to: (0, import_address.addressify)(to).toB256(),
|
2211
2157
|
amount,
|
2212
|
-
assetId
|
2158
|
+
assetId: assetId ?? this.baseAssetId
|
2213
2159
|
});
|
2214
2160
|
return this;
|
2215
2161
|
}
|
@@ -2236,7 +2182,7 @@ var BaseTransactionRequest = class {
|
|
2236
2182
|
* @param to - Address of the owner.
|
2237
2183
|
* @param assetId - Asset ID of coin.
|
2238
2184
|
*/
|
2239
|
-
addChangeOutput(to, assetId
|
2185
|
+
addChangeOutput(to, assetId) {
|
2240
2186
|
const changeOutput = this.getChangeOutputs().find(
|
2241
2187
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2242
2188
|
);
|
@@ -2244,7 +2190,7 @@ var BaseTransactionRequest = class {
|
|
2244
2190
|
this.pushOutput({
|
2245
2191
|
type: import_transactions6.OutputType.Change,
|
2246
2192
|
to: (0, import_address.addressify)(to).toB256(),
|
2247
|
-
assetId
|
2193
|
+
assetId: assetId ?? this.baseAssetId
|
2248
2194
|
});
|
2249
2195
|
}
|
2250
2196
|
}
|
@@ -2276,7 +2222,7 @@ var BaseTransactionRequest = class {
|
|
2276
2222
|
}
|
2277
2223
|
calculateMaxGas(chainInfo, minGas) {
|
2278
2224
|
const { consensusParameters } = chainInfo;
|
2279
|
-
const { gasPerByte
|
2225
|
+
const { gasPerByte } = consensusParameters;
|
2280
2226
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2281
2227
|
(acc, wit) => acc + wit.dataLength,
|
2282
2228
|
0
|
@@ -2285,8 +2231,7 @@ var BaseTransactionRequest = class {
|
|
2285
2231
|
gasPerByte,
|
2286
2232
|
minGas,
|
2287
2233
|
witnessesLength,
|
2288
|
-
witnessLimit: this.witnessLimit
|
2289
|
-
maxGasPerTx
|
2234
|
+
witnessLimit: this.witnessLimit
|
2290
2235
|
});
|
2291
2236
|
}
|
2292
2237
|
/**
|
@@ -2296,6 +2241,12 @@ var BaseTransactionRequest = class {
|
|
2296
2241
|
* @param quantities - CoinQuantity Array.
|
2297
2242
|
*/
|
2298
2243
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2244
|
+
let idCounter = 0;
|
2245
|
+
const generateId = () => {
|
2246
|
+
const counterString = String(idCounter++);
|
2247
|
+
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2248
|
+
return id;
|
2249
|
+
};
|
2299
2250
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2300
2251
|
if ("assetId" in input) {
|
2301
2252
|
return input.assetId === assetId;
|
@@ -2304,27 +2255,24 @@ var BaseTransactionRequest = class {
|
|
2304
2255
|
});
|
2305
2256
|
const updateAssetInput = (assetId, quantity) => {
|
2306
2257
|
const assetInput = findAssetInput(assetId);
|
2307
|
-
let usedQuantity = quantity;
|
2308
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2309
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2310
|
-
}
|
2311
2258
|
if (assetInput && "assetId" in assetInput) {
|
2312
|
-
assetInput.id = (
|
2313
|
-
assetInput.amount =
|
2259
|
+
assetInput.id = generateId();
|
2260
|
+
assetInput.amount = quantity;
|
2314
2261
|
} else {
|
2315
2262
|
this.addResources([
|
2316
2263
|
{
|
2317
|
-
id: (
|
2318
|
-
amount:
|
2264
|
+
id: generateId(),
|
2265
|
+
amount: quantity,
|
2319
2266
|
assetId,
|
2320
2267
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2268
|
+
maturity: 0,
|
2321
2269
|
blockCreated: (0, import_math7.bn)(1),
|
2322
2270
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2323
2271
|
}
|
2324
2272
|
]);
|
2325
2273
|
}
|
2326
2274
|
};
|
2327
|
-
updateAssetInput(
|
2275
|
+
updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
|
2328
2276
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2329
2277
|
}
|
2330
2278
|
/**
|
@@ -2349,7 +2297,7 @@ var BaseTransactionRequest = class {
|
|
2349
2297
|
toJSON() {
|
2350
2298
|
return normalizeJSON(this);
|
2351
2299
|
}
|
2352
|
-
|
2300
|
+
updatePredicateInputs(inputs) {
|
2353
2301
|
this.inputs.forEach((i) => {
|
2354
2302
|
let correspondingInput;
|
2355
2303
|
switch (i.type) {
|
@@ -2371,25 +2319,16 @@ var BaseTransactionRequest = class {
|
|
2371
2319
|
}
|
2372
2320
|
});
|
2373
2321
|
}
|
2374
|
-
shiftPredicateData() {
|
2375
|
-
this.inputs.forEach((input) => {
|
2376
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2377
|
-
input.predicateData = input.paddPredicateData(
|
2378
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2379
|
-
);
|
2380
|
-
}
|
2381
|
-
});
|
2382
|
-
}
|
2383
2322
|
};
|
2384
2323
|
|
2385
2324
|
// src/providers/transaction-request/create-transaction-request.ts
|
2386
|
-
var
|
2325
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2387
2326
|
var import_math9 = require("@fuel-ts/math");
|
2388
2327
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2389
2328
|
var import_utils13 = require("@fuel-ts/utils");
|
2390
2329
|
|
2391
2330
|
// src/providers/transaction-request/hash-transaction.ts
|
2392
|
-
var
|
2331
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2393
2332
|
var import_hasher = require("@fuel-ts/hasher");
|
2394
2333
|
var import_math8 = require("@fuel-ts/math");
|
2395
2334
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2398,7 +2337,7 @@ var import_ramda2 = require("ramda");
|
|
2398
2337
|
function hashTransaction(transactionRequest, chainId) {
|
2399
2338
|
const transaction = transactionRequest.toTransaction();
|
2400
2339
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2401
|
-
transaction.receiptsRoot =
|
2340
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2402
2341
|
}
|
2403
2342
|
transaction.inputs = transaction.inputs.map((input) => {
|
2404
2343
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2420,10 +2359,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2420
2359
|
blockHeight: 0,
|
2421
2360
|
txIndex: 0
|
2422
2361
|
};
|
2423
|
-
inputClone.txID =
|
2362
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2424
2363
|
inputClone.outputIndex = 0;
|
2425
|
-
inputClone.balanceRoot =
|
2426
|
-
inputClone.stateRoot =
|
2364
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2365
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2427
2366
|
return inputClone;
|
2428
2367
|
}
|
2429
2368
|
default:
|
@@ -2434,8 +2373,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2434
2373
|
const outputClone = (0, import_ramda2.clone)(output);
|
2435
2374
|
switch (outputClone.type) {
|
2436
2375
|
case import_transactions7.OutputType.Contract: {
|
2437
|
-
outputClone.balanceRoot =
|
2438
|
-
outputClone.stateRoot =
|
2376
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2377
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2439
2378
|
return outputClone;
|
2440
2379
|
}
|
2441
2380
|
case import_transactions7.OutputType.Change: {
|
@@ -2443,9 +2382,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2443
2382
|
return outputClone;
|
2444
2383
|
}
|
2445
2384
|
case import_transactions7.OutputType.Variable: {
|
2446
|
-
outputClone.to =
|
2385
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2447
2386
|
outputClone.amount = (0, import_math8.bn)(0);
|
2448
|
-
outputClone.assetId =
|
2387
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2449
2388
|
return outputClone;
|
2450
2389
|
}
|
2451
2390
|
default:
|
@@ -2503,15 +2442,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2503
2442
|
*
|
2504
2443
|
* @param createTransactionRequestLike - The initial values for the instance
|
2505
2444
|
*/
|
2506
|
-
constructor({
|
2507
|
-
bytecodeWitnessIndex,
|
2508
|
-
salt,
|
2509
|
-
storageSlots,
|
2510
|
-
...rest
|
2511
|
-
} = {}) {
|
2445
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2512
2446
|
super(rest);
|
2513
2447
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2514
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2448
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2515
2449
|
this.storageSlots = [...storageSlots ?? []];
|
2516
2450
|
}
|
2517
2451
|
/**
|
@@ -2526,9 +2460,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2526
2460
|
return {
|
2527
2461
|
type: import_transactions8.TransactionType.Create,
|
2528
2462
|
...baseTransaction,
|
2463
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2529
2464
|
bytecodeWitnessIndex,
|
2530
|
-
storageSlotsCount:
|
2531
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2465
|
+
storageSlotsCount: storageSlots.length,
|
2466
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2532
2467
|
storageSlots
|
2533
2468
|
};
|
2534
2469
|
}
|
@@ -2578,7 +2513,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2578
2513
|
// src/providers/transaction-request/script-transaction-request.ts
|
2579
2514
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2580
2515
|
var import_address2 = require("@fuel-ts/address");
|
2581
|
-
var
|
2516
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2582
2517
|
var import_math10 = require("@fuel-ts/math");
|
2583
2518
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2584
2519
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2631,7 +2566,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2631
2566
|
*
|
2632
2567
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2633
2568
|
*/
|
2634
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2569
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2635
2570
|
super(rest);
|
2636
2571
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2637
2572
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2650,9 +2585,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2650
2585
|
type: import_transactions9.TransactionType.Script,
|
2651
2586
|
scriptGasLimit: this.gasLimit,
|
2652
2587
|
...super.getBaseTransaction(),
|
2653
|
-
scriptLength:
|
2654
|
-
scriptDataLength:
|
2655
|
-
receiptsRoot:
|
2588
|
+
scriptLength: script.length,
|
2589
|
+
scriptDataLength: scriptData.length,
|
2590
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2656
2591
|
script: (0, import_utils15.hexlify)(script),
|
2657
2592
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2658
2593
|
};
|
@@ -2715,7 +2650,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2715
2650
|
}
|
2716
2651
|
calculateMaxGas(chainInfo, minGas) {
|
2717
2652
|
const { consensusParameters } = chainInfo;
|
2718
|
-
const { gasPerByte
|
2653
|
+
const { gasPerByte } = consensusParameters;
|
2719
2654
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2720
2655
|
(acc, wit) => acc + wit.dataLength,
|
2721
2656
|
0
|
@@ -2725,8 +2660,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2725
2660
|
minGas,
|
2726
2661
|
witnessesLength,
|
2727
2662
|
witnessLimit: this.witnessLimit,
|
2728
|
-
gasLimit: this.gasLimit
|
2729
|
-
maxGasPerTx
|
2663
|
+
gasLimit: this.gasLimit
|
2730
2664
|
});
|
2731
2665
|
}
|
2732
2666
|
/**
|
@@ -2801,32 +2735,15 @@ var transactionRequestify = (obj) => {
|
|
2801
2735
|
}
|
2802
2736
|
}
|
2803
2737
|
};
|
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
2738
|
|
2820
2739
|
// src/providers/transaction-response/transaction-response.ts
|
2821
2740
|
var import_errors13 = require("@fuel-ts/errors");
|
2822
|
-
var
|
2823
|
-
var
|
2824
|
-
var
|
2741
|
+
var import_math14 = require("@fuel-ts/math");
|
2742
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2743
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2825
2744
|
|
2826
2745
|
// 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");
|
2746
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2830
2747
|
|
2831
2748
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2832
2749
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2834,10 +2751,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2834
2751
|
var import_utils16 = require("@fuel-ts/utils");
|
2835
2752
|
var calculateTransactionFee = (params) => {
|
2836
2753
|
const {
|
2837
|
-
|
2754
|
+
gasUsed,
|
2838
2755
|
rawPayload,
|
2839
|
-
|
2840
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2756
|
+
consensusParameters: { gasCosts, feeParams }
|
2841
2757
|
} = params;
|
2842
2758
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2843
2759
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2847,7 +2763,8 @@ var calculateTransactionFee = (params) => {
|
|
2847
2763
|
return {
|
2848
2764
|
fee: (0, import_math11.bn)(0),
|
2849
2765
|
minFee: (0, import_math11.bn)(0),
|
2850
|
-
maxFee: (0, import_math11.bn)(0)
|
2766
|
+
maxFee: (0, import_math11.bn)(0),
|
2767
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2851
2768
|
};
|
2852
2769
|
}
|
2853
2770
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2879,6 +2796,7 @@ var calculateTransactionFee = (params) => {
|
|
2879
2796
|
metadataGas,
|
2880
2797
|
txBytesSize: transactionBytes.length
|
2881
2798
|
});
|
2799
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2882
2800
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2883
2801
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2884
2802
|
const maxGas = getMaxGas({
|
@@ -2886,30 +2804,22 @@ var calculateTransactionFee = (params) => {
|
|
2886
2804
|
minGas,
|
2887
2805
|
witnessesLength,
|
2888
2806
|
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
|
2807
|
+
witnessLimit
|
2903
2808
|
});
|
2809
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2810
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2811
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2812
|
+
const fee = minFee.add(feeFromGasUsed);
|
2904
2813
|
return {
|
2814
|
+
fee,
|
2905
2815
|
minFee,
|
2906
2816
|
maxFee,
|
2907
|
-
|
2817
|
+
feeFromGasUsed
|
2908
2818
|
};
|
2909
2819
|
};
|
2910
2820
|
|
2911
2821
|
// src/providers/transaction-summary/operations.ts
|
2912
|
-
var
|
2822
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2913
2823
|
var import_errors11 = require("@fuel-ts/errors");
|
2914
2824
|
var import_math13 = require("@fuel-ts/math");
|
2915
2825
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3254,7 +3164,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3254
3164
|
const { to: toAddress, assetId, amount } = receipt;
|
3255
3165
|
let { from: fromAddress } = receipt;
|
3256
3166
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3257
|
-
if (
|
3167
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3258
3168
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3259
3169
|
fromAddress = change?.to || fromAddress;
|
3260
3170
|
}
|
@@ -3518,12 +3428,10 @@ function assembleTransactionSummary(params) {
|
|
3518
3428
|
gqlTransactionStatus,
|
3519
3429
|
abiMap = {},
|
3520
3430
|
maxInputs,
|
3521
|
-
gasCosts
|
3522
|
-
maxGasPerTx,
|
3523
|
-
gasPrice
|
3431
|
+
gasCosts
|
3524
3432
|
} = params;
|
3525
3433
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3526
|
-
const rawPayload = (0,
|
3434
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3527
3435
|
const operations = getOperations({
|
3528
3436
|
transactionType: transaction.type,
|
3529
3437
|
inputs: transaction.inputs || [],
|
@@ -3534,14 +3442,11 @@ function assembleTransactionSummary(params) {
|
|
3534
3442
|
maxInputs
|
3535
3443
|
});
|
3536
3444
|
const typeName = getTransactionTypeName(transaction.type);
|
3537
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3538
3445
|
const { fee } = calculateTransactionFee({
|
3539
|
-
|
3446
|
+
gasUsed,
|
3540
3447
|
rawPayload,
|
3541
|
-
tip,
|
3542
3448
|
consensusParameters: {
|
3543
3449
|
gasCosts,
|
3544
|
-
maxGasPerTx,
|
3545
3450
|
feeParams: {
|
3546
3451
|
gasPerByte,
|
3547
3452
|
gasPriceFactor
|
@@ -3553,7 +3458,7 @@ function assembleTransactionSummary(params) {
|
|
3553
3458
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3554
3459
|
let date;
|
3555
3460
|
if (time) {
|
3556
|
-
date =
|
3461
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3557
3462
|
}
|
3558
3463
|
const transactionSummary = {
|
3559
3464
|
id,
|
@@ -3581,12 +3486,12 @@ function assembleTransactionSummary(params) {
|
|
3581
3486
|
|
3582
3487
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3583
3488
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3584
|
-
var
|
3489
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3585
3490
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3586
3491
|
return receipts.reduce((logs, receipt) => {
|
3587
|
-
if (receipt.type ===
|
3492
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3588
3493
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3589
|
-
const data = receipt.type ===
|
3494
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3590
3495
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3591
3496
|
logs.push(decodedLog);
|
3592
3497
|
}
|
@@ -3601,7 +3506,7 @@ var TransactionResponse = class {
|
|
3601
3506
|
/** Current provider */
|
3602
3507
|
provider;
|
3603
3508
|
/** Gas used on the transaction */
|
3604
|
-
gasUsed = (0,
|
3509
|
+
gasUsed = (0, import_math14.bn)(0);
|
3605
3510
|
/** The graphql Transaction with receipts object. */
|
3606
3511
|
gqlTransaction;
|
3607
3512
|
abis;
|
@@ -3659,8 +3564,8 @@ var TransactionResponse = class {
|
|
3659
3564
|
* @returns The decoded transaction.
|
3660
3565
|
*/
|
3661
3566
|
decodeTransaction(transactionWithReceipts) {
|
3662
|
-
return new
|
3663
|
-
(0,
|
3567
|
+
return new import_transactions17.TransactionCoder().decode(
|
3568
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3664
3569
|
0
|
3665
3570
|
)?.[0];
|
3666
3571
|
}
|
@@ -3679,27 +3584,20 @@ var TransactionResponse = class {
|
|
3679
3584
|
const decodedTransaction = this.decodeTransaction(
|
3680
3585
|
transaction
|
3681
3586
|
);
|
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();
|
3587
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3588
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3689
3589
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3690
3590
|
const transactionSummary = assembleTransactionSummary({
|
3691
3591
|
id: this.id,
|
3692
3592
|
receipts,
|
3693
3593
|
transaction: decodedTransaction,
|
3694
|
-
transactionBytes: (0,
|
3594
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3695
3595
|
gqlTransactionStatus: transaction.status,
|
3696
3596
|
gasPerByte,
|
3697
3597
|
gasPriceFactor,
|
3698
3598
|
abiMap: contractsAbiMap,
|
3699
3599
|
maxInputs,
|
3700
|
-
gasCosts
|
3701
|
-
maxGasPerTx,
|
3702
|
-
gasPrice
|
3600
|
+
gasCosts
|
3703
3601
|
});
|
3704
3602
|
return transactionSummary;
|
3705
3603
|
}
|
@@ -3826,29 +3724,30 @@ var processGqlChain = (chain) => {
|
|
3826
3724
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3827
3725
|
return {
|
3828
3726
|
name,
|
3829
|
-
baseChainHeight: (0,
|
3727
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3830
3728
|
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,
|
3729
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3730
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3731
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3732
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3733
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3734
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3735
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3736
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3737
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3738
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3739
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3740
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3741
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3742
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3743
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3744
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3846
3745
|
gasCosts
|
3847
3746
|
},
|
3848
3747
|
gasCosts,
|
3849
3748
|
latestBlock: {
|
3850
3749
|
id: latestBlock.id,
|
3851
|
-
height: (0,
|
3750
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3852
3751
|
time: latestBlock.header.time,
|
3853
3752
|
transactions: latestBlock.transactions.map((i) => ({
|
3854
3753
|
id: i.id
|
@@ -3942,8 +3841,10 @@ var _Provider = class {
|
|
3942
3841
|
* Returns some helpful parameters related to gas fees.
|
3943
3842
|
*/
|
3944
3843
|
getGasConfig() {
|
3844
|
+
const { minGasPrice } = this.getNode();
|
3945
3845
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3946
3846
|
return {
|
3847
|
+
minGasPrice,
|
3947
3848
|
maxGasPerTx,
|
3948
3849
|
maxGasPerPredicate,
|
3949
3850
|
gasPriceFactor,
|
@@ -4031,7 +3932,7 @@ var _Provider = class {
|
|
4031
3932
|
name,
|
4032
3933
|
consensusParameters: { chainId }
|
4033
3934
|
} = await this.getChain();
|
4034
|
-
const network = new
|
3935
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
4035
3936
|
return Promise.resolve(network);
|
4036
3937
|
}
|
4037
3938
|
/**
|
@@ -4041,7 +3942,7 @@ var _Provider = class {
|
|
4041
3942
|
*/
|
4042
3943
|
async getBlockNumber() {
|
4043
3944
|
const { chain } = await this.operations.getChain();
|
4044
|
-
return (0,
|
3945
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
4045
3946
|
}
|
4046
3947
|
/**
|
4047
3948
|
* Returns the chain information.
|
@@ -4051,11 +3952,13 @@ var _Provider = class {
|
|
4051
3952
|
async fetchNode() {
|
4052
3953
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
4053
3954
|
const processedNodeInfo = {
|
4054
|
-
maxDepth: (0,
|
4055
|
-
maxTx: (0,
|
3955
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3956
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3957
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4056
3958
|
nodeVersion: nodeInfo.nodeVersion,
|
4057
3959
|
utxoValidation: nodeInfo.utxoValidation,
|
4058
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3960
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3961
|
+
peers: nodeInfo.peers
|
4059
3962
|
};
|
4060
3963
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
4061
3964
|
return processedNodeInfo;
|
@@ -4081,6 +3984,17 @@ var _Provider = class {
|
|
4081
3984
|
} = this.getChain();
|
4082
3985
|
return chainId.toNumber();
|
4083
3986
|
}
|
3987
|
+
/**
|
3988
|
+
* Returns the base asset ID
|
3989
|
+
*
|
3990
|
+
* @returns A promise that resolves to the base asset ID
|
3991
|
+
*/
|
3992
|
+
getBaseAssetId() {
|
3993
|
+
const {
|
3994
|
+
consensusParameters: { baseAssetId }
|
3995
|
+
} = this.getChain();
|
3996
|
+
return baseAssetId;
|
3997
|
+
}
|
4084
3998
|
/**
|
4085
3999
|
* Submits a transaction to the chain to be executed.
|
4086
4000
|
*
|
@@ -4097,9 +4011,9 @@ var _Provider = class {
|
|
4097
4011
|
if (estimateTxDependencies) {
|
4098
4012
|
await this.estimateTxDependencies(transactionRequest);
|
4099
4013
|
}
|
4100
|
-
const encodedTransaction = (0,
|
4014
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4101
4015
|
let abis;
|
4102
|
-
if (transactionRequest.type ===
|
4016
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4103
4017
|
abis = transactionRequest.abis;
|
4104
4018
|
}
|
4105
4019
|
if (awaitExecution) {
|
@@ -4140,14 +4054,15 @@ var _Provider = class {
|
|
4140
4054
|
if (estimateTxDependencies) {
|
4141
4055
|
return this.estimateTxDependencies(transactionRequest);
|
4142
4056
|
}
|
4143
|
-
const encodedTransaction = (0,
|
4144
|
-
const { dryRun:
|
4145
|
-
|
4057
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4058
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4059
|
+
encodedTransaction,
|
4146
4060
|
utxoValidation: utxoValidation || false
|
4147
4061
|
});
|
4148
|
-
const
|
4149
|
-
|
4150
|
-
|
4062
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4063
|
+
return {
|
4064
|
+
receipts
|
4065
|
+
};
|
4151
4066
|
}
|
4152
4067
|
/**
|
4153
4068
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4158,13 +4073,13 @@ var _Provider = class {
|
|
4158
4073
|
async estimatePredicates(transactionRequest) {
|
4159
4074
|
const shouldEstimatePredicates = Boolean(
|
4160
4075
|
transactionRequest.inputs.find(
|
4161
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4076
|
+
(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
4077
|
)
|
4163
4078
|
);
|
4164
4079
|
if (!shouldEstimatePredicates) {
|
4165
4080
|
return transactionRequest;
|
4166
4081
|
}
|
4167
|
-
const encodedTransaction = (0,
|
4082
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4168
4083
|
const response = await this.operations.estimatePredicates({
|
4169
4084
|
encodedTransaction
|
4170
4085
|
});
|
@@ -4173,7 +4088,7 @@ var _Provider = class {
|
|
4173
4088
|
} = response;
|
4174
4089
|
if (inputs) {
|
4175
4090
|
inputs.forEach((input, index) => {
|
4176
|
-
if ("predicateGasUsed" in input && (0,
|
4091
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
4177
4092
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4178
4093
|
}
|
4179
4094
|
});
|
@@ -4186,31 +4101,31 @@ var _Provider = class {
|
|
4186
4101
|
* If there are missing variable outputs,
|
4187
4102
|
* `addVariableOutputs` is called on the transaction.
|
4188
4103
|
*
|
4104
|
+
* @privateRemarks
|
4105
|
+
* TODO: Investigate support for missing contract IDs
|
4106
|
+
* TODO: Add support for missing output messages
|
4189
4107
|
*
|
4190
4108
|
* @param transactionRequest - The transaction request object.
|
4191
4109
|
* @returns A promise.
|
4192
4110
|
*/
|
4193
4111
|
async estimateTxDependencies(transactionRequest) {
|
4194
|
-
if (transactionRequest.type ===
|
4112
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
4195
4113
|
return {
|
4196
4114
|
receipts: [],
|
4197
4115
|
outputVariables: 0,
|
4198
4116
|
missingContractIds: []
|
4199
4117
|
};
|
4200
4118
|
}
|
4119
|
+
await this.estimatePredicates(transactionRequest);
|
4201
4120
|
let receipts = [];
|
4202
4121
|
const missingContractIds = [];
|
4203
4122
|
let outputVariables = 0;
|
4204
|
-
let dryrunStatus;
|
4205
4123
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4206
|
-
const {
|
4207
|
-
|
4208
|
-
} = await this.operations.dryRun({
|
4209
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4124
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4125
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
4210
4126
|
utxoValidation: false
|
4211
4127
|
});
|
4212
|
-
receipts =
|
4213
|
-
dryrunStatus = status;
|
4128
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4214
4129
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4215
4130
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4216
4131
|
if (hasMissingOutputs) {
|
@@ -4220,11 +4135,6 @@ var _Provider = class {
|
|
4220
4135
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4221
4136
|
missingContractIds.push(contractId);
|
4222
4137
|
});
|
4223
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4224
|
-
transactionRequest,
|
4225
|
-
optimizeGas: false
|
4226
|
-
});
|
4227
|
-
transactionRequest.maxFee = maxFee;
|
4228
4138
|
} else {
|
4229
4139
|
break;
|
4230
4140
|
}
|
@@ -4232,133 +4142,7 @@ var _Provider = class {
|
|
4232
4142
|
return {
|
4233
4143
|
receipts,
|
4234
4144
|
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
|
4145
|
+
missingContractIds
|
4362
4146
|
};
|
4363
4147
|
}
|
4364
4148
|
/**
|
@@ -4376,17 +4160,15 @@ var _Provider = class {
|
|
4376
4160
|
if (estimateTxDependencies) {
|
4377
4161
|
return this.estimateTxDependencies(transactionRequest);
|
4378
4162
|
}
|
4379
|
-
const
|
4380
|
-
const { dryRun:
|
4381
|
-
|
4163
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4164
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4165
|
+
encodedTransaction,
|
4382
4166
|
utxoValidation: true
|
4383
4167
|
});
|
4384
|
-
const
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
});
|
4389
|
-
return { receipts: callResult[0].receipts };
|
4168
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4169
|
+
return {
|
4170
|
+
receipts
|
4171
|
+
};
|
4390
4172
|
}
|
4391
4173
|
/**
|
4392
4174
|
* Returns a transaction cost to enable user
|
@@ -4403,80 +4185,80 @@ var _Provider = class {
|
|
4403
4185
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4404
4186
|
* @returns A promise that resolves to the transaction cost object.
|
4405
4187
|
*/
|
4406
|
-
async getTransactionCost(transactionRequestLike,
|
4188
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4189
|
+
estimateTxDependencies = true,
|
4190
|
+
estimatePredicates = true,
|
4191
|
+
resourcesOwner,
|
4192
|
+
signatureCallback
|
4193
|
+
} = {}) {
|
4407
4194
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4408
|
-
const
|
4195
|
+
const chainInfo = this.getChain();
|
4196
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4197
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4198
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4409
4199
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4410
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4200
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4411
4201
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4202
|
+
if (estimatePredicates) {
|
4203
|
+
if (isScriptTransaction) {
|
4204
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4205
|
+
}
|
4206
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4207
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4208
|
+
}
|
4209
|
+
await this.estimatePredicates(txRequestClone);
|
4418
4210
|
}
|
4419
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4420
|
-
let addedSignatures = 0;
|
4421
4211
|
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;
|
4212
|
+
await signatureCallback(txRequestClone);
|
4213
|
+
}
|
4214
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4215
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4432
4216
|
let receipts = [];
|
4433
4217
|
let missingContractIds = [];
|
4434
4218
|
let outputVariables = 0;
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
if (signatureCallback) {
|
4439
|
-
await signatureCallback(txRequestClone);
|
4440
|
-
}
|
4441
|
-
txRequestClone.gasLimit = gasLimit;
|
4219
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4220
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4221
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4442
4222
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4443
4223
|
receipts = result.receipts;
|
4444
4224
|
outputVariables = result.outputVariables;
|
4445
4225
|
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
4226
|
}
|
4227
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4228
|
+
const usedFee = calculatePriceWithFactor(
|
4229
|
+
gasUsed,
|
4230
|
+
gasPrice,
|
4231
|
+
gasPriceFactor
|
4232
|
+
).normalizeZeroToOne();
|
4233
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4234
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4453
4235
|
return {
|
4454
4236
|
requiredQuantities: allQuantities,
|
4455
4237
|
receipts,
|
4456
4238
|
gasUsed,
|
4239
|
+
minGasPrice,
|
4457
4240
|
gasPrice,
|
4458
4241
|
minGas,
|
4459
4242
|
maxGas,
|
4243
|
+
usedFee,
|
4460
4244
|
minFee,
|
4461
4245
|
maxFee,
|
4246
|
+
estimatedInputs: txRequestClone.inputs,
|
4462
4247
|
outputVariables,
|
4463
|
-
missingContractIds
|
4464
|
-
addedSignatures,
|
4465
|
-
estimatedPredicates: txRequestClone.inputs
|
4248
|
+
missingContractIds
|
4466
4249
|
};
|
4467
4250
|
}
|
4468
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4251
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4469
4252
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4470
4253
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4471
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4472
|
-
quantitiesToContract
|
4473
|
-
});
|
4254
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4474
4255
|
transactionRequest.addResources(
|
4475
4256
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4476
4257
|
);
|
4477
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4478
|
-
|
4479
|
-
|
4258
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4259
|
+
transactionRequest,
|
4260
|
+
forwardingQuantities
|
4261
|
+
);
|
4480
4262
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4481
4263
|
return {
|
4482
4264
|
resources,
|
@@ -4492,16 +4274,17 @@ var _Provider = class {
|
|
4492
4274
|
const result = await this.operations.getCoins({
|
4493
4275
|
first: 10,
|
4494
4276
|
...paginationArgs,
|
4495
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4277
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4496
4278
|
});
|
4497
4279
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4498
4280
|
return coins.map((coin) => ({
|
4499
4281
|
id: coin.utxoId,
|
4500
4282
|
assetId: coin.assetId,
|
4501
|
-
amount: (0,
|
4283
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4502
4284
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4503
|
-
|
4504
|
-
|
4285
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4286
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4287
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4505
4288
|
}));
|
4506
4289
|
}
|
4507
4290
|
/**
|
@@ -4515,19 +4298,19 @@ var _Provider = class {
|
|
4515
4298
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4516
4299
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4517
4300
|
const excludeInput = {
|
4518
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4519
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4301
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4302
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4520
4303
|
};
|
4521
4304
|
if (this.cache) {
|
4522
4305
|
const uniqueUtxos = new Set(
|
4523
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4306
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4524
4307
|
);
|
4525
4308
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4526
4309
|
}
|
4527
4310
|
const coinsQuery = {
|
4528
4311
|
owner: ownerAddress.toB256(),
|
4529
4312
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4530
|
-
assetId: (0,
|
4313
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4531
4314
|
amount: amount.toString(10),
|
4532
4315
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4533
4316
|
})),
|
@@ -4538,9 +4321,9 @@ var _Provider = class {
|
|
4538
4321
|
switch (coin.__typename) {
|
4539
4322
|
case "MessageCoin":
|
4540
4323
|
return {
|
4541
|
-
amount: (0,
|
4324
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4542
4325
|
assetId: coin.assetId,
|
4543
|
-
daHeight: (0,
|
4326
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4544
4327
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4545
4328
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4546
4329
|
nonce: coin.nonce
|
@@ -4548,11 +4331,12 @@ var _Provider = class {
|
|
4548
4331
|
case "Coin":
|
4549
4332
|
return {
|
4550
4333
|
id: coin.utxoId,
|
4551
|
-
amount: (0,
|
4334
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4552
4335
|
assetId: coin.assetId,
|
4553
4336
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4554
|
-
|
4555
|
-
|
4337
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4338
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4339
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4556
4340
|
};
|
4557
4341
|
default:
|
4558
4342
|
return null;
|
@@ -4569,13 +4353,13 @@ var _Provider = class {
|
|
4569
4353
|
async getBlock(idOrHeight) {
|
4570
4354
|
let variables;
|
4571
4355
|
if (typeof idOrHeight === "number") {
|
4572
|
-
variables = { height: (0,
|
4356
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4573
4357
|
} else if (idOrHeight === "latest") {
|
4574
4358
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4575
4359
|
} else if (idOrHeight.length === 66) {
|
4576
4360
|
variables = { blockId: idOrHeight };
|
4577
4361
|
} else {
|
4578
|
-
variables = { blockId: (0,
|
4362
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4579
4363
|
}
|
4580
4364
|
const { block } = await this.operations.getBlock(variables);
|
4581
4365
|
if (!block) {
|
@@ -4583,7 +4367,7 @@ var _Provider = class {
|
|
4583
4367
|
}
|
4584
4368
|
return {
|
4585
4369
|
id: block.id,
|
4586
|
-
height: (0,
|
4370
|
+
height: (0, import_math15.bn)(block.header.height),
|
4587
4371
|
time: block.header.time,
|
4588
4372
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4589
4373
|
};
|
@@ -4598,7 +4382,7 @@ var _Provider = class {
|
|
4598
4382
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4599
4383
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4600
4384
|
id: block.id,
|
4601
|
-
height: (0,
|
4385
|
+
height: (0, import_math15.bn)(block.header.height),
|
4602
4386
|
time: block.header.time,
|
4603
4387
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4604
4388
|
}));
|
@@ -4613,7 +4397,7 @@ var _Provider = class {
|
|
4613
4397
|
async getBlockWithTransactions(idOrHeight) {
|
4614
4398
|
let variables;
|
4615
4399
|
if (typeof idOrHeight === "number") {
|
4616
|
-
variables = { blockHeight: (0,
|
4400
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4617
4401
|
} else if (idOrHeight === "latest") {
|
4618
4402
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4619
4403
|
} else {
|
@@ -4625,11 +4409,11 @@ var _Provider = class {
|
|
4625
4409
|
}
|
4626
4410
|
return {
|
4627
4411
|
id: block.id,
|
4628
|
-
height: (0,
|
4412
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4629
4413
|
time: block.header.time,
|
4630
4414
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4631
4415
|
transactions: block.transactions.map(
|
4632
|
-
(tx) => new
|
4416
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4633
4417
|
)
|
4634
4418
|
};
|
4635
4419
|
}
|
@@ -4644,8 +4428,8 @@ var _Provider = class {
|
|
4644
4428
|
if (!transaction) {
|
4645
4429
|
return null;
|
4646
4430
|
}
|
4647
|
-
return new
|
4648
|
-
(0,
|
4431
|
+
return new import_transactions18.TransactionCoder().decode(
|
4432
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4649
4433
|
0
|
4650
4434
|
)?.[0];
|
4651
4435
|
}
|
@@ -4672,9 +4456,9 @@ var _Provider = class {
|
|
4672
4456
|
async getContractBalance(contractId, assetId) {
|
4673
4457
|
const { contractBalance } = await this.operations.getContractBalance({
|
4674
4458
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4675
|
-
asset: (0,
|
4459
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4676
4460
|
});
|
4677
|
-
return (0,
|
4461
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4678
4462
|
}
|
4679
4463
|
/**
|
4680
4464
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4686,9 +4470,9 @@ var _Provider = class {
|
|
4686
4470
|
async getBalance(owner, assetId) {
|
4687
4471
|
const { balance } = await this.operations.getBalance({
|
4688
4472
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4689
|
-
assetId: (0,
|
4473
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4690
4474
|
});
|
4691
|
-
return (0,
|
4475
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4692
4476
|
}
|
4693
4477
|
/**
|
4694
4478
|
* Returns balances for the given owner.
|
@@ -4706,7 +4490,7 @@ var _Provider = class {
|
|
4706
4490
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4707
4491
|
return balances.map((balance) => ({
|
4708
4492
|
assetId: balance.assetId,
|
4709
|
-
amount: (0,
|
4493
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4710
4494
|
}));
|
4711
4495
|
}
|
4712
4496
|
/**
|
@@ -4724,19 +4508,19 @@ var _Provider = class {
|
|
4724
4508
|
});
|
4725
4509
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4726
4510
|
return messages.map((message) => ({
|
4727
|
-
messageId:
|
4511
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4728
4512
|
sender: message.sender,
|
4729
4513
|
recipient: message.recipient,
|
4730
4514
|
nonce: message.nonce,
|
4731
|
-
amount: (0,
|
4515
|
+
amount: (0, import_math15.bn)(message.amount),
|
4732
4516
|
data: message.data
|
4733
4517
|
}),
|
4734
4518
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4735
4519
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4736
4520
|
nonce: message.nonce,
|
4737
|
-
amount: (0,
|
4738
|
-
data:
|
4739
|
-
daHeight: (0,
|
4521
|
+
amount: (0, import_math15.bn)(message.amount),
|
4522
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4523
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4740
4524
|
}));
|
4741
4525
|
}
|
4742
4526
|
/**
|
@@ -4789,52 +4573,44 @@ var _Provider = class {
|
|
4789
4573
|
} = result.messageProof;
|
4790
4574
|
return {
|
4791
4575
|
messageProof: {
|
4792
|
-
proofIndex: (0,
|
4576
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4793
4577
|
proofSet: messageProof.proofSet
|
4794
4578
|
},
|
4795
4579
|
blockProof: {
|
4796
|
-
proofIndex: (0,
|
4580
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4797
4581
|
proofSet: blockProof.proofSet
|
4798
4582
|
},
|
4799
4583
|
messageBlockHeader: {
|
4800
4584
|
id: messageBlockHeader.id,
|
4801
|
-
daHeight: (0,
|
4802
|
-
transactionsCount: (0,
|
4585
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4586
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4803
4587
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4804
|
-
height: (0,
|
4588
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4805
4589
|
prevRoot: messageBlockHeader.prevRoot,
|
4806
4590
|
time: messageBlockHeader.time,
|
4807
4591
|
applicationHash: messageBlockHeader.applicationHash,
|
4808
|
-
|
4592
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4593
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4809
4594
|
},
|
4810
4595
|
commitBlockHeader: {
|
4811
4596
|
id: commitBlockHeader.id,
|
4812
|
-
daHeight: (0,
|
4813
|
-
transactionsCount: (0,
|
4597
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4598
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4814
4599
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4815
|
-
height: (0,
|
4600
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4816
4601
|
prevRoot: commitBlockHeader.prevRoot,
|
4817
4602
|
time: commitBlockHeader.time,
|
4818
4603
|
applicationHash: commitBlockHeader.applicationHash,
|
4819
|
-
|
4604
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4605
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4820
4606
|
},
|
4821
4607
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4822
4608
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4823
4609
|
nonce,
|
4824
|
-
amount: (0,
|
4610
|
+
amount: (0, import_math15.bn)(amount),
|
4825
4611
|
data
|
4826
4612
|
};
|
4827
4613
|
}
|
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
4614
|
/**
|
4839
4615
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4840
4616
|
*
|
@@ -4854,10 +4630,10 @@ var _Provider = class {
|
|
4854
4630
|
*/
|
4855
4631
|
async produceBlocks(amount, startTime) {
|
4856
4632
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4857
|
-
blocksToProduce: (0,
|
4858
|
-
startTimestamp: startTime ?
|
4633
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4634
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4859
4635
|
});
|
4860
|
-
return (0,
|
4636
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4861
4637
|
}
|
4862
4638
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4863
4639
|
async getTransactionResponse(transactionId) {
|
@@ -4871,7 +4647,7 @@ cacheInputs_fn = function(inputs) {
|
|
4871
4647
|
return;
|
4872
4648
|
}
|
4873
4649
|
inputs.forEach((input) => {
|
4874
|
-
if (input.type ===
|
4650
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4875
4651
|
this.cache?.set(input.id);
|
4876
4652
|
}
|
4877
4653
|
});
|
@@ -4881,9 +4657,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4881
4657
|
|
4882
4658
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4883
4659
|
var import_errors15 = require("@fuel-ts/errors");
|
4884
|
-
var
|
4885
|
-
var
|
4886
|
-
var
|
4660
|
+
var import_math16 = require("@fuel-ts/math");
|
4661
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4662
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4887
4663
|
async function getTransactionSummary(params) {
|
4888
4664
|
const { id, provider, abiMap } = params;
|
4889
4665
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4895,32 +4671,25 @@ async function getTransactionSummary(params) {
|
|
4895
4671
|
`Transaction not found for given id: ${id}.`
|
4896
4672
|
);
|
4897
4673
|
}
|
4898
|
-
const [decodedTransaction] = new
|
4899
|
-
(0,
|
4674
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
|
4675
|
+
(0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4900
4676
|
0
|
4901
4677
|
);
|
4902
|
-
|
4903
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4904
|
-
txReceipts = gqlTransaction.status.receipts;
|
4905
|
-
}
|
4906
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4678
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4907
4679
|
const {
|
4908
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4680
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4909
4681
|
} = provider.getChain();
|
4910
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4911
4682
|
const transactionInfo = assembleTransactionSummary({
|
4912
4683
|
id: gqlTransaction.id,
|
4913
4684
|
receipts,
|
4914
4685
|
transaction: decodedTransaction,
|
4915
|
-
transactionBytes: (0,
|
4686
|
+
transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4916
4687
|
gqlTransactionStatus: gqlTransaction.status,
|
4917
|
-
gasPerByte: (0,
|
4918
|
-
gasPriceFactor: (0,
|
4688
|
+
gasPerByte: (0, import_math16.bn)(gasPerByte),
|
4689
|
+
gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
|
4919
4690
|
abiMap,
|
4920
4691
|
maxInputs,
|
4921
|
-
gasCosts
|
4922
|
-
maxGasPerTx,
|
4923
|
-
gasPrice
|
4692
|
+
gasCosts
|
4924
4693
|
});
|
4925
4694
|
return {
|
4926
4695
|
gqlTransaction,
|
@@ -4930,11 +4699,10 @@ async function getTransactionSummary(params) {
|
|
4930
4699
|
async function getTransactionSummaryFromRequest(params) {
|
4931
4700
|
const { provider, transactionRequest, abiMap } = params;
|
4932
4701
|
const { receipts } = await provider.call(transactionRequest);
|
4933
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4702
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4934
4703
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4935
4704
|
const transaction = transactionRequest.toTransaction();
|
4936
4705
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4937
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4938
4706
|
const transactionSummary = assembleTransactionSummary({
|
4939
4707
|
receipts,
|
4940
4708
|
transaction,
|
@@ -4943,9 +4711,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4943
4711
|
gasPerByte,
|
4944
4712
|
gasPriceFactor,
|
4945
4713
|
maxInputs,
|
4946
|
-
gasCosts
|
4947
|
-
maxGasPerTx,
|
4948
|
-
gasPrice
|
4714
|
+
gasCosts
|
4949
4715
|
});
|
4950
4716
|
return transactionSummary;
|
4951
4717
|
}
|
@@ -4954,31 +4720,24 @@ async function getTransactionsSummaries(params) {
|
|
4954
4720
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4955
4721
|
const { edges, pageInfo } = transactionsByOwner;
|
4956
4722
|
const {
|
4957
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4723
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4958
4724
|
} = provider.getChain();
|
4959
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4960
4725
|
const transactions = edges.map((edge) => {
|
4961
4726
|
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);
|
4727
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4728
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
|
4729
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4969
4730
|
const transactionSummary = assembleTransactionSummary({
|
4970
4731
|
id,
|
4971
4732
|
receipts,
|
4972
4733
|
transaction: decodedTransaction,
|
4973
|
-
transactionBytes: (0,
|
4734
|
+
transactionBytes: (0, import_utils26.arrayify)(rawPayload),
|
4974
4735
|
gqlTransactionStatus: status,
|
4975
4736
|
abiMap,
|
4976
4737
|
gasPerByte,
|
4977
4738
|
gasPriceFactor,
|
4978
4739
|
maxInputs,
|
4979
|
-
gasCosts
|
4980
|
-
maxGasPerTx,
|
4981
|
-
gasPrice
|
4740
|
+
gasCosts
|
4982
4741
|
});
|
4983
4742
|
const output = {
|
4984
4743
|
gqlTransaction,
|
@@ -5115,17 +4874,17 @@ var assets = [
|
|
5115
4874
|
|
5116
4875
|
// src/utils/formatTransferToContractScriptData.ts
|
5117
4876
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5118
|
-
var
|
5119
|
-
var
|
4877
|
+
var import_math17 = require("@fuel-ts/math");
|
4878
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5120
4879
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5121
4880
|
var formatTransferToContractScriptData = (params) => {
|
5122
4881
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5123
4882
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
5124
|
-
const encoded = numberCoder.encode(new
|
4883
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
5125
4884
|
const scriptData = Uint8Array.from([
|
5126
|
-
...(0,
|
4885
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
5127
4886
|
...encoded,
|
5128
|
-
...(0,
|
4887
|
+
...(0, import_utils27.arrayify)(assetId)
|
5129
4888
|
]);
|
5130
4889
|
return scriptData;
|
5131
4890
|
};
|
@@ -5272,8 +5031,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5272
5031
|
* @param assetId - The asset ID to check the balance for.
|
5273
5032
|
* @returns A promise that resolves to the balance amount.
|
5274
5033
|
*/
|
5275
|
-
async getBalance(assetId
|
5276
|
-
const
|
5034
|
+
async getBalance(assetId) {
|
5035
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
5036
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5277
5037
|
return amount;
|
5278
5038
|
}
|
5279
5039
|
/**
|
@@ -5310,33 +5070,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5310
5070
|
* @param fee - The estimated transaction fee.
|
5311
5071
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5312
5072
|
*/
|
5313
|
-
async fund(request,
|
5314
|
-
const
|
5315
|
-
const
|
5316
|
-
|
5317
|
-
|
5318
|
-
|
5319
|
-
coinQuantities: requiredQuantities
|
5073
|
+
async fund(request, coinQuantities, fee) {
|
5074
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5075
|
+
const updatedQuantities = addAmountToAsset({
|
5076
|
+
amount: (0, import_math18.bn)(fee),
|
5077
|
+
assetId: baseAssetId,
|
5078
|
+
coinQuantities
|
5320
5079
|
});
|
5321
5080
|
const quantitiesDict = {};
|
5322
|
-
|
5081
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5323
5082
|
quantitiesDict[assetId] = {
|
5324
5083
|
required: amount,
|
5325
|
-
owned: (0,
|
5084
|
+
owned: (0, import_math18.bn)(0)
|
5326
5085
|
};
|
5327
5086
|
});
|
5328
|
-
|
5087
|
+
const cachedUtxos = [];
|
5088
|
+
const cachedMessages = [];
|
5089
|
+
const owner = this.address.toB256();
|
5090
|
+
request.inputs.forEach((input) => {
|
5329
5091
|
const isResource = "amount" in input;
|
5330
5092
|
if (isResource) {
|
5331
5093
|
const isCoin2 = "owner" in input;
|
5332
5094
|
if (isCoin2) {
|
5333
5095
|
const assetId = String(input.assetId);
|
5334
|
-
if (quantitiesDict[assetId]) {
|
5335
|
-
const amount = (0,
|
5096
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
5097
|
+
const amount = (0, import_math18.bn)(input.amount);
|
5336
5098
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5099
|
+
cachedUtxos.push(input.id);
|
5337
5100
|
}
|
5338
|
-
} else if (input.amount && quantitiesDict[
|
5339
|
-
quantitiesDict[
|
5101
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
5102
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
5103
|
+
cachedMessages.push(input.nonce);
|
5340
5104
|
}
|
5341
5105
|
}
|
5342
5106
|
});
|
@@ -5351,23 +5115,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5351
5115
|
});
|
5352
5116
|
const needsToBeFunded = missingQuantities.length;
|
5353
5117
|
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
|
-
);
|
5118
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5119
|
+
messages: cachedMessages,
|
5120
|
+
utxos: cachedUtxos
|
5121
|
+
});
|
5122
|
+
request.addResources(resources);
|
5365
5123
|
}
|
5366
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5367
|
-
transactionRequest: requestToBeReEstimate
|
5368
|
-
});
|
5369
|
-
txRequest.maxFee = maxFee;
|
5370
|
-
return txRequest;
|
5371
5124
|
}
|
5372
5125
|
/**
|
5373
5126
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5375,25 +5128,30 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5375
5128
|
* @param destination - The address of the destination.
|
5376
5129
|
* @param amount - The amount of coins to transfer.
|
5377
5130
|
* @param assetId - The asset ID of the coins to transfer.
|
5378
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5131
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5379
5132
|
* @returns A promise that resolves to the prepared transaction request.
|
5380
5133
|
*/
|
5381
|
-
async createTransfer(destination, amount, assetId
|
5382
|
-
const
|
5383
|
-
|
5384
|
-
const
|
5134
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5135
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5136
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5137
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5138
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5139
|
+
const request = new ScriptTransactionRequest(params);
|
5140
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5141
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5385
5142
|
estimateTxDependencies: true,
|
5386
5143
|
resourcesOwner: this
|
5387
5144
|
});
|
5388
|
-
|
5389
|
-
|
5390
|
-
|
5391
|
-
|
5392
|
-
|
5393
|
-
|
5394
|
-
|
5395
|
-
|
5396
|
-
await this.fund(request,
|
5145
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
5146
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
5147
|
+
this.validateGas({
|
5148
|
+
gasUsed,
|
5149
|
+
gasPrice: request.gasPrice,
|
5150
|
+
gasLimit: request.gasLimit,
|
5151
|
+
minGasPrice
|
5152
|
+
});
|
5153
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5154
|
+
request.updatePredicateInputs(estimatedInputs);
|
5397
5155
|
return request;
|
5398
5156
|
}
|
5399
5157
|
/**
|
@@ -5405,14 +5163,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5405
5163
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5406
5164
|
* @returns A promise that resolves to the transaction response.
|
5407
5165
|
*/
|
5408
|
-
async transfer(destination, amount, assetId
|
5409
|
-
if ((0,
|
5166
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5167
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5410
5168
|
throw new import_errors16.FuelError(
|
5411
5169
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5412
5170
|
"Transfer amount must be a positive number."
|
5413
5171
|
);
|
5414
5172
|
}
|
5415
|
-
const
|
5173
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5174
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5416
5175
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5417
5176
|
}
|
5418
5177
|
/**
|
@@ -5424,38 +5183,41 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5424
5183
|
* @param txParams - The optional transaction parameters.
|
5425
5184
|
* @returns A promise that resolves to the transaction response.
|
5426
5185
|
*/
|
5427
|
-
async transferToContract(contractId, amount, assetId
|
5428
|
-
if ((0,
|
5186
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5187
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5429
5188
|
throw new import_errors16.FuelError(
|
5430
5189
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5431
5190
|
"Transfer amount must be a positive number."
|
5432
5191
|
);
|
5433
5192
|
}
|
5434
5193
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5194
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5195
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5196
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5197
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5435
5198
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5436
5199
|
hexlifiedContractId: contractAddress.toB256(),
|
5437
|
-
amountToTransfer: (0,
|
5438
|
-
assetId
|
5200
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5201
|
+
assetId: assetIdToTransfer
|
5439
5202
|
});
|
5440
5203
|
const request = new ScriptTransactionRequest({
|
5441
|
-
...
|
5204
|
+
...params,
|
5442
5205
|
script,
|
5443
5206
|
scriptData
|
5444
5207
|
});
|
5445
5208
|
request.addContractInputAndOutput(contractAddress);
|
5446
|
-
const
|
5447
|
-
|
5448
|
-
|
5209
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5210
|
+
request,
|
5211
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5212
|
+
);
|
5213
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5214
|
+
this.validateGas({
|
5215
|
+
gasUsed,
|
5216
|
+
gasPrice: request.gasPrice,
|
5217
|
+
gasLimit: request.gasLimit,
|
5218
|
+
minGasPrice
|
5449
5219
|
});
|
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);
|
5220
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5459
5221
|
return this.sendTransaction(request);
|
5460
5222
|
}
|
5461
5223
|
/**
|
@@ -5467,31 +5229,40 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5467
5229
|
* @returns A promise that resolves to the transaction response.
|
5468
5230
|
*/
|
5469
5231
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5232
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5233
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5470
5234
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5471
|
-
const recipientDataArray = (0,
|
5235
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5472
5236
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5473
5237
|
);
|
5474
|
-
const amountDataArray = (0,
|
5475
|
-
"0x".concat((0,
|
5238
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5239
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5476
5240
|
);
|
5477
5241
|
const script = new Uint8Array([
|
5478
|
-
...(0,
|
5242
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5479
5243
|
...recipientDataArray,
|
5480
5244
|
...amountDataArray
|
5481
5245
|
]);
|
5482
|
-
const params = {
|
5246
|
+
const params = {
|
5247
|
+
script,
|
5248
|
+
gasPrice: minGasPrice,
|
5249
|
+
baseAssetId,
|
5250
|
+
...txParams
|
5251
|
+
};
|
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
|
|
@@ -9093,9 +8874,9 @@ var Predicate = class extends Account {
|
|
9093
8874
|
const request = transactionRequestify(transactionRequestLike);
|
9094
8875
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9095
8876
|
request.inputs?.forEach((input) => {
|
9096
|
-
if (input.type ===
|
9097
|
-
input.predicate =
|
9098
|
-
input.predicateData =
|
8877
|
+
if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
|
8878
|
+
input.predicate = this.bytes;
|
8879
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9099
8880
|
}
|
9100
8881
|
});
|
9101
8882
|
return request;
|
@@ -9109,8 +8890,10 @@ var Predicate = class extends Account {
|
|
9109
8890
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
9110
8891
|
* @returns A promise that resolves to the prepared transaction request.
|
9111
8892
|
*/
|
9112
|
-
async createTransfer(destination, amount, assetId
|
9113
|
-
|
8893
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8894
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8895
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8896
|
+
return this.populateTransactionPredicateData(request);
|
9114
8897
|
}
|
9115
8898
|
/**
|
9116
8899
|
* Sends a transaction with the populated predicate data.
|
@@ -9118,9 +8901,9 @@ var Predicate = class extends Account {
|
|
9118
8901
|
* @param transactionRequestLike - The transaction request-like object.
|
9119
8902
|
* @returns A promise that resolves to the transaction response.
|
9120
8903
|
*/
|
9121
|
-
sendTransaction(transactionRequestLike) {
|
9122
|
-
const transactionRequest =
|
9123
|
-
return super.sendTransaction(transactionRequest,
|
8904
|
+
sendTransaction(transactionRequestLike, options) {
|
8905
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8906
|
+
return super.sendTransaction(transactionRequest, options);
|
9124
8907
|
}
|
9125
8908
|
/**
|
9126
8909
|
* Simulates a transaction with the populated predicate data.
|
@@ -9129,15 +8912,15 @@ var Predicate = class extends Account {
|
|
9129
8912
|
* @returns A promise that resolves to the call result.
|
9130
8913
|
*/
|
9131
8914
|
simulateTransaction(transactionRequestLike) {
|
9132
|
-
const transactionRequest =
|
9133
|
-
return super.simulateTransaction(transactionRequest
|
8915
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8916
|
+
return super.simulateTransaction(transactionRequest);
|
9134
8917
|
}
|
9135
8918
|
getPredicateData(policiesLength) {
|
9136
8919
|
if (!this.predicateData.length) {
|
9137
8920
|
return new Uint8Array();
|
9138
8921
|
}
|
9139
8922
|
const mainFn = this.interface?.functions.main;
|
9140
|
-
const paddedCode = new
|
8923
|
+
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
9141
8924
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
9142
8925
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
9143
8926
|
});
|
@@ -9153,7 +8936,7 @@ var Predicate = class extends Account {
|
|
9153
8936
|
* @returns An object containing the new predicate bytes and interface.
|
9154
8937
|
*/
|
9155
8938
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9156
|
-
let predicateBytes = (0,
|
8939
|
+
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
9157
8940
|
let abiInterface;
|
9158
8941
|
if (jsonAbi) {
|
9159
8942
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
@@ -9176,25 +8959,6 @@ var Predicate = class extends Account {
|
|
9176
8959
|
predicateInterface: abiInterface
|
9177
8960
|
};
|
9178
8961
|
}
|
9179
|
-
/**
|
9180
|
-
* Retrieves resources satisfying the spend query for the account.
|
9181
|
-
*
|
9182
|
-
* @param quantities - IDs of coins to exclude.
|
9183
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9184
|
-
* @returns A promise that resolves to an array of Resources.
|
9185
|
-
*/
|
9186
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9187
|
-
const resources = await this.provider.getResourcesToSpend(
|
9188
|
-
this.address,
|
9189
|
-
quantities,
|
9190
|
-
excludedIds
|
9191
|
-
);
|
9192
|
-
return resources.map((resource) => ({
|
9193
|
-
...resource,
|
9194
|
-
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9195
|
-
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9196
|
-
}));
|
9197
|
-
}
|
9198
8962
|
/**
|
9199
8963
|
* Sets the configurable constants for the predicate.
|
9200
8964
|
*
|
@@ -9944,7 +9708,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9944
9708
|
WalletLocked,
|
9945
9709
|
WalletManager,
|
9946
9710
|
WalletUnlocked,
|
9947
|
-
|
9711
|
+
addAmountToAsset,
|
9948
9712
|
addOperation,
|
9949
9713
|
assemblePanicError,
|
9950
9714
|
assembleReceiptByType,
|
@@ -9953,10 +9717,9 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9953
9717
|
assets,
|
9954
9718
|
buildBlockExplorerUrl,
|
9955
9719
|
cacheFor,
|
9956
|
-
cacheTxInputsFromOwner,
|
9957
|
-
calculateGasFee,
|
9958
9720
|
calculateMetadataGasForTxCreate,
|
9959
9721
|
calculateMetadataGasForTxScript,
|
9722
|
+
calculatePriceWithFactor,
|
9960
9723
|
calculateTransactionFee,
|
9961
9724
|
coinQuantityfy,
|
9962
9725
|
deferPromise,
|