@fuel-ts/account 0.81.0 → 0.83.0
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 +3 -3
- package/dist/account.d.ts +7 -6
- 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 +890 -619
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +853 -604
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +696 -448
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +12 -24
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +810 -359
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +44 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +13 -33
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/providers/utils/merge-quantities.d.ts +1 -1
- package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1615 -1114
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +841 -596
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +696 -451
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -29,37 +29,36 @@ var __privateMethod = (obj, member, method) => {
|
|
29
29
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
32
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
34
33
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
|
-
import { bn as
|
36
|
-
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
34
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
35
|
+
import { arrayify as arrayify14, isDefined } from "@fuel-ts/utils";
|
36
|
+
import { clone as clone4 } from "ramda";
|
37
37
|
|
38
38
|
// src/providers/coin-quantity.ts
|
39
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
40
39
|
import { bn } from "@fuel-ts/math";
|
41
40
|
import { hexlify } from "@fuel-ts/utils";
|
42
41
|
var coinQuantityfy = (coinQuantityLike) => {
|
43
42
|
let assetId;
|
44
43
|
let amount;
|
45
|
-
let
|
44
|
+
let max;
|
46
45
|
if (Array.isArray(coinQuantityLike)) {
|
47
46
|
amount = coinQuantityLike[0];
|
48
|
-
assetId = coinQuantityLike[1]
|
49
|
-
|
47
|
+
assetId = coinQuantityLike[1];
|
48
|
+
max = coinQuantityLike[2] ?? void 0;
|
50
49
|
} else {
|
51
50
|
amount = coinQuantityLike.amount;
|
52
|
-
assetId = coinQuantityLike.assetId
|
53
|
-
|
51
|
+
assetId = coinQuantityLike.assetId;
|
52
|
+
max = coinQuantityLike.max ?? void 0;
|
54
53
|
}
|
55
54
|
const bnAmount = bn(amount);
|
56
55
|
return {
|
57
56
|
assetId: hexlify(assetId),
|
58
57
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
59
|
-
max:
|
58
|
+
max: max ? bn(max) : void 0
|
60
59
|
};
|
61
60
|
};
|
62
|
-
var
|
61
|
+
var addAmountToCoinQuantities = (params) => {
|
63
62
|
const { amount, assetId } = params;
|
64
63
|
const coinQuantities = [...params.coinQuantities];
|
65
64
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -74,9 +73,9 @@ var addAmountToAsset = (params) => {
|
|
74
73
|
// src/providers/provider.ts
|
75
74
|
import { Address as Address2 } from "@fuel-ts/address";
|
76
75
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
77
|
-
import { BN, bn as
|
76
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
78
77
|
import {
|
79
|
-
InputType as
|
78
|
+
InputType as InputType7,
|
80
79
|
TransactionType as TransactionType8,
|
81
80
|
InputMessageCoder,
|
82
81
|
TransactionCoder as TransactionCoder5
|
@@ -90,16 +89,20 @@ import { clone as clone3 } from "ramda";
|
|
90
89
|
|
91
90
|
// src/providers/__generated__/operations.ts
|
92
91
|
import gql from "graphql-tag";
|
92
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
93
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
94
|
+
type: __typename
|
95
|
+
... on SqueezedOutStatus {
|
96
|
+
reason
|
97
|
+
}
|
98
|
+
}
|
99
|
+
`;
|
93
100
|
var ReceiptFragmentFragmentDoc = gql`
|
94
101
|
fragment receiptFragment on Receipt {
|
95
|
-
|
96
|
-
id
|
97
|
-
}
|
102
|
+
id
|
98
103
|
pc
|
99
104
|
is
|
100
|
-
to
|
101
|
-
id
|
102
|
-
}
|
105
|
+
to
|
103
106
|
toAddress
|
104
107
|
amount
|
105
108
|
assetId
|
@@ -137,10 +140,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
137
140
|
id
|
138
141
|
}
|
139
142
|
time
|
143
|
+
receipts {
|
144
|
+
...receiptFragment
|
145
|
+
}
|
140
146
|
programState {
|
141
147
|
returnType
|
142
148
|
data
|
143
149
|
}
|
150
|
+
receipts {
|
151
|
+
...receiptFragment
|
152
|
+
}
|
144
153
|
}
|
145
154
|
... on FailureStatus {
|
146
155
|
block {
|
@@ -148,26 +157,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
148
157
|
}
|
149
158
|
time
|
150
159
|
reason
|
160
|
+
receipts {
|
161
|
+
...receiptFragment
|
162
|
+
}
|
151
163
|
}
|
152
164
|
... on SqueezedOutStatus {
|
153
165
|
reason
|
154
166
|
}
|
155
167
|
}
|
156
|
-
`;
|
168
|
+
${ReceiptFragmentFragmentDoc}`;
|
157
169
|
var TransactionFragmentFragmentDoc = gql`
|
158
170
|
fragment transactionFragment on Transaction {
|
159
171
|
id
|
160
172
|
rawPayload
|
161
|
-
gasPrice
|
162
|
-
receipts {
|
163
|
-
...receiptFragment
|
164
|
-
}
|
165
173
|
status {
|
166
174
|
...transactionStatusFragment
|
167
175
|
}
|
168
176
|
}
|
169
|
-
${
|
170
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
177
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
171
178
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
172
179
|
fragment inputEstimatePredicatesFragment on Input {
|
173
180
|
... on InputCoin {
|
@@ -185,6 +192,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
185
192
|
}
|
186
193
|
}
|
187
194
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
195
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
196
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
197
|
+
reason
|
198
|
+
programState {
|
199
|
+
returnType
|
200
|
+
data
|
201
|
+
}
|
202
|
+
}
|
203
|
+
`;
|
204
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
205
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
206
|
+
programState {
|
207
|
+
returnType
|
208
|
+
data
|
209
|
+
}
|
210
|
+
}
|
211
|
+
`;
|
212
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
213
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
214
|
+
... on DryRunFailureStatus {
|
215
|
+
...dryRunFailureStatusFragment
|
216
|
+
}
|
217
|
+
... on DryRunSuccessStatus {
|
218
|
+
...dryRunSuccessStatusFragment
|
219
|
+
}
|
220
|
+
}
|
221
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
222
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
223
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
224
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
225
|
+
id
|
226
|
+
status {
|
227
|
+
...dryRunTransactionStatusFragment
|
228
|
+
}
|
229
|
+
receipts {
|
230
|
+
...receiptFragment
|
231
|
+
}
|
232
|
+
}
|
233
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
234
|
+
${ReceiptFragmentFragmentDoc}`;
|
188
235
|
var CoinFragmentFragmentDoc = gql`
|
189
236
|
fragment coinFragment on Coin {
|
190
237
|
__typename
|
@@ -192,7 +239,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
192
239
|
owner
|
193
240
|
amount
|
194
241
|
assetId
|
195
|
-
maturity
|
196
242
|
blockCreated
|
197
243
|
txCreatedIdx
|
198
244
|
}
|
@@ -231,26 +277,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
231
277
|
messageBlockHeader {
|
232
278
|
id
|
233
279
|
daHeight
|
280
|
+
consensusParametersVersion
|
281
|
+
stateTransitionBytecodeVersion
|
234
282
|
transactionsCount
|
283
|
+
messageReceiptCount
|
235
284
|
transactionsRoot
|
285
|
+
messageOutboxRoot
|
286
|
+
eventInboxRoot
|
236
287
|
height
|
237
288
|
prevRoot
|
238
289
|
time
|
239
290
|
applicationHash
|
240
|
-
messageReceiptRoot
|
241
|
-
messageReceiptCount
|
242
291
|
}
|
243
292
|
commitBlockHeader {
|
244
293
|
id
|
245
294
|
daHeight
|
295
|
+
consensusParametersVersion
|
296
|
+
stateTransitionBytecodeVersion
|
246
297
|
transactionsCount
|
298
|
+
messageReceiptCount
|
247
299
|
transactionsRoot
|
300
|
+
messageOutboxRoot
|
301
|
+
eventInboxRoot
|
248
302
|
height
|
249
303
|
prevRoot
|
250
304
|
time
|
251
305
|
applicationHash
|
252
|
-
messageReceiptRoot
|
253
|
-
messageReceiptCount
|
254
306
|
}
|
255
307
|
sender
|
256
308
|
recipient
|
@@ -269,8 +321,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
269
321
|
var BlockFragmentFragmentDoc = gql`
|
270
322
|
fragment blockFragment on Block {
|
271
323
|
id
|
324
|
+
height
|
272
325
|
header {
|
273
|
-
height
|
274
326
|
time
|
275
327
|
}
|
276
328
|
transactions {
|
@@ -280,6 +332,7 @@ var BlockFragmentFragmentDoc = gql`
|
|
280
332
|
`;
|
281
333
|
var TxParametersFragmentFragmentDoc = gql`
|
282
334
|
fragment TxParametersFragment on TxParameters {
|
335
|
+
version
|
283
336
|
maxInputs
|
284
337
|
maxOutputs
|
285
338
|
maxWitnesses
|
@@ -289,6 +342,7 @@ var TxParametersFragmentFragmentDoc = gql`
|
|
289
342
|
`;
|
290
343
|
var PredicateParametersFragmentFragmentDoc = gql`
|
291
344
|
fragment PredicateParametersFragment on PredicateParameters {
|
345
|
+
version
|
292
346
|
maxPredicateLength
|
293
347
|
maxPredicateDataLength
|
294
348
|
maxGasPerPredicate
|
@@ -297,18 +351,21 @@ var PredicateParametersFragmentFragmentDoc = gql`
|
|
297
351
|
`;
|
298
352
|
var ScriptParametersFragmentFragmentDoc = gql`
|
299
353
|
fragment ScriptParametersFragment on ScriptParameters {
|
354
|
+
version
|
300
355
|
maxScriptLength
|
301
356
|
maxScriptDataLength
|
302
357
|
}
|
303
358
|
`;
|
304
359
|
var ContractParametersFragmentFragmentDoc = gql`
|
305
360
|
fragment ContractParametersFragment on ContractParameters {
|
361
|
+
version
|
306
362
|
contractMaxSize
|
307
363
|
maxStorageSlots
|
308
364
|
}
|
309
365
|
`;
|
310
366
|
var FeeParametersFragmentFragmentDoc = gql`
|
311
367
|
fragment FeeParametersFragment on FeeParameters {
|
368
|
+
version
|
312
369
|
gasPriceFactor
|
313
370
|
gasPerByte
|
314
371
|
}
|
@@ -328,6 +385,7 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
328
385
|
`;
|
329
386
|
var GasCostsFragmentFragmentDoc = gql`
|
330
387
|
fragment GasCostsFragment on GasCosts {
|
388
|
+
version
|
331
389
|
add
|
332
390
|
addi
|
333
391
|
aloc
|
@@ -340,7 +398,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
340
398
|
cb
|
341
399
|
cfei
|
342
400
|
cfsi
|
343
|
-
croo
|
344
401
|
div
|
345
402
|
divi
|
346
403
|
ecr1
|
@@ -423,6 +480,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
423
480
|
ccp {
|
424
481
|
...DependentCostFragment
|
425
482
|
}
|
483
|
+
croo {
|
484
|
+
...DependentCostFragment
|
485
|
+
}
|
426
486
|
csiz {
|
427
487
|
...DependentCostFragment
|
428
488
|
}
|
@@ -482,6 +542,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
482
542
|
${DependentCostFragmentFragmentDoc}`;
|
483
543
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
484
544
|
fragment consensusParametersFragment on ConsensusParameters {
|
545
|
+
version
|
485
546
|
txParams {
|
486
547
|
...TxParametersFragment
|
487
548
|
}
|
@@ -541,18 +602,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
541
602
|
fragment nodeInfoFragment on NodeInfo {
|
542
603
|
utxoValidation
|
543
604
|
vmBacktrace
|
544
|
-
minGasPrice
|
545
605
|
maxTx
|
546
606
|
maxDepth
|
547
607
|
nodeVersion
|
548
|
-
peers {
|
549
|
-
id
|
550
|
-
addresses
|
551
|
-
clientVersion
|
552
|
-
blockHeight
|
553
|
-
lastHeartbeatMs
|
554
|
-
appScore
|
555
|
-
}
|
556
608
|
}
|
557
609
|
`;
|
558
610
|
var GetVersionDocument = gql`
|
@@ -587,13 +639,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
587
639
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
588
640
|
transaction(id: $transactionId) {
|
589
641
|
...transactionFragment
|
590
|
-
receipts {
|
591
|
-
...receiptFragment
|
592
|
-
}
|
593
642
|
}
|
594
643
|
}
|
595
|
-
${TransactionFragmentFragmentDoc}
|
596
|
-
${ReceiptFragmentFragmentDoc}`;
|
644
|
+
${TransactionFragmentFragmentDoc}`;
|
597
645
|
var GetTransactionsDocument = gql`
|
598
646
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
599
647
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -721,6 +769,20 @@ var GetBalanceDocument = gql`
|
|
721
769
|
}
|
722
770
|
}
|
723
771
|
${BalanceFragmentFragmentDoc}`;
|
772
|
+
var GetLatestGasPriceDocument = gql`
|
773
|
+
query getLatestGasPrice {
|
774
|
+
latestGasPrice {
|
775
|
+
gasPrice
|
776
|
+
}
|
777
|
+
}
|
778
|
+
`;
|
779
|
+
var EstimateGasPriceDocument = gql`
|
780
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
781
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
782
|
+
gasPrice
|
783
|
+
}
|
784
|
+
}
|
785
|
+
`;
|
724
786
|
var GetBalancesDocument = gql`
|
725
787
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
726
788
|
balances(
|
@@ -775,12 +837,12 @@ var GetMessageStatusDocument = gql`
|
|
775
837
|
}
|
776
838
|
`;
|
777
839
|
var DryRunDocument = gql`
|
778
|
-
mutation dryRun($
|
779
|
-
dryRun(
|
780
|
-
...
|
840
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
841
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
842
|
+
...dryRunTransactionExecutionStatusFragment
|
781
843
|
}
|
782
844
|
}
|
783
|
-
${
|
845
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
784
846
|
var SubmitDocument = gql`
|
785
847
|
mutation submit($encodedTransaction: HexString!) {
|
786
848
|
submit(tx: $encodedTransaction) {
|
@@ -799,17 +861,17 @@ var ProduceBlocksDocument = gql`
|
|
799
861
|
var SubmitAndAwaitDocument = gql`
|
800
862
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
801
863
|
submitAndAwait(tx: $encodedTransaction) {
|
802
|
-
...
|
864
|
+
...transactionStatusSubscriptionFragment
|
803
865
|
}
|
804
866
|
}
|
805
|
-
${
|
867
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
806
868
|
var StatusChangeDocument = gql`
|
807
869
|
subscription statusChange($transactionId: TransactionId!) {
|
808
870
|
statusChange(id: $transactionId) {
|
809
|
-
...
|
871
|
+
...transactionStatusSubscriptionFragment
|
810
872
|
}
|
811
873
|
}
|
812
|
-
${
|
874
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
813
875
|
function getSdk(requester) {
|
814
876
|
return {
|
815
877
|
getVersion(variables, options) {
|
@@ -863,6 +925,12 @@ function getSdk(requester) {
|
|
863
925
|
getBalance(variables, options) {
|
864
926
|
return requester(GetBalanceDocument, variables, options);
|
865
927
|
},
|
928
|
+
getLatestGasPrice(variables, options) {
|
929
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
930
|
+
},
|
931
|
+
estimateGasPrice(variables, options) {
|
932
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
933
|
+
},
|
866
934
|
getBalances(variables, options) {
|
867
935
|
return requester(GetBalancesDocument, variables, options);
|
868
936
|
},
|
@@ -1056,10 +1124,9 @@ var inputify = (value) => {
|
|
1056
1124
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1057
1125
|
},
|
1058
1126
|
witnessIndex: value.witnessIndex,
|
1059
|
-
maturity: value.maturity ?? 0,
|
1060
1127
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1061
|
-
predicateLength: predicate.length,
|
1062
|
-
predicateDataLength: predicateData.length,
|
1128
|
+
predicateLength: bn2(predicate.length),
|
1129
|
+
predicateDataLength: bn2(predicateData.length),
|
1063
1130
|
predicate: hexlify3(predicate),
|
1064
1131
|
predicateData: hexlify3(predicateData)
|
1065
1132
|
};
|
@@ -1090,8 +1157,8 @@ var inputify = (value) => {
|
|
1090
1157
|
nonce: hexlify3(value.nonce),
|
1091
1158
|
witnessIndex: value.witnessIndex,
|
1092
1159
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1093
|
-
predicateLength: predicate.length,
|
1094
|
-
predicateDataLength: predicateData.length,
|
1160
|
+
predicateLength: bn2(predicate.length),
|
1161
|
+
predicateDataLength: bn2(predicateData.length),
|
1095
1162
|
predicate: hexlify3(predicate),
|
1096
1163
|
predicateData: hexlify3(predicateData),
|
1097
1164
|
data: hexlify3(data),
|
@@ -1167,7 +1234,7 @@ var outputify = (value) => {
|
|
1167
1234
|
// src/providers/transaction-request/transaction-request.ts
|
1168
1235
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1169
1236
|
import { Address, addressify } from "@fuel-ts/address";
|
1170
|
-
import {
|
1237
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1171
1238
|
import { randomBytes } from "@fuel-ts/crypto";
|
1172
1239
|
import { bn as bn7 } from "@fuel-ts/math";
|
1173
1240
|
import {
|
@@ -1221,8 +1288,8 @@ function assembleReceiptByType(receipt) {
|
|
1221
1288
|
case "CALL" /* Call */: {
|
1222
1289
|
const callReceipt = {
|
1223
1290
|
type: ReceiptType.Call,
|
1224
|
-
from: hexOrZero(receipt.
|
1225
|
-
to: hexOrZero(receipt?.to
|
1291
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1292
|
+
to: hexOrZero(receipt?.to),
|
1226
1293
|
amount: bn4(receipt.amount),
|
1227
1294
|
assetId: hexOrZero(receipt.assetId),
|
1228
1295
|
gas: bn4(receipt.gas),
|
@@ -1236,7 +1303,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1303
|
case "RETURN" /* Return */: {
|
1237
1304
|
const returnReceipt = {
|
1238
1305
|
type: ReceiptType.Return,
|
1239
|
-
id: hexOrZero(receipt.
|
1306
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1240
1307
|
val: bn4(receipt.val),
|
1241
1308
|
pc: bn4(receipt.pc),
|
1242
1309
|
is: bn4(receipt.is)
|
@@ -1246,7 +1313,7 @@ function assembleReceiptByType(receipt) {
|
|
1246
1313
|
case "RETURN_DATA" /* ReturnData */: {
|
1247
1314
|
const returnDataReceipt = {
|
1248
1315
|
type: ReceiptType.ReturnData,
|
1249
|
-
id: hexOrZero(receipt.
|
1316
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1250
1317
|
ptr: bn4(receipt.ptr),
|
1251
1318
|
len: bn4(receipt.len),
|
1252
1319
|
digest: hexOrZero(receipt.digest),
|
@@ -1258,7 +1325,7 @@ function assembleReceiptByType(receipt) {
|
|
1258
1325
|
case "PANIC" /* Panic */: {
|
1259
1326
|
const panicReceipt = {
|
1260
1327
|
type: ReceiptType.Panic,
|
1261
|
-
id: hexOrZero(receipt.
|
1328
|
+
id: hexOrZero(receipt.id),
|
1262
1329
|
reason: bn4(receipt.reason),
|
1263
1330
|
pc: bn4(receipt.pc),
|
1264
1331
|
is: bn4(receipt.is),
|
@@ -1269,7 +1336,7 @@ function assembleReceiptByType(receipt) {
|
|
1269
1336
|
case "REVERT" /* Revert */: {
|
1270
1337
|
const revertReceipt = {
|
1271
1338
|
type: ReceiptType.Revert,
|
1272
|
-
id: hexOrZero(receipt.
|
1339
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1273
1340
|
val: bn4(receipt.ra),
|
1274
1341
|
pc: bn4(receipt.pc),
|
1275
1342
|
is: bn4(receipt.is)
|
@@ -1279,7 +1346,7 @@ function assembleReceiptByType(receipt) {
|
|
1279
1346
|
case "LOG" /* Log */: {
|
1280
1347
|
const logReceipt = {
|
1281
1348
|
type: ReceiptType.Log,
|
1282
|
-
id: hexOrZero(receipt.
|
1349
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1283
1350
|
val0: bn4(receipt.ra),
|
1284
1351
|
val1: bn4(receipt.rb),
|
1285
1352
|
val2: bn4(receipt.rc),
|
@@ -1292,7 +1359,7 @@ function assembleReceiptByType(receipt) {
|
|
1292
1359
|
case "LOG_DATA" /* LogData */: {
|
1293
1360
|
const logDataReceipt = {
|
1294
1361
|
type: ReceiptType.LogData,
|
1295
|
-
id: hexOrZero(receipt.
|
1362
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1296
1363
|
val0: bn4(receipt.ra),
|
1297
1364
|
val1: bn4(receipt.rb),
|
1298
1365
|
ptr: bn4(receipt.ptr),
|
@@ -1306,8 +1373,8 @@ function assembleReceiptByType(receipt) {
|
|
1306
1373
|
case "TRANSFER" /* Transfer */: {
|
1307
1374
|
const transferReceipt = {
|
1308
1375
|
type: ReceiptType.Transfer,
|
1309
|
-
from: hexOrZero(receipt.
|
1310
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1376
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1377
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1311
1378
|
amount: bn4(receipt.amount),
|
1312
1379
|
assetId: hexOrZero(receipt.assetId),
|
1313
1380
|
pc: bn4(receipt.pc),
|
@@ -1318,8 +1385,8 @@ function assembleReceiptByType(receipt) {
|
|
1318
1385
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1319
1386
|
const transferOutReceipt = {
|
1320
1387
|
type: ReceiptType.TransferOut,
|
1321
|
-
from: hexOrZero(receipt.
|
1322
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1388
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1389
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1323
1390
|
amount: bn4(receipt.amount),
|
1324
1391
|
assetId: hexOrZero(receipt.assetId),
|
1325
1392
|
pc: bn4(receipt.pc),
|
@@ -1362,7 +1429,7 @@ function assembleReceiptByType(receipt) {
|
|
1362
1429
|
return receiptMessageOut;
|
1363
1430
|
}
|
1364
1431
|
case "MINT" /* Mint */: {
|
1365
|
-
const contractId = hexOrZero(receipt.
|
1432
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1366
1433
|
const subId = hexOrZero(receipt.subId);
|
1367
1434
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1368
1435
|
const mintReceipt = {
|
@@ -1377,7 +1444,7 @@ function assembleReceiptByType(receipt) {
|
|
1377
1444
|
return mintReceipt;
|
1378
1445
|
}
|
1379
1446
|
case "BURN" /* Burn */: {
|
1380
|
-
const contractId = hexOrZero(receipt.
|
1447
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1381
1448
|
const subId = hexOrZero(receipt.subId);
|
1382
1449
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1383
1450
|
const burnReceipt = {
|
@@ -1462,7 +1529,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1462
1529
|
import { bn as bn5 } from "@fuel-ts/math";
|
1463
1530
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1464
1531
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1465
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1466
1532
|
var getGasUsedFromReceipts = (receipts) => {
|
1467
1533
|
const scriptResult = receipts.filter(
|
1468
1534
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1483,18 +1549,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1483
1549
|
}
|
1484
1550
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1485
1551
|
const witnessCache = [];
|
1486
|
-
const
|
1552
|
+
const chargeableInputs = inputs.filter((input) => {
|
1553
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1554
|
+
if (isCoinOrMessage) {
|
1555
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1556
|
+
return true;
|
1557
|
+
}
|
1558
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1559
|
+
witnessCache.push(input.witnessIndex);
|
1560
|
+
return true;
|
1561
|
+
}
|
1562
|
+
}
|
1563
|
+
return false;
|
1564
|
+
});
|
1565
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1566
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1487
1567
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1488
1568
|
return total.add(
|
1489
|
-
|
1569
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1490
1570
|
);
|
1491
1571
|
}
|
1492
|
-
|
1493
|
-
|
1494
|
-
return total.add(gasCosts.ecr1);
|
1495
|
-
}
|
1496
|
-
return total;
|
1497
|
-
}, bn5());
|
1572
|
+
return total.add(gasCosts.ecr1);
|
1573
|
+
}, bn5(0));
|
1498
1574
|
return totalGas;
|
1499
1575
|
}
|
1500
1576
|
function getMinGas(params) {
|
@@ -1506,12 +1582,20 @@ function getMinGas(params) {
|
|
1506
1582
|
return minGas;
|
1507
1583
|
}
|
1508
1584
|
function getMaxGas(params) {
|
1509
|
-
const {
|
1585
|
+
const {
|
1586
|
+
gasPerByte,
|
1587
|
+
witnessesLength,
|
1588
|
+
witnessLimit,
|
1589
|
+
minGas,
|
1590
|
+
gasLimit = bn5(0),
|
1591
|
+
maxGasPerTx
|
1592
|
+
} = params;
|
1510
1593
|
let remainingAllowedWitnessGas = bn5(0);
|
1511
1594
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1512
1595
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1513
1596
|
}
|
1514
|
-
|
1597
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1598
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1515
1599
|
}
|
1516
1600
|
function calculateMetadataGasForTxCreate({
|
1517
1601
|
gasCosts,
|
@@ -1533,6 +1617,10 @@ function calculateMetadataGasForTxScript({
|
|
1533
1617
|
}) {
|
1534
1618
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1535
1619
|
}
|
1620
|
+
var calculateGasFee = (params) => {
|
1621
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1622
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1623
|
+
};
|
1536
1624
|
|
1537
1625
|
// src/providers/utils/json.ts
|
1538
1626
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1689,7 +1777,7 @@ var witnessify = (value) => {
|
|
1689
1777
|
// src/providers/transaction-request/transaction-request.ts
|
1690
1778
|
var BaseTransactionRequest = class {
|
1691
1779
|
/** Gas price for transaction */
|
1692
|
-
|
1780
|
+
tip;
|
1693
1781
|
/** Block until which tx cannot be included */
|
1694
1782
|
maturity;
|
1695
1783
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1708,7 +1796,7 @@ var BaseTransactionRequest = class {
|
|
1708
1796
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1709
1797
|
*/
|
1710
1798
|
constructor({
|
1711
|
-
|
1799
|
+
tip,
|
1712
1800
|
maturity,
|
1713
1801
|
maxFee,
|
1714
1802
|
witnessLimit,
|
@@ -1716,7 +1804,7 @@ var BaseTransactionRequest = class {
|
|
1716
1804
|
outputs,
|
1717
1805
|
witnesses
|
1718
1806
|
} = {}) {
|
1719
|
-
this.
|
1807
|
+
this.tip = bn7(tip);
|
1720
1808
|
this.maturity = maturity ?? 0;
|
1721
1809
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1722
1810
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1727,9 +1815,9 @@ var BaseTransactionRequest = class {
|
|
1727
1815
|
static getPolicyMeta(req) {
|
1728
1816
|
let policyTypes = 0;
|
1729
1817
|
const policies = [];
|
1730
|
-
if (req.
|
1731
|
-
policyTypes += PolicyType.
|
1732
|
-
policies.push({ data: req.
|
1818
|
+
if (req.tip) {
|
1819
|
+
policyTypes += PolicyType.Tip;
|
1820
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1733
1821
|
}
|
1734
1822
|
if (req.witnessLimit) {
|
1735
1823
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1913,13 +2001,11 @@ var BaseTransactionRequest = class {
|
|
1913
2001
|
* assetId, if one it was not added yet.
|
1914
2002
|
*
|
1915
2003
|
* @param coin - Coin resource.
|
1916
|
-
* @param predicate - Predicate bytes.
|
1917
|
-
* @param predicateData - Predicate data bytes.
|
1918
2004
|
*/
|
1919
|
-
addCoinInput(coin
|
2005
|
+
addCoinInput(coin) {
|
1920
2006
|
const { assetId, owner, amount } = coin;
|
1921
2007
|
let witnessIndex;
|
1922
|
-
if (predicate) {
|
2008
|
+
if (coin.predicate) {
|
1923
2009
|
witnessIndex = 0;
|
1924
2010
|
} else {
|
1925
2011
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1934,25 +2020,21 @@ var BaseTransactionRequest = class {
|
|
1934
2020
|
amount,
|
1935
2021
|
assetId,
|
1936
2022
|
txPointer: "0x00000000000000000000000000000000",
|
1937
|
-
witnessIndex
|
1938
|
-
predicate: predicate?.bytes
|
2023
|
+
witnessIndex
|
1939
2024
|
};
|
1940
2025
|
this.pushInput(input);
|
1941
2026
|
this.addChangeOutput(owner, assetId);
|
1942
2027
|
}
|
1943
2028
|
/**
|
1944
2029
|
* Adds a single message input to the transaction and a change output for the
|
1945
|
-
*
|
2030
|
+
* asset against the message
|
1946
2031
|
*
|
1947
2032
|
* @param message - Message resource.
|
1948
|
-
* @param predicate - Predicate bytes.
|
1949
|
-
* @param predicateData - Predicate data bytes.
|
1950
2033
|
*/
|
1951
|
-
addMessageInput(message
|
1952
|
-
const { recipient, sender, amount } = message;
|
1953
|
-
const assetId = BaseAssetId2;
|
2034
|
+
addMessageInput(message) {
|
2035
|
+
const { recipient, sender, amount, assetId } = message;
|
1954
2036
|
let witnessIndex;
|
1955
|
-
if (predicate) {
|
2037
|
+
if (message.predicate) {
|
1956
2038
|
witnessIndex = 0;
|
1957
2039
|
} else {
|
1958
2040
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1966,8 +2048,7 @@ var BaseTransactionRequest = class {
|
|
1966
2048
|
sender: sender.toB256(),
|
1967
2049
|
recipient: recipient.toB256(),
|
1968
2050
|
amount,
|
1969
|
-
witnessIndex
|
1970
|
-
predicate: predicate?.bytes
|
2051
|
+
witnessIndex
|
1971
2052
|
};
|
1972
2053
|
this.pushInput(input);
|
1973
2054
|
this.addChangeOutput(recipient, assetId);
|
@@ -1998,32 +2079,6 @@ var BaseTransactionRequest = class {
|
|
1998
2079
|
resources.forEach((resource) => this.addResource(resource));
|
1999
2080
|
return this;
|
2000
2081
|
}
|
2001
|
-
/**
|
2002
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2003
|
-
* outputs from the related assetIds.
|
2004
|
-
*
|
2005
|
-
* @param resources - The resources to add.
|
2006
|
-
* @returns This transaction.
|
2007
|
-
*/
|
2008
|
-
addPredicateResource(resource, predicate) {
|
2009
|
-
if (isCoin(resource)) {
|
2010
|
-
this.addCoinInput(resource, predicate);
|
2011
|
-
} else {
|
2012
|
-
this.addMessageInput(resource, predicate);
|
2013
|
-
}
|
2014
|
-
return this;
|
2015
|
-
}
|
2016
|
-
/**
|
2017
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2018
|
-
* from the related assetIds.
|
2019
|
-
*
|
2020
|
-
* @param resources - The resources to add.
|
2021
|
-
* @returns This transaction.
|
2022
|
-
*/
|
2023
|
-
addPredicateResources(resources, predicate) {
|
2024
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2025
|
-
return this;
|
2026
|
-
}
|
2027
2082
|
/**
|
2028
2083
|
* Adds a coin output to the transaction.
|
2029
2084
|
*
|
@@ -2031,7 +2086,7 @@ var BaseTransactionRequest = class {
|
|
2031
2086
|
* @param amount - Amount of coin.
|
2032
2087
|
* @param assetId - Asset ID of coin.
|
2033
2088
|
*/
|
2034
|
-
addCoinOutput(to, amount, assetId
|
2089
|
+
addCoinOutput(to, amount, assetId) {
|
2035
2090
|
this.pushOutput({
|
2036
2091
|
type: OutputType2.Coin,
|
2037
2092
|
to: addressify(to).toB256(),
|
@@ -2063,7 +2118,7 @@ var BaseTransactionRequest = class {
|
|
2063
2118
|
* @param to - Address of the owner.
|
2064
2119
|
* @param assetId - Asset ID of coin.
|
2065
2120
|
*/
|
2066
|
-
addChangeOutput(to, assetId
|
2121
|
+
addChangeOutput(to, assetId) {
|
2067
2122
|
const changeOutput = this.getChangeOutputs().find(
|
2068
2123
|
(output) => hexlify7(output.assetId) === assetId
|
2069
2124
|
);
|
@@ -2103,7 +2158,7 @@ var BaseTransactionRequest = class {
|
|
2103
2158
|
}
|
2104
2159
|
calculateMaxGas(chainInfo, minGas) {
|
2105
2160
|
const { consensusParameters } = chainInfo;
|
2106
|
-
const { gasPerByte } = consensusParameters;
|
2161
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2107
2162
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2108
2163
|
(acc, wit) => acc + wit.dataLength,
|
2109
2164
|
0
|
@@ -2112,7 +2167,8 @@ var BaseTransactionRequest = class {
|
|
2112
2167
|
gasPerByte,
|
2113
2168
|
minGas,
|
2114
2169
|
witnessesLength,
|
2115
|
-
witnessLimit: this.witnessLimit
|
2170
|
+
witnessLimit: this.witnessLimit,
|
2171
|
+
maxGasPerTx
|
2116
2172
|
});
|
2117
2173
|
}
|
2118
2174
|
/**
|
@@ -2120,8 +2176,9 @@ var BaseTransactionRequest = class {
|
|
2120
2176
|
* quantities array.
|
2121
2177
|
*
|
2122
2178
|
* @param quantities - CoinQuantity Array.
|
2179
|
+
* @param baseAssetId - The base asset to fund the transaction.
|
2123
2180
|
*/
|
2124
|
-
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2181
|
+
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2125
2182
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2126
2183
|
if ("assetId" in input) {
|
2127
2184
|
return input.assetId === assetId;
|
@@ -2130,24 +2187,27 @@ var BaseTransactionRequest = class {
|
|
2130
2187
|
});
|
2131
2188
|
const updateAssetInput = (assetId, quantity) => {
|
2132
2189
|
const assetInput = findAssetInput(assetId);
|
2190
|
+
let usedQuantity = quantity;
|
2191
|
+
if (assetId === baseAssetId) {
|
2192
|
+
usedQuantity = bn7("1000000000000000000");
|
2193
|
+
}
|
2133
2194
|
if (assetInput && "assetId" in assetInput) {
|
2134
2195
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2135
|
-
assetInput.amount =
|
2196
|
+
assetInput.amount = usedQuantity;
|
2136
2197
|
} else {
|
2137
2198
|
this.addResources([
|
2138
2199
|
{
|
2139
2200
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2140
|
-
amount:
|
2201
|
+
amount: usedQuantity,
|
2141
2202
|
assetId,
|
2142
2203
|
owner: resourcesOwner || Address.fromRandom(),
|
2143
|
-
maturity: 0,
|
2144
2204
|
blockCreated: bn7(1),
|
2145
2205
|
txCreatedIdx: bn7(1)
|
2146
2206
|
}
|
2147
2207
|
]);
|
2148
2208
|
}
|
2149
2209
|
};
|
2150
|
-
updateAssetInput(
|
2210
|
+
updateAssetInput(baseAssetId, bn7(1e11));
|
2151
2211
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2152
2212
|
}
|
2153
2213
|
/**
|
@@ -2172,7 +2232,7 @@ var BaseTransactionRequest = class {
|
|
2172
2232
|
toJSON() {
|
2173
2233
|
return normalizeJSON(this);
|
2174
2234
|
}
|
2175
|
-
|
2235
|
+
updatePredicateGasUsed(inputs) {
|
2176
2236
|
this.inputs.forEach((i) => {
|
2177
2237
|
let correspondingInput;
|
2178
2238
|
switch (i.type) {
|
@@ -2194,6 +2254,15 @@ var BaseTransactionRequest = class {
|
|
2194
2254
|
}
|
2195
2255
|
});
|
2196
2256
|
}
|
2257
|
+
shiftPredicateData() {
|
2258
|
+
this.inputs.forEach((input) => {
|
2259
|
+
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2260
|
+
input.predicateData = input.padPredicateData(
|
2261
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2262
|
+
);
|
2263
|
+
}
|
2264
|
+
});
|
2265
|
+
}
|
2197
2266
|
};
|
2198
2267
|
|
2199
2268
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2317,12 +2386,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2317
2386
|
*
|
2318
2387
|
* @param createTransactionRequestLike - The initial values for the instance
|
2319
2388
|
*/
|
2320
|
-
constructor({
|
2321
|
-
bytecodeWitnessIndex,
|
2322
|
-
salt,
|
2323
|
-
storageSlots,
|
2324
|
-
...rest
|
2325
|
-
} = {}) {
|
2389
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2326
2390
|
super(rest);
|
2327
2391
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2328
2392
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2340,9 +2404,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2340
2404
|
return {
|
2341
2405
|
type: TransactionType3.Create,
|
2342
2406
|
...baseTransaction,
|
2343
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2344
2407
|
bytecodeWitnessIndex,
|
2345
|
-
storageSlotsCount: storageSlots.length,
|
2408
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2346
2409
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2347
2410
|
storageSlots
|
2348
2411
|
};
|
@@ -2465,8 +2528,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2465
2528
|
type: TransactionType4.Script,
|
2466
2529
|
scriptGasLimit: this.gasLimit,
|
2467
2530
|
...super.getBaseTransaction(),
|
2468
|
-
scriptLength: script.length,
|
2469
|
-
scriptDataLength: scriptData.length,
|
2531
|
+
scriptLength: bn10(script.length),
|
2532
|
+
scriptDataLength: bn10(scriptData.length),
|
2470
2533
|
receiptsRoot: ZeroBytes327,
|
2471
2534
|
script: hexlify10(script),
|
2472
2535
|
scriptData: hexlify10(scriptData)
|
@@ -2530,7 +2593,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2530
2593
|
}
|
2531
2594
|
calculateMaxGas(chainInfo, minGas) {
|
2532
2595
|
const { consensusParameters } = chainInfo;
|
2533
|
-
const { gasPerByte } = consensusParameters;
|
2596
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2534
2597
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2535
2598
|
(acc, wit) => acc + wit.dataLength,
|
2536
2599
|
0
|
@@ -2540,7 +2603,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2540
2603
|
minGas,
|
2541
2604
|
witnessesLength,
|
2542
2605
|
witnessLimit: this.witnessLimit,
|
2543
|
-
gasLimit: this.gasLimit
|
2606
|
+
gasLimit: this.gasLimit,
|
2607
|
+
maxGasPerTx
|
2544
2608
|
});
|
2545
2609
|
}
|
2546
2610
|
/**
|
@@ -2597,7 +2661,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2597
2661
|
|
2598
2662
|
// src/providers/transaction-request/utils.ts
|
2599
2663
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2600
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2664
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2601
2665
|
var transactionRequestify = (obj) => {
|
2602
2666
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2603
2667
|
return obj;
|
@@ -2615,14 +2679,31 @@ var transactionRequestify = (obj) => {
|
|
2615
2679
|
}
|
2616
2680
|
}
|
2617
2681
|
};
|
2682
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2683
|
+
(acc, input) => {
|
2684
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2685
|
+
acc.utxos.push(input.id);
|
2686
|
+
}
|
2687
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2688
|
+
acc.messages.push(input.nonce);
|
2689
|
+
}
|
2690
|
+
return acc;
|
2691
|
+
},
|
2692
|
+
{
|
2693
|
+
utxos: [],
|
2694
|
+
messages: []
|
2695
|
+
}
|
2696
|
+
);
|
2618
2697
|
|
2619
2698
|
// src/providers/transaction-response/transaction-response.ts
|
2620
2699
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2621
|
-
import { bn as
|
2700
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2622
2701
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2623
2702
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2624
2703
|
|
2625
2704
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2705
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2706
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2626
2707
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2627
2708
|
|
2628
2709
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2631,9 +2712,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2631
2712
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2632
2713
|
var calculateTransactionFee = (params) => {
|
2633
2714
|
const {
|
2634
|
-
|
2715
|
+
gasPrice,
|
2635
2716
|
rawPayload,
|
2636
|
-
|
2717
|
+
tip,
|
2718
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2637
2719
|
} = params;
|
2638
2720
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2639
2721
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2643,8 +2725,7 @@ var calculateTransactionFee = (params) => {
|
|
2643
2725
|
return {
|
2644
2726
|
fee: bn11(0),
|
2645
2727
|
minFee: bn11(0),
|
2646
|
-
maxFee: bn11(0)
|
2647
|
-
feeFromGasUsed: bn11(0)
|
2728
|
+
maxFee: bn11(0)
|
2648
2729
|
};
|
2649
2730
|
}
|
2650
2731
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2676,7 +2757,6 @@ var calculateTransactionFee = (params) => {
|
|
2676
2757
|
metadataGas,
|
2677
2758
|
txBytesSize: transactionBytes.length
|
2678
2759
|
});
|
2679
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2680
2760
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2681
2761
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2682
2762
|
const maxGas = getMaxGas({
|
@@ -2684,17 +2764,25 @@ var calculateTransactionFee = (params) => {
|
|
2684
2764
|
minGas,
|
2685
2765
|
witnessesLength,
|
2686
2766
|
gasLimit,
|
2687
|
-
witnessLimit
|
2767
|
+
witnessLimit,
|
2768
|
+
maxGasPerTx
|
2769
|
+
});
|
2770
|
+
const minFee = calculateGasFee({
|
2771
|
+
gasPrice,
|
2772
|
+
gas: minGas,
|
2773
|
+
priceFactor: gasPriceFactor,
|
2774
|
+
tip
|
2775
|
+
});
|
2776
|
+
const maxFee = calculateGasFee({
|
2777
|
+
gasPrice,
|
2778
|
+
gas: maxGas,
|
2779
|
+
priceFactor: gasPriceFactor,
|
2780
|
+
tip
|
2688
2781
|
});
|
2689
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2690
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2691
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2692
|
-
const fee = minFee.add(feeFromGasUsed);
|
2693
2782
|
return {
|
2694
|
-
fee,
|
2695
2783
|
minFee,
|
2696
2784
|
maxFee,
|
2697
|
-
|
2785
|
+
fee: maxFee
|
2698
2786
|
};
|
2699
2787
|
};
|
2700
2788
|
|
@@ -2750,7 +2838,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2750
2838
|
|
2751
2839
|
// src/providers/transaction-summary/input.ts
|
2752
2840
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2753
|
-
import { InputType as
|
2841
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2754
2842
|
function getInputsByTypes(inputs, types) {
|
2755
2843
|
return inputs.filter((i) => types.includes(i.type));
|
2756
2844
|
}
|
@@ -2758,16 +2846,16 @@ function getInputsByType(inputs, type) {
|
|
2758
2846
|
return inputs.filter((i) => i.type === type);
|
2759
2847
|
}
|
2760
2848
|
function getInputsCoin(inputs) {
|
2761
|
-
return getInputsByType(inputs,
|
2849
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2762
2850
|
}
|
2763
2851
|
function getInputsMessage(inputs) {
|
2764
|
-
return getInputsByType(inputs,
|
2852
|
+
return getInputsByType(inputs, InputType6.Message);
|
2765
2853
|
}
|
2766
2854
|
function getInputsCoinAndMessage(inputs) {
|
2767
|
-
return getInputsByTypes(inputs, [
|
2855
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2768
2856
|
}
|
2769
2857
|
function getInputsContract(inputs) {
|
2770
|
-
return getInputsByType(inputs,
|
2858
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2771
2859
|
}
|
2772
2860
|
function getInputFromAssetId(inputs, assetId) {
|
2773
2861
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2786,7 +2874,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2786
2874
|
if (!contractInput) {
|
2787
2875
|
return void 0;
|
2788
2876
|
}
|
2789
|
-
if (contractInput.type !==
|
2877
|
+
if (contractInput.type !== InputType6.Contract) {
|
2790
2878
|
throw new FuelError9(
|
2791
2879
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2792
2880
|
`Contract input should be of type 'contract'.`
|
@@ -2795,10 +2883,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2795
2883
|
return contractInput;
|
2796
2884
|
}
|
2797
2885
|
function getInputAccountAddress(input) {
|
2798
|
-
if (input.type ===
|
2886
|
+
if (input.type === InputType6.Coin) {
|
2799
2887
|
return input.owner.toString();
|
2800
2888
|
}
|
2801
|
-
if (input.type ===
|
2889
|
+
if (input.type === InputType6.Message) {
|
2802
2890
|
return input.recipient.toString();
|
2803
2891
|
}
|
2804
2892
|
return "";
|
@@ -3308,7 +3396,9 @@ function assembleTransactionSummary(params) {
|
|
3308
3396
|
gqlTransactionStatus,
|
3309
3397
|
abiMap = {},
|
3310
3398
|
maxInputs,
|
3311
|
-
gasCosts
|
3399
|
+
gasCosts,
|
3400
|
+
maxGasPerTx,
|
3401
|
+
gasPrice
|
3312
3402
|
} = params;
|
3313
3403
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3314
3404
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3322,11 +3412,14 @@ function assembleTransactionSummary(params) {
|
|
3322
3412
|
maxInputs
|
3323
3413
|
});
|
3324
3414
|
const typeName = getTransactionTypeName(transaction.type);
|
3415
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3325
3416
|
const { fee } = calculateTransactionFee({
|
3326
|
-
|
3417
|
+
gasPrice,
|
3327
3418
|
rawPayload,
|
3419
|
+
tip,
|
3328
3420
|
consensusParameters: {
|
3329
3421
|
gasCosts,
|
3422
|
+
maxGasPerTx,
|
3330
3423
|
feeParams: {
|
3331
3424
|
gasPerByte,
|
3332
3425
|
gasPriceFactor
|
@@ -3386,7 +3479,7 @@ var TransactionResponse = class {
|
|
3386
3479
|
/** Current provider */
|
3387
3480
|
provider;
|
3388
3481
|
/** Gas used on the transaction */
|
3389
|
-
gasUsed =
|
3482
|
+
gasUsed = bn15(0);
|
3390
3483
|
/** The graphql Transaction with receipts object. */
|
3391
3484
|
gqlTransaction;
|
3392
3485
|
abis;
|
@@ -3464,8 +3557,13 @@ var TransactionResponse = class {
|
|
3464
3557
|
const decodedTransaction = this.decodeTransaction(
|
3465
3558
|
transaction
|
3466
3559
|
);
|
3467
|
-
|
3468
|
-
|
3560
|
+
let txReceipts = [];
|
3561
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3562
|
+
txReceipts = transaction.status.receipts;
|
3563
|
+
}
|
3564
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3565
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3566
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3469
3567
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3470
3568
|
const transactionSummary = assembleTransactionSummary({
|
3471
3569
|
id: this.id,
|
@@ -3477,7 +3575,9 @@ var TransactionResponse = class {
|
|
3477
3575
|
gasPriceFactor,
|
3478
3576
|
abiMap: contractsAbiMap,
|
3479
3577
|
maxInputs,
|
3480
|
-
gasCosts
|
3578
|
+
gasCosts,
|
3579
|
+
maxGasPerTx,
|
3580
|
+
gasPrice
|
3481
3581
|
});
|
3482
3582
|
return transactionSummary;
|
3483
3583
|
}
|
@@ -3583,7 +3683,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3583
3683
|
}
|
3584
3684
|
|
3585
3685
|
// src/providers/utils/merge-quantities.ts
|
3586
|
-
var mergeQuantities = (
|
3686
|
+
var mergeQuantities = (...coinQuantities) => {
|
3587
3687
|
const resultMap = {};
|
3588
3688
|
function addToMap({ amount, assetId }) {
|
3589
3689
|
if (resultMap[assetId]) {
|
@@ -3592,8 +3692,7 @@ var mergeQuantities = (arr1, arr2) => {
|
|
3592
3692
|
resultMap[assetId] = amount;
|
3593
3693
|
}
|
3594
3694
|
}
|
3595
|
-
|
3596
|
-
arr2.forEach(addToMap);
|
3695
|
+
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
3597
3696
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
3598
3697
|
};
|
3599
3698
|
|
@@ -3604,29 +3703,30 @@ var processGqlChain = (chain) => {
|
|
3604
3703
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3605
3704
|
return {
|
3606
3705
|
name,
|
3607
|
-
baseChainHeight:
|
3706
|
+
baseChainHeight: bn16(daHeight),
|
3608
3707
|
consensusParameters: {
|
3609
|
-
contractMaxSize:
|
3610
|
-
maxInputs:
|
3611
|
-
maxOutputs:
|
3612
|
-
maxWitnesses:
|
3613
|
-
maxGasPerTx:
|
3614
|
-
maxScriptLength:
|
3615
|
-
maxScriptDataLength:
|
3616
|
-
maxStorageSlots:
|
3617
|
-
maxPredicateLength:
|
3618
|
-
maxPredicateDataLength:
|
3619
|
-
maxGasPerPredicate:
|
3620
|
-
gasPriceFactor:
|
3621
|
-
gasPerByte:
|
3622
|
-
maxMessageDataLength:
|
3623
|
-
chainId:
|
3708
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3709
|
+
maxInputs: bn16(txParams.maxInputs),
|
3710
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3711
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3712
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3713
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3714
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3715
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3716
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3717
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3718
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3719
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3720
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3721
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3722
|
+
chainId: bn16(consensusParameters.chainId),
|
3723
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3624
3724
|
gasCosts
|
3625
3725
|
},
|
3626
3726
|
gasCosts,
|
3627
3727
|
latestBlock: {
|
3628
3728
|
id: latestBlock.id,
|
3629
|
-
height:
|
3729
|
+
height: bn16(latestBlock.height),
|
3630
3730
|
time: latestBlock.header.time,
|
3631
3731
|
transactions: latestBlock.transactions.map((i) => ({
|
3632
3732
|
id: i.id
|
@@ -3720,10 +3820,8 @@ var _Provider = class {
|
|
3720
3820
|
* Returns some helpful parameters related to gas fees.
|
3721
3821
|
*/
|
3722
3822
|
getGasConfig() {
|
3723
|
-
const { minGasPrice } = this.getNode();
|
3724
3823
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3725
3824
|
return {
|
3726
|
-
minGasPrice,
|
3727
3825
|
maxGasPerTx,
|
3728
3826
|
maxGasPerPredicate,
|
3729
3827
|
gasPriceFactor,
|
@@ -3821,7 +3919,7 @@ var _Provider = class {
|
|
3821
3919
|
*/
|
3822
3920
|
async getBlockNumber() {
|
3823
3921
|
const { chain } = await this.operations.getChain();
|
3824
|
-
return
|
3922
|
+
return bn16(chain.latestBlock.height, 10);
|
3825
3923
|
}
|
3826
3924
|
/**
|
3827
3925
|
* Returns the chain information.
|
@@ -3831,13 +3929,11 @@ var _Provider = class {
|
|
3831
3929
|
async fetchNode() {
|
3832
3930
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3833
3931
|
const processedNodeInfo = {
|
3834
|
-
maxDepth:
|
3835
|
-
maxTx:
|
3836
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3932
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3933
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3837
3934
|
nodeVersion: nodeInfo.nodeVersion,
|
3838
3935
|
utxoValidation: nodeInfo.utxoValidation,
|
3839
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3840
|
-
peers: nodeInfo.peers
|
3936
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3841
3937
|
};
|
3842
3938
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3843
3939
|
return processedNodeInfo;
|
@@ -3863,6 +3959,17 @@ var _Provider = class {
|
|
3863
3959
|
} = this.getChain();
|
3864
3960
|
return chainId.toNumber();
|
3865
3961
|
}
|
3962
|
+
/**
|
3963
|
+
* Returns the base asset ID for the current provider network
|
3964
|
+
*
|
3965
|
+
* @returns the base asset ID
|
3966
|
+
*/
|
3967
|
+
getBaseAssetId() {
|
3968
|
+
const {
|
3969
|
+
consensusParameters: { baseAssetId }
|
3970
|
+
} = this.getChain();
|
3971
|
+
return baseAssetId;
|
3972
|
+
}
|
3866
3973
|
/**
|
3867
3974
|
* Submits a transaction to the chain to be executed.
|
3868
3975
|
*
|
@@ -3923,14 +4030,13 @@ var _Provider = class {
|
|
3923
4030
|
return this.estimateTxDependencies(transactionRequest);
|
3924
4031
|
}
|
3925
4032
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3926
|
-
const { dryRun:
|
3927
|
-
encodedTransaction,
|
4033
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4034
|
+
encodedTransactions: encodedTransaction,
|
3928
4035
|
utxoValidation: utxoValidation || false
|
3929
4036
|
});
|
3930
|
-
const receipts =
|
3931
|
-
|
3932
|
-
|
3933
|
-
};
|
4037
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4038
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4039
|
+
return { receipts, dryrunStatus: status };
|
3934
4040
|
}
|
3935
4041
|
/**
|
3936
4042
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3956,7 +4062,7 @@ var _Provider = class {
|
|
3956
4062
|
} = response;
|
3957
4063
|
if (inputs) {
|
3958
4064
|
inputs.forEach((input, index) => {
|
3959
|
-
if ("predicateGasUsed" in input &&
|
4065
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3960
4066
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3961
4067
|
}
|
3962
4068
|
});
|
@@ -3969,9 +4075,6 @@ var _Provider = class {
|
|
3969
4075
|
* If there are missing variable outputs,
|
3970
4076
|
* `addVariableOutputs` is called on the transaction.
|
3971
4077
|
*
|
3972
|
-
* @privateRemarks
|
3973
|
-
* TODO: Investigate support for missing contract IDs
|
3974
|
-
* TODO: Add support for missing output messages
|
3975
4078
|
*
|
3976
4079
|
* @param transactionRequest - The transaction request object.
|
3977
4080
|
* @returns A promise.
|
@@ -3984,16 +4087,19 @@ var _Provider = class {
|
|
3984
4087
|
missingContractIds: []
|
3985
4088
|
};
|
3986
4089
|
}
|
3987
|
-
await this.estimatePredicates(transactionRequest);
|
3988
4090
|
let receipts = [];
|
3989
4091
|
const missingContractIds = [];
|
3990
4092
|
let outputVariables = 0;
|
4093
|
+
let dryrunStatus;
|
3991
4094
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3992
|
-
const {
|
3993
|
-
|
4095
|
+
const {
|
4096
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4097
|
+
} = await this.operations.dryRun({
|
4098
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3994
4099
|
utxoValidation: false
|
3995
4100
|
});
|
3996
|
-
receipts =
|
4101
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4102
|
+
dryrunStatus = status;
|
3997
4103
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3998
4104
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3999
4105
|
if (hasMissingOutputs) {
|
@@ -4003,6 +4109,10 @@ var _Provider = class {
|
|
4003
4109
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4004
4110
|
missingContractIds.push(contractId);
|
4005
4111
|
});
|
4112
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4113
|
+
transactionRequest
|
4114
|
+
});
|
4115
|
+
transactionRequest.maxFee = maxFee;
|
4006
4116
|
} else {
|
4007
4117
|
break;
|
4008
4118
|
}
|
@@ -4010,37 +4120,136 @@ var _Provider = class {
|
|
4010
4120
|
return {
|
4011
4121
|
receipts,
|
4012
4122
|
outputVariables,
|
4013
|
-
missingContractIds
|
4123
|
+
missingContractIds,
|
4124
|
+
dryrunStatus
|
4014
4125
|
};
|
4015
4126
|
}
|
4127
|
+
/**
|
4128
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4129
|
+
*
|
4130
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4131
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4132
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4133
|
+
*
|
4134
|
+
* @param transactionRequests - Array of transaction request objects.
|
4135
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4136
|
+
*/
|
4137
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4138
|
+
const results = transactionRequests.map(() => ({
|
4139
|
+
receipts: [],
|
4140
|
+
outputVariables: 0,
|
4141
|
+
missingContractIds: [],
|
4142
|
+
dryrunStatus: void 0
|
4143
|
+
}));
|
4144
|
+
const allRequests = clone3(transactionRequests);
|
4145
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4146
|
+
allRequests.forEach((req, index) => {
|
4147
|
+
if (req.type === TransactionType8.Script) {
|
4148
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4149
|
+
}
|
4150
|
+
});
|
4151
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4152
|
+
let attempt = 0;
|
4153
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4154
|
+
const encodedTransactions = transactionsToProcess.map(
|
4155
|
+
(index) => serializedTransactionsMap.get(index)
|
4156
|
+
);
|
4157
|
+
const dryRunResults = await this.operations.dryRun({
|
4158
|
+
encodedTransactions,
|
4159
|
+
utxoValidation: false
|
4160
|
+
});
|
4161
|
+
const nextRoundTransactions = [];
|
4162
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4163
|
+
const requestIdx = transactionsToProcess[i];
|
4164
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4165
|
+
const result = results[requestIdx];
|
4166
|
+
result.receipts = rawReceipts.map(processGqlReceipt);
|
4167
|
+
result.dryrunStatus = status;
|
4168
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4169
|
+
result.receipts
|
4170
|
+
);
|
4171
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4172
|
+
const request = allRequests[requestIdx];
|
4173
|
+
if (hasMissingOutputs && request?.type === TransactionType8.Script) {
|
4174
|
+
result.outputVariables += missingOutputVariables.length;
|
4175
|
+
request.addVariableOutputs(missingOutputVariables.length);
|
4176
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4177
|
+
request.addContractInputAndOutput(Address2.fromString(contractId));
|
4178
|
+
result.missingContractIds.push(contractId);
|
4179
|
+
});
|
4180
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4181
|
+
transactionRequest: request
|
4182
|
+
});
|
4183
|
+
request.maxFee = maxFee;
|
4184
|
+
serializedTransactionsMap.set(requestIdx, hexlify12(request.toTransactionBytes()));
|
4185
|
+
nextRoundTransactions.push(requestIdx);
|
4186
|
+
}
|
4187
|
+
}
|
4188
|
+
transactionsToProcess = nextRoundTransactions;
|
4189
|
+
attempt += 1;
|
4190
|
+
}
|
4191
|
+
return results;
|
4192
|
+
}
|
4193
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4194
|
+
if (estimateTxDependencies) {
|
4195
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4196
|
+
}
|
4197
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4198
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4199
|
+
encodedTransactions,
|
4200
|
+
utxoValidation: utxoValidation || false
|
4201
|
+
});
|
4202
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4203
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4204
|
+
return { receipts, dryrunStatus: status };
|
4205
|
+
});
|
4206
|
+
return results;
|
4207
|
+
}
|
4016
4208
|
/**
|
4017
4209
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4018
4210
|
* @param transactionRequest - The transaction request object.
|
4019
4211
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4020
4212
|
*/
|
4021
|
-
estimateTxGasAndFee(params) {
|
4213
|
+
async estimateTxGasAndFee(params) {
|
4022
4214
|
const { transactionRequest } = params;
|
4023
|
-
|
4215
|
+
let { gasPrice } = params;
|
4024
4216
|
const chainInfo = this.getChain();
|
4025
|
-
const
|
4026
|
-
transactionRequest.gasPrice = gasPrice;
|
4217
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4027
4218
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4028
|
-
|
4219
|
+
if (!gasPrice) {
|
4220
|
+
gasPrice = await this.estimateGasPrice(10);
|
4221
|
+
}
|
4222
|
+
const minFee = calculateGasFee({
|
4223
|
+
gasPrice: bn16(gasPrice),
|
4224
|
+
gas: minGas,
|
4225
|
+
priceFactor: gasPriceFactor,
|
4226
|
+
tip: transactionRequest.tip
|
4227
|
+
}).add(1);
|
4228
|
+
let gasLimit = bn16(0);
|
4029
4229
|
if (transactionRequest.type === TransactionType8.Script) {
|
4230
|
+
gasLimit = transactionRequest.gasLimit;
|
4030
4231
|
if (transactionRequest.gasLimit.eq(0)) {
|
4031
4232
|
transactionRequest.gasLimit = minGas;
|
4032
4233
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4033
4234
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4034
4235
|
);
|
4236
|
+
gasLimit = transactionRequest.gasLimit;
|
4035
4237
|
}
|
4036
4238
|
}
|
4037
4239
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4038
|
-
const maxFee =
|
4240
|
+
const maxFee = calculateGasFee({
|
4241
|
+
gasPrice: bn16(gasPrice),
|
4242
|
+
gas: maxGas,
|
4243
|
+
priceFactor: gasPriceFactor,
|
4244
|
+
tip: transactionRequest.tip
|
4245
|
+
}).add(1);
|
4039
4246
|
return {
|
4040
4247
|
minGas,
|
4041
4248
|
minFee,
|
4042
4249
|
maxGas,
|
4043
|
-
maxFee
|
4250
|
+
maxFee,
|
4251
|
+
gasPrice,
|
4252
|
+
gasLimit
|
4044
4253
|
};
|
4045
4254
|
}
|
4046
4255
|
/**
|
@@ -4058,15 +4267,17 @@ var _Provider = class {
|
|
4058
4267
|
if (estimateTxDependencies) {
|
4059
4268
|
return this.estimateTxDependencies(transactionRequest);
|
4060
4269
|
}
|
4061
|
-
const
|
4062
|
-
const { dryRun:
|
4063
|
-
|
4270
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4271
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4272
|
+
encodedTransactions,
|
4064
4273
|
utxoValidation: true
|
4065
4274
|
});
|
4066
|
-
const
|
4067
|
-
|
4068
|
-
receipts
|
4069
|
-
|
4275
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4276
|
+
const { id, receipts, status } = dryRunStatus;
|
4277
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4278
|
+
return { id, receipts: processedReceipts, status };
|
4279
|
+
});
|
4280
|
+
return { receipts: callResult[0].receipts };
|
4070
4281
|
}
|
4071
4282
|
/**
|
4072
4283
|
* Returns a transaction cost to enable user
|
@@ -4083,77 +4294,80 @@ var _Provider = class {
|
|
4083
4294
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4084
4295
|
* @returns A promise that resolves to the transaction cost object.
|
4085
4296
|
*/
|
4086
|
-
async getTransactionCost(transactionRequestLike,
|
4087
|
-
estimateTxDependencies = true,
|
4088
|
-
estimatePredicates = true,
|
4089
|
-
resourcesOwner,
|
4090
|
-
signatureCallback
|
4091
|
-
} = {}) {
|
4297
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4092
4298
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4093
|
-
const { minGasPrice } = this.getGasConfig();
|
4094
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4095
4299
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4300
|
+
const baseAssetId = this.getBaseAssetId();
|
4096
4301
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4097
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4098
|
-
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4302
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4303
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4304
|
+
txRequestClone.maxFee = bn16(0);
|
4099
4305
|
if (isScriptTransaction) {
|
4100
|
-
txRequestClone.gasLimit =
|
4306
|
+
txRequestClone.gasLimit = bn16(0);
|
4101
4307
|
}
|
4102
|
-
if (
|
4103
|
-
|
4104
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4105
|
-
}
|
4106
|
-
await this.estimatePredicates(txRequestClone);
|
4308
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4309
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4107
4310
|
}
|
4311
|
+
const signedRequest = clone3(txRequestClone);
|
4312
|
+
let addedSignatures = 0;
|
4108
4313
|
if (signatureCallback && isScriptTransaction) {
|
4109
|
-
|
4314
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4315
|
+
await signatureCallback(signedRequest);
|
4316
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4110
4317
|
}
|
4111
|
-
|
4112
|
-
|
4318
|
+
await this.estimatePredicates(signedRequest);
|
4319
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4320
|
+
transactionRequest: signedRequest
|
4113
4321
|
});
|
4114
4322
|
let receipts = [];
|
4115
4323
|
let missingContractIds = [];
|
4116
4324
|
let outputVariables = 0;
|
4117
|
-
let gasUsed =
|
4118
|
-
|
4119
|
-
|
4325
|
+
let gasUsed = bn16(0);
|
4326
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4327
|
+
txRequestClone.maxFee = maxFee;
|
4328
|
+
if (isScriptTransaction) {
|
4329
|
+
txRequestClone.gasLimit = gasLimit;
|
4330
|
+
if (signatureCallback) {
|
4331
|
+
await signatureCallback(txRequestClone);
|
4332
|
+
}
|
4120
4333
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4121
4334
|
receipts = result.receipts;
|
4122
4335
|
outputVariables = result.outputVariables;
|
4123
4336
|
missingContractIds = result.missingContractIds;
|
4124
4337
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4125
4338
|
txRequestClone.gasLimit = gasUsed;
|
4126
|
-
|
4127
|
-
|
4128
|
-
|
4339
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4340
|
+
transactionRequest: txRequestClone,
|
4341
|
+
gasPrice
|
4129
4342
|
}));
|
4130
4343
|
}
|
4131
4344
|
return {
|
4132
4345
|
requiredQuantities: allQuantities,
|
4133
4346
|
receipts,
|
4134
4347
|
gasUsed,
|
4135
|
-
|
4136
|
-
gasPrice: setGasPrice,
|
4348
|
+
gasPrice,
|
4137
4349
|
minGas,
|
4138
4350
|
maxGas,
|
4139
4351
|
minFee,
|
4140
4352
|
maxFee,
|
4141
|
-
estimatedInputs: txRequestClone.inputs,
|
4142
4353
|
outputVariables,
|
4143
|
-
missingContractIds
|
4354
|
+
missingContractIds,
|
4355
|
+
addedSignatures,
|
4356
|
+
estimatedPredicates: txRequestClone.inputs
|
4144
4357
|
};
|
4145
4358
|
}
|
4146
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4359
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4147
4360
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4148
4361
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4149
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4362
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4363
|
+
quantitiesToContract
|
4364
|
+
});
|
4150
4365
|
transactionRequest.addResources(
|
4151
4366
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4152
4367
|
);
|
4153
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4154
|
-
|
4155
|
-
|
4156
|
-
);
|
4368
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4369
|
+
quantitiesToContract
|
4370
|
+
});
|
4157
4371
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4158
4372
|
return {
|
4159
4373
|
resources,
|
@@ -4175,11 +4389,10 @@ var _Provider = class {
|
|
4175
4389
|
return coins.map((coin) => ({
|
4176
4390
|
id: coin.utxoId,
|
4177
4391
|
assetId: coin.assetId,
|
4178
|
-
amount:
|
4392
|
+
amount: bn16(coin.amount),
|
4179
4393
|
owner: Address2.fromAddressOrString(coin.owner),
|
4180
|
-
|
4181
|
-
|
4182
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4394
|
+
blockCreated: bn16(coin.blockCreated),
|
4395
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4183
4396
|
}));
|
4184
4397
|
}
|
4185
4398
|
/**
|
@@ -4216,9 +4429,9 @@ var _Provider = class {
|
|
4216
4429
|
switch (coin.__typename) {
|
4217
4430
|
case "MessageCoin":
|
4218
4431
|
return {
|
4219
|
-
amount:
|
4432
|
+
amount: bn16(coin.amount),
|
4220
4433
|
assetId: coin.assetId,
|
4221
|
-
daHeight:
|
4434
|
+
daHeight: bn16(coin.daHeight),
|
4222
4435
|
sender: Address2.fromAddressOrString(coin.sender),
|
4223
4436
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4224
4437
|
nonce: coin.nonce
|
@@ -4226,12 +4439,11 @@ var _Provider = class {
|
|
4226
4439
|
case "Coin":
|
4227
4440
|
return {
|
4228
4441
|
id: coin.utxoId,
|
4229
|
-
amount:
|
4442
|
+
amount: bn16(coin.amount),
|
4230
4443
|
assetId: coin.assetId,
|
4231
4444
|
owner: Address2.fromAddressOrString(coin.owner),
|
4232
|
-
|
4233
|
-
|
4234
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4445
|
+
blockCreated: bn16(coin.blockCreated),
|
4446
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4235
4447
|
};
|
4236
4448
|
default:
|
4237
4449
|
return null;
|
@@ -4248,13 +4460,13 @@ var _Provider = class {
|
|
4248
4460
|
async getBlock(idOrHeight) {
|
4249
4461
|
let variables;
|
4250
4462
|
if (typeof idOrHeight === "number") {
|
4251
|
-
variables = { height:
|
4463
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4252
4464
|
} else if (idOrHeight === "latest") {
|
4253
4465
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4254
4466
|
} else if (idOrHeight.length === 66) {
|
4255
4467
|
variables = { blockId: idOrHeight };
|
4256
4468
|
} else {
|
4257
|
-
variables = { blockId:
|
4469
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4258
4470
|
}
|
4259
4471
|
const { block } = await this.operations.getBlock(variables);
|
4260
4472
|
if (!block) {
|
@@ -4262,7 +4474,7 @@ var _Provider = class {
|
|
4262
4474
|
}
|
4263
4475
|
return {
|
4264
4476
|
id: block.id,
|
4265
|
-
height:
|
4477
|
+
height: bn16(block.height),
|
4266
4478
|
time: block.header.time,
|
4267
4479
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4268
4480
|
};
|
@@ -4277,7 +4489,7 @@ var _Provider = class {
|
|
4277
4489
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4278
4490
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4279
4491
|
id: block.id,
|
4280
|
-
height:
|
4492
|
+
height: bn16(block.height),
|
4281
4493
|
time: block.header.time,
|
4282
4494
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4283
4495
|
}));
|
@@ -4292,7 +4504,7 @@ var _Provider = class {
|
|
4292
4504
|
async getBlockWithTransactions(idOrHeight) {
|
4293
4505
|
let variables;
|
4294
4506
|
if (typeof idOrHeight === "number") {
|
4295
|
-
variables = { blockHeight:
|
4507
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4296
4508
|
} else if (idOrHeight === "latest") {
|
4297
4509
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4298
4510
|
} else {
|
@@ -4304,7 +4516,7 @@ var _Provider = class {
|
|
4304
4516
|
}
|
4305
4517
|
return {
|
4306
4518
|
id: block.id,
|
4307
|
-
height:
|
4519
|
+
height: bn16(block.height, 10),
|
4308
4520
|
time: block.header.time,
|
4309
4521
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4310
4522
|
transactions: block.transactions.map(
|
@@ -4353,7 +4565,7 @@ var _Provider = class {
|
|
4353
4565
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4354
4566
|
asset: hexlify12(assetId)
|
4355
4567
|
});
|
4356
|
-
return
|
4568
|
+
return bn16(contractBalance.amount, 10);
|
4357
4569
|
}
|
4358
4570
|
/**
|
4359
4571
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4367,7 +4579,7 @@ var _Provider = class {
|
|
4367
4579
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4368
4580
|
assetId: hexlify12(assetId)
|
4369
4581
|
});
|
4370
|
-
return
|
4582
|
+
return bn16(balance.amount, 10);
|
4371
4583
|
}
|
4372
4584
|
/**
|
4373
4585
|
* Returns balances for the given owner.
|
@@ -4385,7 +4597,7 @@ var _Provider = class {
|
|
4385
4597
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4386
4598
|
return balances.map((balance) => ({
|
4387
4599
|
assetId: balance.assetId,
|
4388
|
-
amount:
|
4600
|
+
amount: bn16(balance.amount)
|
4389
4601
|
}));
|
4390
4602
|
}
|
4391
4603
|
/**
|
@@ -4407,15 +4619,15 @@ var _Provider = class {
|
|
4407
4619
|
sender: message.sender,
|
4408
4620
|
recipient: message.recipient,
|
4409
4621
|
nonce: message.nonce,
|
4410
|
-
amount:
|
4622
|
+
amount: bn16(message.amount),
|
4411
4623
|
data: message.data
|
4412
4624
|
}),
|
4413
4625
|
sender: Address2.fromAddressOrString(message.sender),
|
4414
4626
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4415
4627
|
nonce: message.nonce,
|
4416
|
-
amount:
|
4628
|
+
amount: bn16(message.amount),
|
4417
4629
|
data: InputMessageCoder.decodeData(message.data),
|
4418
|
-
daHeight:
|
4630
|
+
daHeight: bn16(message.daHeight)
|
4419
4631
|
}));
|
4420
4632
|
}
|
4421
4633
|
/**
|
@@ -4468,44 +4680,60 @@ var _Provider = class {
|
|
4468
4680
|
} = result.messageProof;
|
4469
4681
|
return {
|
4470
4682
|
messageProof: {
|
4471
|
-
proofIndex:
|
4683
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4472
4684
|
proofSet: messageProof.proofSet
|
4473
4685
|
},
|
4474
4686
|
blockProof: {
|
4475
|
-
proofIndex:
|
4687
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4476
4688
|
proofSet: blockProof.proofSet
|
4477
4689
|
},
|
4478
4690
|
messageBlockHeader: {
|
4479
4691
|
id: messageBlockHeader.id,
|
4480
|
-
daHeight:
|
4481
|
-
transactionsCount:
|
4692
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4693
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4482
4694
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4483
|
-
height:
|
4695
|
+
height: bn16(messageBlockHeader.height),
|
4484
4696
|
prevRoot: messageBlockHeader.prevRoot,
|
4485
4697
|
time: messageBlockHeader.time,
|
4486
4698
|
applicationHash: messageBlockHeader.applicationHash,
|
4487
|
-
|
4488
|
-
|
4699
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4700
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4701
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4702
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4703
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4489
4704
|
},
|
4490
4705
|
commitBlockHeader: {
|
4491
4706
|
id: commitBlockHeader.id,
|
4492
|
-
daHeight:
|
4493
|
-
transactionsCount:
|
4707
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4708
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4494
4709
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4495
|
-
height:
|
4710
|
+
height: bn16(commitBlockHeader.height),
|
4496
4711
|
prevRoot: commitBlockHeader.prevRoot,
|
4497
4712
|
time: commitBlockHeader.time,
|
4498
4713
|
applicationHash: commitBlockHeader.applicationHash,
|
4499
|
-
|
4500
|
-
|
4714
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4715
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4716
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4717
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4718
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4501
4719
|
},
|
4502
4720
|
sender: Address2.fromAddressOrString(sender),
|
4503
4721
|
recipient: Address2.fromAddressOrString(recipient),
|
4504
4722
|
nonce,
|
4505
|
-
amount:
|
4723
|
+
amount: bn16(amount),
|
4506
4724
|
data
|
4507
4725
|
};
|
4508
4726
|
}
|
4727
|
+
async getLatestGasPrice() {
|
4728
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4729
|
+
return bn16(latestGasPrice.gasPrice);
|
4730
|
+
}
|
4731
|
+
async estimateGasPrice(blockHorizon) {
|
4732
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4733
|
+
blockHorizon: String(blockHorizon)
|
4734
|
+
});
|
4735
|
+
return bn16(estimateGasPrice.gasPrice);
|
4736
|
+
}
|
4509
4737
|
/**
|
4510
4738
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4511
4739
|
*
|
@@ -4525,10 +4753,10 @@ var _Provider = class {
|
|
4525
4753
|
*/
|
4526
4754
|
async produceBlocks(amount, startTime) {
|
4527
4755
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4528
|
-
blocksToProduce:
|
4756
|
+
blocksToProduce: bn16(amount).toString(10),
|
4529
4757
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4530
4758
|
});
|
4531
|
-
return
|
4759
|
+
return bn16(latestBlockHeight);
|
4532
4760
|
}
|
4533
4761
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4534
4762
|
async getTransactionResponse(transactionId) {
|
@@ -4542,7 +4770,7 @@ cacheInputs_fn = function(inputs) {
|
|
4542
4770
|
return;
|
4543
4771
|
}
|
4544
4772
|
inputs.forEach((input) => {
|
4545
|
-
if (input.type ===
|
4773
|
+
if (input.type === InputType7.Coin) {
|
4546
4774
|
this.cache?.set(input.id);
|
4547
4775
|
}
|
4548
4776
|
});
|
@@ -4552,7 +4780,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4552
4780
|
|
4553
4781
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4554
4782
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4555
|
-
import { bn as
|
4783
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4556
4784
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4557
4785
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4558
4786
|
async function getTransactionSummary(params) {
|
@@ -4570,21 +4798,28 @@ async function getTransactionSummary(params) {
|
|
4570
4798
|
arrayify12(gqlTransaction.rawPayload),
|
4571
4799
|
0
|
4572
4800
|
);
|
4573
|
-
|
4801
|
+
let txReceipts = [];
|
4802
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4803
|
+
txReceipts = gqlTransaction.status.receipts;
|
4804
|
+
}
|
4805
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4574
4806
|
const {
|
4575
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4807
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4576
4808
|
} = provider.getChain();
|
4809
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4577
4810
|
const transactionInfo = assembleTransactionSummary({
|
4578
4811
|
id: gqlTransaction.id,
|
4579
4812
|
receipts,
|
4580
4813
|
transaction: decodedTransaction,
|
4581
4814
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4582
4815
|
gqlTransactionStatus: gqlTransaction.status,
|
4583
|
-
gasPerByte:
|
4584
|
-
gasPriceFactor:
|
4816
|
+
gasPerByte: bn17(gasPerByte),
|
4817
|
+
gasPriceFactor: bn17(gasPriceFactor),
|
4585
4818
|
abiMap,
|
4586
4819
|
maxInputs,
|
4587
|
-
gasCosts
|
4820
|
+
gasCosts,
|
4821
|
+
maxGasPerTx,
|
4822
|
+
gasPrice
|
4588
4823
|
});
|
4589
4824
|
return {
|
4590
4825
|
gqlTransaction,
|
@@ -4594,10 +4829,11 @@ async function getTransactionSummary(params) {
|
|
4594
4829
|
async function getTransactionSummaryFromRequest(params) {
|
4595
4830
|
const { provider, transactionRequest, abiMap } = params;
|
4596
4831
|
const { receipts } = await provider.call(transactionRequest);
|
4597
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4832
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4598
4833
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4599
4834
|
const transaction = transactionRequest.toTransaction();
|
4600
4835
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4836
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4601
4837
|
const transactionSummary = assembleTransactionSummary({
|
4602
4838
|
receipts,
|
4603
4839
|
transaction,
|
@@ -4606,7 +4842,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4606
4842
|
gasPerByte,
|
4607
4843
|
gasPriceFactor,
|
4608
4844
|
maxInputs,
|
4609
|
-
gasCosts
|
4845
|
+
gasCosts,
|
4846
|
+
maxGasPerTx,
|
4847
|
+
gasPrice
|
4610
4848
|
});
|
4611
4849
|
return transactionSummary;
|
4612
4850
|
}
|
@@ -4615,13 +4853,18 @@ async function getTransactionsSummaries(params) {
|
|
4615
4853
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4616
4854
|
const { edges, pageInfo } = transactionsByOwner;
|
4617
4855
|
const {
|
4618
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4856
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4619
4857
|
} = provider.getChain();
|
4858
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4620
4859
|
const transactions = edges.map((edge) => {
|
4621
4860
|
const { node: gqlTransaction } = edge;
|
4622
|
-
const { id, rawPayload,
|
4861
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4623
4862
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4624
|
-
|
4863
|
+
let txReceipts = [];
|
4864
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4865
|
+
txReceipts = gqlTransaction.status.receipts;
|
4866
|
+
}
|
4867
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4625
4868
|
const transactionSummary = assembleTransactionSummary({
|
4626
4869
|
id,
|
4627
4870
|
receipts,
|
@@ -4632,7 +4875,9 @@ async function getTransactionsSummaries(params) {
|
|
4632
4875
|
gasPerByte,
|
4633
4876
|
gasPriceFactor,
|
4634
4877
|
maxInputs,
|
4635
|
-
gasCosts
|
4878
|
+
gasCosts,
|
4879
|
+
maxGasPerTx,
|
4880
|
+
gasPrice
|
4636
4881
|
});
|
4637
4882
|
const output = {
|
4638
4883
|
gqlTransaction,
|
@@ -4926,8 +5171,9 @@ var Account = class extends AbstractAccount {
|
|
4926
5171
|
* @param assetId - The asset ID to check the balance for.
|
4927
5172
|
* @returns A promise that resolves to the balance amount.
|
4928
5173
|
*/
|
4929
|
-
async getBalance(assetId
|
4930
|
-
const
|
5174
|
+
async getBalance(assetId) {
|
5175
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
5176
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4931
5177
|
return amount;
|
4932
5178
|
}
|
4933
5179
|
/**
|
@@ -4964,37 +5210,31 @@ var Account = class extends AbstractAccount {
|
|
4964
5210
|
* @param fee - The estimated transaction fee.
|
4965
5211
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4966
5212
|
*/
|
4967
|
-
async fund(request,
|
4968
|
-
const
|
4969
|
-
|
4970
|
-
|
4971
|
-
|
5213
|
+
async fund(request, params) {
|
5214
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5215
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5216
|
+
const txRequest = request;
|
5217
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5218
|
+
amount: bn18(fee),
|
5219
|
+
assetId: baseAssetId,
|
5220
|
+
coinQuantities: requiredQuantities
|
4972
5221
|
});
|
4973
5222
|
const quantitiesDict = {};
|
4974
|
-
|
5223
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4975
5224
|
quantitiesDict[assetId] = {
|
4976
5225
|
required: amount,
|
4977
|
-
owned:
|
5226
|
+
owned: bn18(0)
|
4978
5227
|
};
|
4979
5228
|
});
|
4980
|
-
|
4981
|
-
const cachedMessages = [];
|
4982
|
-
const owner = this.address.toB256();
|
4983
|
-
request.inputs.forEach((input) => {
|
5229
|
+
txRequest.inputs.forEach((input) => {
|
4984
5230
|
const isResource = "amount" in input;
|
4985
|
-
if (isResource) {
|
4986
|
-
|
4987
|
-
|
4988
|
-
|
4989
|
-
|
4990
|
-
|
4991
|
-
|
4992
|
-
cachedUtxos.push(input.id);
|
4993
|
-
}
|
4994
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4995
|
-
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4996
|
-
cachedMessages.push(input.nonce);
|
4997
|
-
}
|
5231
|
+
if (!isResource) {
|
5232
|
+
return;
|
5233
|
+
}
|
5234
|
+
const isCoin2 = "owner" in input;
|
5235
|
+
const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
|
5236
|
+
if (quantitiesDict[assetId]) {
|
5237
|
+
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
|
4998
5238
|
}
|
4999
5239
|
});
|
5000
5240
|
const missingQuantities = [];
|
@@ -5008,12 +5248,21 @@ var Account = class extends AbstractAccount {
|
|
5008
5248
|
});
|
5009
5249
|
const needsToBeFunded = missingQuantities.length;
|
5010
5250
|
if (needsToBeFunded) {
|
5011
|
-
const
|
5012
|
-
|
5013
|
-
|
5014
|
-
|
5015
|
-
|
5016
|
-
|
5251
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5252
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5253
|
+
txRequest.addResources(resources);
|
5254
|
+
}
|
5255
|
+
txRequest.shiftPredicateData();
|
5256
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5257
|
+
const requestToReestimate = clone4(txRequest);
|
5258
|
+
if (addedSignatures) {
|
5259
|
+
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
5260
|
+
}
|
5261
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5262
|
+
transactionRequest: requestToReestimate
|
5263
|
+
});
|
5264
|
+
txRequest.maxFee = maxFee;
|
5265
|
+
return txRequest;
|
5017
5266
|
}
|
5018
5267
|
/**
|
5019
5268
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5021,28 +5270,25 @@ var Account = class extends AbstractAccount {
|
|
5021
5270
|
* @param destination - The address of the destination.
|
5022
5271
|
* @param amount - The amount of coins to transfer.
|
5023
5272
|
* @param assetId - The asset ID of the coins to transfer.
|
5024
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5273
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5025
5274
|
* @returns A promise that resolves to the prepared transaction request.
|
5026
5275
|
*/
|
5027
|
-
async createTransfer(destination, amount, assetId
|
5028
|
-
const
|
5029
|
-
const
|
5030
|
-
|
5031
|
-
|
5032
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5276
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5277
|
+
const request = new ScriptTransactionRequest(txParams);
|
5278
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5279
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5280
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5033
5281
|
estimateTxDependencies: true,
|
5034
5282
|
resourcesOwner: this
|
5035
5283
|
});
|
5036
|
-
|
5037
|
-
|
5038
|
-
|
5039
|
-
|
5040
|
-
gasPrice: request.gasPrice,
|
5041
|
-
gasLimit: request.gasLimit,
|
5042
|
-
minGasPrice
|
5284
|
+
this.validateGasLimitAndMaxFee({
|
5285
|
+
gasUsed: txCost.gasUsed,
|
5286
|
+
maxFee: txCost.maxFee,
|
5287
|
+
txParams
|
5043
5288
|
});
|
5044
|
-
|
5045
|
-
request.
|
5289
|
+
request.gasLimit = txCost.gasUsed;
|
5290
|
+
request.maxFee = txCost.maxFee;
|
5291
|
+
await this.fund(request, txCost);
|
5046
5292
|
return request;
|
5047
5293
|
}
|
5048
5294
|
/**
|
@@ -5051,17 +5297,18 @@ var Account = class extends AbstractAccount {
|
|
5051
5297
|
* @param destination - The address of the destination.
|
5052
5298
|
* @param amount - The amount of coins to transfer.
|
5053
5299
|
* @param assetId - The asset ID of the coins to transfer.
|
5054
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5300
|
+
* @param txParams - The transaction parameters (gasLimit, maturity).
|
5055
5301
|
* @returns A promise that resolves to the transaction response.
|
5056
5302
|
*/
|
5057
|
-
async transfer(destination, amount, assetId
|
5058
|
-
if (
|
5303
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5304
|
+
if (bn18(amount).lte(0)) {
|
5059
5305
|
throw new FuelError15(
|
5060
5306
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5061
5307
|
"Transfer amount must be a positive number."
|
5062
5308
|
);
|
5063
5309
|
}
|
5064
|
-
const
|
5310
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5311
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5065
5312
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5066
5313
|
}
|
5067
5314
|
/**
|
@@ -5073,39 +5320,38 @@ var Account = class extends AbstractAccount {
|
|
5073
5320
|
* @param txParams - The optional transaction parameters.
|
5074
5321
|
* @returns A promise that resolves to the transaction response.
|
5075
5322
|
*/
|
5076
|
-
async transferToContract(contractId, amount, assetId
|
5077
|
-
if (
|
5323
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5324
|
+
if (bn18(amount).lte(0)) {
|
5078
5325
|
throw new FuelError15(
|
5079
5326
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5080
5327
|
"Transfer amount must be a positive number."
|
5081
5328
|
);
|
5082
5329
|
}
|
5083
5330
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5084
|
-
const
|
5085
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5331
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5086
5332
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5087
5333
|
hexlifiedContractId: contractAddress.toB256(),
|
5088
|
-
amountToTransfer:
|
5089
|
-
assetId
|
5334
|
+
amountToTransfer: bn18(amount),
|
5335
|
+
assetId: assetIdToTransfer
|
5090
5336
|
});
|
5091
5337
|
const request = new ScriptTransactionRequest({
|
5092
|
-
...
|
5338
|
+
...txParams,
|
5093
5339
|
script,
|
5094
5340
|
scriptData
|
5095
5341
|
});
|
5096
5342
|
request.addContractInputAndOutput(contractAddress);
|
5097
|
-
const
|
5098
|
-
|
5099
|
-
[{ amount:
|
5100
|
-
);
|
5101
|
-
|
5102
|
-
|
5103
|
-
|
5104
|
-
|
5105
|
-
gasLimit: request.gasLimit,
|
5106
|
-
minGasPrice
|
5343
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5344
|
+
resourcesOwner: this,
|
5345
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetIdToTransfer) }]
|
5346
|
+
});
|
5347
|
+
this.validateGasLimitAndMaxFee({
|
5348
|
+
gasUsed: txCost.gasUsed,
|
5349
|
+
maxFee: txCost.maxFee,
|
5350
|
+
txParams
|
5107
5351
|
});
|
5108
|
-
|
5352
|
+
request.gasLimit = txCost.gasUsed;
|
5353
|
+
request.maxFee = txCost.maxFee;
|
5354
|
+
await this.fund(request, txCost);
|
5109
5355
|
return this.sendTransaction(request);
|
5110
5356
|
}
|
5111
5357
|
/**
|
@@ -5117,34 +5363,31 @@ var Account = class extends AbstractAccount {
|
|
5117
5363
|
* @returns A promise that resolves to the transaction response.
|
5118
5364
|
*/
|
5119
5365
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5120
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5121
5366
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5122
5367
|
const recipientDataArray = arrayify14(
|
5123
5368
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5124
5369
|
);
|
5125
5370
|
const amountDataArray = arrayify14(
|
5126
|
-
"0x".concat(
|
5371
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
5127
5372
|
);
|
5128
5373
|
const script = new Uint8Array([
|
5129
5374
|
...arrayify14(withdrawScript.bytes),
|
5130
5375
|
...recipientDataArray,
|
5131
5376
|
...amountDataArray
|
5132
5377
|
]);
|
5133
|
-
const params = { script,
|
5378
|
+
const params = { script, ...txParams };
|
5379
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5134
5380
|
const request = new ScriptTransactionRequest(params);
|
5135
|
-
const
|
5136
|
-
const
|
5137
|
-
|
5138
|
-
|
5139
|
-
|
5140
|
-
|
5141
|
-
this.validateGas({
|
5142
|
-
gasUsed,
|
5143
|
-
gasPrice: request.gasPrice,
|
5144
|
-
gasLimit: request.gasLimit,
|
5145
|
-
minGasPrice
|
5381
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: baseAssetId }];
|
5382
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5383
|
+
this.validateGasLimitAndMaxFee({
|
5384
|
+
gasUsed: txCost.gasUsed,
|
5385
|
+
maxFee: txCost.maxFee,
|
5386
|
+
txParams
|
5146
5387
|
});
|
5147
|
-
|
5388
|
+
request.maxFee = txCost.maxFee;
|
5389
|
+
request.gasLimit = txCost.gasUsed;
|
5390
|
+
await this.fund(request, txCost);
|
5148
5391
|
return this.sendTransaction(request);
|
5149
5392
|
}
|
5150
5393
|
async signMessage(message) {
|
@@ -5202,22 +5445,21 @@ var Account = class extends AbstractAccount {
|
|
5202
5445
|
}
|
5203
5446
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5204
5447
|
}
|
5205
|
-
|
5448
|
+
validateGasLimitAndMaxFee({
|
5449
|
+
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
5206
5450
|
gasUsed,
|
5207
|
-
|
5208
|
-
gasLimit,
|
5209
|
-
minGasPrice
|
5451
|
+
maxFee
|
5210
5452
|
}) {
|
5211
|
-
if (
|
5453
|
+
if (isDefined(setGasLimit) && gasUsed.gt(setGasLimit)) {
|
5212
5454
|
throw new FuelError15(
|
5213
|
-
ErrorCode15.
|
5214
|
-
`Gas
|
5455
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5456
|
+
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
5215
5457
|
);
|
5216
5458
|
}
|
5217
|
-
if (
|
5459
|
+
if (isDefined(setMaxFee) && maxFee.gt(setMaxFee)) {
|
5218
5460
|
throw new FuelError15(
|
5219
|
-
ErrorCode15.
|
5220
|
-
`
|
5461
|
+
ErrorCode15.MAX_FEE_TOO_LOW,
|
5462
|
+
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
5221
5463
|
);
|
5222
5464
|
}
|
5223
5465
|
}
|
@@ -5509,7 +5751,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5509
5751
|
* @param transactionRequestLike - The transaction request to send.
|
5510
5752
|
* @returns A promise that resolves to the TransactionResponse object.
|
5511
5753
|
*/
|
5512
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5754
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5513
5755
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5514
5756
|
if (estimateTxDependencies) {
|
5515
5757
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5550,7 +5792,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5550
5792
|
// src/hdwallet/hdwallet.ts
|
5551
5793
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5552
5794
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5553
|
-
import { bn as
|
5795
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5554
5796
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5555
5797
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5556
5798
|
|
@@ -8022,7 +8264,7 @@ var HDWallet = class {
|
|
8022
8264
|
const IR = bytes.slice(32);
|
8023
8265
|
if (privateKey) {
|
8024
8266
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8025
|
-
const ki =
|
8267
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
8026
8268
|
return new HDWallet({
|
8027
8269
|
privateKey: ki,
|
8028
8270
|
chainCode: IR,
|
@@ -8709,9 +8951,8 @@ import {
|
|
8709
8951
|
SCRIPT_FIXED_SIZE
|
8710
8952
|
} from "@fuel-ts/abi-coder";
|
8711
8953
|
import { Address as Address9 } from "@fuel-ts/address";
|
8712
|
-
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8713
8954
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8714
|
-
import { ByteArrayCoder, InputType as
|
8955
|
+
import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
|
8715
8956
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8716
8957
|
|
8717
8958
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8771,35 +9012,22 @@ var Predicate = class extends Account {
|
|
8771
9012
|
const request = transactionRequestify(transactionRequestLike);
|
8772
9013
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8773
9014
|
request.inputs?.forEach((input) => {
|
8774
|
-
if (input.type ===
|
8775
|
-
input.predicate = this.bytes;
|
8776
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9015
|
+
if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
9016
|
+
input.predicate = hexlify19(this.bytes);
|
9017
|
+
input.predicateData = hexlify19(this.getPredicateData(policies.length));
|
8777
9018
|
}
|
8778
9019
|
});
|
8779
9020
|
return request;
|
8780
9021
|
}
|
8781
|
-
/**
|
8782
|
-
* A helper that creates a transfer transaction request and returns it.
|
8783
|
-
*
|
8784
|
-
* @param destination - The address of the destination.
|
8785
|
-
* @param amount - The amount of coins to transfer.
|
8786
|
-
* @param assetId - The asset ID of the coins to transfer.
|
8787
|
-
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8788
|
-
* @returns A promise that resolves to the prepared transaction request.
|
8789
|
-
*/
|
8790
|
-
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8791
|
-
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8792
|
-
return this.populateTransactionPredicateData(request);
|
8793
|
-
}
|
8794
9022
|
/**
|
8795
9023
|
* Sends a transaction with the populated predicate data.
|
8796
9024
|
*
|
8797
9025
|
* @param transactionRequestLike - The transaction request-like object.
|
8798
9026
|
* @returns A promise that resolves to the transaction response.
|
8799
9027
|
*/
|
8800
|
-
sendTransaction(transactionRequestLike
|
8801
|
-
const transactionRequest =
|
8802
|
-
return super.sendTransaction(transactionRequest,
|
9028
|
+
sendTransaction(transactionRequestLike) {
|
9029
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9030
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8803
9031
|
}
|
8804
9032
|
/**
|
8805
9033
|
* Simulates a transaction with the populated predicate data.
|
@@ -8808,8 +9036,8 @@ var Predicate = class extends Account {
|
|
8808
9036
|
* @returns A promise that resolves to the call result.
|
8809
9037
|
*/
|
8810
9038
|
simulateTransaction(transactionRequestLike) {
|
8811
|
-
const transactionRequest =
|
8812
|
-
return super.simulateTransaction(transactionRequest);
|
9039
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9040
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8813
9041
|
}
|
8814
9042
|
getPredicateData(policiesLength) {
|
8815
9043
|
if (!this.predicateData.length) {
|
@@ -8855,6 +9083,25 @@ var Predicate = class extends Account {
|
|
8855
9083
|
predicateInterface: abiInterface
|
8856
9084
|
};
|
8857
9085
|
}
|
9086
|
+
/**
|
9087
|
+
* Retrieves resources satisfying the spend query for the account.
|
9088
|
+
*
|
9089
|
+
* @param quantities - IDs of coins to exclude.
|
9090
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9091
|
+
* @returns A promise that resolves to an array of Resources.
|
9092
|
+
*/
|
9093
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9094
|
+
const resources = await this.provider.getResourcesToSpend(
|
9095
|
+
this.address,
|
9096
|
+
quantities,
|
9097
|
+
excludedIds
|
9098
|
+
);
|
9099
|
+
return resources.map((resource) => ({
|
9100
|
+
...resource,
|
9101
|
+
predicate: hexlify19(this.bytes),
|
9102
|
+
padPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9103
|
+
}));
|
9104
|
+
}
|
8858
9105
|
/**
|
8859
9106
|
* Sets the configurable constants for the predicate.
|
8860
9107
|
*
|
@@ -9603,7 +9850,7 @@ export {
|
|
9603
9850
|
WalletLocked,
|
9604
9851
|
WalletManager,
|
9605
9852
|
WalletUnlocked,
|
9606
|
-
|
9853
|
+
addAmountToCoinQuantities,
|
9607
9854
|
addOperation,
|
9608
9855
|
assemblePanicError,
|
9609
9856
|
assembleReceiptByType,
|
@@ -9612,9 +9859,10 @@ export {
|
|
9612
9859
|
assets,
|
9613
9860
|
buildBlockExplorerUrl,
|
9614
9861
|
cacheFor,
|
9862
|
+
cacheTxInputsFromOwner,
|
9863
|
+
calculateGasFee,
|
9615
9864
|
calculateMetadataGasForTxCreate,
|
9616
9865
|
calculateMetadataGasForTxScript,
|
9617
|
-
calculatePriceWithFactor,
|
9618
9866
|
calculateTransactionFee,
|
9619
9867
|
coinQuantityfy,
|
9620
9868
|
deferPromise,
|