@fuel-ts/account 0.0.0-rc-2021-20240424121206 → 0.0.0-rc-1976-20240424150847
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 +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +686 -942
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +605 -865
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +448 -707
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +327 -821
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -37
- 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 +33 -12
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/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.map +1 -1
- package/dist/test-utils.global.js +1218 -1690
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +604 -846
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +458 -700
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/index.mjs
CHANGED
@@ -29,38 +29,35 @@ 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
|
34
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
36
35
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
|
-
import { clone as clone4 } from "ramda";
|
38
36
|
|
39
37
|
// src/providers/coin-quantity.ts
|
40
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
41
38
|
import { bn } from "@fuel-ts/math";
|
42
39
|
import { hexlify } from "@fuel-ts/utils";
|
43
40
|
var coinQuantityfy = (coinQuantityLike) => {
|
44
41
|
let assetId;
|
45
42
|
let amount;
|
46
|
-
let
|
43
|
+
let max2;
|
47
44
|
if (Array.isArray(coinQuantityLike)) {
|
48
45
|
amount = coinQuantityLike[0];
|
49
|
-
assetId = coinQuantityLike[1]
|
50
|
-
|
46
|
+
assetId = coinQuantityLike[1];
|
47
|
+
max2 = coinQuantityLike[2];
|
51
48
|
} else {
|
52
49
|
amount = coinQuantityLike.amount;
|
53
|
-
assetId = coinQuantityLike.assetId
|
54
|
-
|
50
|
+
assetId = coinQuantityLike.assetId;
|
51
|
+
max2 = coinQuantityLike.max ?? void 0;
|
55
52
|
}
|
56
53
|
const bnAmount = bn(amount);
|
57
54
|
return {
|
58
55
|
assetId: hexlify(assetId),
|
59
56
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
60
|
-
max:
|
57
|
+
max: max2 ? bn(max2) : void 0
|
61
58
|
};
|
62
59
|
};
|
63
|
-
var
|
60
|
+
var addAmountToAsset = (params) => {
|
64
61
|
const { amount, assetId } = params;
|
65
62
|
const coinQuantities = [...params.coinQuantities];
|
66
63
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -75,9 +72,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
75
72
|
// src/providers/provider.ts
|
76
73
|
import { Address as Address2 } from "@fuel-ts/address";
|
77
74
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
78
|
-
import { BN, bn as
|
75
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
79
76
|
import {
|
80
|
-
InputType as
|
77
|
+
InputType as InputType6,
|
81
78
|
TransactionType as TransactionType8,
|
82
79
|
InputMessageCoder,
|
83
80
|
TransactionCoder as TransactionCoder5
|
@@ -91,40 +88,16 @@ import { clone as clone3 } from "ramda";
|
|
91
88
|
|
92
89
|
// src/providers/__generated__/operations.ts
|
93
90
|
import gql from "graphql-tag";
|
94
|
-
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
95
|
-
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
96
|
-
type: __typename
|
97
|
-
... on SubmittedStatus {
|
98
|
-
time
|
99
|
-
}
|
100
|
-
... on SuccessStatus {
|
101
|
-
block {
|
102
|
-
id
|
103
|
-
}
|
104
|
-
time
|
105
|
-
programState {
|
106
|
-
returnType
|
107
|
-
data
|
108
|
-
}
|
109
|
-
}
|
110
|
-
... on FailureStatus {
|
111
|
-
block {
|
112
|
-
id
|
113
|
-
}
|
114
|
-
time
|
115
|
-
reason
|
116
|
-
}
|
117
|
-
... on SqueezedOutStatus {
|
118
|
-
reason
|
119
|
-
}
|
120
|
-
}
|
121
|
-
`;
|
122
91
|
var ReceiptFragmentFragmentDoc = gql`
|
123
92
|
fragment receiptFragment on Receipt {
|
124
|
-
|
93
|
+
contract {
|
94
|
+
id
|
95
|
+
}
|
125
96
|
pc
|
126
97
|
is
|
127
|
-
to
|
98
|
+
to {
|
99
|
+
id
|
100
|
+
}
|
128
101
|
toAddress
|
129
102
|
amount
|
130
103
|
assetId
|
@@ -162,16 +135,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
162
135
|
id
|
163
136
|
}
|
164
137
|
time
|
165
|
-
receipts {
|
166
|
-
...receiptFragment
|
167
|
-
}
|
168
138
|
programState {
|
169
139
|
returnType
|
170
140
|
data
|
171
141
|
}
|
172
|
-
receipts {
|
173
|
-
...receiptFragment
|
174
|
-
}
|
175
142
|
}
|
176
143
|
... on FailureStatus {
|
177
144
|
block {
|
@@ -179,24 +146,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
179
146
|
}
|
180
147
|
time
|
181
148
|
reason
|
182
|
-
receipts {
|
183
|
-
...receiptFragment
|
184
|
-
}
|
185
149
|
}
|
186
150
|
... on SqueezedOutStatus {
|
187
151
|
reason
|
188
152
|
}
|
189
153
|
}
|
190
|
-
|
154
|
+
`;
|
191
155
|
var TransactionFragmentFragmentDoc = gql`
|
192
156
|
fragment transactionFragment on Transaction {
|
193
157
|
id
|
194
158
|
rawPayload
|
159
|
+
gasPrice
|
160
|
+
receipts {
|
161
|
+
...receiptFragment
|
162
|
+
}
|
195
163
|
status {
|
196
164
|
...transactionStatusFragment
|
197
165
|
}
|
198
166
|
}
|
199
|
-
${
|
167
|
+
${ReceiptFragmentFragmentDoc}
|
168
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
200
169
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
201
170
|
fragment inputEstimatePredicatesFragment on Input {
|
202
171
|
... on InputCoin {
|
@@ -214,46 +183,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
214
183
|
}
|
215
184
|
}
|
216
185
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
217
|
-
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
218
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
219
|
-
reason
|
220
|
-
programState {
|
221
|
-
returnType
|
222
|
-
data
|
223
|
-
}
|
224
|
-
}
|
225
|
-
`;
|
226
|
-
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
227
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
228
|
-
programState {
|
229
|
-
returnType
|
230
|
-
data
|
231
|
-
}
|
232
|
-
}
|
233
|
-
`;
|
234
|
-
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
235
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
236
|
-
... on DryRunFailureStatus {
|
237
|
-
...dryRunFailureStatusFragment
|
238
|
-
}
|
239
|
-
... on DryRunSuccessStatus {
|
240
|
-
...dryRunSuccessStatusFragment
|
241
|
-
}
|
242
|
-
}
|
243
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
244
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
245
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
246
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
247
|
-
id
|
248
|
-
status {
|
249
|
-
...dryRunTransactionStatusFragment
|
250
|
-
}
|
251
|
-
receipts {
|
252
|
-
...receiptFragment
|
253
|
-
}
|
254
|
-
}
|
255
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
256
|
-
${ReceiptFragmentFragmentDoc}`;
|
257
186
|
var CoinFragmentFragmentDoc = gql`
|
258
187
|
fragment coinFragment on Coin {
|
259
188
|
__typename
|
@@ -261,6 +190,7 @@ var CoinFragmentFragmentDoc = gql`
|
|
261
190
|
owner
|
262
191
|
amount
|
263
192
|
assetId
|
193
|
+
maturity
|
264
194
|
blockCreated
|
265
195
|
txCreatedIdx
|
266
196
|
}
|
@@ -299,32 +229,26 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
299
229
|
messageBlockHeader {
|
300
230
|
id
|
301
231
|
daHeight
|
302
|
-
consensusParametersVersion
|
303
|
-
stateTransitionBytecodeVersion
|
304
232
|
transactionsCount
|
305
|
-
messageReceiptCount
|
306
233
|
transactionsRoot
|
307
|
-
messageOutboxRoot
|
308
|
-
eventInboxRoot
|
309
234
|
height
|
310
235
|
prevRoot
|
311
236
|
time
|
312
237
|
applicationHash
|
238
|
+
messageReceiptRoot
|
239
|
+
messageReceiptCount
|
313
240
|
}
|
314
241
|
commitBlockHeader {
|
315
242
|
id
|
316
243
|
daHeight
|
317
|
-
consensusParametersVersion
|
318
|
-
stateTransitionBytecodeVersion
|
319
244
|
transactionsCount
|
320
|
-
messageReceiptCount
|
321
245
|
transactionsRoot
|
322
|
-
messageOutboxRoot
|
323
|
-
eventInboxRoot
|
324
246
|
height
|
325
247
|
prevRoot
|
326
248
|
time
|
327
249
|
applicationHash
|
250
|
+
messageReceiptRoot
|
251
|
+
messageReceiptCount
|
328
252
|
}
|
329
253
|
sender
|
330
254
|
recipient
|
@@ -343,8 +267,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
343
267
|
var BlockFragmentFragmentDoc = gql`
|
344
268
|
fragment blockFragment on Block {
|
345
269
|
id
|
346
|
-
height
|
347
270
|
header {
|
271
|
+
height
|
348
272
|
time
|
349
273
|
}
|
350
274
|
transactions {
|
@@ -402,11 +326,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
402
326
|
`;
|
403
327
|
var GasCostsFragmentFragmentDoc = gql`
|
404
328
|
fragment GasCostsFragment on GasCosts {
|
405
|
-
version {
|
406
|
-
... on Version {
|
407
|
-
value
|
408
|
-
}
|
409
|
-
}
|
410
329
|
add
|
411
330
|
addi
|
412
331
|
aloc
|
@@ -419,6 +338,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
419
338
|
cb
|
420
339
|
cfei
|
421
340
|
cfsi
|
341
|
+
croo
|
422
342
|
div
|
423
343
|
divi
|
424
344
|
ecr1
|
@@ -501,9 +421,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
501
421
|
ccp {
|
502
422
|
...DependentCostFragment
|
503
423
|
}
|
504
|
-
croo {
|
505
|
-
...DependentCostFragment
|
506
|
-
}
|
507
424
|
csiz {
|
508
425
|
...DependentCostFragment
|
509
426
|
}
|
@@ -563,11 +480,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
563
480
|
${DependentCostFragmentFragmentDoc}`;
|
564
481
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
565
482
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
-
version {
|
567
|
-
... on Version {
|
568
|
-
value
|
569
|
-
}
|
570
|
-
}
|
571
483
|
txParams {
|
572
484
|
...TxParametersFragment
|
573
485
|
}
|
@@ -627,9 +539,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
627
539
|
fragment nodeInfoFragment on NodeInfo {
|
628
540
|
utxoValidation
|
629
541
|
vmBacktrace
|
542
|
+
minGasPrice
|
630
543
|
maxTx
|
631
544
|
maxDepth
|
632
545
|
nodeVersion
|
546
|
+
peers {
|
547
|
+
id
|
548
|
+
addresses
|
549
|
+
clientVersion
|
550
|
+
blockHeight
|
551
|
+
lastHeartbeatMs
|
552
|
+
appScore
|
553
|
+
}
|
633
554
|
}
|
634
555
|
`;
|
635
556
|
var GetVersionDocument = gql`
|
@@ -664,9 +585,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
664
585
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
665
586
|
transaction(id: $transactionId) {
|
666
587
|
...transactionFragment
|
588
|
+
receipts {
|
589
|
+
...receiptFragment
|
590
|
+
}
|
667
591
|
}
|
668
592
|
}
|
669
|
-
${TransactionFragmentFragmentDoc}
|
593
|
+
${TransactionFragmentFragmentDoc}
|
594
|
+
${ReceiptFragmentFragmentDoc}`;
|
670
595
|
var GetTransactionsDocument = gql`
|
671
596
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
672
597
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -794,20 +719,6 @@ var GetBalanceDocument = gql`
|
|
794
719
|
}
|
795
720
|
}
|
796
721
|
${BalanceFragmentFragmentDoc}`;
|
797
|
-
var GetLatestGasPriceDocument = gql`
|
798
|
-
query getLatestGasPrice {
|
799
|
-
latestGasPrice {
|
800
|
-
gasPrice
|
801
|
-
}
|
802
|
-
}
|
803
|
-
`;
|
804
|
-
var EstimateGasPriceDocument = gql`
|
805
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
806
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
807
|
-
gasPrice
|
808
|
-
}
|
809
|
-
}
|
810
|
-
`;
|
811
722
|
var GetBalancesDocument = gql`
|
812
723
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
813
724
|
balances(
|
@@ -862,12 +773,12 @@ var GetMessageStatusDocument = gql`
|
|
862
773
|
}
|
863
774
|
`;
|
864
775
|
var DryRunDocument = gql`
|
865
|
-
mutation dryRun($
|
866
|
-
dryRun(
|
867
|
-
...
|
776
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
777
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
778
|
+
...receiptFragment
|
868
779
|
}
|
869
780
|
}
|
870
|
-
${
|
781
|
+
${ReceiptFragmentFragmentDoc}`;
|
871
782
|
var SubmitDocument = gql`
|
872
783
|
mutation submit($encodedTransaction: HexString!) {
|
873
784
|
submit(tx: $encodedTransaction) {
|
@@ -886,17 +797,17 @@ var ProduceBlocksDocument = gql`
|
|
886
797
|
var SubmitAndAwaitDocument = gql`
|
887
798
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
888
799
|
submitAndAwait(tx: $encodedTransaction) {
|
889
|
-
...
|
800
|
+
...transactionStatusFragment
|
890
801
|
}
|
891
802
|
}
|
892
|
-
${
|
803
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
893
804
|
var StatusChangeDocument = gql`
|
894
805
|
subscription statusChange($transactionId: TransactionId!) {
|
895
806
|
statusChange(id: $transactionId) {
|
896
|
-
...
|
807
|
+
...transactionStatusFragment
|
897
808
|
}
|
898
809
|
}
|
899
|
-
${
|
810
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
900
811
|
function getSdk(requester) {
|
901
812
|
return {
|
902
813
|
getVersion(variables, options) {
|
@@ -950,12 +861,6 @@ function getSdk(requester) {
|
|
950
861
|
getBalance(variables, options) {
|
951
862
|
return requester(GetBalanceDocument, variables, options);
|
952
863
|
},
|
953
|
-
getLatestGasPrice(variables, options) {
|
954
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
-
},
|
956
|
-
estimateGasPrice(variables, options) {
|
957
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
-
},
|
959
864
|
getBalances(variables, options) {
|
960
865
|
return requester(GetBalancesDocument, variables, options);
|
961
866
|
},
|
@@ -1149,9 +1054,10 @@ var inputify = (value) => {
|
|
1149
1054
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1150
1055
|
},
|
1151
1056
|
witnessIndex: value.witnessIndex,
|
1057
|
+
maturity: value.maturity ?? 0,
|
1152
1058
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1153
|
-
predicateLength:
|
1154
|
-
predicateDataLength:
|
1059
|
+
predicateLength: predicate.length,
|
1060
|
+
predicateDataLength: predicateData.length,
|
1155
1061
|
predicate: hexlify3(predicate),
|
1156
1062
|
predicateData: hexlify3(predicateData)
|
1157
1063
|
};
|
@@ -1182,8 +1088,8 @@ var inputify = (value) => {
|
|
1182
1088
|
nonce: hexlify3(value.nonce),
|
1183
1089
|
witnessIndex: value.witnessIndex,
|
1184
1090
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1185
|
-
predicateLength:
|
1186
|
-
predicateDataLength:
|
1091
|
+
predicateLength: predicate.length,
|
1092
|
+
predicateDataLength: predicateData.length,
|
1187
1093
|
predicate: hexlify3(predicate),
|
1188
1094
|
predicateData: hexlify3(predicateData),
|
1189
1095
|
data: hexlify3(data),
|
@@ -1259,7 +1165,7 @@ var outputify = (value) => {
|
|
1259
1165
|
// src/providers/transaction-request/transaction-request.ts
|
1260
1166
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1261
1167
|
import { Address, addressify } from "@fuel-ts/address";
|
1262
|
-
import {
|
1168
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1263
1169
|
import { randomBytes } from "@fuel-ts/crypto";
|
1264
1170
|
import { bn as bn7 } from "@fuel-ts/math";
|
1265
1171
|
import {
|
@@ -1313,8 +1219,8 @@ function assembleReceiptByType(receipt) {
|
|
1313
1219
|
case "CALL" /* Call */: {
|
1314
1220
|
const callReceipt = {
|
1315
1221
|
type: ReceiptType.Call,
|
1316
|
-
from: hexOrZero(receipt.id
|
1317
|
-
to: hexOrZero(receipt?.to),
|
1222
|
+
from: hexOrZero(receipt.contract?.id),
|
1223
|
+
to: hexOrZero(receipt?.to?.id),
|
1318
1224
|
amount: bn4(receipt.amount),
|
1319
1225
|
assetId: hexOrZero(receipt.assetId),
|
1320
1226
|
gas: bn4(receipt.gas),
|
@@ -1328,7 +1234,7 @@ function assembleReceiptByType(receipt) {
|
|
1328
1234
|
case "RETURN" /* Return */: {
|
1329
1235
|
const returnReceipt = {
|
1330
1236
|
type: ReceiptType.Return,
|
1331
|
-
id: hexOrZero(receipt.id
|
1237
|
+
id: hexOrZero(receipt.contract?.id),
|
1332
1238
|
val: bn4(receipt.val),
|
1333
1239
|
pc: bn4(receipt.pc),
|
1334
1240
|
is: bn4(receipt.is)
|
@@ -1338,7 +1244,7 @@ function assembleReceiptByType(receipt) {
|
|
1338
1244
|
case "RETURN_DATA" /* ReturnData */: {
|
1339
1245
|
const returnDataReceipt = {
|
1340
1246
|
type: ReceiptType.ReturnData,
|
1341
|
-
id: hexOrZero(receipt.id
|
1247
|
+
id: hexOrZero(receipt.contract?.id),
|
1342
1248
|
ptr: bn4(receipt.ptr),
|
1343
1249
|
len: bn4(receipt.len),
|
1344
1250
|
digest: hexOrZero(receipt.digest),
|
@@ -1350,7 +1256,7 @@ function assembleReceiptByType(receipt) {
|
|
1350
1256
|
case "PANIC" /* Panic */: {
|
1351
1257
|
const panicReceipt = {
|
1352
1258
|
type: ReceiptType.Panic,
|
1353
|
-
id: hexOrZero(receipt.id),
|
1259
|
+
id: hexOrZero(receipt.contract?.id),
|
1354
1260
|
reason: bn4(receipt.reason),
|
1355
1261
|
pc: bn4(receipt.pc),
|
1356
1262
|
is: bn4(receipt.is),
|
@@ -1361,7 +1267,7 @@ function assembleReceiptByType(receipt) {
|
|
1361
1267
|
case "REVERT" /* Revert */: {
|
1362
1268
|
const revertReceipt = {
|
1363
1269
|
type: ReceiptType.Revert,
|
1364
|
-
id: hexOrZero(receipt.id
|
1270
|
+
id: hexOrZero(receipt.contract?.id),
|
1365
1271
|
val: bn4(receipt.ra),
|
1366
1272
|
pc: bn4(receipt.pc),
|
1367
1273
|
is: bn4(receipt.is)
|
@@ -1371,7 +1277,7 @@ function assembleReceiptByType(receipt) {
|
|
1371
1277
|
case "LOG" /* Log */: {
|
1372
1278
|
const logReceipt = {
|
1373
1279
|
type: ReceiptType.Log,
|
1374
|
-
id: hexOrZero(receipt.id
|
1280
|
+
id: hexOrZero(receipt.contract?.id),
|
1375
1281
|
val0: bn4(receipt.ra),
|
1376
1282
|
val1: bn4(receipt.rb),
|
1377
1283
|
val2: bn4(receipt.rc),
|
@@ -1384,7 +1290,7 @@ function assembleReceiptByType(receipt) {
|
|
1384
1290
|
case "LOG_DATA" /* LogData */: {
|
1385
1291
|
const logDataReceipt = {
|
1386
1292
|
type: ReceiptType.LogData,
|
1387
|
-
id: hexOrZero(receipt.id
|
1293
|
+
id: hexOrZero(receipt.contract?.id),
|
1388
1294
|
val0: bn4(receipt.ra),
|
1389
1295
|
val1: bn4(receipt.rb),
|
1390
1296
|
ptr: bn4(receipt.ptr),
|
@@ -1398,8 +1304,8 @@ function assembleReceiptByType(receipt) {
|
|
1398
1304
|
case "TRANSFER" /* Transfer */: {
|
1399
1305
|
const transferReceipt = {
|
1400
1306
|
type: ReceiptType.Transfer,
|
1401
|
-
from: hexOrZero(receipt.id
|
1402
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1307
|
+
from: hexOrZero(receipt.contract?.id),
|
1308
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1403
1309
|
amount: bn4(receipt.amount),
|
1404
1310
|
assetId: hexOrZero(receipt.assetId),
|
1405
1311
|
pc: bn4(receipt.pc),
|
@@ -1410,8 +1316,8 @@ function assembleReceiptByType(receipt) {
|
|
1410
1316
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1411
1317
|
const transferOutReceipt = {
|
1412
1318
|
type: ReceiptType.TransferOut,
|
1413
|
-
from: hexOrZero(receipt.id
|
1414
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1319
|
+
from: hexOrZero(receipt.contract?.id),
|
1320
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1415
1321
|
amount: bn4(receipt.amount),
|
1416
1322
|
assetId: hexOrZero(receipt.assetId),
|
1417
1323
|
pc: bn4(receipt.pc),
|
@@ -1454,7 +1360,7 @@ function assembleReceiptByType(receipt) {
|
|
1454
1360
|
return receiptMessageOut;
|
1455
1361
|
}
|
1456
1362
|
case "MINT" /* Mint */: {
|
1457
|
-
const contractId = hexOrZero(receipt.id
|
1363
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1458
1364
|
const subId = hexOrZero(receipt.subId);
|
1459
1365
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1460
1366
|
const mintReceipt = {
|
@@ -1469,7 +1375,7 @@ function assembleReceiptByType(receipt) {
|
|
1469
1375
|
return mintReceipt;
|
1470
1376
|
}
|
1471
1377
|
case "BURN" /* Burn */: {
|
1472
|
-
const contractId = hexOrZero(receipt.id
|
1378
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1473
1379
|
const subId = hexOrZero(receipt.subId);
|
1474
1380
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1475
1381
|
const burnReceipt = {
|
@@ -1554,6 +1460,7 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1554
1460
|
import { bn as bn5 } from "@fuel-ts/math";
|
1555
1461
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1556
1462
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1463
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1557
1464
|
var getGasUsedFromReceipts = (receipts) => {
|
1558
1465
|
const scriptResult = receipts.filter(
|
1559
1466
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1574,28 +1481,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1574
1481
|
}
|
1575
1482
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1576
1483
|
const witnessCache = [];
|
1577
|
-
const
|
1578
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1579
|
-
if (isCoinOrMessage) {
|
1580
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1581
|
-
return true;
|
1582
|
-
}
|
1583
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1584
|
-
witnessCache.push(input.witnessIndex);
|
1585
|
-
return true;
|
1586
|
-
}
|
1587
|
-
}
|
1588
|
-
return false;
|
1589
|
-
});
|
1590
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1591
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1484
|
+
const totalGas = inputs.reduce((total, input) => {
|
1592
1485
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1593
1486
|
return total.add(
|
1594
|
-
|
1487
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1595
1488
|
);
|
1596
1489
|
}
|
1597
|
-
|
1598
|
-
|
1490
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1491
|
+
witnessCache.push(input.witnessIndex);
|
1492
|
+
return total.add(gasCosts.ecr1);
|
1493
|
+
}
|
1494
|
+
return total;
|
1495
|
+
}, bn5());
|
1599
1496
|
return totalGas;
|
1600
1497
|
}
|
1601
1498
|
function getMinGas(params) {
|
@@ -1607,20 +1504,12 @@ function getMinGas(params) {
|
|
1607
1504
|
return minGas;
|
1608
1505
|
}
|
1609
1506
|
function getMaxGas(params) {
|
1610
|
-
const {
|
1611
|
-
gasPerByte,
|
1612
|
-
witnessesLength,
|
1613
|
-
witnessLimit,
|
1614
|
-
minGas,
|
1615
|
-
gasLimit = bn5(0),
|
1616
|
-
maxGasPerTx
|
1617
|
-
} = params;
|
1507
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1618
1508
|
let remainingAllowedWitnessGas = bn5(0);
|
1619
1509
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1620
1510
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1621
1511
|
}
|
1622
|
-
|
1623
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1512
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1624
1513
|
}
|
1625
1514
|
function calculateMetadataGasForTxCreate({
|
1626
1515
|
gasCosts,
|
@@ -1642,10 +1531,6 @@ function calculateMetadataGasForTxScript({
|
|
1642
1531
|
}) {
|
1643
1532
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1644
1533
|
}
|
1645
|
-
var calculateGasFee = (params) => {
|
1646
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1647
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1648
|
-
};
|
1649
1534
|
|
1650
1535
|
// src/providers/utils/json.ts
|
1651
1536
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1802,7 +1687,7 @@ var witnessify = (value) => {
|
|
1802
1687
|
// src/providers/transaction-request/transaction-request.ts
|
1803
1688
|
var BaseTransactionRequest = class {
|
1804
1689
|
/** Gas price for transaction */
|
1805
|
-
|
1690
|
+
gasPrice;
|
1806
1691
|
/** Block until which tx cannot be included */
|
1807
1692
|
maturity;
|
1808
1693
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1821,7 +1706,7 @@ var BaseTransactionRequest = class {
|
|
1821
1706
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1822
1707
|
*/
|
1823
1708
|
constructor({
|
1824
|
-
|
1709
|
+
gasPrice,
|
1825
1710
|
maturity,
|
1826
1711
|
maxFee,
|
1827
1712
|
witnessLimit,
|
@@ -1829,7 +1714,7 @@ var BaseTransactionRequest = class {
|
|
1829
1714
|
outputs,
|
1830
1715
|
witnesses
|
1831
1716
|
} = {}) {
|
1832
|
-
this.
|
1717
|
+
this.gasPrice = bn7(gasPrice);
|
1833
1718
|
this.maturity = maturity ?? 0;
|
1834
1719
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1835
1720
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1840,9 +1725,9 @@ var BaseTransactionRequest = class {
|
|
1840
1725
|
static getPolicyMeta(req) {
|
1841
1726
|
let policyTypes = 0;
|
1842
1727
|
const policies = [];
|
1843
|
-
if (req.
|
1844
|
-
policyTypes += PolicyType.
|
1845
|
-
policies.push({ data: req.
|
1728
|
+
if (req.gasPrice) {
|
1729
|
+
policyTypes += PolicyType.GasPrice;
|
1730
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1846
1731
|
}
|
1847
1732
|
if (req.witnessLimit) {
|
1848
1733
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -2026,11 +1911,13 @@ var BaseTransactionRequest = class {
|
|
2026
1911
|
* assetId, if one it was not added yet.
|
2027
1912
|
*
|
2028
1913
|
* @param coin - Coin resource.
|
1914
|
+
* @param predicate - Predicate bytes.
|
1915
|
+
* @param predicateData - Predicate data bytes.
|
2029
1916
|
*/
|
2030
|
-
addCoinInput(coin) {
|
1917
|
+
addCoinInput(coin, predicate) {
|
2031
1918
|
const { assetId, owner, amount } = coin;
|
2032
1919
|
let witnessIndex;
|
2033
|
-
if (
|
1920
|
+
if (predicate) {
|
2034
1921
|
witnessIndex = 0;
|
2035
1922
|
} else {
|
2036
1923
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2045,22 +1932,23 @@ var BaseTransactionRequest = class {
|
|
2045
1932
|
amount,
|
2046
1933
|
assetId,
|
2047
1934
|
txPointer: "0x00000000000000000000000000000000",
|
2048
|
-
witnessIndex
|
1935
|
+
witnessIndex,
|
1936
|
+
predicate: predicate?.bytes
|
2049
1937
|
};
|
2050
1938
|
this.pushInput(input);
|
2051
1939
|
this.addChangeOutput(owner, assetId);
|
2052
1940
|
}
|
2053
1941
|
/**
|
2054
1942
|
* Adds a single message input to the transaction and a change output for the
|
2055
|
-
*
|
1943
|
+
* asset against the message
|
2056
1944
|
*
|
2057
1945
|
* @param message - Message resource.
|
1946
|
+
* @param predicate - Predicate bytes.
|
2058
1947
|
*/
|
2059
|
-
addMessageInput(message) {
|
2060
|
-
const { recipient, sender, amount } = message;
|
2061
|
-
const assetId = BaseAssetId2;
|
1948
|
+
addMessageInput(message, predicate) {
|
1949
|
+
const { recipient, sender, amount, assetId } = message;
|
2062
1950
|
let witnessIndex;
|
2063
|
-
if (
|
1951
|
+
if (predicate) {
|
2064
1952
|
witnessIndex = 0;
|
2065
1953
|
} else {
|
2066
1954
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2074,7 +1962,8 @@ var BaseTransactionRequest = class {
|
|
2074
1962
|
sender: sender.toB256(),
|
2075
1963
|
recipient: recipient.toB256(),
|
2076
1964
|
amount,
|
2077
|
-
witnessIndex
|
1965
|
+
witnessIndex,
|
1966
|
+
predicate: predicate?.bytes
|
2078
1967
|
};
|
2079
1968
|
this.pushInput(input);
|
2080
1969
|
this.addChangeOutput(recipient, assetId);
|
@@ -2105,6 +1994,32 @@ var BaseTransactionRequest = class {
|
|
2105
1994
|
resources.forEach((resource) => this.addResource(resource));
|
2106
1995
|
return this;
|
2107
1996
|
}
|
1997
|
+
/**
|
1998
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1999
|
+
* outputs from the related assetIds.
|
2000
|
+
*
|
2001
|
+
* @param resources - The resources to add.
|
2002
|
+
* @returns This transaction.
|
2003
|
+
*/
|
2004
|
+
addPredicateResource(resource, predicate) {
|
2005
|
+
if (isCoin(resource)) {
|
2006
|
+
this.addCoinInput(resource, predicate);
|
2007
|
+
} else {
|
2008
|
+
this.addMessageInput(resource, predicate);
|
2009
|
+
}
|
2010
|
+
return this;
|
2011
|
+
}
|
2012
|
+
/**
|
2013
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2014
|
+
* from the related assetIds.
|
2015
|
+
*
|
2016
|
+
* @param resources - The resources to add.
|
2017
|
+
* @returns This transaction.
|
2018
|
+
*/
|
2019
|
+
addPredicateResources(resources, predicate) {
|
2020
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2021
|
+
return this;
|
2022
|
+
}
|
2108
2023
|
/**
|
2109
2024
|
* Adds a coin output to the transaction.
|
2110
2025
|
*
|
@@ -2112,7 +2027,7 @@ var BaseTransactionRequest = class {
|
|
2112
2027
|
* @param amount - Amount of coin.
|
2113
2028
|
* @param assetId - Asset ID of coin.
|
2114
2029
|
*/
|
2115
|
-
addCoinOutput(to, amount, assetId
|
2030
|
+
addCoinOutput(to, amount, assetId) {
|
2116
2031
|
this.pushOutput({
|
2117
2032
|
type: OutputType2.Coin,
|
2118
2033
|
to: addressify(to).toB256(),
|
@@ -2144,7 +2059,7 @@ var BaseTransactionRequest = class {
|
|
2144
2059
|
* @param to - Address of the owner.
|
2145
2060
|
* @param assetId - Asset ID of coin.
|
2146
2061
|
*/
|
2147
|
-
addChangeOutput(to, assetId
|
2062
|
+
addChangeOutput(to, assetId) {
|
2148
2063
|
const changeOutput = this.getChangeOutputs().find(
|
2149
2064
|
(output) => hexlify7(output.assetId) === assetId
|
2150
2065
|
);
|
@@ -2184,7 +2099,7 @@ var BaseTransactionRequest = class {
|
|
2184
2099
|
}
|
2185
2100
|
calculateMaxGas(chainInfo, minGas) {
|
2186
2101
|
const { consensusParameters } = chainInfo;
|
2187
|
-
const { gasPerByte
|
2102
|
+
const { gasPerByte } = consensusParameters;
|
2188
2103
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2189
2104
|
(acc, wit) => acc + wit.dataLength,
|
2190
2105
|
0
|
@@ -2193,8 +2108,7 @@ var BaseTransactionRequest = class {
|
|
2193
2108
|
gasPerByte,
|
2194
2109
|
minGas,
|
2195
2110
|
witnessesLength,
|
2196
|
-
witnessLimit: this.witnessLimit
|
2197
|
-
maxGasPerTx
|
2111
|
+
witnessLimit: this.witnessLimit
|
2198
2112
|
});
|
2199
2113
|
}
|
2200
2114
|
/**
|
@@ -2202,8 +2116,9 @@ var BaseTransactionRequest = class {
|
|
2202
2116
|
* quantities array.
|
2203
2117
|
*
|
2204
2118
|
* @param quantities - CoinQuantity Array.
|
2119
|
+
* @param baseAssetId - The base asset to fund the transaction.
|
2205
2120
|
*/
|
2206
|
-
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2121
|
+
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2207
2122
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2208
2123
|
if ("assetId" in input) {
|
2209
2124
|
return input.assetId === assetId;
|
@@ -2212,27 +2127,24 @@ var BaseTransactionRequest = class {
|
|
2212
2127
|
});
|
2213
2128
|
const updateAssetInput = (assetId, quantity) => {
|
2214
2129
|
const assetInput = findAssetInput(assetId);
|
2215
|
-
let usedQuantity = quantity;
|
2216
|
-
if (assetId === BaseAssetId2) {
|
2217
|
-
usedQuantity = bn7("1000000000000000000");
|
2218
|
-
}
|
2219
2130
|
if (assetInput && "assetId" in assetInput) {
|
2220
2131
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2221
|
-
assetInput.amount =
|
2132
|
+
assetInput.amount = quantity;
|
2222
2133
|
} else {
|
2223
2134
|
this.addResources([
|
2224
2135
|
{
|
2225
2136
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2226
|
-
amount:
|
2137
|
+
amount: quantity,
|
2227
2138
|
assetId,
|
2228
2139
|
owner: resourcesOwner || Address.fromRandom(),
|
2140
|
+
maturity: 0,
|
2229
2141
|
blockCreated: bn7(1),
|
2230
2142
|
txCreatedIdx: bn7(1)
|
2231
2143
|
}
|
2232
2144
|
]);
|
2233
2145
|
}
|
2234
2146
|
};
|
2235
|
-
updateAssetInput(
|
2147
|
+
updateAssetInput(baseAssetId, bn7(1e11));
|
2236
2148
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2237
2149
|
}
|
2238
2150
|
/**
|
@@ -2257,7 +2169,7 @@ var BaseTransactionRequest = class {
|
|
2257
2169
|
toJSON() {
|
2258
2170
|
return normalizeJSON(this);
|
2259
2171
|
}
|
2260
|
-
|
2172
|
+
updatePredicateInputs(inputs) {
|
2261
2173
|
this.inputs.forEach((i) => {
|
2262
2174
|
let correspondingInput;
|
2263
2175
|
switch (i.type) {
|
@@ -2279,15 +2191,6 @@ var BaseTransactionRequest = class {
|
|
2279
2191
|
}
|
2280
2192
|
});
|
2281
2193
|
}
|
2282
|
-
shiftPredicateData() {
|
2283
|
-
this.inputs.forEach((input) => {
|
2284
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2285
|
-
input.predicateData = input.paddPredicateData(
|
2286
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2287
|
-
);
|
2288
|
-
}
|
2289
|
-
});
|
2290
|
-
}
|
2291
2194
|
};
|
2292
2195
|
|
2293
2196
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2411,12 +2314,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2411
2314
|
*
|
2412
2315
|
* @param createTransactionRequestLike - The initial values for the instance
|
2413
2316
|
*/
|
2414
|
-
constructor({
|
2415
|
-
bytecodeWitnessIndex,
|
2416
|
-
salt,
|
2417
|
-
storageSlots,
|
2418
|
-
...rest
|
2419
|
-
} = {}) {
|
2317
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2420
2318
|
super(rest);
|
2421
2319
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2422
2320
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2434,8 +2332,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2434
2332
|
return {
|
2435
2333
|
type: TransactionType3.Create,
|
2436
2334
|
...baseTransaction,
|
2335
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2437
2336
|
bytecodeWitnessIndex,
|
2438
|
-
storageSlotsCount:
|
2337
|
+
storageSlotsCount: storageSlots.length,
|
2439
2338
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2440
2339
|
storageSlots
|
2441
2340
|
};
|
@@ -2558,8 +2457,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2558
2457
|
type: TransactionType4.Script,
|
2559
2458
|
scriptGasLimit: this.gasLimit,
|
2560
2459
|
...super.getBaseTransaction(),
|
2561
|
-
scriptLength:
|
2562
|
-
scriptDataLength:
|
2460
|
+
scriptLength: script.length,
|
2461
|
+
scriptDataLength: scriptData.length,
|
2563
2462
|
receiptsRoot: ZeroBytes327,
|
2564
2463
|
script: hexlify10(script),
|
2565
2464
|
scriptData: hexlify10(scriptData)
|
@@ -2623,7 +2522,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2623
2522
|
}
|
2624
2523
|
calculateMaxGas(chainInfo, minGas) {
|
2625
2524
|
const { consensusParameters } = chainInfo;
|
2626
|
-
const { gasPerByte
|
2525
|
+
const { gasPerByte } = consensusParameters;
|
2627
2526
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2628
2527
|
(acc, wit) => acc + wit.dataLength,
|
2629
2528
|
0
|
@@ -2633,8 +2532,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2633
2532
|
minGas,
|
2634
2533
|
witnessesLength,
|
2635
2534
|
witnessLimit: this.witnessLimit,
|
2636
|
-
gasLimit: this.gasLimit
|
2637
|
-
maxGasPerTx
|
2535
|
+
gasLimit: this.gasLimit
|
2638
2536
|
});
|
2639
2537
|
}
|
2640
2538
|
/**
|
@@ -2691,7 +2589,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2691
2589
|
|
2692
2590
|
// src/providers/transaction-request/utils.ts
|
2693
2591
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2694
|
-
import { TransactionType as TransactionType5
|
2592
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2695
2593
|
var transactionRequestify = (obj) => {
|
2696
2594
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2697
2595
|
return obj;
|
@@ -2709,31 +2607,14 @@ var transactionRequestify = (obj) => {
|
|
2709
2607
|
}
|
2710
2608
|
}
|
2711
2609
|
};
|
2712
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2713
|
-
(acc, input) => {
|
2714
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2715
|
-
acc.utxos.push(input.id);
|
2716
|
-
}
|
2717
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2718
|
-
acc.messages.push(input.nonce);
|
2719
|
-
}
|
2720
|
-
return acc;
|
2721
|
-
},
|
2722
|
-
{
|
2723
|
-
utxos: [],
|
2724
|
-
messages: []
|
2725
|
-
}
|
2726
|
-
);
|
2727
2610
|
|
2728
2611
|
// src/providers/transaction-response/transaction-response.ts
|
2729
2612
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2730
|
-
import { bn as
|
2613
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2731
2614
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2732
2615
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2733
2616
|
|
2734
2617
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2735
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2736
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2737
2618
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2738
2619
|
|
2739
2620
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2742,10 +2623,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2742
2623
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2743
2624
|
var calculateTransactionFee = (params) => {
|
2744
2625
|
const {
|
2745
|
-
|
2626
|
+
gasUsed,
|
2746
2627
|
rawPayload,
|
2747
|
-
|
2748
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2628
|
+
consensusParameters: { gasCosts, feeParams }
|
2749
2629
|
} = params;
|
2750
2630
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2751
2631
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2755,7 +2635,8 @@ var calculateTransactionFee = (params) => {
|
|
2755
2635
|
return {
|
2756
2636
|
fee: bn11(0),
|
2757
2637
|
minFee: bn11(0),
|
2758
|
-
maxFee: bn11(0)
|
2638
|
+
maxFee: bn11(0),
|
2639
|
+
feeFromGasUsed: bn11(0)
|
2759
2640
|
};
|
2760
2641
|
}
|
2761
2642
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2787,6 +2668,7 @@ var calculateTransactionFee = (params) => {
|
|
2787
2668
|
metadataGas,
|
2788
2669
|
txBytesSize: transactionBytes.length
|
2789
2670
|
});
|
2671
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2790
2672
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2791
2673
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2792
2674
|
const maxGas = getMaxGas({
|
@@ -2794,25 +2676,17 @@ var calculateTransactionFee = (params) => {
|
|
2794
2676
|
minGas,
|
2795
2677
|
witnessesLength,
|
2796
2678
|
gasLimit,
|
2797
|
-
witnessLimit
|
2798
|
-
maxGasPerTx
|
2799
|
-
});
|
2800
|
-
const minFee = calculateGasFee({
|
2801
|
-
gasPrice,
|
2802
|
-
gas: minGas,
|
2803
|
-
priceFactor: gasPriceFactor,
|
2804
|
-
tip
|
2805
|
-
});
|
2806
|
-
const maxFee = calculateGasFee({
|
2807
|
-
gasPrice,
|
2808
|
-
gas: maxGas,
|
2809
|
-
priceFactor: gasPriceFactor,
|
2810
|
-
tip
|
2679
|
+
witnessLimit
|
2811
2680
|
});
|
2681
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2682
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2683
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2684
|
+
const fee = minFee.add(feeFromGasUsed);
|
2812
2685
|
return {
|
2686
|
+
fee,
|
2813
2687
|
minFee,
|
2814
2688
|
maxFee,
|
2815
|
-
|
2689
|
+
feeFromGasUsed
|
2816
2690
|
};
|
2817
2691
|
};
|
2818
2692
|
|
@@ -2868,7 +2742,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2868
2742
|
|
2869
2743
|
// src/providers/transaction-summary/input.ts
|
2870
2744
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2871
|
-
import { InputType as
|
2745
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2872
2746
|
function getInputsByTypes(inputs, types) {
|
2873
2747
|
return inputs.filter((i) => types.includes(i.type));
|
2874
2748
|
}
|
@@ -2876,16 +2750,16 @@ function getInputsByType(inputs, type) {
|
|
2876
2750
|
return inputs.filter((i) => i.type === type);
|
2877
2751
|
}
|
2878
2752
|
function getInputsCoin(inputs) {
|
2879
|
-
return getInputsByType(inputs,
|
2753
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2880
2754
|
}
|
2881
2755
|
function getInputsMessage(inputs) {
|
2882
|
-
return getInputsByType(inputs,
|
2756
|
+
return getInputsByType(inputs, InputType5.Message);
|
2883
2757
|
}
|
2884
2758
|
function getInputsCoinAndMessage(inputs) {
|
2885
|
-
return getInputsByTypes(inputs, [
|
2759
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2886
2760
|
}
|
2887
2761
|
function getInputsContract(inputs) {
|
2888
|
-
return getInputsByType(inputs,
|
2762
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2889
2763
|
}
|
2890
2764
|
function getInputFromAssetId(inputs, assetId) {
|
2891
2765
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2904,7 +2778,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2904
2778
|
if (!contractInput) {
|
2905
2779
|
return void 0;
|
2906
2780
|
}
|
2907
|
-
if (contractInput.type !==
|
2781
|
+
if (contractInput.type !== InputType5.Contract) {
|
2908
2782
|
throw new FuelError9(
|
2909
2783
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2910
2784
|
`Contract input should be of type 'contract'.`
|
@@ -2913,10 +2787,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2913
2787
|
return contractInput;
|
2914
2788
|
}
|
2915
2789
|
function getInputAccountAddress(input) {
|
2916
|
-
if (input.type ===
|
2790
|
+
if (input.type === InputType5.Coin) {
|
2917
2791
|
return input.owner.toString();
|
2918
2792
|
}
|
2919
|
-
if (input.type ===
|
2793
|
+
if (input.type === InputType5.Message) {
|
2920
2794
|
return input.recipient.toString();
|
2921
2795
|
}
|
2922
2796
|
return "";
|
@@ -3426,9 +3300,7 @@ function assembleTransactionSummary(params) {
|
|
3426
3300
|
gqlTransactionStatus,
|
3427
3301
|
abiMap = {},
|
3428
3302
|
maxInputs,
|
3429
|
-
gasCosts
|
3430
|
-
maxGasPerTx,
|
3431
|
-
gasPrice
|
3303
|
+
gasCosts
|
3432
3304
|
} = params;
|
3433
3305
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3434
3306
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3442,14 +3314,11 @@ function assembleTransactionSummary(params) {
|
|
3442
3314
|
maxInputs
|
3443
3315
|
});
|
3444
3316
|
const typeName = getTransactionTypeName(transaction.type);
|
3445
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3446
3317
|
const { fee } = calculateTransactionFee({
|
3447
|
-
|
3318
|
+
gasUsed,
|
3448
3319
|
rawPayload,
|
3449
|
-
tip,
|
3450
3320
|
consensusParameters: {
|
3451
3321
|
gasCosts,
|
3452
|
-
maxGasPerTx,
|
3453
3322
|
feeParams: {
|
3454
3323
|
gasPerByte,
|
3455
3324
|
gasPriceFactor
|
@@ -3509,7 +3378,7 @@ var TransactionResponse = class {
|
|
3509
3378
|
/** Current provider */
|
3510
3379
|
provider;
|
3511
3380
|
/** Gas used on the transaction */
|
3512
|
-
gasUsed =
|
3381
|
+
gasUsed = bn14(0);
|
3513
3382
|
/** The graphql Transaction with receipts object. */
|
3514
3383
|
gqlTransaction;
|
3515
3384
|
abis;
|
@@ -3587,13 +3456,8 @@ var TransactionResponse = class {
|
|
3587
3456
|
const decodedTransaction = this.decodeTransaction(
|
3588
3457
|
transaction
|
3589
3458
|
);
|
3590
|
-
|
3591
|
-
|
3592
|
-
txReceipts = transaction.status.receipts;
|
3593
|
-
}
|
3594
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3595
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3596
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3459
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3460
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3597
3461
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3598
3462
|
const transactionSummary = assembleTransactionSummary({
|
3599
3463
|
id: this.id,
|
@@ -3605,9 +3469,7 @@ var TransactionResponse = class {
|
|
3605
3469
|
gasPriceFactor,
|
3606
3470
|
abiMap: contractsAbiMap,
|
3607
3471
|
maxInputs,
|
3608
|
-
gasCosts
|
3609
|
-
maxGasPerTx,
|
3610
|
-
gasPrice
|
3472
|
+
gasCosts
|
3611
3473
|
});
|
3612
3474
|
return transactionSummary;
|
3613
3475
|
}
|
@@ -3713,7 +3575,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3713
3575
|
}
|
3714
3576
|
|
3715
3577
|
// src/providers/utils/merge-quantities.ts
|
3716
|
-
var mergeQuantities = (
|
3578
|
+
var mergeQuantities = (...coinQuantities) => {
|
3717
3579
|
const resultMap = {};
|
3718
3580
|
function addToMap({ amount, assetId }) {
|
3719
3581
|
if (resultMap[assetId]) {
|
@@ -3722,8 +3584,7 @@ var mergeQuantities = (arr1, arr2) => {
|
|
3722
3584
|
resultMap[assetId] = amount;
|
3723
3585
|
}
|
3724
3586
|
}
|
3725
|
-
|
3726
|
-
arr2.forEach(addToMap);
|
3587
|
+
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
3727
3588
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
3728
3589
|
};
|
3729
3590
|
|
@@ -3734,29 +3595,30 @@ var processGqlChain = (chain) => {
|
|
3734
3595
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3735
3596
|
return {
|
3736
3597
|
name,
|
3737
|
-
baseChainHeight:
|
3598
|
+
baseChainHeight: bn15(daHeight),
|
3738
3599
|
consensusParameters: {
|
3739
|
-
contractMaxSize:
|
3740
|
-
maxInputs:
|
3741
|
-
maxOutputs:
|
3742
|
-
maxWitnesses:
|
3743
|
-
maxGasPerTx:
|
3744
|
-
maxScriptLength:
|
3745
|
-
maxScriptDataLength:
|
3746
|
-
maxStorageSlots:
|
3747
|
-
maxPredicateLength:
|
3748
|
-
maxPredicateDataLength:
|
3749
|
-
maxGasPerPredicate:
|
3750
|
-
gasPriceFactor:
|
3751
|
-
gasPerByte:
|
3752
|
-
maxMessageDataLength:
|
3753
|
-
chainId:
|
3600
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3601
|
+
maxInputs: bn15(txParams.maxInputs),
|
3602
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3603
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3604
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3605
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3606
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3607
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3608
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3609
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3610
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3611
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3612
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3613
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3614
|
+
chainId: bn15(consensusParameters.chainId),
|
3615
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3754
3616
|
gasCosts
|
3755
3617
|
},
|
3756
3618
|
gasCosts,
|
3757
3619
|
latestBlock: {
|
3758
3620
|
id: latestBlock.id,
|
3759
|
-
height:
|
3621
|
+
height: bn15(latestBlock.header.height),
|
3760
3622
|
time: latestBlock.header.time,
|
3761
3623
|
transactions: latestBlock.transactions.map((i) => ({
|
3762
3624
|
id: i.id
|
@@ -3850,8 +3712,10 @@ var _Provider = class {
|
|
3850
3712
|
* Returns some helpful parameters related to gas fees.
|
3851
3713
|
*/
|
3852
3714
|
getGasConfig() {
|
3715
|
+
const { minGasPrice } = this.getNode();
|
3853
3716
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3854
3717
|
return {
|
3718
|
+
minGasPrice,
|
3855
3719
|
maxGasPerTx,
|
3856
3720
|
maxGasPerPredicate,
|
3857
3721
|
gasPriceFactor,
|
@@ -3949,7 +3813,7 @@ var _Provider = class {
|
|
3949
3813
|
*/
|
3950
3814
|
async getBlockNumber() {
|
3951
3815
|
const { chain } = await this.operations.getChain();
|
3952
|
-
return
|
3816
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3953
3817
|
}
|
3954
3818
|
/**
|
3955
3819
|
* Returns the chain information.
|
@@ -3959,11 +3823,13 @@ var _Provider = class {
|
|
3959
3823
|
async fetchNode() {
|
3960
3824
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3961
3825
|
const processedNodeInfo = {
|
3962
|
-
maxDepth:
|
3963
|
-
maxTx:
|
3826
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3827
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3828
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3964
3829
|
nodeVersion: nodeInfo.nodeVersion,
|
3965
3830
|
utxoValidation: nodeInfo.utxoValidation,
|
3966
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3831
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3832
|
+
peers: nodeInfo.peers
|
3967
3833
|
};
|
3968
3834
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3969
3835
|
return processedNodeInfo;
|
@@ -3989,6 +3855,17 @@ var _Provider = class {
|
|
3989
3855
|
} = this.getChain();
|
3990
3856
|
return chainId.toNumber();
|
3991
3857
|
}
|
3858
|
+
/**
|
3859
|
+
* Returns the base asset ID
|
3860
|
+
*
|
3861
|
+
* @returns A promise that resolves to the base asset ID
|
3862
|
+
*/
|
3863
|
+
getBaseAssetId() {
|
3864
|
+
const {
|
3865
|
+
consensusParameters: { baseAssetId }
|
3866
|
+
} = this.getChain();
|
3867
|
+
return baseAssetId;
|
3868
|
+
}
|
3992
3869
|
/**
|
3993
3870
|
* Submits a transaction to the chain to be executed.
|
3994
3871
|
*
|
@@ -4049,13 +3926,14 @@ var _Provider = class {
|
|
4049
3926
|
return this.estimateTxDependencies(transactionRequest);
|
4050
3927
|
}
|
4051
3928
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
4052
|
-
const { dryRun:
|
4053
|
-
|
3929
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3930
|
+
encodedTransaction,
|
4054
3931
|
utxoValidation: utxoValidation || false
|
4055
3932
|
});
|
4056
|
-
const
|
4057
|
-
|
4058
|
-
|
3933
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3934
|
+
return {
|
3935
|
+
receipts
|
3936
|
+
};
|
4059
3937
|
}
|
4060
3938
|
/**
|
4061
3939
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4081,7 +3959,7 @@ var _Provider = class {
|
|
4081
3959
|
} = response;
|
4082
3960
|
if (inputs) {
|
4083
3961
|
inputs.forEach((input, index) => {
|
4084
|
-
if ("predicateGasUsed" in input &&
|
3962
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
4085
3963
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4086
3964
|
}
|
4087
3965
|
});
|
@@ -4094,6 +3972,9 @@ var _Provider = class {
|
|
4094
3972
|
* If there are missing variable outputs,
|
4095
3973
|
* `addVariableOutputs` is called on the transaction.
|
4096
3974
|
*
|
3975
|
+
* @privateRemarks
|
3976
|
+
* TODO: Investigate support for missing contract IDs
|
3977
|
+
* TODO: Add support for missing output messages
|
4097
3978
|
*
|
4098
3979
|
* @param transactionRequest - The transaction request object.
|
4099
3980
|
* @returns A promise.
|
@@ -4106,19 +3987,16 @@ var _Provider = class {
|
|
4106
3987
|
missingContractIds: []
|
4107
3988
|
};
|
4108
3989
|
}
|
3990
|
+
await this.estimatePredicates(transactionRequest);
|
4109
3991
|
let receipts = [];
|
4110
3992
|
const missingContractIds = [];
|
4111
3993
|
let outputVariables = 0;
|
4112
|
-
let dryrunStatus;
|
4113
3994
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4114
|
-
const {
|
4115
|
-
|
4116
|
-
} = await this.operations.dryRun({
|
4117
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3995
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3996
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
4118
3997
|
utxoValidation: false
|
4119
3998
|
});
|
4120
|
-
receipts =
|
4121
|
-
dryrunStatus = status;
|
3999
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4122
4000
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4123
4001
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4124
4002
|
if (hasMissingOutputs) {
|
@@ -4128,10 +4006,6 @@ var _Provider = class {
|
|
4128
4006
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4129
4007
|
missingContractIds.push(contractId);
|
4130
4008
|
});
|
4131
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4132
|
-
transactionRequest
|
4133
|
-
});
|
4134
|
-
transactionRequest.maxFee = maxFee;
|
4135
4009
|
} else {
|
4136
4010
|
break;
|
4137
4011
|
}
|
@@ -4139,139 +4013,37 @@ var _Provider = class {
|
|
4139
4013
|
return {
|
4140
4014
|
receipts,
|
4141
4015
|
outputVariables,
|
4142
|
-
missingContractIds
|
4143
|
-
dryrunStatus
|
4016
|
+
missingContractIds
|
4144
4017
|
};
|
4145
4018
|
}
|
4146
|
-
/**
|
4147
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4148
|
-
*
|
4149
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4150
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4151
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4152
|
-
*
|
4153
|
-
* @param transactionRequests - Array of transaction request objects.
|
4154
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4155
|
-
*/
|
4156
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4157
|
-
const results = transactionRequests.map(() => ({
|
4158
|
-
receipts: [],
|
4159
|
-
outputVariables: 0,
|
4160
|
-
missingContractIds: [],
|
4161
|
-
dryrunStatus: void 0
|
4162
|
-
}));
|
4163
|
-
const allRequests = clone3(transactionRequests);
|
4164
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4165
|
-
allRequests.forEach((req, index) => {
|
4166
|
-
if (req.type === TransactionType8.Script) {
|
4167
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4168
|
-
}
|
4169
|
-
});
|
4170
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4171
|
-
let attempt = 0;
|
4172
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4173
|
-
const encodedTransactions = transactionsToProcess.map(
|
4174
|
-
(index) => serializedTransactionsMap.get(index)
|
4175
|
-
);
|
4176
|
-
const dryRunResults = await this.operations.dryRun({
|
4177
|
-
encodedTransactions,
|
4178
|
-
utxoValidation: false
|
4179
|
-
});
|
4180
|
-
const nextRoundTransactions = [];
|
4181
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4182
|
-
const currentResultIndex = transactionsToProcess[i];
|
4183
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4184
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4185
|
-
results[currentResultIndex].dryrunStatus = status;
|
4186
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4187
|
-
results[currentResultIndex].receipts
|
4188
|
-
);
|
4189
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4190
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4191
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4192
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4193
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4194
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4195
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4196
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4197
|
-
});
|
4198
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4199
|
-
transactionRequest: requestToProcess
|
4200
|
-
});
|
4201
|
-
requestToProcess.maxFee = maxFee;
|
4202
|
-
serializedTransactionsMap.set(
|
4203
|
-
currentResultIndex,
|
4204
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4205
|
-
);
|
4206
|
-
nextRoundTransactions.push(currentResultIndex);
|
4207
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4208
|
-
}
|
4209
|
-
}
|
4210
|
-
transactionsToProcess = nextRoundTransactions;
|
4211
|
-
attempt += 1;
|
4212
|
-
}
|
4213
|
-
return results;
|
4214
|
-
}
|
4215
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4216
|
-
if (estimateTxDependencies) {
|
4217
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4218
|
-
}
|
4219
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4220
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4221
|
-
encodedTransactions,
|
4222
|
-
utxoValidation: utxoValidation || false
|
4223
|
-
});
|
4224
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4225
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4226
|
-
return { receipts, dryrunStatus: status };
|
4227
|
-
});
|
4228
|
-
return results;
|
4229
|
-
}
|
4230
4019
|
/**
|
4231
4020
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4232
4021
|
* @param transactionRequest - The transaction request object.
|
4233
4022
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4234
4023
|
*/
|
4235
|
-
|
4024
|
+
estimateTxGasAndFee(params) {
|
4236
4025
|
const { transactionRequest } = params;
|
4237
|
-
|
4026
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4238
4027
|
const chainInfo = this.getChain();
|
4239
|
-
const
|
4028
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4029
|
+
transactionRequest.gasPrice = gasPrice;
|
4240
4030
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4241
|
-
|
4242
|
-
gasPrice = await this.estimateGasPrice(10);
|
4243
|
-
}
|
4244
|
-
const minFee = calculateGasFee({
|
4245
|
-
gasPrice: bn16(gasPrice),
|
4246
|
-
gas: minGas,
|
4247
|
-
priceFactor: gasPriceFactor,
|
4248
|
-
tip: transactionRequest.tip
|
4249
|
-
}).add(1);
|
4250
|
-
let gasLimit = bn16(0);
|
4031
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4251
4032
|
if (transactionRequest.type === TransactionType8.Script) {
|
4252
|
-
gasLimit = transactionRequest.gasLimit;
|
4253
4033
|
if (transactionRequest.gasLimit.eq(0)) {
|
4254
4034
|
transactionRequest.gasLimit = minGas;
|
4255
4035
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4256
4036
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4257
4037
|
);
|
4258
|
-
gasLimit = transactionRequest.gasLimit;
|
4259
4038
|
}
|
4260
4039
|
}
|
4261
4040
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4262
|
-
const maxFee =
|
4263
|
-
gasPrice: bn16(gasPrice),
|
4264
|
-
gas: maxGas,
|
4265
|
-
priceFactor: gasPriceFactor,
|
4266
|
-
tip: transactionRequest.tip
|
4267
|
-
}).add(1);
|
4041
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4268
4042
|
return {
|
4269
4043
|
minGas,
|
4270
4044
|
minFee,
|
4271
4045
|
maxGas,
|
4272
|
-
maxFee
|
4273
|
-
gasPrice,
|
4274
|
-
gasLimit
|
4046
|
+
maxFee
|
4275
4047
|
};
|
4276
4048
|
}
|
4277
4049
|
/**
|
@@ -4289,17 +4061,15 @@ var _Provider = class {
|
|
4289
4061
|
if (estimateTxDependencies) {
|
4290
4062
|
return this.estimateTxDependencies(transactionRequest);
|
4291
4063
|
}
|
4292
|
-
const
|
4293
|
-
const { dryRun:
|
4294
|
-
|
4064
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
4065
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4066
|
+
encodedTransaction,
|
4295
4067
|
utxoValidation: true
|
4296
4068
|
});
|
4297
|
-
const
|
4298
|
-
|
4299
|
-
|
4300
|
-
|
4301
|
-
});
|
4302
|
-
return { receipts: callResult[0].receipts };
|
4069
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4070
|
+
return {
|
4071
|
+
receipts
|
4072
|
+
};
|
4303
4073
|
}
|
4304
4074
|
/**
|
4305
4075
|
* Returns a transaction cost to enable user
|
@@ -4316,79 +4086,78 @@ var _Provider = class {
|
|
4316
4086
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4317
4087
|
* @returns A promise that resolves to the transaction cost object.
|
4318
4088
|
*/
|
4319
|
-
async getTransactionCost(transactionRequestLike,
|
4089
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4090
|
+
estimateTxDependencies = true,
|
4091
|
+
estimatePredicates = true,
|
4092
|
+
resourcesOwner,
|
4093
|
+
signatureCallback
|
4094
|
+
} = {}) {
|
4320
4095
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4096
|
+
const { minGasPrice } = this.getGasConfig();
|
4097
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4321
4098
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4099
|
+
const baseAssetId = this.getBaseAssetId();
|
4322
4100
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4323
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4324
|
-
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4325
|
-
txRequestClone.maxFee = bn16(0);
|
4101
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4102
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4326
4103
|
if (isScriptTransaction) {
|
4327
|
-
txRequestClone.gasLimit =
|
4104
|
+
txRequestClone.gasLimit = bn15(0);
|
4328
4105
|
}
|
4329
|
-
if (
|
4330
|
-
resourcesOwner
|
4106
|
+
if (estimatePredicates) {
|
4107
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4108
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4109
|
+
}
|
4110
|
+
await this.estimatePredicates(txRequestClone);
|
4331
4111
|
}
|
4332
|
-
const signedRequest = clone3(txRequestClone);
|
4333
|
-
let addedSignatures = 0;
|
4334
4112
|
if (signatureCallback && isScriptTransaction) {
|
4335
|
-
|
4336
|
-
await signatureCallback(signedRequest);
|
4337
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4113
|
+
await signatureCallback(txRequestClone);
|
4338
4114
|
}
|
4339
|
-
|
4340
|
-
|
4341
|
-
transactionRequest: signedRequest
|
4115
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4116
|
+
transactionRequest: txRequestClone
|
4342
4117
|
});
|
4343
4118
|
let receipts = [];
|
4344
4119
|
let missingContractIds = [];
|
4345
4120
|
let outputVariables = 0;
|
4346
|
-
let gasUsed =
|
4347
|
-
|
4348
|
-
|
4349
|
-
if (isScriptTransaction) {
|
4350
|
-
txRequestClone.gasLimit = gasLimit;
|
4351
|
-
if (signatureCallback) {
|
4352
|
-
await signatureCallback(txRequestClone);
|
4353
|
-
}
|
4121
|
+
let gasUsed = bn15(0);
|
4122
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4123
|
+
txRequestClone.gasPrice = bn15(0);
|
4354
4124
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4355
4125
|
receipts = result.receipts;
|
4356
4126
|
outputVariables = result.outputVariables;
|
4357
4127
|
missingContractIds = result.missingContractIds;
|
4358
4128
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4359
4129
|
txRequestClone.gasLimit = gasUsed;
|
4360
|
-
|
4361
|
-
|
4362
|
-
|
4130
|
+
txRequestClone.gasPrice = setGasPrice;
|
4131
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4132
|
+
transactionRequest: txRequestClone
|
4363
4133
|
}));
|
4364
4134
|
}
|
4365
4135
|
return {
|
4366
4136
|
requiredQuantities: allQuantities,
|
4367
4137
|
receipts,
|
4368
4138
|
gasUsed,
|
4369
|
-
|
4139
|
+
minGasPrice,
|
4140
|
+
gasPrice: setGasPrice,
|
4370
4141
|
minGas,
|
4371
4142
|
maxGas,
|
4372
4143
|
minFee,
|
4373
4144
|
maxFee,
|
4145
|
+
estimatedInputs: txRequestClone.inputs,
|
4374
4146
|
outputVariables,
|
4375
|
-
missingContractIds
|
4376
|
-
addedSignatures,
|
4377
|
-
estimatedPredicates: txRequestClone.inputs
|
4147
|
+
missingContractIds
|
4378
4148
|
};
|
4379
4149
|
}
|
4380
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4150
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4381
4151
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4382
4152
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4383
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4384
|
-
quantitiesToContract
|
4385
|
-
});
|
4153
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4386
4154
|
transactionRequest.addResources(
|
4387
4155
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4388
4156
|
);
|
4389
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4390
|
-
|
4391
|
-
|
4157
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4158
|
+
transactionRequest,
|
4159
|
+
forwardingQuantities
|
4160
|
+
);
|
4392
4161
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4393
4162
|
return {
|
4394
4163
|
resources,
|
@@ -4410,10 +4179,11 @@ var _Provider = class {
|
|
4410
4179
|
return coins.map((coin) => ({
|
4411
4180
|
id: coin.utxoId,
|
4412
4181
|
assetId: coin.assetId,
|
4413
|
-
amount:
|
4182
|
+
amount: bn15(coin.amount),
|
4414
4183
|
owner: Address2.fromAddressOrString(coin.owner),
|
4415
|
-
|
4416
|
-
|
4184
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4185
|
+
blockCreated: bn15(coin.blockCreated),
|
4186
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4417
4187
|
}));
|
4418
4188
|
}
|
4419
4189
|
/**
|
@@ -4450,9 +4220,9 @@ var _Provider = class {
|
|
4450
4220
|
switch (coin.__typename) {
|
4451
4221
|
case "MessageCoin":
|
4452
4222
|
return {
|
4453
|
-
amount:
|
4223
|
+
amount: bn15(coin.amount),
|
4454
4224
|
assetId: coin.assetId,
|
4455
|
-
daHeight:
|
4225
|
+
daHeight: bn15(coin.daHeight),
|
4456
4226
|
sender: Address2.fromAddressOrString(coin.sender),
|
4457
4227
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4458
4228
|
nonce: coin.nonce
|
@@ -4460,11 +4230,12 @@ var _Provider = class {
|
|
4460
4230
|
case "Coin":
|
4461
4231
|
return {
|
4462
4232
|
id: coin.utxoId,
|
4463
|
-
amount:
|
4233
|
+
amount: bn15(coin.amount),
|
4464
4234
|
assetId: coin.assetId,
|
4465
4235
|
owner: Address2.fromAddressOrString(coin.owner),
|
4466
|
-
|
4467
|
-
|
4236
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4237
|
+
blockCreated: bn15(coin.blockCreated),
|
4238
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4468
4239
|
};
|
4469
4240
|
default:
|
4470
4241
|
return null;
|
@@ -4481,13 +4252,13 @@ var _Provider = class {
|
|
4481
4252
|
async getBlock(idOrHeight) {
|
4482
4253
|
let variables;
|
4483
4254
|
if (typeof idOrHeight === "number") {
|
4484
|
-
variables = { height:
|
4255
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4485
4256
|
} else if (idOrHeight === "latest") {
|
4486
4257
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4487
4258
|
} else if (idOrHeight.length === 66) {
|
4488
4259
|
variables = { blockId: idOrHeight };
|
4489
4260
|
} else {
|
4490
|
-
variables = { blockId:
|
4261
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4491
4262
|
}
|
4492
4263
|
const { block } = await this.operations.getBlock(variables);
|
4493
4264
|
if (!block) {
|
@@ -4495,7 +4266,7 @@ var _Provider = class {
|
|
4495
4266
|
}
|
4496
4267
|
return {
|
4497
4268
|
id: block.id,
|
4498
|
-
height:
|
4269
|
+
height: bn15(block.header.height),
|
4499
4270
|
time: block.header.time,
|
4500
4271
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4501
4272
|
};
|
@@ -4510,7 +4281,7 @@ var _Provider = class {
|
|
4510
4281
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4511
4282
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4512
4283
|
id: block.id,
|
4513
|
-
height:
|
4284
|
+
height: bn15(block.header.height),
|
4514
4285
|
time: block.header.time,
|
4515
4286
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4516
4287
|
}));
|
@@ -4525,7 +4296,7 @@ var _Provider = class {
|
|
4525
4296
|
async getBlockWithTransactions(idOrHeight) {
|
4526
4297
|
let variables;
|
4527
4298
|
if (typeof idOrHeight === "number") {
|
4528
|
-
variables = { blockHeight:
|
4299
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4529
4300
|
} else if (idOrHeight === "latest") {
|
4530
4301
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4531
4302
|
} else {
|
@@ -4537,7 +4308,7 @@ var _Provider = class {
|
|
4537
4308
|
}
|
4538
4309
|
return {
|
4539
4310
|
id: block.id,
|
4540
|
-
height:
|
4311
|
+
height: bn15(block.header.height, 10),
|
4541
4312
|
time: block.header.time,
|
4542
4313
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4543
4314
|
transactions: block.transactions.map(
|
@@ -4586,7 +4357,7 @@ var _Provider = class {
|
|
4586
4357
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4587
4358
|
asset: hexlify12(assetId)
|
4588
4359
|
});
|
4589
|
-
return
|
4360
|
+
return bn15(contractBalance.amount, 10);
|
4590
4361
|
}
|
4591
4362
|
/**
|
4592
4363
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4600,7 +4371,7 @@ var _Provider = class {
|
|
4600
4371
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4601
4372
|
assetId: hexlify12(assetId)
|
4602
4373
|
});
|
4603
|
-
return
|
4374
|
+
return bn15(balance.amount, 10);
|
4604
4375
|
}
|
4605
4376
|
/**
|
4606
4377
|
* Returns balances for the given owner.
|
@@ -4618,7 +4389,7 @@ var _Provider = class {
|
|
4618
4389
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4619
4390
|
return balances.map((balance) => ({
|
4620
4391
|
assetId: balance.assetId,
|
4621
|
-
amount:
|
4392
|
+
amount: bn15(balance.amount)
|
4622
4393
|
}));
|
4623
4394
|
}
|
4624
4395
|
/**
|
@@ -4640,15 +4411,15 @@ var _Provider = class {
|
|
4640
4411
|
sender: message.sender,
|
4641
4412
|
recipient: message.recipient,
|
4642
4413
|
nonce: message.nonce,
|
4643
|
-
amount:
|
4414
|
+
amount: bn15(message.amount),
|
4644
4415
|
data: message.data
|
4645
4416
|
}),
|
4646
4417
|
sender: Address2.fromAddressOrString(message.sender),
|
4647
4418
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4648
4419
|
nonce: message.nonce,
|
4649
|
-
amount:
|
4420
|
+
amount: bn15(message.amount),
|
4650
4421
|
data: InputMessageCoder.decodeData(message.data),
|
4651
|
-
daHeight:
|
4422
|
+
daHeight: bn15(message.daHeight)
|
4652
4423
|
}));
|
4653
4424
|
}
|
4654
4425
|
/**
|
@@ -4701,60 +4472,44 @@ var _Provider = class {
|
|
4701
4472
|
} = result.messageProof;
|
4702
4473
|
return {
|
4703
4474
|
messageProof: {
|
4704
|
-
proofIndex:
|
4475
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4705
4476
|
proofSet: messageProof.proofSet
|
4706
4477
|
},
|
4707
4478
|
blockProof: {
|
4708
|
-
proofIndex:
|
4479
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4709
4480
|
proofSet: blockProof.proofSet
|
4710
4481
|
},
|
4711
4482
|
messageBlockHeader: {
|
4712
4483
|
id: messageBlockHeader.id,
|
4713
|
-
daHeight:
|
4714
|
-
transactionsCount:
|
4484
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4485
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4715
4486
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4716
|
-
height:
|
4487
|
+
height: bn15(messageBlockHeader.height),
|
4717
4488
|
prevRoot: messageBlockHeader.prevRoot,
|
4718
4489
|
time: messageBlockHeader.time,
|
4719
4490
|
applicationHash: messageBlockHeader.applicationHash,
|
4720
|
-
|
4721
|
-
|
4722
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4723
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4724
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4491
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4492
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4725
4493
|
},
|
4726
4494
|
commitBlockHeader: {
|
4727
4495
|
id: commitBlockHeader.id,
|
4728
|
-
daHeight:
|
4729
|
-
transactionsCount:
|
4496
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4497
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4730
4498
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4731
|
-
height:
|
4499
|
+
height: bn15(commitBlockHeader.height),
|
4732
4500
|
prevRoot: commitBlockHeader.prevRoot,
|
4733
4501
|
time: commitBlockHeader.time,
|
4734
4502
|
applicationHash: commitBlockHeader.applicationHash,
|
4735
|
-
|
4736
|
-
|
4737
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4738
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4739
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4503
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4504
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4740
4505
|
},
|
4741
4506
|
sender: Address2.fromAddressOrString(sender),
|
4742
4507
|
recipient: Address2.fromAddressOrString(recipient),
|
4743
4508
|
nonce,
|
4744
|
-
amount:
|
4509
|
+
amount: bn15(amount),
|
4745
4510
|
data
|
4746
4511
|
};
|
4747
4512
|
}
|
4748
|
-
async getLatestGasPrice() {
|
4749
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4750
|
-
return bn16(latestGasPrice.gasPrice);
|
4751
|
-
}
|
4752
|
-
async estimateGasPrice(blockHorizon) {
|
4753
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4754
|
-
blockHorizon: String(blockHorizon)
|
4755
|
-
});
|
4756
|
-
return bn16(estimateGasPrice.gasPrice);
|
4757
|
-
}
|
4758
4513
|
/**
|
4759
4514
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4760
4515
|
*
|
@@ -4774,10 +4529,10 @@ var _Provider = class {
|
|
4774
4529
|
*/
|
4775
4530
|
async produceBlocks(amount, startTime) {
|
4776
4531
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4777
|
-
blocksToProduce:
|
4532
|
+
blocksToProduce: bn15(amount).toString(10),
|
4778
4533
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4779
4534
|
});
|
4780
|
-
return
|
4535
|
+
return bn15(latestBlockHeight);
|
4781
4536
|
}
|
4782
4537
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4783
4538
|
async getTransactionResponse(transactionId) {
|
@@ -4791,7 +4546,7 @@ cacheInputs_fn = function(inputs) {
|
|
4791
4546
|
return;
|
4792
4547
|
}
|
4793
4548
|
inputs.forEach((input) => {
|
4794
|
-
if (input.type ===
|
4549
|
+
if (input.type === InputType6.Coin) {
|
4795
4550
|
this.cache?.set(input.id);
|
4796
4551
|
}
|
4797
4552
|
});
|
@@ -4801,7 +4556,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4801
4556
|
|
4802
4557
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4803
4558
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4804
|
-
import { bn as
|
4559
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4805
4560
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4806
4561
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4807
4562
|
async function getTransactionSummary(params) {
|
@@ -4819,28 +4574,21 @@ async function getTransactionSummary(params) {
|
|
4819
4574
|
arrayify12(gqlTransaction.rawPayload),
|
4820
4575
|
0
|
4821
4576
|
);
|
4822
|
-
|
4823
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4824
|
-
txReceipts = gqlTransaction.status.receipts;
|
4825
|
-
}
|
4826
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4577
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4827
4578
|
const {
|
4828
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4579
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4829
4580
|
} = provider.getChain();
|
4830
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4831
4581
|
const transactionInfo = assembleTransactionSummary({
|
4832
4582
|
id: gqlTransaction.id,
|
4833
4583
|
receipts,
|
4834
4584
|
transaction: decodedTransaction,
|
4835
4585
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4836
4586
|
gqlTransactionStatus: gqlTransaction.status,
|
4837
|
-
gasPerByte:
|
4838
|
-
gasPriceFactor:
|
4587
|
+
gasPerByte: bn16(gasPerByte),
|
4588
|
+
gasPriceFactor: bn16(gasPriceFactor),
|
4839
4589
|
abiMap,
|
4840
4590
|
maxInputs,
|
4841
|
-
gasCosts
|
4842
|
-
maxGasPerTx,
|
4843
|
-
gasPrice
|
4591
|
+
gasCosts
|
4844
4592
|
});
|
4845
4593
|
return {
|
4846
4594
|
gqlTransaction,
|
@@ -4850,11 +4598,10 @@ async function getTransactionSummary(params) {
|
|
4850
4598
|
async function getTransactionSummaryFromRequest(params) {
|
4851
4599
|
const { provider, transactionRequest, abiMap } = params;
|
4852
4600
|
const { receipts } = await provider.call(transactionRequest);
|
4853
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4601
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4854
4602
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4855
4603
|
const transaction = transactionRequest.toTransaction();
|
4856
4604
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4857
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4858
4605
|
const transactionSummary = assembleTransactionSummary({
|
4859
4606
|
receipts,
|
4860
4607
|
transaction,
|
@@ -4863,9 +4610,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4863
4610
|
gasPerByte,
|
4864
4611
|
gasPriceFactor,
|
4865
4612
|
maxInputs,
|
4866
|
-
gasCosts
|
4867
|
-
maxGasPerTx,
|
4868
|
-
gasPrice
|
4613
|
+
gasCosts
|
4869
4614
|
});
|
4870
4615
|
return transactionSummary;
|
4871
4616
|
}
|
@@ -4874,18 +4619,13 @@ async function getTransactionsSummaries(params) {
|
|
4874
4619
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4875
4620
|
const { edges, pageInfo } = transactionsByOwner;
|
4876
4621
|
const {
|
4877
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4622
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4878
4623
|
} = provider.getChain();
|
4879
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4880
4624
|
const transactions = edges.map((edge) => {
|
4881
4625
|
const { node: gqlTransaction } = edge;
|
4882
|
-
const { id, rawPayload, status } = gqlTransaction;
|
4626
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4883
4627
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4884
|
-
|
4885
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4886
|
-
txReceipts = gqlTransaction.status.receipts;
|
4887
|
-
}
|
4888
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4628
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4889
4629
|
const transactionSummary = assembleTransactionSummary({
|
4890
4630
|
id,
|
4891
4631
|
receipts,
|
@@ -4896,9 +4636,7 @@ async function getTransactionsSummaries(params) {
|
|
4896
4636
|
gasPerByte,
|
4897
4637
|
gasPriceFactor,
|
4898
4638
|
maxInputs,
|
4899
|
-
gasCosts
|
4900
|
-
maxGasPerTx,
|
4901
|
-
gasPrice
|
4639
|
+
gasCosts
|
4902
4640
|
});
|
4903
4641
|
const output = {
|
4904
4642
|
gqlTransaction,
|
@@ -5192,8 +4930,9 @@ var Account = class extends AbstractAccount {
|
|
5192
4930
|
* @param assetId - The asset ID to check the balance for.
|
5193
4931
|
* @returns A promise that resolves to the balance amount.
|
5194
4932
|
*/
|
5195
|
-
async getBalance(assetId
|
5196
|
-
const
|
4933
|
+
async getBalance(assetId) {
|
4934
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4935
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5197
4936
|
return amount;
|
5198
4937
|
}
|
5199
4938
|
/**
|
@@ -5230,33 +4969,37 @@ var Account = class extends AbstractAccount {
|
|
5230
4969
|
* @param fee - The estimated transaction fee.
|
5231
4970
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5232
4971
|
*/
|
5233
|
-
async fund(request,
|
5234
|
-
const
|
5235
|
-
const
|
5236
|
-
|
5237
|
-
|
5238
|
-
|
5239
|
-
coinQuantities: requiredQuantities
|
4972
|
+
async fund(request, coinQuantities, fee) {
|
4973
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4974
|
+
const updatedQuantities = addAmountToAsset({
|
4975
|
+
amount: bn17(fee),
|
4976
|
+
assetId: baseAssetId,
|
4977
|
+
coinQuantities
|
5240
4978
|
});
|
5241
4979
|
const quantitiesDict = {};
|
5242
|
-
|
4980
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5243
4981
|
quantitiesDict[assetId] = {
|
5244
4982
|
required: amount,
|
5245
|
-
owned:
|
4983
|
+
owned: bn17(0)
|
5246
4984
|
};
|
5247
4985
|
});
|
5248
|
-
|
4986
|
+
const cachedUtxos = [];
|
4987
|
+
const cachedMessages = [];
|
4988
|
+
const owner = this.address.toB256();
|
4989
|
+
request.inputs.forEach((input) => {
|
5249
4990
|
const isResource = "amount" in input;
|
5250
4991
|
if (isResource) {
|
5251
4992
|
const isCoin2 = "owner" in input;
|
5252
4993
|
if (isCoin2) {
|
5253
4994
|
const assetId = String(input.assetId);
|
5254
|
-
if (quantitiesDict[assetId]) {
|
5255
|
-
const amount =
|
4995
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4996
|
+
const amount = bn17(input.amount);
|
5256
4997
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4998
|
+
cachedUtxos.push(input.id);
|
5257
4999
|
}
|
5258
|
-
} else if (input.amount && quantitiesDict[
|
5259
|
-
quantitiesDict[
|
5000
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
5001
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
5002
|
+
cachedMessages.push(input.nonce);
|
5260
5003
|
}
|
5261
5004
|
}
|
5262
5005
|
});
|
@@ -5271,23 +5014,12 @@ var Account = class extends AbstractAccount {
|
|
5271
5014
|
});
|
5272
5015
|
const needsToBeFunded = missingQuantities.length;
|
5273
5016
|
if (needsToBeFunded) {
|
5274
|
-
const
|
5275
|
-
|
5276
|
-
|
5277
|
-
|
5278
|
-
|
5279
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5280
|
-
const requestToBeReEstimate = clone4(txRequest);
|
5281
|
-
if (addedSignatures) {
|
5282
|
-
Array.from({ length: addedSignatures }).forEach(
|
5283
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
5284
|
-
);
|
5017
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5018
|
+
messages: cachedMessages,
|
5019
|
+
utxos: cachedUtxos
|
5020
|
+
});
|
5021
|
+
request.addResources(resources);
|
5285
5022
|
}
|
5286
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5287
|
-
transactionRequest: requestToBeReEstimate
|
5288
|
-
});
|
5289
|
-
txRequest.maxFee = maxFee;
|
5290
|
-
return txRequest;
|
5291
5023
|
}
|
5292
5024
|
/**
|
5293
5025
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5295,25 +5027,30 @@ var Account = class extends AbstractAccount {
|
|
5295
5027
|
* @param destination - The address of the destination.
|
5296
5028
|
* @param amount - The amount of coins to transfer.
|
5297
5029
|
* @param assetId - The asset ID of the coins to transfer.
|
5298
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5030
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5299
5031
|
* @returns A promise that resolves to the prepared transaction request.
|
5300
5032
|
*/
|
5301
|
-
async createTransfer(destination, amount, assetId
|
5302
|
-
const
|
5303
|
-
|
5304
|
-
const
|
5033
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5034
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5035
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5036
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5037
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5038
|
+
const request = new ScriptTransactionRequest(params);
|
5039
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5040
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5305
5041
|
estimateTxDependencies: true,
|
5306
5042
|
resourcesOwner: this
|
5307
5043
|
});
|
5308
|
-
|
5309
|
-
|
5310
|
-
|
5311
|
-
|
5312
|
-
|
5313
|
-
|
5314
|
-
|
5315
|
-
|
5316
|
-
await this.fund(request,
|
5044
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
5045
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
5046
|
+
this.validateGas({
|
5047
|
+
gasUsed,
|
5048
|
+
gasPrice: request.gasPrice,
|
5049
|
+
gasLimit: request.gasLimit,
|
5050
|
+
minGasPrice
|
5051
|
+
});
|
5052
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5053
|
+
request.updatePredicateInputs(estimatedInputs);
|
5317
5054
|
return request;
|
5318
5055
|
}
|
5319
5056
|
/**
|
@@ -5325,14 +5062,15 @@ var Account = class extends AbstractAccount {
|
|
5325
5062
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5326
5063
|
* @returns A promise that resolves to the transaction response.
|
5327
5064
|
*/
|
5328
|
-
async transfer(destination, amount, assetId
|
5329
|
-
if (
|
5065
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5066
|
+
if (bn17(amount).lte(0)) {
|
5330
5067
|
throw new FuelError15(
|
5331
5068
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5332
5069
|
"Transfer amount must be a positive number."
|
5333
5070
|
);
|
5334
5071
|
}
|
5335
|
-
const
|
5072
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5073
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5336
5074
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5337
5075
|
}
|
5338
5076
|
/**
|
@@ -5344,38 +5082,41 @@ var Account = class extends AbstractAccount {
|
|
5344
5082
|
* @param txParams - The optional transaction parameters.
|
5345
5083
|
* @returns A promise that resolves to the transaction response.
|
5346
5084
|
*/
|
5347
|
-
async transferToContract(contractId, amount, assetId
|
5348
|
-
if (
|
5085
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5086
|
+
if (bn17(amount).lte(0)) {
|
5349
5087
|
throw new FuelError15(
|
5350
5088
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5351
5089
|
"Transfer amount must be a positive number."
|
5352
5090
|
);
|
5353
5091
|
}
|
5354
5092
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5093
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5094
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5095
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5096
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5355
5097
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5356
5098
|
hexlifiedContractId: contractAddress.toB256(),
|
5357
|
-
amountToTransfer:
|
5358
|
-
assetId
|
5099
|
+
amountToTransfer: bn17(amount),
|
5100
|
+
assetId: assetIdToTransfer
|
5359
5101
|
});
|
5360
5102
|
const request = new ScriptTransactionRequest({
|
5361
|
-
...
|
5103
|
+
...params,
|
5362
5104
|
script,
|
5363
5105
|
scriptData
|
5364
5106
|
});
|
5365
5107
|
request.addContractInputAndOutput(contractAddress);
|
5366
|
-
const
|
5367
|
-
|
5368
|
-
|
5108
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5109
|
+
request,
|
5110
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
5111
|
+
);
|
5112
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5113
|
+
this.validateGas({
|
5114
|
+
gasUsed,
|
5115
|
+
gasPrice: request.gasPrice,
|
5116
|
+
gasLimit: request.gasLimit,
|
5117
|
+
minGasPrice
|
5369
5118
|
});
|
5370
|
-
|
5371
|
-
this.validateGas({
|
5372
|
-
gasUsed: txCost.gasUsed,
|
5373
|
-
gasLimit: request.gasLimit
|
5374
|
-
});
|
5375
|
-
}
|
5376
|
-
request.gasLimit = txCost.gasUsed;
|
5377
|
-
request.maxFee = txCost.maxFee;
|
5378
|
-
await this.fund(request, txCost);
|
5119
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5379
5120
|
return this.sendTransaction(request);
|
5380
5121
|
}
|
5381
5122
|
/**
|
@@ -5387,31 +5128,39 @@ var Account = class extends AbstractAccount {
|
|
5387
5128
|
* @returns A promise that resolves to the transaction response.
|
5388
5129
|
*/
|
5389
5130
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5131
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5132
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5390
5133
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5391
5134
|
const recipientDataArray = arrayify14(
|
5392
5135
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5393
5136
|
);
|
5394
5137
|
const amountDataArray = arrayify14(
|
5395
|
-
"0x".concat(
|
5138
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5396
5139
|
);
|
5397
5140
|
const script = new Uint8Array([
|
5398
5141
|
...arrayify14(withdrawScript.bytes),
|
5399
5142
|
...recipientDataArray,
|
5400
5143
|
...amountDataArray
|
5401
5144
|
]);
|
5402
|
-
const params = {
|
5145
|
+
const params = {
|
5146
|
+
script,
|
5147
|
+
gasPrice: minGasPrice,
|
5148
|
+
...txParams
|
5149
|
+
};
|
5403
5150
|
const request = new ScriptTransactionRequest(params);
|
5404
|
-
const
|
5405
|
-
const
|
5406
|
-
|
5407
|
-
|
5408
|
-
|
5409
|
-
|
5410
|
-
|
5411
|
-
|
5412
|
-
|
5413
|
-
|
5414
|
-
|
5151
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
5152
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5153
|
+
request,
|
5154
|
+
forwardingQuantities
|
5155
|
+
);
|
5156
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5157
|
+
this.validateGas({
|
5158
|
+
gasUsed,
|
5159
|
+
gasPrice: request.gasPrice,
|
5160
|
+
gasLimit: request.gasLimit,
|
5161
|
+
minGasPrice
|
5162
|
+
});
|
5163
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5415
5164
|
return this.sendTransaction(request);
|
5416
5165
|
}
|
5417
5166
|
async signMessage(message) {
|
@@ -5469,7 +5218,18 @@ var Account = class extends AbstractAccount {
|
|
5469
5218
|
}
|
5470
5219
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5471
5220
|
}
|
5472
|
-
validateGas({
|
5221
|
+
validateGas({
|
5222
|
+
gasUsed,
|
5223
|
+
gasPrice,
|
5224
|
+
gasLimit,
|
5225
|
+
minGasPrice
|
5226
|
+
}) {
|
5227
|
+
if (minGasPrice.gt(gasPrice)) {
|
5228
|
+
throw new FuelError15(
|
5229
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5230
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5231
|
+
);
|
5232
|
+
}
|
5473
5233
|
if (gasUsed.gt(gasLimit)) {
|
5474
5234
|
throw new FuelError15(
|
5475
5235
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5765,7 +5525,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5765
5525
|
* @param transactionRequestLike - The transaction request to send.
|
5766
5526
|
* @returns A promise that resolves to the TransactionResponse object.
|
5767
5527
|
*/
|
5768
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5528
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5769
5529
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5770
5530
|
if (estimateTxDependencies) {
|
5771
5531
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5806,7 +5566,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5806
5566
|
// src/hdwallet/hdwallet.ts
|
5807
5567
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5808
5568
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5809
|
-
import { bn as
|
5569
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5810
5570
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5811
5571
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5812
5572
|
|
@@ -8278,7 +8038,7 @@ var HDWallet = class {
|
|
8278
8038
|
const IR = bytes.slice(32);
|
8279
8039
|
if (privateKey) {
|
8280
8040
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8281
|
-
const ki =
|
8041
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
8282
8042
|
return new HDWallet({
|
8283
8043
|
privateKey: ki,
|
8284
8044
|
chainCode: IR,
|
@@ -8965,9 +8725,8 @@ import {
|
|
8965
8725
|
SCRIPT_FIXED_SIZE
|
8966
8726
|
} from "@fuel-ts/abi-coder";
|
8967
8727
|
import { Address as Address9 } from "@fuel-ts/address";
|
8968
|
-
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8969
8728
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8970
|
-
import { ByteArrayCoder, InputType as
|
8729
|
+
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8971
8730
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8972
8731
|
|
8973
8732
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -9027,9 +8786,9 @@ var Predicate = class extends Account {
|
|
9027
8786
|
const request = transactionRequestify(transactionRequestLike);
|
9028
8787
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9029
8788
|
request.inputs?.forEach((input) => {
|
9030
|
-
if (input.type ===
|
9031
|
-
input.predicate =
|
9032
|
-
input.predicateData =
|
8789
|
+
if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
8790
|
+
input.predicate = this.bytes;
|
8791
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9033
8792
|
}
|
9034
8793
|
});
|
9035
8794
|
return request;
|
@@ -9043,8 +8802,10 @@ var Predicate = class extends Account {
|
|
9043
8802
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
9044
8803
|
* @returns A promise that resolves to the prepared transaction request.
|
9045
8804
|
*/
|
9046
|
-
async createTransfer(destination, amount, assetId
|
9047
|
-
|
8805
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8806
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8807
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8808
|
+
return this.populateTransactionPredicateData(request);
|
9048
8809
|
}
|
9049
8810
|
/**
|
9050
8811
|
* Sends a transaction with the populated predicate data.
|
@@ -9052,9 +8813,9 @@ var Predicate = class extends Account {
|
|
9052
8813
|
* @param transactionRequestLike - The transaction request-like object.
|
9053
8814
|
* @returns A promise that resolves to the transaction response.
|
9054
8815
|
*/
|
9055
|
-
sendTransaction(transactionRequestLike) {
|
9056
|
-
const transactionRequest =
|
9057
|
-
return super.sendTransaction(transactionRequest,
|
8816
|
+
sendTransaction(transactionRequestLike, options) {
|
8817
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8818
|
+
return super.sendTransaction(transactionRequest, options);
|
9058
8819
|
}
|
9059
8820
|
/**
|
9060
8821
|
* Simulates a transaction with the populated predicate data.
|
@@ -9063,8 +8824,8 @@ var Predicate = class extends Account {
|
|
9063
8824
|
* @returns A promise that resolves to the call result.
|
9064
8825
|
*/
|
9065
8826
|
simulateTransaction(transactionRequestLike) {
|
9066
|
-
const transactionRequest =
|
9067
|
-
return super.simulateTransaction(transactionRequest
|
8827
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8828
|
+
return super.simulateTransaction(transactionRequest);
|
9068
8829
|
}
|
9069
8830
|
getPredicateData(policiesLength) {
|
9070
8831
|
if (!this.predicateData.length) {
|
@@ -9110,25 +8871,6 @@ var Predicate = class extends Account {
|
|
9110
8871
|
predicateInterface: abiInterface
|
9111
8872
|
};
|
9112
8873
|
}
|
9113
|
-
/**
|
9114
|
-
* Retrieves resources satisfying the spend query for the account.
|
9115
|
-
*
|
9116
|
-
* @param quantities - IDs of coins to exclude.
|
9117
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9118
|
-
* @returns A promise that resolves to an array of Resources.
|
9119
|
-
*/
|
9120
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9121
|
-
const resources = await this.provider.getResourcesToSpend(
|
9122
|
-
this.address,
|
9123
|
-
quantities,
|
9124
|
-
excludedIds
|
9125
|
-
);
|
9126
|
-
return resources.map((resource) => ({
|
9127
|
-
...resource,
|
9128
|
-
predicate: hexlify19(this.bytes),
|
9129
|
-
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9130
|
-
}));
|
9131
|
-
}
|
9132
8874
|
/**
|
9133
8875
|
* Sets the configurable constants for the predicate.
|
9134
8876
|
*
|
@@ -9877,7 +9619,7 @@ export {
|
|
9877
9619
|
WalletLocked,
|
9878
9620
|
WalletManager,
|
9879
9621
|
WalletUnlocked,
|
9880
|
-
|
9622
|
+
addAmountToAsset,
|
9881
9623
|
addOperation,
|
9882
9624
|
assemblePanicError,
|
9883
9625
|
assembleReceiptByType,
|
@@ -9886,10 +9628,9 @@ export {
|
|
9886
9628
|
assets,
|
9887
9629
|
buildBlockExplorerUrl,
|
9888
9630
|
cacheFor,
|
9889
|
-
cacheTxInputsFromOwner,
|
9890
|
-
calculateGasFee,
|
9891
9631
|
calculateMetadataGasForTxCreate,
|
9892
9632
|
calculateMetadataGasForTxScript,
|
9633
|
+
calculatePriceWithFactor,
|
9893
9634
|
calculateTransactionFee,
|
9894
9635
|
coinQuantityfy,
|
9895
9636
|
deferPromise,
|