@fuel-ts/account 0.0.0-rc-2021-20240424175107 → 0.0.0-rc-2037-20240424175231
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 +6 -7
- 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 +622 -814
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +659 -837
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +478 -661
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +39 -12
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +359 -810
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +1 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -6
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -37
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +10 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
- package/dist/providers/transaction-request/index.d.ts +1 -0
- package/dist/providers/transaction-request/index.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +11 -6
- 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/index.d.ts +1 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/resources.d.ts +4 -0
- package/dist/test-utils/resources.d.ts.map +1 -0
- package/dist/test-utils/seedTestWallet.d.ts +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils/transactionRequest.d.ts +5 -0
- package/dist/test-utils/transactionRequest.d.ts.map +1 -0
- package/dist/test-utils.global.js +1089 -1533
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +624 -820
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +457 -656
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -48,6 +48,9 @@ var __privateMethod = (obj, member, method) => {
|
|
48
48
|
// src/test-utils/index.ts
|
49
49
|
var test_utils_exports = {};
|
50
50
|
__export(test_utils_exports, {
|
51
|
+
generateFakeRequestInputCoin: () => generateFakeRequestInputCoin,
|
52
|
+
generateFakeRequestInputContract: () => generateFakeRequestInputContract,
|
53
|
+
generateFakeRequestInputMessage: () => generateFakeRequestInputMessage,
|
51
54
|
generateTestWallet: () => generateTestWallet,
|
52
55
|
killNode: () => killNode,
|
53
56
|
launchNode: () => launchNode,
|
@@ -58,16 +61,15 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
61
|
|
59
62
|
// src/wallet/base-wallet-unlocked.ts
|
60
63
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
64
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
65
|
|
63
66
|
// src/account.ts
|
64
67
|
var import_address4 = require("@fuel-ts/address");
|
65
68
|
var import_configs12 = require("@fuel-ts/address/configs");
|
66
69
|
var import_errors16 = require("@fuel-ts/errors");
|
67
70
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
|
-
var
|
69
|
-
var
|
70
|
-
var import_ramda4 = require("ramda");
|
71
|
+
var import_math18 = require("@fuel-ts/math");
|
72
|
+
var import_utils28 = require("@fuel-ts/utils");
|
71
73
|
|
72
74
|
// src/providers/coin-quantity.ts
|
73
75
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -76,24 +78,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
76
78
|
var coinQuantityfy = (coinQuantityLike) => {
|
77
79
|
let assetId;
|
78
80
|
let amount;
|
79
|
-
let
|
81
|
+
let max2;
|
80
82
|
if (Array.isArray(coinQuantityLike)) {
|
81
83
|
amount = coinQuantityLike[0];
|
82
84
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
83
|
-
|
85
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
84
86
|
} else {
|
85
87
|
amount = coinQuantityLike.amount;
|
86
88
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
87
|
-
|
89
|
+
max2 = coinQuantityLike.max ?? void 0;
|
88
90
|
}
|
89
91
|
const bnAmount = (0, import_math.bn)(amount);
|
90
92
|
return {
|
91
93
|
assetId: (0, import_utils.hexlify)(assetId),
|
92
94
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
93
|
-
max:
|
95
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
94
96
|
};
|
95
97
|
};
|
96
|
-
var
|
98
|
+
var addAmountToAsset = (params) => {
|
97
99
|
const { amount, assetId } = params;
|
98
100
|
const coinQuantities = [...params.coinQuantities];
|
99
101
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -108,31 +110,27 @@ var addAmountToCoinQuantities = (params) => {
|
|
108
110
|
// src/providers/provider.ts
|
109
111
|
var import_address3 = require("@fuel-ts/address");
|
110
112
|
var import_errors14 = require("@fuel-ts/errors");
|
111
|
-
var
|
113
|
+
var import_math15 = require("@fuel-ts/math");
|
112
114
|
var import_transactions19 = require("@fuel-ts/transactions");
|
113
|
-
var
|
115
|
+
var import_utils23 = require("@fuel-ts/utils");
|
114
116
|
var import_versions = require("@fuel-ts/versions");
|
115
|
-
var
|
117
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
116
118
|
var import_ethers = require("ethers");
|
117
119
|
var import_graphql_request = require("graphql-request");
|
118
120
|
var import_ramda3 = require("ramda");
|
119
121
|
|
120
122
|
// src/providers/__generated__/operations.ts
|
121
123
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
122
|
-
var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
|
123
|
-
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
124
|
-
type: __typename
|
125
|
-
... on SqueezedOutStatus {
|
126
|
-
reason
|
127
|
-
}
|
128
|
-
}
|
129
|
-
`;
|
130
124
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
131
125
|
fragment receiptFragment on Receipt {
|
132
|
-
|
126
|
+
contract {
|
127
|
+
id
|
128
|
+
}
|
133
129
|
pc
|
134
130
|
is
|
135
|
-
to
|
131
|
+
to {
|
132
|
+
id
|
133
|
+
}
|
136
134
|
toAddress
|
137
135
|
amount
|
138
136
|
assetId
|
@@ -170,16 +168,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
170
168
|
id
|
171
169
|
}
|
172
170
|
time
|
173
|
-
receipts {
|
174
|
-
...receiptFragment
|
175
|
-
}
|
176
171
|
programState {
|
177
172
|
returnType
|
178
173
|
data
|
179
174
|
}
|
180
|
-
receipts {
|
181
|
-
...receiptFragment
|
182
|
-
}
|
183
175
|
}
|
184
176
|
... on FailureStatus {
|
185
177
|
block {
|
@@ -187,24 +179,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
187
179
|
}
|
188
180
|
time
|
189
181
|
reason
|
190
|
-
receipts {
|
191
|
-
...receiptFragment
|
192
|
-
}
|
193
182
|
}
|
194
183
|
... on SqueezedOutStatus {
|
195
184
|
reason
|
196
185
|
}
|
197
186
|
}
|
198
|
-
|
187
|
+
`;
|
199
188
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
200
189
|
fragment transactionFragment on Transaction {
|
201
190
|
id
|
202
191
|
rawPayload
|
192
|
+
gasPrice
|
193
|
+
receipts {
|
194
|
+
...receiptFragment
|
195
|
+
}
|
203
196
|
status {
|
204
197
|
...transactionStatusFragment
|
205
198
|
}
|
206
199
|
}
|
207
|
-
${
|
200
|
+
${ReceiptFragmentFragmentDoc}
|
201
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
208
202
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
209
203
|
fragment inputEstimatePredicatesFragment on Input {
|
210
204
|
... on InputCoin {
|
@@ -222,46 +216,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
222
216
|
}
|
223
217
|
}
|
224
218
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
225
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
226
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
227
|
-
reason
|
228
|
-
programState {
|
229
|
-
returnType
|
230
|
-
data
|
231
|
-
}
|
232
|
-
}
|
233
|
-
`;
|
234
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
235
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
236
|
-
programState {
|
237
|
-
returnType
|
238
|
-
data
|
239
|
-
}
|
240
|
-
}
|
241
|
-
`;
|
242
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
243
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
244
|
-
... on DryRunFailureStatus {
|
245
|
-
...dryRunFailureStatusFragment
|
246
|
-
}
|
247
|
-
... on DryRunSuccessStatus {
|
248
|
-
...dryRunSuccessStatusFragment
|
249
|
-
}
|
250
|
-
}
|
251
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
252
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
253
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
254
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
255
|
-
id
|
256
|
-
status {
|
257
|
-
...dryRunTransactionStatusFragment
|
258
|
-
}
|
259
|
-
receipts {
|
260
|
-
...receiptFragment
|
261
|
-
}
|
262
|
-
}
|
263
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
264
|
-
${ReceiptFragmentFragmentDoc}`;
|
265
219
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
266
220
|
fragment coinFragment on Coin {
|
267
221
|
__typename
|
@@ -269,6 +223,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
269
223
|
owner
|
270
224
|
amount
|
271
225
|
assetId
|
226
|
+
maturity
|
272
227
|
blockCreated
|
273
228
|
txCreatedIdx
|
274
229
|
}
|
@@ -307,32 +262,26 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
307
262
|
messageBlockHeader {
|
308
263
|
id
|
309
264
|
daHeight
|
310
|
-
consensusParametersVersion
|
311
|
-
stateTransitionBytecodeVersion
|
312
265
|
transactionsCount
|
313
|
-
messageReceiptCount
|
314
266
|
transactionsRoot
|
315
|
-
messageOutboxRoot
|
316
|
-
eventInboxRoot
|
317
267
|
height
|
318
268
|
prevRoot
|
319
269
|
time
|
320
270
|
applicationHash
|
271
|
+
messageReceiptRoot
|
272
|
+
messageReceiptCount
|
321
273
|
}
|
322
274
|
commitBlockHeader {
|
323
275
|
id
|
324
276
|
daHeight
|
325
|
-
consensusParametersVersion
|
326
|
-
stateTransitionBytecodeVersion
|
327
277
|
transactionsCount
|
328
|
-
messageReceiptCount
|
329
278
|
transactionsRoot
|
330
|
-
messageOutboxRoot
|
331
|
-
eventInboxRoot
|
332
279
|
height
|
333
280
|
prevRoot
|
334
281
|
time
|
335
282
|
applicationHash
|
283
|
+
messageReceiptRoot
|
284
|
+
messageReceiptCount
|
336
285
|
}
|
337
286
|
sender
|
338
287
|
recipient
|
@@ -351,8 +300,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
351
300
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
352
301
|
fragment blockFragment on Block {
|
353
302
|
id
|
354
|
-
height
|
355
303
|
header {
|
304
|
+
height
|
356
305
|
time
|
357
306
|
}
|
358
307
|
transactions {
|
@@ -362,7 +311,6 @@ var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
|
362
311
|
`;
|
363
312
|
var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
364
313
|
fragment TxParametersFragment on TxParameters {
|
365
|
-
version
|
366
314
|
maxInputs
|
367
315
|
maxOutputs
|
368
316
|
maxWitnesses
|
@@ -372,7 +320,6 @@ var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
372
320
|
`;
|
373
321
|
var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
374
322
|
fragment PredicateParametersFragment on PredicateParameters {
|
375
|
-
version
|
376
323
|
maxPredicateLength
|
377
324
|
maxPredicateDataLength
|
378
325
|
maxGasPerPredicate
|
@@ -381,21 +328,18 @@ var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
381
328
|
`;
|
382
329
|
var ScriptParametersFragmentFragmentDoc = import_graphql_tag.default`
|
383
330
|
fragment ScriptParametersFragment on ScriptParameters {
|
384
|
-
version
|
385
331
|
maxScriptLength
|
386
332
|
maxScriptDataLength
|
387
333
|
}
|
388
334
|
`;
|
389
335
|
var ContractParametersFragmentFragmentDoc = import_graphql_tag.default`
|
390
336
|
fragment ContractParametersFragment on ContractParameters {
|
391
|
-
version
|
392
337
|
contractMaxSize
|
393
338
|
maxStorageSlots
|
394
339
|
}
|
395
340
|
`;
|
396
341
|
var FeeParametersFragmentFragmentDoc = import_graphql_tag.default`
|
397
342
|
fragment FeeParametersFragment on FeeParameters {
|
398
|
-
version
|
399
343
|
gasPriceFactor
|
400
344
|
gasPerByte
|
401
345
|
}
|
@@ -415,7 +359,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
415
359
|
`;
|
416
360
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
417
361
|
fragment GasCostsFragment on GasCosts {
|
418
|
-
version
|
419
362
|
add
|
420
363
|
addi
|
421
364
|
aloc
|
@@ -428,6 +371,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
428
371
|
cb
|
429
372
|
cfei
|
430
373
|
cfsi
|
374
|
+
croo
|
431
375
|
div
|
432
376
|
divi
|
433
377
|
ecr1
|
@@ -510,9 +454,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
510
454
|
ccp {
|
511
455
|
...DependentCostFragment
|
512
456
|
}
|
513
|
-
croo {
|
514
|
-
...DependentCostFragment
|
515
|
-
}
|
516
457
|
csiz {
|
517
458
|
...DependentCostFragment
|
518
459
|
}
|
@@ -572,7 +513,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
572
513
|
${DependentCostFragmentFragmentDoc}`;
|
573
514
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
574
515
|
fragment consensusParametersFragment on ConsensusParameters {
|
575
|
-
version
|
576
516
|
txParams {
|
577
517
|
...TxParametersFragment
|
578
518
|
}
|
@@ -632,9 +572,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
632
572
|
fragment nodeInfoFragment on NodeInfo {
|
633
573
|
utxoValidation
|
634
574
|
vmBacktrace
|
575
|
+
minGasPrice
|
635
576
|
maxTx
|
636
577
|
maxDepth
|
637
578
|
nodeVersion
|
579
|
+
peers {
|
580
|
+
id
|
581
|
+
addresses
|
582
|
+
clientVersion
|
583
|
+
blockHeight
|
584
|
+
lastHeartbeatMs
|
585
|
+
appScore
|
586
|
+
}
|
638
587
|
}
|
639
588
|
`;
|
640
589
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -669,9 +618,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
669
618
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
670
619
|
transaction(id: $transactionId) {
|
671
620
|
...transactionFragment
|
621
|
+
receipts {
|
622
|
+
...receiptFragment
|
623
|
+
}
|
672
624
|
}
|
673
625
|
}
|
674
|
-
${TransactionFragmentFragmentDoc}
|
626
|
+
${TransactionFragmentFragmentDoc}
|
627
|
+
${ReceiptFragmentFragmentDoc}`;
|
675
628
|
var GetTransactionsDocument = import_graphql_tag.default`
|
676
629
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
677
630
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -799,20 +752,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
799
752
|
}
|
800
753
|
}
|
801
754
|
${BalanceFragmentFragmentDoc}`;
|
802
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
803
|
-
query getLatestGasPrice {
|
804
|
-
latestGasPrice {
|
805
|
-
gasPrice
|
806
|
-
}
|
807
|
-
}
|
808
|
-
`;
|
809
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
810
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
811
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
812
|
-
gasPrice
|
813
|
-
}
|
814
|
-
}
|
815
|
-
`;
|
816
755
|
var GetBalancesDocument = import_graphql_tag.default`
|
817
756
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
818
757
|
balances(
|
@@ -867,12 +806,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
867
806
|
}
|
868
807
|
`;
|
869
808
|
var DryRunDocument = import_graphql_tag.default`
|
870
|
-
mutation dryRun($
|
871
|
-
dryRun(
|
872
|
-
...
|
809
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
810
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
811
|
+
...receiptFragment
|
873
812
|
}
|
874
813
|
}
|
875
|
-
${
|
814
|
+
${ReceiptFragmentFragmentDoc}`;
|
876
815
|
var SubmitDocument = import_graphql_tag.default`
|
877
816
|
mutation submit($encodedTransaction: HexString!) {
|
878
817
|
submit(tx: $encodedTransaction) {
|
@@ -891,17 +830,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
|
|
891
830
|
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
892
831
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
893
832
|
submitAndAwait(tx: $encodedTransaction) {
|
894
|
-
...
|
833
|
+
...transactionStatusFragment
|
895
834
|
}
|
896
835
|
}
|
897
|
-
${
|
836
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
898
837
|
var StatusChangeDocument = import_graphql_tag.default`
|
899
838
|
subscription statusChange($transactionId: TransactionId!) {
|
900
839
|
statusChange(id: $transactionId) {
|
901
|
-
...
|
840
|
+
...transactionStatusFragment
|
902
841
|
}
|
903
842
|
}
|
904
|
-
${
|
843
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
905
844
|
function getSdk(requester) {
|
906
845
|
return {
|
907
846
|
getVersion(variables, options) {
|
@@ -955,12 +894,6 @@ function getSdk(requester) {
|
|
955
894
|
getBalance(variables, options) {
|
956
895
|
return requester(GetBalanceDocument, variables, options);
|
957
896
|
},
|
958
|
-
getLatestGasPrice(variables, options) {
|
959
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
960
|
-
},
|
961
|
-
estimateGasPrice(variables, options) {
|
962
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
963
|
-
},
|
964
897
|
getBalances(variables, options) {
|
965
898
|
return requester(GetBalancesDocument, variables, options);
|
966
899
|
},
|
@@ -1154,9 +1087,10 @@ var inputify = (value) => {
|
|
1154
1087
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1155
1088
|
},
|
1156
1089
|
witnessIndex: value.witnessIndex,
|
1090
|
+
maturity: value.maturity ?? 0,
|
1157
1091
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1158
|
-
predicateLength:
|
1159
|
-
predicateDataLength:
|
1092
|
+
predicateLength: predicate.length,
|
1093
|
+
predicateDataLength: predicateData.length,
|
1160
1094
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1161
1095
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1162
1096
|
};
|
@@ -1187,8 +1121,8 @@ var inputify = (value) => {
|
|
1187
1121
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1188
1122
|
witnessIndex: value.witnessIndex,
|
1189
1123
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1190
|
-
predicateLength:
|
1191
|
-
predicateDataLength:
|
1124
|
+
predicateLength: predicate.length,
|
1125
|
+
predicateDataLength: predicateData.length,
|
1192
1126
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1193
1127
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1194
1128
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1267,7 +1201,7 @@ var import_address = require("@fuel-ts/address");
|
|
1267
1201
|
var import_configs7 = require("@fuel-ts/address/configs");
|
1268
1202
|
var import_crypto = require("@fuel-ts/crypto");
|
1269
1203
|
var import_math7 = require("@fuel-ts/math");
|
1270
|
-
var
|
1204
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
1271
1205
|
var import_utils9 = require("@fuel-ts/utils");
|
1272
1206
|
|
1273
1207
|
// src/providers/resource.ts
|
@@ -1304,8 +1238,8 @@ function assembleReceiptByType(receipt) {
|
|
1304
1238
|
case "CALL" /* Call */: {
|
1305
1239
|
const callReceipt = {
|
1306
1240
|
type: import_transactions3.ReceiptType.Call,
|
1307
|
-
from: hexOrZero(receipt.id
|
1308
|
-
to: hexOrZero(receipt?.to),
|
1241
|
+
from: hexOrZero(receipt.contract?.id),
|
1242
|
+
to: hexOrZero(receipt?.to?.id),
|
1309
1243
|
amount: (0, import_math4.bn)(receipt.amount),
|
1310
1244
|
assetId: hexOrZero(receipt.assetId),
|
1311
1245
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1319,7 +1253,7 @@ function assembleReceiptByType(receipt) {
|
|
1319
1253
|
case "RETURN" /* Return */: {
|
1320
1254
|
const returnReceipt = {
|
1321
1255
|
type: import_transactions3.ReceiptType.Return,
|
1322
|
-
id: hexOrZero(receipt.id
|
1256
|
+
id: hexOrZero(receipt.contract?.id),
|
1323
1257
|
val: (0, import_math4.bn)(receipt.val),
|
1324
1258
|
pc: (0, import_math4.bn)(receipt.pc),
|
1325
1259
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1329,7 +1263,7 @@ function assembleReceiptByType(receipt) {
|
|
1329
1263
|
case "RETURN_DATA" /* ReturnData */: {
|
1330
1264
|
const returnDataReceipt = {
|
1331
1265
|
type: import_transactions3.ReceiptType.ReturnData,
|
1332
|
-
id: hexOrZero(receipt.id
|
1266
|
+
id: hexOrZero(receipt.contract?.id),
|
1333
1267
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1334
1268
|
len: (0, import_math4.bn)(receipt.len),
|
1335
1269
|
digest: hexOrZero(receipt.digest),
|
@@ -1341,7 +1275,7 @@ function assembleReceiptByType(receipt) {
|
|
1341
1275
|
case "PANIC" /* Panic */: {
|
1342
1276
|
const panicReceipt = {
|
1343
1277
|
type: import_transactions3.ReceiptType.Panic,
|
1344
|
-
id: hexOrZero(receipt.id),
|
1278
|
+
id: hexOrZero(receipt.contract?.id),
|
1345
1279
|
reason: (0, import_math4.bn)(receipt.reason),
|
1346
1280
|
pc: (0, import_math4.bn)(receipt.pc),
|
1347
1281
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1352,7 +1286,7 @@ function assembleReceiptByType(receipt) {
|
|
1352
1286
|
case "REVERT" /* Revert */: {
|
1353
1287
|
const revertReceipt = {
|
1354
1288
|
type: import_transactions3.ReceiptType.Revert,
|
1355
|
-
id: hexOrZero(receipt.id
|
1289
|
+
id: hexOrZero(receipt.contract?.id),
|
1356
1290
|
val: (0, import_math4.bn)(receipt.ra),
|
1357
1291
|
pc: (0, import_math4.bn)(receipt.pc),
|
1358
1292
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1362,7 +1296,7 @@ function assembleReceiptByType(receipt) {
|
|
1362
1296
|
case "LOG" /* Log */: {
|
1363
1297
|
const logReceipt = {
|
1364
1298
|
type: import_transactions3.ReceiptType.Log,
|
1365
|
-
id: hexOrZero(receipt.id
|
1299
|
+
id: hexOrZero(receipt.contract?.id),
|
1366
1300
|
val0: (0, import_math4.bn)(receipt.ra),
|
1367
1301
|
val1: (0, import_math4.bn)(receipt.rb),
|
1368
1302
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1375,7 +1309,7 @@ function assembleReceiptByType(receipt) {
|
|
1375
1309
|
case "LOG_DATA" /* LogData */: {
|
1376
1310
|
const logDataReceipt = {
|
1377
1311
|
type: import_transactions3.ReceiptType.LogData,
|
1378
|
-
id: hexOrZero(receipt.id
|
1312
|
+
id: hexOrZero(receipt.contract?.id),
|
1379
1313
|
val0: (0, import_math4.bn)(receipt.ra),
|
1380
1314
|
val1: (0, import_math4.bn)(receipt.rb),
|
1381
1315
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1389,8 +1323,8 @@ function assembleReceiptByType(receipt) {
|
|
1389
1323
|
case "TRANSFER" /* Transfer */: {
|
1390
1324
|
const transferReceipt = {
|
1391
1325
|
type: import_transactions3.ReceiptType.Transfer,
|
1392
|
-
from: hexOrZero(receipt.id
|
1393
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1326
|
+
from: hexOrZero(receipt.contract?.id),
|
1327
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1394
1328
|
amount: (0, import_math4.bn)(receipt.amount),
|
1395
1329
|
assetId: hexOrZero(receipt.assetId),
|
1396
1330
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1401,8 +1335,8 @@ function assembleReceiptByType(receipt) {
|
|
1401
1335
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1402
1336
|
const transferOutReceipt = {
|
1403
1337
|
type: import_transactions3.ReceiptType.TransferOut,
|
1404
|
-
from: hexOrZero(receipt.id
|
1405
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1338
|
+
from: hexOrZero(receipt.contract?.id),
|
1339
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1406
1340
|
amount: (0, import_math4.bn)(receipt.amount),
|
1407
1341
|
assetId: hexOrZero(receipt.assetId),
|
1408
1342
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1445,7 +1379,7 @@ function assembleReceiptByType(receipt) {
|
|
1445
1379
|
return receiptMessageOut;
|
1446
1380
|
}
|
1447
1381
|
case "MINT" /* Mint */: {
|
1448
|
-
const contractId = hexOrZero(receipt.id
|
1382
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1449
1383
|
const subId = hexOrZero(receipt.subId);
|
1450
1384
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1451
1385
|
const mintReceipt = {
|
@@ -1460,7 +1394,7 @@ function assembleReceiptByType(receipt) {
|
|
1460
1394
|
return mintReceipt;
|
1461
1395
|
}
|
1462
1396
|
case "BURN" /* Burn */: {
|
1463
|
-
const contractId = hexOrZero(receipt.id
|
1397
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1464
1398
|
const subId = hexOrZero(receipt.subId);
|
1465
1399
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1466
1400
|
const burnReceipt = {
|
@@ -1486,6 +1420,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1486
1420
|
var import_math5 = require("@fuel-ts/math");
|
1487
1421
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1488
1422
|
var import_utils6 = require("@fuel-ts/utils");
|
1423
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1489
1424
|
var getGasUsedFromReceipts = (receipts) => {
|
1490
1425
|
const scriptResult = receipts.filter(
|
1491
1426
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1506,28 +1441,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1506
1441
|
}
|
1507
1442
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1508
1443
|
const witnessCache = [];
|
1509
|
-
const
|
1510
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1511
|
-
if (isCoinOrMessage) {
|
1512
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1513
|
-
return true;
|
1514
|
-
}
|
1515
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1516
|
-
witnessCache.push(input.witnessIndex);
|
1517
|
-
return true;
|
1518
|
-
}
|
1519
|
-
}
|
1520
|
-
return false;
|
1521
|
-
});
|
1522
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1523
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1444
|
+
const totalGas = inputs.reduce((total, input) => {
|
1524
1445
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1525
1446
|
return total.add(
|
1526
|
-
|
1447
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1527
1448
|
);
|
1528
1449
|
}
|
1529
|
-
|
1530
|
-
|
1450
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1451
|
+
witnessCache.push(input.witnessIndex);
|
1452
|
+
return total.add(gasCosts.ecr1);
|
1453
|
+
}
|
1454
|
+
return total;
|
1455
|
+
}, (0, import_math5.bn)());
|
1531
1456
|
return totalGas;
|
1532
1457
|
}
|
1533
1458
|
function getMinGas(params) {
|
@@ -1539,20 +1464,12 @@ function getMinGas(params) {
|
|
1539
1464
|
return minGas;
|
1540
1465
|
}
|
1541
1466
|
function getMaxGas(params) {
|
1542
|
-
const {
|
1543
|
-
gasPerByte,
|
1544
|
-
witnessesLength,
|
1545
|
-
witnessLimit,
|
1546
|
-
minGas,
|
1547
|
-
gasLimit = (0, import_math5.bn)(0),
|
1548
|
-
maxGasPerTx
|
1549
|
-
} = params;
|
1467
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1550
1468
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1551
1469
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1552
1470
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1553
1471
|
}
|
1554
|
-
|
1555
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1472
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1556
1473
|
}
|
1557
1474
|
function calculateMetadataGasForTxCreate({
|
1558
1475
|
gasCosts,
|
@@ -1574,10 +1491,6 @@ function calculateMetadataGasForTxScript({
|
|
1574
1491
|
}) {
|
1575
1492
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1576
1493
|
}
|
1577
|
-
var calculateGasFee = (params) => {
|
1578
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1579
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1580
|
-
};
|
1581
1494
|
|
1582
1495
|
// src/providers/utils/json.ts
|
1583
1496
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1701,6 +1614,12 @@ var NoWitnessAtIndexError = class extends Error {
|
|
1701
1614
|
name = "NoWitnessAtIndexError";
|
1702
1615
|
};
|
1703
1616
|
|
1617
|
+
// src/providers/transaction-request/helpers.ts
|
1618
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1619
|
+
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
1620
|
+
var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
|
1621
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1622
|
+
|
1704
1623
|
// src/providers/transaction-request/witness.ts
|
1705
1624
|
var import_utils8 = require("@fuel-ts/utils");
|
1706
1625
|
var witnessify = (value) => {
|
@@ -1714,7 +1633,7 @@ var witnessify = (value) => {
|
|
1714
1633
|
// src/providers/transaction-request/transaction-request.ts
|
1715
1634
|
var BaseTransactionRequest = class {
|
1716
1635
|
/** Gas price for transaction */
|
1717
|
-
|
1636
|
+
gasPrice;
|
1718
1637
|
/** Block until which tx cannot be included */
|
1719
1638
|
maturity;
|
1720
1639
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1733,7 +1652,7 @@ var BaseTransactionRequest = class {
|
|
1733
1652
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1734
1653
|
*/
|
1735
1654
|
constructor({
|
1736
|
-
|
1655
|
+
gasPrice,
|
1737
1656
|
maturity,
|
1738
1657
|
maxFee,
|
1739
1658
|
witnessLimit,
|
@@ -1741,7 +1660,7 @@ var BaseTransactionRequest = class {
|
|
1741
1660
|
outputs,
|
1742
1661
|
witnesses
|
1743
1662
|
} = {}) {
|
1744
|
-
this.
|
1663
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1745
1664
|
this.maturity = maturity ?? 0;
|
1746
1665
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1747
1666
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1752,21 +1671,21 @@ var BaseTransactionRequest = class {
|
|
1752
1671
|
static getPolicyMeta(req) {
|
1753
1672
|
let policyTypes = 0;
|
1754
1673
|
const policies = [];
|
1755
|
-
if (req.
|
1756
|
-
policyTypes +=
|
1757
|
-
policies.push({ data: req.
|
1674
|
+
if (req.gasPrice) {
|
1675
|
+
policyTypes += import_transactions7.PolicyType.GasPrice;
|
1676
|
+
policies.push({ data: req.gasPrice, type: import_transactions7.PolicyType.GasPrice });
|
1758
1677
|
}
|
1759
1678
|
if (req.witnessLimit) {
|
1760
|
-
policyTypes +=
|
1761
|
-
policies.push({ data: req.witnessLimit, type:
|
1679
|
+
policyTypes += import_transactions7.PolicyType.WitnessLimit;
|
1680
|
+
policies.push({ data: req.witnessLimit, type: import_transactions7.PolicyType.WitnessLimit });
|
1762
1681
|
}
|
1763
1682
|
if (req.maturity > 0) {
|
1764
|
-
policyTypes +=
|
1765
|
-
policies.push({ data: req.maturity, type:
|
1683
|
+
policyTypes += import_transactions7.PolicyType.Maturity;
|
1684
|
+
policies.push({ data: req.maturity, type: import_transactions7.PolicyType.Maturity });
|
1766
1685
|
}
|
1767
1686
|
if (req.maxFee) {
|
1768
|
-
policyTypes +=
|
1769
|
-
policies.push({ data: req.maxFee, type:
|
1687
|
+
policyTypes += import_transactions7.PolicyType.MaxFee;
|
1688
|
+
policies.push({ data: req.maxFee, type: import_transactions7.PolicyType.MaxFee });
|
1770
1689
|
}
|
1771
1690
|
return {
|
1772
1691
|
policyTypes,
|
@@ -1800,7 +1719,7 @@ var BaseTransactionRequest = class {
|
|
1800
1719
|
* @returns The transaction bytes.
|
1801
1720
|
*/
|
1802
1721
|
toTransactionBytes() {
|
1803
|
-
return new
|
1722
|
+
return new import_transactions7.TransactionCoder().encode(this.toTransaction());
|
1804
1723
|
}
|
1805
1724
|
/**
|
1806
1725
|
* @hidden
|
@@ -1891,7 +1810,7 @@ var BaseTransactionRequest = class {
|
|
1891
1810
|
*/
|
1892
1811
|
getCoinInputs() {
|
1893
1812
|
return this.inputs.filter(
|
1894
|
-
(input) => input.type ===
|
1813
|
+
(input) => input.type === import_transactions7.InputType.Coin
|
1895
1814
|
);
|
1896
1815
|
}
|
1897
1816
|
/**
|
@@ -1901,7 +1820,7 @@ var BaseTransactionRequest = class {
|
|
1901
1820
|
*/
|
1902
1821
|
getCoinOutputs() {
|
1903
1822
|
return this.outputs.filter(
|
1904
|
-
(output) => output.type ===
|
1823
|
+
(output) => output.type === import_transactions7.OutputType.Coin
|
1905
1824
|
);
|
1906
1825
|
}
|
1907
1826
|
/**
|
@@ -1911,7 +1830,7 @@ var BaseTransactionRequest = class {
|
|
1911
1830
|
*/
|
1912
1831
|
getChangeOutputs() {
|
1913
1832
|
return this.outputs.filter(
|
1914
|
-
(output) => output.type ===
|
1833
|
+
(output) => output.type === import_transactions7.OutputType.Change
|
1915
1834
|
);
|
1916
1835
|
}
|
1917
1836
|
/**
|
@@ -1923,9 +1842,9 @@ var BaseTransactionRequest = class {
|
|
1923
1842
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1924
1843
|
const found = this.inputs.find((input) => {
|
1925
1844
|
switch (input.type) {
|
1926
|
-
case
|
1845
|
+
case import_transactions7.InputType.Coin:
|
1927
1846
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1928
|
-
case
|
1847
|
+
case import_transactions7.InputType.Message:
|
1929
1848
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1930
1849
|
default:
|
1931
1850
|
return false;
|
@@ -1938,11 +1857,13 @@ var BaseTransactionRequest = class {
|
|
1938
1857
|
* assetId, if one it was not added yet.
|
1939
1858
|
*
|
1940
1859
|
* @param coin - Coin resource.
|
1860
|
+
* @param predicate - Predicate bytes.
|
1861
|
+
* @param predicateData - Predicate data bytes.
|
1941
1862
|
*/
|
1942
1863
|
addCoinInput(coin) {
|
1943
|
-
const { assetId, owner, amount } = coin;
|
1864
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
1944
1865
|
let witnessIndex;
|
1945
|
-
if (
|
1866
|
+
if (predicate) {
|
1946
1867
|
witnessIndex = 0;
|
1947
1868
|
} else {
|
1948
1869
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1951,13 +1872,14 @@ var BaseTransactionRequest = class {
|
|
1951
1872
|
}
|
1952
1873
|
}
|
1953
1874
|
const input = {
|
1954
|
-
|
1955
|
-
type:
|
1875
|
+
id,
|
1876
|
+
type: import_transactions7.InputType.Coin,
|
1956
1877
|
owner: owner.toB256(),
|
1957
1878
|
amount,
|
1958
1879
|
assetId,
|
1959
1880
|
txPointer: "0x00000000000000000000000000000000",
|
1960
|
-
witnessIndex
|
1881
|
+
witnessIndex,
|
1882
|
+
predicate
|
1961
1883
|
};
|
1962
1884
|
this.pushInput(input);
|
1963
1885
|
this.addChangeOutput(owner, assetId);
|
@@ -1967,12 +1889,14 @@ var BaseTransactionRequest = class {
|
|
1967
1889
|
* baseAssetId, if one it was not added yet.
|
1968
1890
|
*
|
1969
1891
|
* @param message - Message resource.
|
1892
|
+
* @param predicate - Predicate bytes.
|
1893
|
+
* @param predicateData - Predicate data bytes.
|
1970
1894
|
*/
|
1971
1895
|
addMessageInput(message) {
|
1972
|
-
const { recipient, sender, amount } = message;
|
1896
|
+
const { recipient, sender, amount, predicate, nonce } = message;
|
1973
1897
|
const assetId = import_configs7.BaseAssetId;
|
1974
1898
|
let witnessIndex;
|
1975
|
-
if (
|
1899
|
+
if (predicate) {
|
1976
1900
|
witnessIndex = 0;
|
1977
1901
|
} else {
|
1978
1902
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1981,12 +1905,13 @@ var BaseTransactionRequest = class {
|
|
1981
1905
|
}
|
1982
1906
|
}
|
1983
1907
|
const input = {
|
1984
|
-
|
1985
|
-
type:
|
1908
|
+
nonce,
|
1909
|
+
type: import_transactions7.InputType.Message,
|
1986
1910
|
sender: sender.toB256(),
|
1987
1911
|
recipient: recipient.toB256(),
|
1988
1912
|
amount,
|
1989
|
-
witnessIndex
|
1913
|
+
witnessIndex,
|
1914
|
+
predicate
|
1990
1915
|
};
|
1991
1916
|
this.pushInput(input);
|
1992
1917
|
this.addChangeOutput(recipient, assetId);
|
@@ -2026,7 +1951,7 @@ var BaseTransactionRequest = class {
|
|
2026
1951
|
*/
|
2027
1952
|
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
2028
1953
|
this.pushOutput({
|
2029
|
-
type:
|
1954
|
+
type: import_transactions7.OutputType.Coin,
|
2030
1955
|
to: (0, import_address.addressify)(to).toB256(),
|
2031
1956
|
amount,
|
2032
1957
|
assetId
|
@@ -2042,7 +1967,7 @@ var BaseTransactionRequest = class {
|
|
2042
1967
|
addCoinOutputs(to, quantities) {
|
2043
1968
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
2044
1969
|
this.pushOutput({
|
2045
|
-
type:
|
1970
|
+
type: import_transactions7.OutputType.Coin,
|
2046
1971
|
to: (0, import_address.addressify)(to).toB256(),
|
2047
1972
|
amount: quantity.amount,
|
2048
1973
|
assetId: quantity.assetId
|
@@ -2062,7 +1987,7 @@ var BaseTransactionRequest = class {
|
|
2062
1987
|
);
|
2063
1988
|
if (!changeOutput) {
|
2064
1989
|
this.pushOutput({
|
2065
|
-
type:
|
1990
|
+
type: import_transactions7.OutputType.Change,
|
2066
1991
|
to: (0, import_address.addressify)(to).toB256(),
|
2067
1992
|
assetId
|
2068
1993
|
});
|
@@ -2096,7 +2021,7 @@ var BaseTransactionRequest = class {
|
|
2096
2021
|
}
|
2097
2022
|
calculateMaxGas(chainInfo, minGas) {
|
2098
2023
|
const { consensusParameters } = chainInfo;
|
2099
|
-
const { gasPerByte
|
2024
|
+
const { gasPerByte } = consensusParameters;
|
2100
2025
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2101
2026
|
(acc, wit) => acc + wit.dataLength,
|
2102
2027
|
0
|
@@ -2105,8 +2030,7 @@ var BaseTransactionRequest = class {
|
|
2105
2030
|
gasPerByte,
|
2106
2031
|
minGas,
|
2107
2032
|
witnessesLength,
|
2108
|
-
witnessLimit: this.witnessLimit
|
2109
|
-
maxGasPerTx
|
2033
|
+
witnessLimit: this.witnessLimit
|
2110
2034
|
});
|
2111
2035
|
}
|
2112
2036
|
/**
|
@@ -2124,20 +2048,17 @@ var BaseTransactionRequest = class {
|
|
2124
2048
|
});
|
2125
2049
|
const updateAssetInput = (assetId, quantity) => {
|
2126
2050
|
const assetInput = findAssetInput(assetId);
|
2127
|
-
let usedQuantity = quantity;
|
2128
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2129
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2130
|
-
}
|
2131
2051
|
if (assetInput && "assetId" in assetInput) {
|
2132
2052
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2133
|
-
assetInput.amount =
|
2053
|
+
assetInput.amount = quantity;
|
2134
2054
|
} else {
|
2135
2055
|
this.addResources([
|
2136
2056
|
{
|
2137
2057
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2138
|
-
amount:
|
2058
|
+
amount: quantity,
|
2139
2059
|
assetId,
|
2140
2060
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2061
|
+
maturity: 0,
|
2141
2062
|
blockCreated: (0, import_math7.bn)(1),
|
2142
2063
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2143
2064
|
}
|
@@ -2169,16 +2090,20 @@ var BaseTransactionRequest = class {
|
|
2169
2090
|
toJSON() {
|
2170
2091
|
return normalizeJSON(this);
|
2171
2092
|
}
|
2172
|
-
|
2093
|
+
removeWitness(index) {
|
2094
|
+
this.witnesses.splice(index, 1);
|
2095
|
+
this.adjustWitnessIndexes(index);
|
2096
|
+
}
|
2097
|
+
updatePredicateInputs(inputs) {
|
2173
2098
|
this.inputs.forEach((i) => {
|
2174
2099
|
let correspondingInput;
|
2175
2100
|
switch (i.type) {
|
2176
|
-
case
|
2177
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2101
|
+
case import_transactions7.InputType.Coin:
|
2102
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions7.InputType.Coin && x.owner === i.owner);
|
2178
2103
|
break;
|
2179
|
-
case
|
2104
|
+
case import_transactions7.InputType.Message:
|
2180
2105
|
correspondingInput = inputs.find(
|
2181
|
-
(x) => x.type ===
|
2106
|
+
(x) => x.type === import_transactions7.InputType.Message && x.sender === i.sender
|
2182
2107
|
);
|
2183
2108
|
break;
|
2184
2109
|
default:
|
@@ -2191,12 +2116,10 @@ var BaseTransactionRequest = class {
|
|
2191
2116
|
}
|
2192
2117
|
});
|
2193
2118
|
}
|
2194
|
-
|
2195
|
-
this.inputs.forEach((input) => {
|
2196
|
-
if (
|
2197
|
-
input.
|
2198
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2199
|
-
);
|
2119
|
+
adjustWitnessIndexes(removedIndex) {
|
2120
|
+
this.inputs.filter(isRequestInputResource).forEach((input) => {
|
2121
|
+
if (input.witnessIndex > removedIndex) {
|
2122
|
+
input.witnessIndex -= 1;
|
2200
2123
|
}
|
2201
2124
|
});
|
2202
2125
|
}
|
@@ -2205,25 +2128,25 @@ var BaseTransactionRequest = class {
|
|
2205
2128
|
// src/providers/transaction-request/create-transaction-request.ts
|
2206
2129
|
var import_configs9 = require("@fuel-ts/address/configs");
|
2207
2130
|
var import_math9 = require("@fuel-ts/math");
|
2208
|
-
var
|
2131
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2209
2132
|
var import_utils13 = require("@fuel-ts/utils");
|
2210
2133
|
|
2211
2134
|
// src/providers/transaction-request/hash-transaction.ts
|
2212
2135
|
var import_configs8 = require("@fuel-ts/address/configs");
|
2213
2136
|
var import_hasher = require("@fuel-ts/hasher");
|
2214
2137
|
var import_math8 = require("@fuel-ts/math");
|
2215
|
-
var
|
2138
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2216
2139
|
var import_utils11 = require("@fuel-ts/utils");
|
2217
2140
|
var import_ramda2 = require("ramda");
|
2218
2141
|
function hashTransaction(transactionRequest, chainId) {
|
2219
2142
|
const transaction = transactionRequest.toTransaction();
|
2220
|
-
if (transaction.type ===
|
2143
|
+
if (transaction.type === import_transactions8.TransactionType.Script) {
|
2221
2144
|
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2222
2145
|
}
|
2223
2146
|
transaction.inputs = transaction.inputs.map((input) => {
|
2224
2147
|
const inputClone = (0, import_ramda2.clone)(input);
|
2225
2148
|
switch (inputClone.type) {
|
2226
|
-
case
|
2149
|
+
case import_transactions8.InputType.Coin: {
|
2227
2150
|
inputClone.txPointer = {
|
2228
2151
|
blockHeight: 0,
|
2229
2152
|
txIndex: 0
|
@@ -2231,11 +2154,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2231
2154
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2232
2155
|
return inputClone;
|
2233
2156
|
}
|
2234
|
-
case
|
2157
|
+
case import_transactions8.InputType.Message: {
|
2235
2158
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2236
2159
|
return inputClone;
|
2237
2160
|
}
|
2238
|
-
case
|
2161
|
+
case import_transactions8.InputType.Contract: {
|
2239
2162
|
inputClone.txPointer = {
|
2240
2163
|
blockHeight: 0,
|
2241
2164
|
txIndex: 0
|
@@ -2253,16 +2176,16 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2253
2176
|
transaction.outputs = transaction.outputs.map((output) => {
|
2254
2177
|
const outputClone = (0, import_ramda2.clone)(output);
|
2255
2178
|
switch (outputClone.type) {
|
2256
|
-
case
|
2179
|
+
case import_transactions8.OutputType.Contract: {
|
2257
2180
|
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2258
2181
|
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2259
2182
|
return outputClone;
|
2260
2183
|
}
|
2261
|
-
case
|
2184
|
+
case import_transactions8.OutputType.Change: {
|
2262
2185
|
outputClone.amount = (0, import_math8.bn)(0);
|
2263
2186
|
return outputClone;
|
2264
2187
|
}
|
2265
|
-
case
|
2188
|
+
case import_transactions8.OutputType.Variable: {
|
2266
2189
|
outputClone.to = import_configs8.ZeroBytes32;
|
2267
2190
|
outputClone.amount = (0, import_math8.bn)(0);
|
2268
2191
|
outputClone.assetId = import_configs8.ZeroBytes32;
|
@@ -2275,7 +2198,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2275
2198
|
transaction.witnessesCount = 0;
|
2276
2199
|
transaction.witnesses = [];
|
2277
2200
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2278
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2201
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions8.TransactionCoder().encode(transaction)]);
|
2279
2202
|
return (0, import_hasher.sha256)(concatenatedData);
|
2280
2203
|
}
|
2281
2204
|
|
@@ -2311,7 +2234,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2311
2234
|
return new this(obj);
|
2312
2235
|
}
|
2313
2236
|
/** Type of the transaction */
|
2314
|
-
type =
|
2237
|
+
type = import_transactions9.TransactionType.Create;
|
2315
2238
|
/** Witness index of contract bytecode to create */
|
2316
2239
|
bytecodeWitnessIndex;
|
2317
2240
|
/** Salt */
|
@@ -2344,10 +2267,11 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2344
2267
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2345
2268
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2346
2269
|
return {
|
2347
|
-
type:
|
2270
|
+
type: import_transactions9.TransactionType.Create,
|
2348
2271
|
...baseTransaction,
|
2272
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2349
2273
|
bytecodeWitnessIndex,
|
2350
|
-
storageSlotsCount:
|
2274
|
+
storageSlotsCount: storageSlots.length,
|
2351
2275
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2352
2276
|
storageSlots
|
2353
2277
|
};
|
@@ -2359,7 +2283,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2359
2283
|
*/
|
2360
2284
|
getContractCreatedOutputs() {
|
2361
2285
|
return this.outputs.filter(
|
2362
|
-
(output) => output.type ===
|
2286
|
+
(output) => output.type === import_transactions9.OutputType.ContractCreated
|
2363
2287
|
);
|
2364
2288
|
}
|
2365
2289
|
/**
|
@@ -2380,7 +2304,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2380
2304
|
*/
|
2381
2305
|
addContractCreatedOutput(contractId, stateRoot) {
|
2382
2306
|
this.pushOutput({
|
2383
|
-
type:
|
2307
|
+
type: import_transactions9.OutputType.ContractCreated,
|
2384
2308
|
contractId,
|
2385
2309
|
stateRoot
|
2386
2310
|
});
|
@@ -2400,7 +2324,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
2400
2324
|
var import_address2 = require("@fuel-ts/address");
|
2401
2325
|
var import_configs10 = require("@fuel-ts/address/configs");
|
2402
2326
|
var import_math10 = require("@fuel-ts/math");
|
2403
|
-
var
|
2327
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2404
2328
|
var import_utils15 = require("@fuel-ts/utils");
|
2405
2329
|
|
2406
2330
|
// src/providers/transaction-request/scripts.ts
|
@@ -2438,7 +2362,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2438
2362
|
return new this(obj);
|
2439
2363
|
}
|
2440
2364
|
/** Type of the transaction */
|
2441
|
-
type =
|
2365
|
+
type = import_transactions10.TransactionType.Script;
|
2442
2366
|
/** Gas limit for transaction */
|
2443
2367
|
gasLimit;
|
2444
2368
|
/** Script to execute */
|
@@ -2467,11 +2391,11 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2467
2391
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2468
2392
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2469
2393
|
return {
|
2470
|
-
type:
|
2394
|
+
type: import_transactions10.TransactionType.Script,
|
2471
2395
|
scriptGasLimit: this.gasLimit,
|
2472
2396
|
...super.getBaseTransaction(),
|
2473
|
-
scriptLength:
|
2474
|
-
scriptDataLength:
|
2397
|
+
scriptLength: script.length,
|
2398
|
+
scriptDataLength: scriptData.length,
|
2475
2399
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2476
2400
|
script: (0, import_utils15.hexlify)(script),
|
2477
2401
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2484,7 +2408,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2484
2408
|
*/
|
2485
2409
|
getContractInputs() {
|
2486
2410
|
return this.inputs.filter(
|
2487
|
-
(input) => input.type ===
|
2411
|
+
(input) => input.type === import_transactions10.InputType.Contract
|
2488
2412
|
);
|
2489
2413
|
}
|
2490
2414
|
/**
|
@@ -2494,7 +2418,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2494
2418
|
*/
|
2495
2419
|
getContractOutputs() {
|
2496
2420
|
return this.outputs.filter(
|
2497
|
-
(output) => output.type ===
|
2421
|
+
(output) => output.type === import_transactions10.OutputType.Contract
|
2498
2422
|
);
|
2499
2423
|
}
|
2500
2424
|
/**
|
@@ -2504,7 +2428,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2504
2428
|
*/
|
2505
2429
|
getVariableOutputs() {
|
2506
2430
|
return this.outputs.filter(
|
2507
|
-
(output) => output.type ===
|
2431
|
+
(output) => output.type === import_transactions10.OutputType.Variable
|
2508
2432
|
);
|
2509
2433
|
}
|
2510
2434
|
/**
|
@@ -2527,7 +2451,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2527
2451
|
let outputsNumber = numberOfVariables;
|
2528
2452
|
while (outputsNumber) {
|
2529
2453
|
this.pushOutput({
|
2530
|
-
type:
|
2454
|
+
type: import_transactions10.OutputType.Variable
|
2531
2455
|
});
|
2532
2456
|
outputsNumber -= 1;
|
2533
2457
|
}
|
@@ -2535,7 +2459,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2535
2459
|
}
|
2536
2460
|
calculateMaxGas(chainInfo, minGas) {
|
2537
2461
|
const { consensusParameters } = chainInfo;
|
2538
|
-
const { gasPerByte
|
2462
|
+
const { gasPerByte } = consensusParameters;
|
2539
2463
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2540
2464
|
(acc, wit) => acc + wit.dataLength,
|
2541
2465
|
0
|
@@ -2545,8 +2469,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2545
2469
|
minGas,
|
2546
2470
|
witnessesLength,
|
2547
2471
|
witnessLimit: this.witnessLimit,
|
2548
|
-
gasLimit: this.gasLimit
|
2549
|
-
maxGasPerTx
|
2472
|
+
gasLimit: this.gasLimit
|
2550
2473
|
});
|
2551
2474
|
}
|
2552
2475
|
/**
|
@@ -2561,12 +2484,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2561
2484
|
return this;
|
2562
2485
|
}
|
2563
2486
|
const inputIndex = super.pushInput({
|
2564
|
-
type:
|
2487
|
+
type: import_transactions10.InputType.Contract,
|
2565
2488
|
contractId: contractAddress.toB256(),
|
2566
2489
|
txPointer: "0x00000000000000000000000000000000"
|
2567
2490
|
});
|
2568
2491
|
this.pushOutput({
|
2569
|
-
type:
|
2492
|
+
type: import_transactions10.OutputType.Contract,
|
2570
2493
|
inputIndex
|
2571
2494
|
});
|
2572
2495
|
return this;
|
@@ -2603,17 +2526,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2603
2526
|
|
2604
2527
|
// src/providers/transaction-request/utils.ts
|
2605
2528
|
var import_errors9 = require("@fuel-ts/errors");
|
2606
|
-
var
|
2529
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2607
2530
|
var transactionRequestify = (obj) => {
|
2608
2531
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2609
2532
|
return obj;
|
2610
2533
|
}
|
2611
2534
|
const { type } = obj;
|
2612
2535
|
switch (obj.type) {
|
2613
|
-
case
|
2536
|
+
case import_transactions11.TransactionType.Script: {
|
2614
2537
|
return ScriptTransactionRequest.from(obj);
|
2615
2538
|
}
|
2616
|
-
case
|
2539
|
+
case import_transactions11.TransactionType.Create: {
|
2617
2540
|
return CreateTransactionRequest.from(obj);
|
2618
2541
|
}
|
2619
2542
|
default: {
|
@@ -2621,59 +2544,42 @@ var transactionRequestify = (obj) => {
|
|
2621
2544
|
}
|
2622
2545
|
}
|
2623
2546
|
};
|
2624
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2625
|
-
(acc, input) => {
|
2626
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2627
|
-
acc.utxos.push(input.id);
|
2628
|
-
}
|
2629
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2630
|
-
acc.messages.push(input.nonce);
|
2631
|
-
}
|
2632
|
-
return acc;
|
2633
|
-
},
|
2634
|
-
{
|
2635
|
-
utxos: [],
|
2636
|
-
messages: []
|
2637
|
-
}
|
2638
|
-
);
|
2639
2547
|
|
2640
2548
|
// src/providers/transaction-response/transaction-response.ts
|
2641
2549
|
var import_errors13 = require("@fuel-ts/errors");
|
2642
|
-
var
|
2550
|
+
var import_math14 = require("@fuel-ts/math");
|
2643
2551
|
var import_transactions18 = require("@fuel-ts/transactions");
|
2644
|
-
var
|
2552
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2645
2553
|
|
2646
2554
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2647
|
-
var
|
2648
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2649
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2555
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2650
2556
|
|
2651
2557
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2652
2558
|
var import_math11 = require("@fuel-ts/math");
|
2653
|
-
var
|
2559
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2654
2560
|
var import_utils16 = require("@fuel-ts/utils");
|
2655
2561
|
var calculateTransactionFee = (params) => {
|
2656
2562
|
const {
|
2657
|
-
|
2563
|
+
gasUsed,
|
2658
2564
|
rawPayload,
|
2659
|
-
|
2660
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2565
|
+
consensusParameters: { gasCosts, feeParams }
|
2661
2566
|
} = params;
|
2662
2567
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2663
2568
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2664
2569
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2665
|
-
const [transaction] = new
|
2666
|
-
if (transaction.type ===
|
2570
|
+
const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
|
2571
|
+
if (transaction.type === import_transactions12.TransactionType.Mint) {
|
2667
2572
|
return {
|
2668
2573
|
fee: (0, import_math11.bn)(0),
|
2669
2574
|
minFee: (0, import_math11.bn)(0),
|
2670
|
-
maxFee: (0, import_math11.bn)(0)
|
2575
|
+
maxFee: (0, import_math11.bn)(0),
|
2576
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2671
2577
|
};
|
2672
2578
|
}
|
2673
2579
|
const { type, witnesses, inputs, policies } = transaction;
|
2674
2580
|
let metadataGas = (0, import_math11.bn)(0);
|
2675
2581
|
let gasLimit = (0, import_math11.bn)(0);
|
2676
|
-
if (type ===
|
2582
|
+
if (type === import_transactions12.TransactionType.Create) {
|
2677
2583
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2678
2584
|
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2679
2585
|
metadataGas = calculateMetadataGasForTxCreate({
|
@@ -2699,32 +2605,25 @@ var calculateTransactionFee = (params) => {
|
|
2699
2605
|
metadataGas,
|
2700
2606
|
txBytesSize: transactionBytes.length
|
2701
2607
|
});
|
2702
|
-
const
|
2608
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions12.PolicyType.GasPrice)?.data);
|
2609
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions12.PolicyType.WitnessLimit)?.data;
|
2703
2610
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2704
2611
|
const maxGas = getMaxGas({
|
2705
2612
|
gasPerByte,
|
2706
2613
|
minGas,
|
2707
2614
|
witnessesLength,
|
2708
2615
|
gasLimit,
|
2709
|
-
witnessLimit
|
2710
|
-
maxGasPerTx
|
2711
|
-
});
|
2712
|
-
const minFee = calculateGasFee({
|
2713
|
-
gasPrice,
|
2714
|
-
gas: minGas,
|
2715
|
-
priceFactor: gasPriceFactor,
|
2716
|
-
tip
|
2717
|
-
});
|
2718
|
-
const maxFee = calculateGasFee({
|
2719
|
-
gasPrice,
|
2720
|
-
gas: maxGas,
|
2721
|
-
priceFactor: gasPriceFactor,
|
2722
|
-
tip
|
2616
|
+
witnessLimit
|
2723
2617
|
});
|
2618
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2619
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2620
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2621
|
+
const fee = minFee.add(feeFromGasUsed);
|
2724
2622
|
return {
|
2623
|
+
fee,
|
2725
2624
|
minFee,
|
2726
2625
|
maxFee,
|
2727
|
-
|
2626
|
+
feeFromGasUsed
|
2728
2627
|
};
|
2729
2628
|
};
|
2730
2629
|
|
@@ -2732,7 +2631,7 @@ var calculateTransactionFee = (params) => {
|
|
2732
2631
|
var import_configs11 = require("@fuel-ts/address/configs");
|
2733
2632
|
var import_errors11 = require("@fuel-ts/errors");
|
2734
2633
|
var import_math13 = require("@fuel-ts/math");
|
2735
|
-
var
|
2634
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
2736
2635
|
|
2737
2636
|
// src/providers/transaction-summary/call.ts
|
2738
2637
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
@@ -2780,7 +2679,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2780
2679
|
|
2781
2680
|
// src/providers/transaction-summary/input.ts
|
2782
2681
|
var import_errors10 = require("@fuel-ts/errors");
|
2783
|
-
var
|
2682
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2784
2683
|
function getInputsByTypes(inputs, types) {
|
2785
2684
|
return inputs.filter((i) => types.includes(i.type));
|
2786
2685
|
}
|
@@ -2788,16 +2687,16 @@ function getInputsByType(inputs, type) {
|
|
2788
2687
|
return inputs.filter((i) => i.type === type);
|
2789
2688
|
}
|
2790
2689
|
function getInputsCoin(inputs) {
|
2791
|
-
return getInputsByType(inputs,
|
2690
|
+
return getInputsByType(inputs, import_transactions13.InputType.Coin);
|
2792
2691
|
}
|
2793
2692
|
function getInputsMessage(inputs) {
|
2794
|
-
return getInputsByType(inputs,
|
2693
|
+
return getInputsByType(inputs, import_transactions13.InputType.Message);
|
2795
2694
|
}
|
2796
2695
|
function getInputsCoinAndMessage(inputs) {
|
2797
|
-
return getInputsByTypes(inputs, [
|
2696
|
+
return getInputsByTypes(inputs, [import_transactions13.InputType.Coin, import_transactions13.InputType.Message]);
|
2798
2697
|
}
|
2799
2698
|
function getInputsContract(inputs) {
|
2800
|
-
return getInputsByType(inputs,
|
2699
|
+
return getInputsByType(inputs, import_transactions13.InputType.Contract);
|
2801
2700
|
}
|
2802
2701
|
function getInputFromAssetId(inputs, assetId) {
|
2803
2702
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2816,7 +2715,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2816
2715
|
if (!contractInput) {
|
2817
2716
|
return void 0;
|
2818
2717
|
}
|
2819
|
-
if (contractInput.type !==
|
2718
|
+
if (contractInput.type !== import_transactions13.InputType.Contract) {
|
2820
2719
|
throw new import_errors10.FuelError(
|
2821
2720
|
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2822
2721
|
`Contract input should be of type 'contract'.`
|
@@ -2825,31 +2724,31 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2825
2724
|
return contractInput;
|
2826
2725
|
}
|
2827
2726
|
function getInputAccountAddress(input) {
|
2828
|
-
if (input.type ===
|
2727
|
+
if (input.type === import_transactions13.InputType.Coin) {
|
2829
2728
|
return input.owner.toString();
|
2830
2729
|
}
|
2831
|
-
if (input.type ===
|
2730
|
+
if (input.type === import_transactions13.InputType.Message) {
|
2832
2731
|
return input.recipient.toString();
|
2833
2732
|
}
|
2834
2733
|
return "";
|
2835
2734
|
}
|
2836
2735
|
|
2837
2736
|
// src/providers/transaction-summary/output.ts
|
2838
|
-
var
|
2737
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2839
2738
|
function getOutputsByType(outputs, type) {
|
2840
2739
|
return outputs.filter((o) => o.type === type);
|
2841
2740
|
}
|
2842
2741
|
function getOutputsContractCreated(outputs) {
|
2843
|
-
return getOutputsByType(outputs,
|
2742
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.ContractCreated);
|
2844
2743
|
}
|
2845
2744
|
function getOutputsCoin(outputs) {
|
2846
|
-
return getOutputsByType(outputs,
|
2745
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.Coin);
|
2847
2746
|
}
|
2848
2747
|
function getOutputsChange(outputs) {
|
2849
|
-
return getOutputsByType(outputs,
|
2748
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.Change);
|
2850
2749
|
}
|
2851
2750
|
function getOutputsContract(outputs) {
|
2852
|
-
return getOutputsByType(outputs,
|
2751
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.Contract);
|
2853
2752
|
}
|
2854
2753
|
|
2855
2754
|
// src/providers/transaction-summary/operations.ts
|
@@ -2858,11 +2757,11 @@ function getReceiptsByType(receipts, type) {
|
|
2858
2757
|
}
|
2859
2758
|
function getTransactionTypeName(transactionType) {
|
2860
2759
|
switch (transactionType) {
|
2861
|
-
case
|
2760
|
+
case import_transactions15.TransactionType.Mint:
|
2862
2761
|
return "Mint" /* Mint */;
|
2863
|
-
case
|
2762
|
+
case import_transactions15.TransactionType.Create:
|
2864
2763
|
return "Create" /* Create */;
|
2865
|
-
case
|
2764
|
+
case import_transactions15.TransactionType.Script:
|
2866
2765
|
return "Script" /* Script */;
|
2867
2766
|
default:
|
2868
2767
|
throw new import_errors11.FuelError(
|
@@ -2885,10 +2784,10 @@ function isTypeScript(transactionType) {
|
|
2885
2784
|
return isType(transactionType, "Script" /* Script */);
|
2886
2785
|
}
|
2887
2786
|
function getReceiptsCall(receipts) {
|
2888
|
-
return getReceiptsByType(receipts,
|
2787
|
+
return getReceiptsByType(receipts, import_transactions15.ReceiptType.Call);
|
2889
2788
|
}
|
2890
2789
|
function getReceiptsMessageOut(receipts) {
|
2891
|
-
return getReceiptsByType(receipts,
|
2790
|
+
return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
|
2892
2791
|
}
|
2893
2792
|
var mergeAssets = (op1, op2) => {
|
2894
2793
|
const assets1 = op1.assetsSent || [];
|
@@ -3084,11 +2983,11 @@ function getTransferOperations({
|
|
3084
2983
|
});
|
3085
2984
|
const transferReceipts = getReceiptsByType(
|
3086
2985
|
receipts,
|
3087
|
-
|
2986
|
+
import_transactions15.ReceiptType.Transfer
|
3088
2987
|
);
|
3089
2988
|
const transferOutReceipts = getReceiptsByType(
|
3090
2989
|
receipts,
|
3091
|
-
|
2990
|
+
import_transactions15.ReceiptType.TransferOut
|
3092
2991
|
);
|
3093
2992
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3094
2993
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3173,17 +3072,17 @@ function getOperations({
|
|
3173
3072
|
}
|
3174
3073
|
|
3175
3074
|
// src/providers/transaction-summary/receipt.ts
|
3176
|
-
var
|
3075
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3177
3076
|
var processGqlReceipt = (gqlReceipt) => {
|
3178
3077
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3179
3078
|
switch (receipt.type) {
|
3180
|
-
case
|
3079
|
+
case import_transactions16.ReceiptType.ReturnData: {
|
3181
3080
|
return {
|
3182
3081
|
...receipt,
|
3183
3082
|
data: gqlReceipt.data || "0x"
|
3184
3083
|
};
|
3185
3084
|
}
|
3186
|
-
case
|
3085
|
+
case import_transactions16.ReceiptType.LogData: {
|
3187
3086
|
return {
|
3188
3087
|
...receipt,
|
3189
3088
|
data: gqlReceipt.data || "0x"
|
@@ -3196,7 +3095,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3196
3095
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3197
3096
|
const mintedAssets = [];
|
3198
3097
|
receipts.forEach((receipt) => {
|
3199
|
-
if (receipt.type ===
|
3098
|
+
if (receipt.type === import_transactions16.ReceiptType.Mint) {
|
3200
3099
|
mintedAssets.push({
|
3201
3100
|
subId: receipt.subId,
|
3202
3101
|
contractId: receipt.contractId,
|
@@ -3210,7 +3109,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3210
3109
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3211
3110
|
const burnedAssets = [];
|
3212
3111
|
receipts.forEach((receipt) => {
|
3213
|
-
if (receipt.type ===
|
3112
|
+
if (receipt.type === import_transactions16.ReceiptType.Burn) {
|
3214
3113
|
burnedAssets.push({
|
3215
3114
|
subId: receipt.subId,
|
3216
3115
|
contractId: receipt.contractId,
|
@@ -3291,12 +3190,10 @@ function assembleTransactionSummary(params) {
|
|
3291
3190
|
gqlTransactionStatus,
|
3292
3191
|
abiMap = {},
|
3293
3192
|
maxInputs,
|
3294
|
-
gasCosts
|
3295
|
-
maxGasPerTx,
|
3296
|
-
gasPrice
|
3193
|
+
gasCosts
|
3297
3194
|
} = params;
|
3298
3195
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3299
|
-
const rawPayload = (0,
|
3196
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3300
3197
|
const operations = getOperations({
|
3301
3198
|
transactionType: transaction.type,
|
3302
3199
|
inputs: transaction.inputs || [],
|
@@ -3307,14 +3204,11 @@ function assembleTransactionSummary(params) {
|
|
3307
3204
|
maxInputs
|
3308
3205
|
});
|
3309
3206
|
const typeName = getTransactionTypeName(transaction.type);
|
3310
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3311
3207
|
const { fee } = calculateTransactionFee({
|
3312
|
-
|
3208
|
+
gasUsed,
|
3313
3209
|
rawPayload,
|
3314
|
-
tip,
|
3315
3210
|
consensusParameters: {
|
3316
3211
|
gasCosts,
|
3317
|
-
maxGasPerTx,
|
3318
3212
|
feeParams: {
|
3319
3213
|
gasPerByte,
|
3320
3214
|
gasPriceFactor
|
@@ -3326,7 +3220,7 @@ function assembleTransactionSummary(params) {
|
|
3326
3220
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3327
3221
|
let date;
|
3328
3222
|
if (time) {
|
3329
|
-
date =
|
3223
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3330
3224
|
}
|
3331
3225
|
const transactionSummary = {
|
3332
3226
|
id,
|
@@ -3374,7 +3268,7 @@ var TransactionResponse = class {
|
|
3374
3268
|
/** Current provider */
|
3375
3269
|
provider;
|
3376
3270
|
/** Gas used on the transaction */
|
3377
|
-
gasUsed = (0,
|
3271
|
+
gasUsed = (0, import_math14.bn)(0);
|
3378
3272
|
/** The graphql Transaction with receipts object. */
|
3379
3273
|
gqlTransaction;
|
3380
3274
|
abis;
|
@@ -3433,7 +3327,7 @@ var TransactionResponse = class {
|
|
3433
3327
|
*/
|
3434
3328
|
decodeTransaction(transactionWithReceipts) {
|
3435
3329
|
return new import_transactions18.TransactionCoder().decode(
|
3436
|
-
(0,
|
3330
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3437
3331
|
0
|
3438
3332
|
)?.[0];
|
3439
3333
|
}
|
@@ -3452,27 +3346,20 @@ var TransactionResponse = class {
|
|
3452
3346
|
const decodedTransaction = this.decodeTransaction(
|
3453
3347
|
transaction
|
3454
3348
|
);
|
3455
|
-
|
3456
|
-
|
3457
|
-
txReceipts = transaction.status.receipts;
|
3458
|
-
}
|
3459
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3460
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3461
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3349
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3350
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3462
3351
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3463
3352
|
const transactionSummary = assembleTransactionSummary({
|
3464
3353
|
id: this.id,
|
3465
3354
|
receipts,
|
3466
3355
|
transaction: decodedTransaction,
|
3467
|
-
transactionBytes: (0,
|
3356
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3468
3357
|
gqlTransactionStatus: transaction.status,
|
3469
3358
|
gasPerByte,
|
3470
3359
|
gasPriceFactor,
|
3471
3360
|
abiMap: contractsAbiMap,
|
3472
3361
|
maxInputs,
|
3473
|
-
gasCosts
|
3474
|
-
maxGasPerTx,
|
3475
|
-
gasPrice
|
3362
|
+
gasCosts
|
3476
3363
|
});
|
3477
3364
|
return transactionSummary;
|
3478
3365
|
}
|
@@ -3599,29 +3486,29 @@ var processGqlChain = (chain) => {
|
|
3599
3486
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3600
3487
|
return {
|
3601
3488
|
name,
|
3602
|
-
baseChainHeight: (0,
|
3489
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3603
3490
|
consensusParameters: {
|
3604
|
-
contractMaxSize: (0,
|
3605
|
-
maxInputs: (0,
|
3606
|
-
maxOutputs: (0,
|
3607
|
-
maxWitnesses: (0,
|
3608
|
-
maxGasPerTx: (0,
|
3609
|
-
maxScriptLength: (0,
|
3610
|
-
maxScriptDataLength: (0,
|
3611
|
-
maxStorageSlots: (0,
|
3612
|
-
maxPredicateLength: (0,
|
3613
|
-
maxPredicateDataLength: (0,
|
3614
|
-
maxGasPerPredicate: (0,
|
3615
|
-
gasPriceFactor: (0,
|
3616
|
-
gasPerByte: (0,
|
3617
|
-
maxMessageDataLength: (0,
|
3618
|
-
chainId: (0,
|
3491
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3492
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3493
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3494
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3495
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3496
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3497
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3498
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3499
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3500
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3501
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3502
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3503
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3504
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3505
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3619
3506
|
gasCosts
|
3620
3507
|
},
|
3621
3508
|
gasCosts,
|
3622
3509
|
latestBlock: {
|
3623
3510
|
id: latestBlock.id,
|
3624
|
-
height: (0,
|
3511
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3625
3512
|
time: latestBlock.header.time,
|
3626
3513
|
transactions: latestBlock.transactions.map((i) => ({
|
3627
3514
|
id: i.id
|
@@ -3715,8 +3602,10 @@ var _Provider = class {
|
|
3715
3602
|
* Returns some helpful parameters related to gas fees.
|
3716
3603
|
*/
|
3717
3604
|
getGasConfig() {
|
3605
|
+
const { minGasPrice } = this.getNode();
|
3718
3606
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3719
3607
|
return {
|
3608
|
+
minGasPrice,
|
3720
3609
|
maxGasPerTx,
|
3721
3610
|
maxGasPerPredicate,
|
3722
3611
|
gasPriceFactor,
|
@@ -3814,7 +3703,7 @@ var _Provider = class {
|
|
3814
3703
|
*/
|
3815
3704
|
async getBlockNumber() {
|
3816
3705
|
const { chain } = await this.operations.getChain();
|
3817
|
-
return (0,
|
3706
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3818
3707
|
}
|
3819
3708
|
/**
|
3820
3709
|
* Returns the chain information.
|
@@ -3824,11 +3713,13 @@ var _Provider = class {
|
|
3824
3713
|
async fetchNode() {
|
3825
3714
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3826
3715
|
const processedNodeInfo = {
|
3827
|
-
maxDepth: (0,
|
3828
|
-
maxTx: (0,
|
3716
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3717
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3718
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3829
3719
|
nodeVersion: nodeInfo.nodeVersion,
|
3830
3720
|
utxoValidation: nodeInfo.utxoValidation,
|
3831
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3721
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3722
|
+
peers: nodeInfo.peers
|
3832
3723
|
};
|
3833
3724
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3834
3725
|
return processedNodeInfo;
|
@@ -3870,7 +3761,7 @@ var _Provider = class {
|
|
3870
3761
|
if (estimateTxDependencies) {
|
3871
3762
|
await this.estimateTxDependencies(transactionRequest);
|
3872
3763
|
}
|
3873
|
-
const encodedTransaction = (0,
|
3764
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3874
3765
|
let abis;
|
3875
3766
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3876
3767
|
abis = transactionRequest.abis;
|
@@ -3913,14 +3804,15 @@ var _Provider = class {
|
|
3913
3804
|
if (estimateTxDependencies) {
|
3914
3805
|
return this.estimateTxDependencies(transactionRequest);
|
3915
3806
|
}
|
3916
|
-
const encodedTransaction = (0,
|
3917
|
-
const { dryRun:
|
3918
|
-
|
3807
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3808
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3809
|
+
encodedTransaction,
|
3919
3810
|
utxoValidation: utxoValidation || false
|
3920
3811
|
});
|
3921
|
-
const
|
3922
|
-
|
3923
|
-
|
3812
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3813
|
+
return {
|
3814
|
+
receipts
|
3815
|
+
};
|
3924
3816
|
}
|
3925
3817
|
/**
|
3926
3818
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3931,13 +3823,13 @@ var _Provider = class {
|
|
3931
3823
|
async estimatePredicates(transactionRequest) {
|
3932
3824
|
const shouldEstimatePredicates = Boolean(
|
3933
3825
|
transactionRequest.inputs.find(
|
3934
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3826
|
+
(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()
|
3935
3827
|
)
|
3936
3828
|
);
|
3937
3829
|
if (!shouldEstimatePredicates) {
|
3938
3830
|
return transactionRequest;
|
3939
3831
|
}
|
3940
|
-
const encodedTransaction = (0,
|
3832
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3941
3833
|
const response = await this.operations.estimatePredicates({
|
3942
3834
|
encodedTransaction
|
3943
3835
|
});
|
@@ -3946,7 +3838,7 @@ var _Provider = class {
|
|
3946
3838
|
} = response;
|
3947
3839
|
if (inputs) {
|
3948
3840
|
inputs.forEach((input, index) => {
|
3949
|
-
if ("predicateGasUsed" in input && (0,
|
3841
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3950
3842
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3951
3843
|
}
|
3952
3844
|
});
|
@@ -3959,6 +3851,9 @@ var _Provider = class {
|
|
3959
3851
|
* If there are missing variable outputs,
|
3960
3852
|
* `addVariableOutputs` is called on the transaction.
|
3961
3853
|
*
|
3854
|
+
* @privateRemarks
|
3855
|
+
* TODO: Investigate support for missing contract IDs
|
3856
|
+
* TODO: Add support for missing output messages
|
3962
3857
|
*
|
3963
3858
|
* @param transactionRequest - The transaction request object.
|
3964
3859
|
* @returns A promise.
|
@@ -3971,19 +3866,16 @@ var _Provider = class {
|
|
3971
3866
|
missingContractIds: []
|
3972
3867
|
};
|
3973
3868
|
}
|
3869
|
+
await this.estimatePredicates(transactionRequest);
|
3974
3870
|
let receipts = [];
|
3975
3871
|
const missingContractIds = [];
|
3976
3872
|
let outputVariables = 0;
|
3977
|
-
let dryrunStatus;
|
3978
3873
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3979
|
-
const {
|
3980
|
-
|
3981
|
-
} = await this.operations.dryRun({
|
3982
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3874
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3875
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3983
3876
|
utxoValidation: false
|
3984
3877
|
});
|
3985
|
-
receipts =
|
3986
|
-
dryrunStatus = status;
|
3878
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3987
3879
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3988
3880
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3989
3881
|
if (hasMissingOutputs) {
|
@@ -3993,10 +3885,6 @@ var _Provider = class {
|
|
3993
3885
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3994
3886
|
missingContractIds.push(contractId);
|
3995
3887
|
});
|
3996
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3997
|
-
transactionRequest
|
3998
|
-
});
|
3999
|
-
transactionRequest.maxFee = maxFee;
|
4000
3888
|
} else {
|
4001
3889
|
break;
|
4002
3890
|
}
|
@@ -4004,136 +3892,37 @@ var _Provider = class {
|
|
4004
3892
|
return {
|
4005
3893
|
receipts,
|
4006
3894
|
outputVariables,
|
4007
|
-
missingContractIds
|
4008
|
-
dryrunStatus
|
3895
|
+
missingContractIds
|
4009
3896
|
};
|
4010
3897
|
}
|
4011
|
-
/**
|
4012
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4013
|
-
*
|
4014
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4015
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4016
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4017
|
-
*
|
4018
|
-
* @param transactionRequests - Array of transaction request objects.
|
4019
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4020
|
-
*/
|
4021
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4022
|
-
const results = transactionRequests.map(() => ({
|
4023
|
-
receipts: [],
|
4024
|
-
outputVariables: 0,
|
4025
|
-
missingContractIds: [],
|
4026
|
-
dryrunStatus: void 0
|
4027
|
-
}));
|
4028
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4029
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4030
|
-
allRequests.forEach((req, index) => {
|
4031
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4032
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4033
|
-
}
|
4034
|
-
});
|
4035
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4036
|
-
let attempt = 0;
|
4037
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4038
|
-
const encodedTransactions = transactionsToProcess.map(
|
4039
|
-
(index) => serializedTransactionsMap.get(index)
|
4040
|
-
);
|
4041
|
-
const dryRunResults = await this.operations.dryRun({
|
4042
|
-
encodedTransactions,
|
4043
|
-
utxoValidation: false
|
4044
|
-
});
|
4045
|
-
const nextRoundTransactions = [];
|
4046
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4047
|
-
const requestIdx = transactionsToProcess[i];
|
4048
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4049
|
-
const result = results[requestIdx];
|
4050
|
-
result.receipts = rawReceipts.map(processGqlReceipt);
|
4051
|
-
result.dryrunStatus = status;
|
4052
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4053
|
-
result.receipts
|
4054
|
-
);
|
4055
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4056
|
-
const request = allRequests[requestIdx];
|
4057
|
-
if (hasMissingOutputs && request?.type === import_transactions19.TransactionType.Script) {
|
4058
|
-
result.outputVariables += missingOutputVariables.length;
|
4059
|
-
request.addVariableOutputs(missingOutputVariables.length);
|
4060
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4061
|
-
request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4062
|
-
result.missingContractIds.push(contractId);
|
4063
|
-
});
|
4064
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4065
|
-
transactionRequest: request
|
4066
|
-
});
|
4067
|
-
request.maxFee = maxFee;
|
4068
|
-
serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
|
4069
|
-
nextRoundTransactions.push(requestIdx);
|
4070
|
-
}
|
4071
|
-
}
|
4072
|
-
transactionsToProcess = nextRoundTransactions;
|
4073
|
-
attempt += 1;
|
4074
|
-
}
|
4075
|
-
return results;
|
4076
|
-
}
|
4077
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4078
|
-
if (estimateTxDependencies) {
|
4079
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4080
|
-
}
|
4081
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4082
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4083
|
-
encodedTransactions,
|
4084
|
-
utxoValidation: utxoValidation || false
|
4085
|
-
});
|
4086
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4087
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4088
|
-
return { receipts, dryrunStatus: status };
|
4089
|
-
});
|
4090
|
-
return results;
|
4091
|
-
}
|
4092
3898
|
/**
|
4093
3899
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4094
3900
|
* @param transactionRequest - The transaction request object.
|
4095
3901
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4096
3902
|
*/
|
4097
|
-
|
3903
|
+
estimateTxGasAndFee(params) {
|
4098
3904
|
const { transactionRequest } = params;
|
4099
|
-
|
3905
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4100
3906
|
const chainInfo = this.getChain();
|
4101
|
-
const
|
3907
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3908
|
+
transactionRequest.gasPrice = gasPrice;
|
4102
3909
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4103
|
-
|
4104
|
-
gasPrice = await this.estimateGasPrice(10);
|
4105
|
-
}
|
4106
|
-
const minFee = calculateGasFee({
|
4107
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4108
|
-
gas: minGas,
|
4109
|
-
priceFactor: gasPriceFactor,
|
4110
|
-
tip: transactionRequest.tip
|
4111
|
-
}).add(1);
|
4112
|
-
let gasLimit = (0, import_math16.bn)(0);
|
3910
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4113
3911
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4114
|
-
gasLimit = transactionRequest.gasLimit;
|
4115
3912
|
if (transactionRequest.gasLimit.eq(0)) {
|
4116
3913
|
transactionRequest.gasLimit = minGas;
|
4117
3914
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4118
3915
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4119
3916
|
);
|
4120
|
-
gasLimit = transactionRequest.gasLimit;
|
4121
3917
|
}
|
4122
3918
|
}
|
4123
3919
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4124
|
-
const maxFee =
|
4125
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4126
|
-
gas: maxGas,
|
4127
|
-
priceFactor: gasPriceFactor,
|
4128
|
-
tip: transactionRequest.tip
|
4129
|
-
}).add(1);
|
3920
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4130
3921
|
return {
|
4131
3922
|
minGas,
|
4132
3923
|
minFee,
|
4133
3924
|
maxGas,
|
4134
|
-
maxFee
|
4135
|
-
gasPrice,
|
4136
|
-
gasLimit
|
3925
|
+
maxFee
|
4137
3926
|
};
|
4138
3927
|
}
|
4139
3928
|
/**
|
@@ -4151,17 +3940,15 @@ var _Provider = class {
|
|
4151
3940
|
if (estimateTxDependencies) {
|
4152
3941
|
return this.estimateTxDependencies(transactionRequest);
|
4153
3942
|
}
|
4154
|
-
const
|
4155
|
-
const { dryRun:
|
4156
|
-
|
3943
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3944
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3945
|
+
encodedTransaction,
|
4157
3946
|
utxoValidation: true
|
4158
3947
|
});
|
4159
|
-
const
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
});
|
4164
|
-
return { receipts: callResult[0].receipts };
|
3948
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3949
|
+
return {
|
3950
|
+
receipts
|
3951
|
+
};
|
4165
3952
|
}
|
4166
3953
|
/**
|
4167
3954
|
* Returns a transaction cost to enable user
|
@@ -4178,79 +3965,77 @@ var _Provider = class {
|
|
4178
3965
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4179
3966
|
* @returns A promise that resolves to the transaction cost object.
|
4180
3967
|
*/
|
4181
|
-
async getTransactionCost(transactionRequestLike,
|
3968
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3969
|
+
estimateTxDependencies = true,
|
3970
|
+
estimatePredicates = true,
|
3971
|
+
resourcesOwner,
|
3972
|
+
signatureCallback
|
3973
|
+
} = {}) {
|
4182
3974
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3975
|
+
const { minGasPrice } = this.getGasConfig();
|
3976
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4183
3977
|
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4184
3978
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4185
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3979
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4186
3980
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4187
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4188
3981
|
if (isScriptTransaction) {
|
4189
|
-
txRequestClone.gasLimit = (0,
|
3982
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4190
3983
|
}
|
4191
|
-
if (
|
4192
|
-
resourcesOwner
|
3984
|
+
if (estimatePredicates) {
|
3985
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3986
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3987
|
+
}
|
3988
|
+
await this.estimatePredicates(txRequestClone);
|
4193
3989
|
}
|
4194
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4195
|
-
let addedSignatures = 0;
|
4196
3990
|
if (signatureCallback && isScriptTransaction) {
|
4197
|
-
|
4198
|
-
await signatureCallback(signedRequest);
|
4199
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3991
|
+
await signatureCallback(txRequestClone);
|
4200
3992
|
}
|
4201
|
-
|
4202
|
-
|
4203
|
-
transactionRequest: signedRequest
|
3993
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3994
|
+
transactionRequest: txRequestClone
|
4204
3995
|
});
|
4205
3996
|
let receipts = [];
|
4206
3997
|
let missingContractIds = [];
|
4207
3998
|
let outputVariables = 0;
|
4208
|
-
let gasUsed = (0,
|
4209
|
-
|
4210
|
-
|
4211
|
-
if (isScriptTransaction) {
|
4212
|
-
txRequestClone.gasLimit = gasLimit;
|
4213
|
-
if (signatureCallback) {
|
4214
|
-
await signatureCallback(txRequestClone);
|
4215
|
-
}
|
3999
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4000
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4001
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4216
4002
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4217
4003
|
receipts = result.receipts;
|
4218
4004
|
outputVariables = result.outputVariables;
|
4219
4005
|
missingContractIds = result.missingContractIds;
|
4220
4006
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4221
4007
|
txRequestClone.gasLimit = gasUsed;
|
4222
|
-
|
4223
|
-
|
4224
|
-
|
4008
|
+
txRequestClone.gasPrice = setGasPrice;
|
4009
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4010
|
+
transactionRequest: txRequestClone
|
4225
4011
|
}));
|
4226
4012
|
}
|
4227
4013
|
return {
|
4228
4014
|
requiredQuantities: allQuantities,
|
4229
4015
|
receipts,
|
4230
4016
|
gasUsed,
|
4231
|
-
|
4017
|
+
minGasPrice,
|
4018
|
+
gasPrice: setGasPrice,
|
4232
4019
|
minGas,
|
4233
4020
|
maxGas,
|
4234
4021
|
minFee,
|
4235
4022
|
maxFee,
|
4023
|
+
estimatedInputs: txRequestClone.inputs,
|
4236
4024
|
outputVariables,
|
4237
|
-
missingContractIds
|
4238
|
-
addedSignatures,
|
4239
|
-
estimatedPredicates: txRequestClone.inputs
|
4025
|
+
missingContractIds
|
4240
4026
|
};
|
4241
4027
|
}
|
4242
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4028
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4243
4029
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4244
4030
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4245
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4246
|
-
quantitiesToContract
|
4247
|
-
});
|
4031
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4248
4032
|
transactionRequest.addResources(
|
4249
4033
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4250
4034
|
);
|
4251
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4252
|
-
|
4253
|
-
|
4035
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4036
|
+
transactionRequest,
|
4037
|
+
forwardingQuantities
|
4038
|
+
);
|
4254
4039
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4255
4040
|
return {
|
4256
4041
|
resources,
|
@@ -4266,16 +4051,17 @@ var _Provider = class {
|
|
4266
4051
|
const result = await this.operations.getCoins({
|
4267
4052
|
first: 10,
|
4268
4053
|
...paginationArgs,
|
4269
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4054
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4270
4055
|
});
|
4271
4056
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4272
4057
|
return coins.map((coin) => ({
|
4273
4058
|
id: coin.utxoId,
|
4274
4059
|
assetId: coin.assetId,
|
4275
|
-
amount: (0,
|
4060
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4276
4061
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4277
|
-
|
4278
|
-
|
4062
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4063
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4064
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4279
4065
|
}));
|
4280
4066
|
}
|
4281
4067
|
/**
|
@@ -4289,19 +4075,19 @@ var _Provider = class {
|
|
4289
4075
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4290
4076
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4291
4077
|
const excludeInput = {
|
4292
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4293
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4078
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4079
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4294
4080
|
};
|
4295
4081
|
if (this.cache) {
|
4296
4082
|
const uniqueUtxos = new Set(
|
4297
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4083
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4298
4084
|
);
|
4299
4085
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4300
4086
|
}
|
4301
4087
|
const coinsQuery = {
|
4302
4088
|
owner: ownerAddress.toB256(),
|
4303
4089
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4304
|
-
assetId: (0,
|
4090
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4305
4091
|
amount: amount.toString(10),
|
4306
4092
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4307
4093
|
})),
|
@@ -4312,9 +4098,9 @@ var _Provider = class {
|
|
4312
4098
|
switch (coin.__typename) {
|
4313
4099
|
case "MessageCoin":
|
4314
4100
|
return {
|
4315
|
-
amount: (0,
|
4101
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4316
4102
|
assetId: coin.assetId,
|
4317
|
-
daHeight: (0,
|
4103
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4318
4104
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4319
4105
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4320
4106
|
nonce: coin.nonce
|
@@ -4322,11 +4108,12 @@ var _Provider = class {
|
|
4322
4108
|
case "Coin":
|
4323
4109
|
return {
|
4324
4110
|
id: coin.utxoId,
|
4325
|
-
amount: (0,
|
4111
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4326
4112
|
assetId: coin.assetId,
|
4327
4113
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4328
|
-
|
4329
|
-
|
4114
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4115
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4116
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4330
4117
|
};
|
4331
4118
|
default:
|
4332
4119
|
return null;
|
@@ -4343,13 +4130,13 @@ var _Provider = class {
|
|
4343
4130
|
async getBlock(idOrHeight) {
|
4344
4131
|
let variables;
|
4345
4132
|
if (typeof idOrHeight === "number") {
|
4346
|
-
variables = { height: (0,
|
4133
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4347
4134
|
} else if (idOrHeight === "latest") {
|
4348
4135
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4349
4136
|
} else if (idOrHeight.length === 66) {
|
4350
4137
|
variables = { blockId: idOrHeight };
|
4351
4138
|
} else {
|
4352
|
-
variables = { blockId: (0,
|
4139
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4353
4140
|
}
|
4354
4141
|
const { block } = await this.operations.getBlock(variables);
|
4355
4142
|
if (!block) {
|
@@ -4357,7 +4144,7 @@ var _Provider = class {
|
|
4357
4144
|
}
|
4358
4145
|
return {
|
4359
4146
|
id: block.id,
|
4360
|
-
height: (0,
|
4147
|
+
height: (0, import_math15.bn)(block.header.height),
|
4361
4148
|
time: block.header.time,
|
4362
4149
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4363
4150
|
};
|
@@ -4372,7 +4159,7 @@ var _Provider = class {
|
|
4372
4159
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4373
4160
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4374
4161
|
id: block.id,
|
4375
|
-
height: (0,
|
4162
|
+
height: (0, import_math15.bn)(block.header.height),
|
4376
4163
|
time: block.header.time,
|
4377
4164
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4378
4165
|
}));
|
@@ -4387,7 +4174,7 @@ var _Provider = class {
|
|
4387
4174
|
async getBlockWithTransactions(idOrHeight) {
|
4388
4175
|
let variables;
|
4389
4176
|
if (typeof idOrHeight === "number") {
|
4390
|
-
variables = { blockHeight: (0,
|
4177
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4391
4178
|
} else if (idOrHeight === "latest") {
|
4392
4179
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4393
4180
|
} else {
|
@@ -4399,11 +4186,11 @@ var _Provider = class {
|
|
4399
4186
|
}
|
4400
4187
|
return {
|
4401
4188
|
id: block.id,
|
4402
|
-
height: (0,
|
4189
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4403
4190
|
time: block.header.time,
|
4404
4191
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4405
4192
|
transactions: block.transactions.map(
|
4406
|
-
(tx) => new import_transactions19.TransactionCoder().decode((0,
|
4193
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4407
4194
|
)
|
4408
4195
|
};
|
4409
4196
|
}
|
@@ -4419,7 +4206,7 @@ var _Provider = class {
|
|
4419
4206
|
return null;
|
4420
4207
|
}
|
4421
4208
|
return new import_transactions19.TransactionCoder().decode(
|
4422
|
-
(0,
|
4209
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4423
4210
|
0
|
4424
4211
|
)?.[0];
|
4425
4212
|
}
|
@@ -4446,9 +4233,9 @@ var _Provider = class {
|
|
4446
4233
|
async getContractBalance(contractId, assetId) {
|
4447
4234
|
const { contractBalance } = await this.operations.getContractBalance({
|
4448
4235
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4449
|
-
asset: (0,
|
4236
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4450
4237
|
});
|
4451
|
-
return (0,
|
4238
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4452
4239
|
}
|
4453
4240
|
/**
|
4454
4241
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4460,9 +4247,9 @@ var _Provider = class {
|
|
4460
4247
|
async getBalance(owner, assetId) {
|
4461
4248
|
const { balance } = await this.operations.getBalance({
|
4462
4249
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4463
|
-
assetId: (0,
|
4250
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4464
4251
|
});
|
4465
|
-
return (0,
|
4252
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4466
4253
|
}
|
4467
4254
|
/**
|
4468
4255
|
* Returns balances for the given owner.
|
@@ -4480,7 +4267,7 @@ var _Provider = class {
|
|
4480
4267
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4481
4268
|
return balances.map((balance) => ({
|
4482
4269
|
assetId: balance.assetId,
|
4483
|
-
amount: (0,
|
4270
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4484
4271
|
}));
|
4485
4272
|
}
|
4486
4273
|
/**
|
@@ -4502,15 +4289,15 @@ var _Provider = class {
|
|
4502
4289
|
sender: message.sender,
|
4503
4290
|
recipient: message.recipient,
|
4504
4291
|
nonce: message.nonce,
|
4505
|
-
amount: (0,
|
4292
|
+
amount: (0, import_math15.bn)(message.amount),
|
4506
4293
|
data: message.data
|
4507
4294
|
}),
|
4508
4295
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4509
4296
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4510
4297
|
nonce: message.nonce,
|
4511
|
-
amount: (0,
|
4298
|
+
amount: (0, import_math15.bn)(message.amount),
|
4512
4299
|
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4513
|
-
daHeight: (0,
|
4300
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4514
4301
|
}));
|
4515
4302
|
}
|
4516
4303
|
/**
|
@@ -4563,60 +4350,44 @@ var _Provider = class {
|
|
4563
4350
|
} = result.messageProof;
|
4564
4351
|
return {
|
4565
4352
|
messageProof: {
|
4566
|
-
proofIndex: (0,
|
4353
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4567
4354
|
proofSet: messageProof.proofSet
|
4568
4355
|
},
|
4569
4356
|
blockProof: {
|
4570
|
-
proofIndex: (0,
|
4357
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4571
4358
|
proofSet: blockProof.proofSet
|
4572
4359
|
},
|
4573
4360
|
messageBlockHeader: {
|
4574
4361
|
id: messageBlockHeader.id,
|
4575
|
-
daHeight: (0,
|
4576
|
-
transactionsCount: (0,
|
4362
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4363
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4577
4364
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4578
|
-
height: (0,
|
4365
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4579
4366
|
prevRoot: messageBlockHeader.prevRoot,
|
4580
4367
|
time: messageBlockHeader.time,
|
4581
4368
|
applicationHash: messageBlockHeader.applicationHash,
|
4582
|
-
|
4583
|
-
|
4584
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4585
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4586
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4369
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4370
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4587
4371
|
},
|
4588
4372
|
commitBlockHeader: {
|
4589
4373
|
id: commitBlockHeader.id,
|
4590
|
-
daHeight: (0,
|
4591
|
-
transactionsCount: (0,
|
4374
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4375
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4592
4376
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4593
|
-
height: (0,
|
4377
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4594
4378
|
prevRoot: commitBlockHeader.prevRoot,
|
4595
4379
|
time: commitBlockHeader.time,
|
4596
4380
|
applicationHash: commitBlockHeader.applicationHash,
|
4597
|
-
|
4598
|
-
|
4599
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4600
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4601
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4381
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4382
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4602
4383
|
},
|
4603
4384
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4604
4385
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4605
4386
|
nonce,
|
4606
|
-
amount: (0,
|
4387
|
+
amount: (0, import_math15.bn)(amount),
|
4607
4388
|
data
|
4608
4389
|
};
|
4609
4390
|
}
|
4610
|
-
async getLatestGasPrice() {
|
4611
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4612
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4613
|
-
}
|
4614
|
-
async estimateGasPrice(blockHorizon) {
|
4615
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4616
|
-
blockHorizon: String(blockHorizon)
|
4617
|
-
});
|
4618
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4619
|
-
}
|
4620
4391
|
/**
|
4621
4392
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4622
4393
|
*
|
@@ -4636,10 +4407,10 @@ var _Provider = class {
|
|
4636
4407
|
*/
|
4637
4408
|
async produceBlocks(amount, startTime) {
|
4638
4409
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4639
|
-
blocksToProduce: (0,
|
4640
|
-
startTimestamp: startTime ?
|
4410
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4411
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4641
4412
|
});
|
4642
|
-
return (0,
|
4413
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4643
4414
|
}
|
4644
4415
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4645
4416
|
async getTransactionResponse(transactionId) {
|
@@ -4663,9 +4434,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4663
4434
|
|
4664
4435
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4665
4436
|
var import_errors15 = require("@fuel-ts/errors");
|
4666
|
-
var
|
4437
|
+
var import_math16 = require("@fuel-ts/math");
|
4667
4438
|
var import_transactions20 = require("@fuel-ts/transactions");
|
4668
|
-
var
|
4439
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4669
4440
|
|
4670
4441
|
// src/providers/chains.ts
|
4671
4442
|
var CHAIN_IDS = {
|
@@ -4714,17 +4485,17 @@ var assets = [
|
|
4714
4485
|
|
4715
4486
|
// src/utils/formatTransferToContractScriptData.ts
|
4716
4487
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4717
|
-
var
|
4718
|
-
var
|
4488
|
+
var import_math17 = require("@fuel-ts/math");
|
4489
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4719
4490
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4720
4491
|
var formatTransferToContractScriptData = (params) => {
|
4721
4492
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4722
4493
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4723
|
-
const encoded = numberCoder.encode(new
|
4494
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4724
4495
|
const scriptData = Uint8Array.from([
|
4725
|
-
...(0,
|
4496
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4726
4497
|
...encoded,
|
4727
|
-
...(0,
|
4498
|
+
...(0, import_utils27.arrayify)(assetId)
|
4728
4499
|
]);
|
4729
4500
|
return scriptData;
|
4730
4501
|
};
|
@@ -4909,30 +4680,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4909
4680
|
* @param fee - The estimated transaction fee.
|
4910
4681
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4911
4682
|
*/
|
4912
|
-
async fund(request,
|
4913
|
-
const
|
4914
|
-
|
4915
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4916
|
-
amount: (0, import_math19.bn)(fee),
|
4683
|
+
async fund(request, coinQuantities, fee) {
|
4684
|
+
const updatedQuantities = addAmountToAsset({
|
4685
|
+
amount: (0, import_math18.bn)(fee),
|
4917
4686
|
assetId: import_configs12.BaseAssetId,
|
4918
|
-
coinQuantities
|
4687
|
+
coinQuantities
|
4919
4688
|
});
|
4920
4689
|
const quantitiesDict = {};
|
4921
|
-
|
4690
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4922
4691
|
quantitiesDict[assetId] = {
|
4923
4692
|
required: amount,
|
4924
|
-
owned: (0,
|
4693
|
+
owned: (0, import_math18.bn)(0)
|
4925
4694
|
};
|
4926
4695
|
});
|
4927
|
-
|
4696
|
+
const cachedUtxos = [];
|
4697
|
+
const cachedMessages = [];
|
4698
|
+
const owner = this.address.toB256();
|
4699
|
+
request.inputs.forEach((input) => {
|
4928
4700
|
const isResource = "amount" in input;
|
4929
|
-
if (
|
4930
|
-
|
4931
|
-
|
4932
|
-
|
4933
|
-
|
4934
|
-
|
4935
|
-
|
4701
|
+
if (isResource) {
|
4702
|
+
const isCoin2 = "owner" in input;
|
4703
|
+
if (isCoin2) {
|
4704
|
+
const assetId = String(input.assetId);
|
4705
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4706
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4707
|
+
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4708
|
+
cachedUtxos.push(input.id);
|
4709
|
+
}
|
4710
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4711
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4712
|
+
cachedMessages.push(input.nonce);
|
4713
|
+
}
|
4936
4714
|
}
|
4937
4715
|
});
|
4938
4716
|
const missingQuantities = [];
|
@@ -4946,21 +4724,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4946
4724
|
});
|
4947
4725
|
const needsToBeFunded = missingQuantities.length;
|
4948
4726
|
if (needsToBeFunded) {
|
4949
|
-
const
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
const requestToReestimate = (0, import_ramda4.clone)(txRequest);
|
4956
|
-
if (addedSignatures) {
|
4957
|
-
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
4958
|
-
}
|
4959
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4960
|
-
transactionRequest: requestToReestimate
|
4961
|
-
});
|
4962
|
-
txRequest.maxFee = maxFee;
|
4963
|
-
return txRequest;
|
4727
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4728
|
+
messages: cachedMessages,
|
4729
|
+
utxos: cachedUtxos
|
4730
|
+
});
|
4731
|
+
request.addResources(resources);
|
4732
|
+
}
|
4964
4733
|
}
|
4965
4734
|
/**
|
4966
4735
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4968,24 +4737,28 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4968
4737
|
* @param destination - The address of the destination.
|
4969
4738
|
* @param amount - The amount of coins to transfer.
|
4970
4739
|
* @param assetId - The asset ID of the coins to transfer.
|
4971
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4740
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4972
4741
|
* @returns A promise that resolves to the prepared transaction request.
|
4973
4742
|
*/
|
4974
4743
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4975
|
-
const
|
4744
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4745
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4746
|
+
const request = new ScriptTransactionRequest(params);
|
4976
4747
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4977
|
-
const
|
4748
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4978
4749
|
estimateTxDependencies: true,
|
4979
4750
|
resourcesOwner: this
|
4980
4751
|
});
|
4981
|
-
|
4982
|
-
|
4983
|
-
|
4984
|
-
|
4752
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4753
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4754
|
+
this.validateGas({
|
4755
|
+
gasUsed,
|
4756
|
+
gasPrice: request.gasPrice,
|
4757
|
+
gasLimit: request.gasLimit,
|
4758
|
+
minGasPrice
|
4985
4759
|
});
|
4986
|
-
request
|
4987
|
-
request.
|
4988
|
-
await this.fund(request, txCost);
|
4760
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4761
|
+
request.updatePredicateInputs(estimatedInputs);
|
4989
4762
|
return request;
|
4990
4763
|
}
|
4991
4764
|
/**
|
@@ -4994,11 +4767,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4994
4767
|
* @param destination - The address of the destination.
|
4995
4768
|
* @param amount - The amount of coins to transfer.
|
4996
4769
|
* @param assetId - The asset ID of the coins to transfer.
|
4997
|
-
* @param txParams - The transaction parameters (gasLimit, maturity).
|
4770
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4998
4771
|
* @returns A promise that resolves to the transaction response.
|
4999
4772
|
*/
|
5000
4773
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5001
|
-
if ((0,
|
4774
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5002
4775
|
throw new import_errors16.FuelError(
|
5003
4776
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5004
4777
|
"Transfer amount must be a positive number."
|
@@ -5017,36 +4790,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5017
4790
|
* @returns A promise that resolves to the transaction response.
|
5018
4791
|
*/
|
5019
4792
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5020
|
-
if ((0,
|
4793
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5021
4794
|
throw new import_errors16.FuelError(
|
5022
4795
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5023
4796
|
"Transfer amount must be a positive number."
|
5024
4797
|
);
|
5025
4798
|
}
|
5026
4799
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4800
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4801
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5027
4802
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5028
4803
|
hexlifiedContractId: contractAddress.toB256(),
|
5029
|
-
amountToTransfer: (0,
|
4804
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5030
4805
|
assetId
|
5031
4806
|
});
|
5032
4807
|
const request = new ScriptTransactionRequest({
|
5033
|
-
...
|
4808
|
+
...params,
|
5034
4809
|
script,
|
5035
4810
|
scriptData
|
5036
4811
|
});
|
5037
4812
|
request.addContractInputAndOutput(contractAddress);
|
5038
|
-
const
|
5039
|
-
|
5040
|
-
|
5041
|
-
|
5042
|
-
|
5043
|
-
|
5044
|
-
|
5045
|
-
|
4813
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4814
|
+
request,
|
4815
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4816
|
+
);
|
4817
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4818
|
+
this.validateGas({
|
4819
|
+
gasUsed,
|
4820
|
+
gasPrice: request.gasPrice,
|
4821
|
+
gasLimit: request.gasLimit,
|
4822
|
+
minGasPrice
|
5046
4823
|
});
|
5047
|
-
request
|
5048
|
-
request.maxFee = txCost.maxFee;
|
5049
|
-
await this.fund(request, txCost);
|
4824
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5050
4825
|
return this.sendTransaction(request);
|
5051
4826
|
}
|
5052
4827
|
/**
|
@@ -5058,30 +4833,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5058
4833
|
* @returns A promise that resolves to the transaction response.
|
5059
4834
|
*/
|
5060
4835
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4836
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5061
4837
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5062
|
-
const recipientDataArray = (0,
|
4838
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5063
4839
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5064
4840
|
);
|
5065
|
-
const amountDataArray = (0,
|
5066
|
-
"0x".concat((0,
|
4841
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4842
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5067
4843
|
);
|
5068
4844
|
const script = new Uint8Array([
|
5069
|
-
...(0,
|
4845
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5070
4846
|
...recipientDataArray,
|
5071
4847
|
...amountDataArray
|
5072
4848
|
]);
|
5073
|
-
const params = { script, ...txParams };
|
4849
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5074
4850
|
const request = new ScriptTransactionRequest(params);
|
5075
|
-
const
|
5076
|
-
const
|
5077
|
-
|
5078
|
-
|
5079
|
-
|
5080
|
-
|
4851
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4852
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4853
|
+
request,
|
4854
|
+
forwardingQuantities
|
4855
|
+
);
|
4856
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4857
|
+
this.validateGas({
|
4858
|
+
gasUsed,
|
4859
|
+
gasPrice: request.gasPrice,
|
4860
|
+
gasLimit: request.gasLimit,
|
4861
|
+
minGasPrice
|
5081
4862
|
});
|
5082
|
-
request
|
5083
|
-
request.gasLimit = txCost.gasUsed;
|
5084
|
-
await this.fund(request, txCost);
|
4863
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5085
4864
|
return this.sendTransaction(request);
|
5086
4865
|
}
|
5087
4866
|
async signMessage(message) {
|
@@ -5139,21 +4918,22 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5139
4918
|
}
|
5140
4919
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5141
4920
|
}
|
5142
|
-
|
5143
|
-
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
4921
|
+
validateGas({
|
5144
4922
|
gasUsed,
|
5145
|
-
|
4923
|
+
gasPrice,
|
4924
|
+
gasLimit,
|
4925
|
+
minGasPrice
|
5146
4926
|
}) {
|
5147
|
-
if (
|
4927
|
+
if (minGasPrice.gt(gasPrice)) {
|
5148
4928
|
throw new import_errors16.FuelError(
|
5149
|
-
import_errors16.ErrorCode.
|
5150
|
-
`Gas
|
4929
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4930
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5151
4931
|
);
|
5152
4932
|
}
|
5153
|
-
if (
|
4933
|
+
if (gasUsed.gt(gasLimit)) {
|
5154
4934
|
throw new import_errors16.FuelError(
|
5155
|
-
import_errors16.ErrorCode.
|
5156
|
-
`
|
4935
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
4936
|
+
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5157
4937
|
);
|
5158
4938
|
}
|
5159
4939
|
}
|
@@ -5163,8 +4943,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5163
4943
|
var import_address5 = require("@fuel-ts/address");
|
5164
4944
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5165
4945
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5166
|
-
var
|
5167
|
-
var
|
4946
|
+
var import_math19 = require("@fuel-ts/math");
|
4947
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5168
4948
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5169
4949
|
var Signer = class {
|
5170
4950
|
address;
|
@@ -5183,10 +4963,10 @@ var Signer = class {
|
|
5183
4963
|
privateKey = `0x${privateKey}`;
|
5184
4964
|
}
|
5185
4965
|
}
|
5186
|
-
const privateKeyBytes = (0,
|
5187
|
-
this.privateKey = (0,
|
5188
|
-
this.publicKey = (0,
|
5189
|
-
this.compressedPublicKey = (0,
|
4966
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4967
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4968
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4969
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5190
4970
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5191
4971
|
}
|
5192
4972
|
/**
|
@@ -5200,11 +4980,11 @@ var Signer = class {
|
|
5200
4980
|
* @returns hashed signature
|
5201
4981
|
*/
|
5202
4982
|
sign(data) {
|
5203
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5204
|
-
const r = (0,
|
5205
|
-
const s = (0,
|
4983
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4984
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4985
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5206
4986
|
s[0] |= (signature.recovery || 0) << 7;
|
5207
|
-
return (0,
|
4987
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5208
4988
|
}
|
5209
4989
|
/**
|
5210
4990
|
* Add point on the current elliptic curve
|
@@ -5213,8 +4993,8 @@ var Signer = class {
|
|
5213
4993
|
* @returns compressed point on the curve
|
5214
4994
|
*/
|
5215
4995
|
addPoint(point) {
|
5216
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5217
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4996
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4997
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5218
4998
|
const result = p0.add(p1);
|
5219
4999
|
return `0x${result.toHex(true)}`;
|
5220
5000
|
}
|
@@ -5226,16 +5006,16 @@ var Signer = class {
|
|
5226
5006
|
* @returns public key from signature from the
|
5227
5007
|
*/
|
5228
5008
|
static recoverPublicKey(data, signature) {
|
5229
|
-
const signedMessageBytes = (0,
|
5009
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5230
5010
|
const r = signedMessageBytes.slice(0, 32);
|
5231
5011
|
const s = signedMessageBytes.slice(32, 64);
|
5232
5012
|
const recoveryParam = (s[0] & 128) >> 7;
|
5233
5013
|
s[0] &= 127;
|
5234
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5014
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5235
5015
|
recoveryParam
|
5236
5016
|
);
|
5237
|
-
const publicKey = sig.recoverPublicKey((0,
|
5238
|
-
return (0,
|
5017
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5018
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5239
5019
|
}
|
5240
5020
|
/**
|
5241
5021
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5254,7 +5034,7 @@ var Signer = class {
|
|
5254
5034
|
* @returns random 32-byte hashed
|
5255
5035
|
*/
|
5256
5036
|
static generatePrivateKey(entropy) {
|
5257
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5037
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5258
5038
|
}
|
5259
5039
|
/**
|
5260
5040
|
* Extended publicKey from a compact publicKey
|
@@ -5263,8 +5043,8 @@ var Signer = class {
|
|
5263
5043
|
* @returns extended publicKey
|
5264
5044
|
*/
|
5265
5045
|
static extendPublicKey(publicKey) {
|
5266
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5267
|
-
return (0,
|
5046
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5047
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5268
5048
|
}
|
5269
5049
|
};
|
5270
5050
|
|
@@ -5272,7 +5052,7 @@ var Signer = class {
|
|
5272
5052
|
var import_address6 = require("@fuel-ts/address");
|
5273
5053
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5274
5054
|
var import_errors17 = require("@fuel-ts/errors");
|
5275
|
-
var
|
5055
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5276
5056
|
var import_uuid = require("uuid");
|
5277
5057
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5278
5058
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5355,7 +5135,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5355
5135
|
);
|
5356
5136
|
}
|
5357
5137
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5358
|
-
const privateKey = (0,
|
5138
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5359
5139
|
return privateKey;
|
5360
5140
|
}
|
5361
5141
|
|
@@ -5400,7 +5180,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5400
5180
|
*/
|
5401
5181
|
async signMessage(message) {
|
5402
5182
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5403
|
-
return (0,
|
5183
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5404
5184
|
}
|
5405
5185
|
/**
|
5406
5186
|
* Signs a transaction with the wallet's private key.
|
@@ -5413,7 +5193,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5413
5193
|
const chainId = this.provider.getChainId();
|
5414
5194
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5415
5195
|
const signature = await this.signer().sign(hashedTransaction);
|
5416
|
-
return (0,
|
5196
|
+
return (0, import_utils31.hexlify)(signature);
|
5417
5197
|
}
|
5418
5198
|
/**
|
5419
5199
|
* Populates a transaction with the witnesses signature.
|
@@ -5433,7 +5213,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5433
5213
|
* @param transactionRequestLike - The transaction request to send.
|
5434
5214
|
* @returns A promise that resolves to the TransactionResponse object.
|
5435
5215
|
*/
|
5436
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5216
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5437
5217
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5438
5218
|
if (estimateTxDependencies) {
|
5439
5219
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5474,15 +5254,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5474
5254
|
// src/hdwallet/hdwallet.ts
|
5475
5255
|
var import_errors20 = require("@fuel-ts/errors");
|
5476
5256
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5477
|
-
var
|
5478
|
-
var
|
5257
|
+
var import_math20 = require("@fuel-ts/math");
|
5258
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5479
5259
|
var import_ethers3 = require("ethers");
|
5480
5260
|
|
5481
5261
|
// src/mnemonic/mnemonic.ts
|
5482
5262
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5483
5263
|
var import_errors19 = require("@fuel-ts/errors");
|
5484
5264
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5485
|
-
var
|
5265
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5486
5266
|
var import_ethers2 = require("ethers");
|
5487
5267
|
|
5488
5268
|
// src/wordlists/words/english.ts
|
@@ -7540,7 +7320,7 @@ var english = [
|
|
7540
7320
|
// src/mnemonic/utils.ts
|
7541
7321
|
var import_errors18 = require("@fuel-ts/errors");
|
7542
7322
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7543
|
-
var
|
7323
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7544
7324
|
function toUtf8Bytes(stri) {
|
7545
7325
|
const str = stri.normalize("NFKD");
|
7546
7326
|
const result = [];
|
@@ -7607,14 +7387,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7607
7387
|
}
|
7608
7388
|
}
|
7609
7389
|
const checksumBits = entropy.length / 4;
|
7610
|
-
const checksum = (0,
|
7390
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7611
7391
|
indices[indices.length - 1] <<= checksumBits;
|
7612
7392
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7613
7393
|
return indices;
|
7614
7394
|
}
|
7615
7395
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7616
7396
|
const size = Math.ceil(11 * words.length / 8);
|
7617
|
-
const entropy = (0,
|
7397
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7618
7398
|
let offset = 0;
|
7619
7399
|
for (let i = 0; i < words.length; i += 1) {
|
7620
7400
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7634,7 +7414,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7634
7414
|
const entropyBits = 32 * words.length / 3;
|
7635
7415
|
const checksumBits = words.length / 3;
|
7636
7416
|
const checksumMask = getUpperMask(checksumBits);
|
7637
|
-
const checksum = (0,
|
7417
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7638
7418
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7639
7419
|
throw new import_errors18.FuelError(
|
7640
7420
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7709,7 +7489,7 @@ var Mnemonic = class {
|
|
7709
7489
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7710
7490
|
const words = getWords(phrase);
|
7711
7491
|
assertMnemonic(words);
|
7712
|
-
return (0,
|
7492
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7713
7493
|
}
|
7714
7494
|
/**
|
7715
7495
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7717,7 +7497,7 @@ var Mnemonic = class {
|
|
7717
7497
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7718
7498
|
*/
|
7719
7499
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7720
|
-
const entropyBytes = (0,
|
7500
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7721
7501
|
assertWordList(wordlist);
|
7722
7502
|
assertEntropy(entropyBytes);
|
7723
7503
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7786,14 +7566,14 @@ var Mnemonic = class {
|
|
7786
7566
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7787
7567
|
*/
|
7788
7568
|
static masterKeysFromSeed(seed) {
|
7789
|
-
const seedArray = (0,
|
7569
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7790
7570
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7791
7571
|
throw new import_errors19.FuelError(
|
7792
7572
|
import_errors19.ErrorCode.INVALID_SEED,
|
7793
7573
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7794
7574
|
);
|
7795
7575
|
}
|
7796
|
-
return (0,
|
7576
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7797
7577
|
}
|
7798
7578
|
/**
|
7799
7579
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7804,22 +7584,22 @@ var Mnemonic = class {
|
|
7804
7584
|
*/
|
7805
7585
|
static seedToExtendedKey(seed, testnet = false) {
|
7806
7586
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7807
|
-
const prefix = (0,
|
7587
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7808
7588
|
const depth = "0x00";
|
7809
7589
|
const fingerprint = "0x00000000";
|
7810
7590
|
const index = "0x00000000";
|
7811
7591
|
const chainCode = masterKey.slice(32);
|
7812
7592
|
const privateKey = masterKey.slice(0, 32);
|
7813
|
-
const extendedKey = (0,
|
7593
|
+
const extendedKey = (0, import_utils33.concat)([
|
7814
7594
|
prefix,
|
7815
7595
|
depth,
|
7816
7596
|
fingerprint,
|
7817
7597
|
index,
|
7818
7598
|
chainCode,
|
7819
|
-
(0,
|
7599
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7820
7600
|
]);
|
7821
7601
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7822
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7602
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7823
7603
|
}
|
7824
7604
|
/**
|
7825
7605
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7834,7 +7614,7 @@ var Mnemonic = class {
|
|
7834
7614
|
* @returns A randomly generated mnemonic
|
7835
7615
|
*/
|
7836
7616
|
static generate(size = 32, extraEntropy = "") {
|
7837
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7617
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7838
7618
|
return Mnemonic.entropyToMnemonic(entropy);
|
7839
7619
|
}
|
7840
7620
|
};
|
@@ -7842,12 +7622,12 @@ var mnemonic_default = Mnemonic;
|
|
7842
7622
|
|
7843
7623
|
// src/hdwallet/hdwallet.ts
|
7844
7624
|
var HARDENED_INDEX = 2147483648;
|
7845
|
-
var MainnetPRV2 = (0,
|
7846
|
-
var MainnetPUB = (0,
|
7847
|
-
var TestnetPRV2 = (0,
|
7848
|
-
var TestnetPUB = (0,
|
7625
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7626
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7627
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7628
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7849
7629
|
function base58check(data) {
|
7850
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7630
|
+
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)]));
|
7851
7631
|
}
|
7852
7632
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7853
7633
|
if (isPublic) {
|
@@ -7856,11 +7636,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7856
7636
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7857
7637
|
}
|
7858
7638
|
function isPublicExtendedKey(extendedKey) {
|
7859
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7639
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7860
7640
|
}
|
7861
7641
|
function isValidExtendedKey(extendedKey) {
|
7862
7642
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7863
|
-
(0,
|
7643
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7864
7644
|
);
|
7865
7645
|
}
|
7866
7646
|
function parsePath(path2, depth = 0) {
|
@@ -7878,8 +7658,8 @@ function parsePath(path2, depth = 0) {
|
|
7878
7658
|
var HDWallet = class {
|
7879
7659
|
depth = 0;
|
7880
7660
|
index = 0;
|
7881
|
-
fingerprint = (0,
|
7882
|
-
parentFingerprint = (0,
|
7661
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7662
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7883
7663
|
privateKey;
|
7884
7664
|
publicKey;
|
7885
7665
|
chainCode;
|
@@ -7891,8 +7671,8 @@ var HDWallet = class {
|
|
7891
7671
|
constructor(config) {
|
7892
7672
|
if (config.privateKey) {
|
7893
7673
|
const signer = new Signer(config.privateKey);
|
7894
|
-
this.publicKey = (0,
|
7895
|
-
this.privateKey = (0,
|
7674
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7675
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7896
7676
|
} else {
|
7897
7677
|
if (!config.publicKey) {
|
7898
7678
|
throw new import_errors20.FuelError(
|
@@ -7900,7 +7680,7 @@ var HDWallet = class {
|
|
7900
7680
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7901
7681
|
);
|
7902
7682
|
}
|
7903
|
-
this.publicKey = (0,
|
7683
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7904
7684
|
}
|
7905
7685
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7906
7686
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7919,9 +7699,9 @@ var HDWallet = class {
|
|
7919
7699
|
* @returns A new instance of HDWallet on the derived index
|
7920
7700
|
*/
|
7921
7701
|
deriveIndex(index) {
|
7922
|
-
const privateKey = this.privateKey && (0,
|
7923
|
-
const publicKey = (0,
|
7924
|
-
const chainCode = (0,
|
7702
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7703
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7704
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7925
7705
|
const data = new Uint8Array(37);
|
7926
7706
|
if (index & HARDENED_INDEX) {
|
7927
7707
|
if (!privateKey) {
|
@@ -7932,15 +7712,15 @@ var HDWallet = class {
|
|
7932
7712
|
}
|
7933
7713
|
data.set(privateKey, 1);
|
7934
7714
|
} else {
|
7935
|
-
data.set((0,
|
7715
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7936
7716
|
}
|
7937
|
-
data.set((0,
|
7938
|
-
const bytes = (0,
|
7717
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7718
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7939
7719
|
const IL = bytes.slice(0, 32);
|
7940
7720
|
const IR = bytes.slice(32);
|
7941
7721
|
if (privateKey) {
|
7942
7722
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7943
|
-
const ki = (0,
|
7723
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7944
7724
|
return new HDWallet({
|
7945
7725
|
privateKey: ki,
|
7946
7726
|
chainCode: IR,
|
@@ -7949,7 +7729,7 @@ var HDWallet = class {
|
|
7949
7729
|
parentFingerprint: this.fingerprint
|
7950
7730
|
});
|
7951
7731
|
}
|
7952
|
-
const signer = new Signer((0,
|
7732
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7953
7733
|
const Ki = signer.addPoint(publicKey);
|
7954
7734
|
return new HDWallet({
|
7955
7735
|
publicKey: Ki,
|
@@ -7984,12 +7764,12 @@ var HDWallet = class {
|
|
7984
7764
|
);
|
7985
7765
|
}
|
7986
7766
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7987
|
-
const depth = (0,
|
7767
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7988
7768
|
const parentFingerprint = this.parentFingerprint;
|
7989
|
-
const index = (0,
|
7769
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7990
7770
|
const chainCode = this.chainCode;
|
7991
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7992
|
-
const extendedKey = (0,
|
7771
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7772
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7993
7773
|
return base58check(extendedKey);
|
7994
7774
|
}
|
7995
7775
|
/**
|
@@ -8001,13 +7781,13 @@ var HDWallet = class {
|
|
8001
7781
|
static fromSeed(seed) {
|
8002
7782
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8003
7783
|
return new HDWallet({
|
8004
|
-
chainCode: (0,
|
8005
|
-
privateKey: (0,
|
7784
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7785
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8006
7786
|
});
|
8007
7787
|
}
|
8008
7788
|
static fromExtendedKey(extendedKey) {
|
8009
7789
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8010
|
-
const bytes = (0,
|
7790
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8011
7791
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8012
7792
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8013
7793
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8016,9 +7796,9 @@ var HDWallet = class {
|
|
8016
7796
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8017
7797
|
}
|
8018
7798
|
const depth = bytes[4];
|
8019
|
-
const parentFingerprint = (0,
|
8020
|
-
const index = parseInt((0,
|
8021
|
-
const chainCode = (0,
|
7799
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7800
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7801
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8022
7802
|
const key = bytes.slice(45, 78);
|
8023
7803
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8024
7804
|
throw new import_errors20.FuelError(
|
@@ -8206,20 +7986,26 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8206
7986
|
|
8207
7987
|
// src/test-utils/seedTestWallet.ts
|
8208
7988
|
var import_crypto5 = require("@fuel-ts/crypto");
|
8209
|
-
var seedTestWallet = async (wallet, quantities) => {
|
7989
|
+
var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
|
7990
|
+
const toFundAccounts = Array.isArray(wallet) ? wallet : [wallet];
|
8210
7991
|
const genesisWallet = new WalletUnlocked(
|
8211
7992
|
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
8212
|
-
|
7993
|
+
toFundAccounts[0].provider
|
8213
7994
|
);
|
8214
|
-
const
|
8215
|
-
|
8216
|
-
|
8217
|
-
|
7995
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7996
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7997
|
+
const request = new ScriptTransactionRequest({
|
7998
|
+
gasLimit: 1e4,
|
7999
|
+
gasPrice: minGasPrice
|
8218
8000
|
});
|
8219
|
-
|
8220
|
-
|
8221
|
-
|
8222
|
-
|
8001
|
+
request.addResources(resources);
|
8002
|
+
quantities.map(coinQuantityfy).forEach(
|
8003
|
+
({ amount, assetId }) => toFundAccounts.forEach(({ address }) => {
|
8004
|
+
for (let i = 0; i < utxosAmount; i++) {
|
8005
|
+
request.addCoinOutput(address, amount.div(utxosAmount), assetId);
|
8006
|
+
}
|
8007
|
+
})
|
8008
|
+
);
|
8223
8009
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8224
8010
|
};
|
8225
8011
|
|
@@ -8233,13 +8019,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8233
8019
|
};
|
8234
8020
|
|
8235
8021
|
// src/test-utils/launchNode.ts
|
8236
|
-
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8237
8022
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8238
|
-
var
|
8239
|
-
var
|
8023
|
+
var import_math21 = require("@fuel-ts/math");
|
8024
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8240
8025
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8241
8026
|
var import_child_process = require("child_process");
|
8242
|
-
var
|
8027
|
+
var import_crypto6 = require("crypto");
|
8243
8028
|
var import_fs = require("fs");
|
8244
8029
|
var import_os = __toESM(require("os"));
|
8245
8030
|
var import_path = __toESM(require("path"));
|
@@ -8288,13 +8073,13 @@ var launchNode = async ({
|
|
8288
8073
|
// eslint-disable-next-line no-async-promise-executor
|
8289
8074
|
new Promise(async (resolve, reject) => {
|
8290
8075
|
const remainingArgs = extractRemainingArgs(args, [
|
8291
|
-
"--
|
8076
|
+
"--chain",
|
8292
8077
|
"--consensus-key",
|
8293
8078
|
"--db-type",
|
8294
8079
|
"--poa-instant"
|
8295
8080
|
]);
|
8296
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8297
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8081
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8082
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8298
8083
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8299
8084
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8300
8085
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8311,55 +8096,37 @@ var launchNode = async ({
|
|
8311
8096
|
})).toString();
|
8312
8097
|
let chainConfigPathToUse;
|
8313
8098
|
const prefix = basePath || import_os.default.tmpdir();
|
8314
|
-
const suffix = basePath ? "" : (0,
|
8315
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix
|
8099
|
+
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8100
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8316
8101
|
if (chainConfigPath) {
|
8317
8102
|
chainConfigPathToUse = chainConfigPath;
|
8318
8103
|
} else {
|
8319
8104
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8320
8105
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8321
8106
|
}
|
8322
|
-
|
8323
|
-
|
8324
|
-
stateConfigJson = {
|
8325
|
-
...stateConfigJson,
|
8326
|
-
coins: [
|
8327
|
-
...stateConfigJson.coins.map((coin) => ({
|
8328
|
-
...coin,
|
8329
|
-
amount: "18446744073709551615"
|
8330
|
-
}))
|
8331
|
-
],
|
8332
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8333
|
-
...message,
|
8334
|
-
amount: "18446744073709551615"
|
8335
|
-
}))
|
8336
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8337
|
-
};
|
8107
|
+
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8108
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8338
8109
|
if (!process.env.GENESIS_SECRET) {
|
8339
8110
|
const pk = Signer.generatePrivateKey();
|
8340
8111
|
const signer = new Signer(pk);
|
8341
|
-
process.env.GENESIS_SECRET = (0,
|
8342
|
-
|
8343
|
-
|
8344
|
-
|
8345
|
-
|
8346
|
-
|
8347
|
-
|
8348
|
-
|
8349
|
-
|
8350
|
-
|
8351
|
-
|
8112
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8113
|
+
chainConfig = {
|
8114
|
+
...import_utils36.defaultChainConfig,
|
8115
|
+
initial_state: {
|
8116
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8117
|
+
coins: [
|
8118
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8119
|
+
{
|
8120
|
+
owner: signer.address.toHexString(),
|
8121
|
+
amount: (0, import_math21.toHex)(1e9),
|
8122
|
+
asset_id: import_configs13.BaseAssetId
|
8123
|
+
}
|
8124
|
+
]
|
8125
|
+
}
|
8126
|
+
};
|
8352
8127
|
}
|
8353
|
-
|
8354
|
-
|
8355
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8356
|
-
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8357
|
-
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8358
|
-
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8359
|
-
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8360
|
-
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8361
|
-
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8362
|
-
chainConfigPathToUse = tempDirPath;
|
8128
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8129
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8363
8130
|
}
|
8364
8131
|
const child = (0, import_child_process.spawn)(
|
8365
8132
|
command,
|
@@ -8368,10 +8135,10 @@ var launchNode = async ({
|
|
8368
8135
|
["--ip", ipToUse],
|
8369
8136
|
["--port", portToUse],
|
8370
8137
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8371
|
-
["--min-gas-price", "
|
8138
|
+
["--min-gas-price", "0"],
|
8372
8139
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8373
8140
|
["--consensus-key", consensusKey],
|
8374
|
-
["--
|
8141
|
+
["--chain", chainConfigPathToUse],
|
8375
8142
|
"--vm-backtrace",
|
8376
8143
|
"--utxo-validation",
|
8377
8144
|
"--debug",
|
@@ -8430,15 +8197,52 @@ var launchNodeAndGetWallets = async ({
|
|
8430
8197
|
walletCount = 10
|
8431
8198
|
} = {}) => {
|
8432
8199
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8433
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8200
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8434
8201
|
const wallets = await generateWallets(walletCount, provider);
|
8435
8202
|
const cleanup = () => {
|
8436
8203
|
closeNode();
|
8437
8204
|
};
|
8438
8205
|
return { wallets, stop: cleanup, provider };
|
8439
8206
|
};
|
8207
|
+
|
8208
|
+
// src/test-utils/transactionRequest.ts
|
8209
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8210
|
+
var import_address7 = require("@fuel-ts/address");
|
8211
|
+
var import_configs14 = require("@fuel-ts/address/configs");
|
8212
|
+
var import_crypto7 = require("@fuel-ts/crypto");
|
8213
|
+
var import_math22 = require("@fuel-ts/math");
|
8214
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
8215
|
+
var import_utils37 = require("@fuel-ts/utils");
|
8216
|
+
var generateFakeRequestInputCoin = (partial = {}) => ({
|
8217
|
+
id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8218
|
+
type: import_transactions21.InputType.Coin,
|
8219
|
+
owner: (0, import_address7.getRandomB256)(),
|
8220
|
+
amount: (0, import_math22.bn)(100),
|
8221
|
+
assetId: import_configs14.ZeroBytes32,
|
8222
|
+
txPointer: "0x00000000000000000000000000000000",
|
8223
|
+
witnessIndex: 0,
|
8224
|
+
...partial
|
8225
|
+
});
|
8226
|
+
var generateFakeRequestInputMessage = (partial = {}) => ({
|
8227
|
+
nonce: (0, import_address7.getRandomB256)(),
|
8228
|
+
type: import_transactions21.InputType.Message,
|
8229
|
+
sender: (0, import_address7.getRandomB256)(),
|
8230
|
+
recipient: (0, import_address7.getRandomB256)(),
|
8231
|
+
amount: (0, import_math22.bn)(100),
|
8232
|
+
witnessIndex: 0,
|
8233
|
+
...partial
|
8234
|
+
});
|
8235
|
+
var generateFakeRequestInputContract = (partial = {}) => ({
|
8236
|
+
contractId: (0, import_address7.getRandomB256)(),
|
8237
|
+
type: import_transactions21.InputType.Contract,
|
8238
|
+
txPointer: "0x00000000000000000000000000000000",
|
8239
|
+
...partial
|
8240
|
+
});
|
8440
8241
|
// Annotate the CommonJS export names for ESM import in node:
|
8441
8242
|
0 && (module.exports = {
|
8243
|
+
generateFakeRequestInputCoin,
|
8244
|
+
generateFakeRequestInputContract,
|
8245
|
+
generateFakeRequestInputMessage,
|
8442
8246
|
generateTestWallet,
|
8443
8247
|
killNode,
|
8444
8248
|
launchNode,
|