@fuel-ts/account 0.0.0-rc-1976-20240419101644 → 0.0.0-rc-2021-20240419145341
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- 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 +830 -604
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +833 -601
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +675 -444
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +906 -324
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1579 -1118
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +811 -600
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +667 -456
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -29,35 +29,38 @@ 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";
|
32
33
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
33
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
|
-
import { bn as
|
35
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
35
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
|
+
import { clone as clone4 } from "ramda";
|
36
38
|
|
37
39
|
// src/providers/coin-quantity.ts
|
40
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
38
41
|
import { bn } from "@fuel-ts/math";
|
39
42
|
import { hexlify } from "@fuel-ts/utils";
|
40
43
|
var coinQuantityfy = (coinQuantityLike) => {
|
41
44
|
let assetId;
|
42
45
|
let amount;
|
43
|
-
let
|
46
|
+
let max;
|
44
47
|
if (Array.isArray(coinQuantityLike)) {
|
45
48
|
amount = coinQuantityLike[0];
|
46
|
-
assetId = coinQuantityLike[1];
|
47
|
-
|
49
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
50
|
+
max = coinQuantityLike[2] ?? void 0;
|
48
51
|
} else {
|
49
52
|
amount = coinQuantityLike.amount;
|
50
|
-
assetId = coinQuantityLike.assetId;
|
51
|
-
|
53
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
54
|
+
max = coinQuantityLike.max ?? void 0;
|
52
55
|
}
|
53
56
|
const bnAmount = bn(amount);
|
54
57
|
return {
|
55
58
|
assetId: hexlify(assetId),
|
56
59
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
57
|
-
max:
|
60
|
+
max: max ? bn(max) : void 0
|
58
61
|
};
|
59
62
|
};
|
60
|
-
var
|
63
|
+
var addAmountToCoinQuantities = (params) => {
|
61
64
|
const { amount, assetId } = params;
|
62
65
|
const coinQuantities = [...params.coinQuantities];
|
63
66
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -72,9 +75,9 @@ var addAmountToAsset = (params) => {
|
|
72
75
|
// src/providers/provider.ts
|
73
76
|
import { Address as Address2 } from "@fuel-ts/address";
|
74
77
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
75
|
-
import { BN, bn as
|
78
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
76
79
|
import {
|
77
|
-
InputType as
|
80
|
+
InputType as InputType7,
|
78
81
|
TransactionType as TransactionType8,
|
79
82
|
InputMessageCoder,
|
80
83
|
TransactionCoder as TransactionCoder5
|
@@ -90,14 +93,10 @@ import { clone as clone3 } from "ramda";
|
|
90
93
|
import gql from "graphql-tag";
|
91
94
|
var ReceiptFragmentFragmentDoc = gql`
|
92
95
|
fragment receiptFragment on Receipt {
|
93
|
-
|
94
|
-
id
|
95
|
-
}
|
96
|
+
id
|
96
97
|
pc
|
97
98
|
is
|
98
|
-
to
|
99
|
-
id
|
100
|
-
}
|
99
|
+
to
|
101
100
|
toAddress
|
102
101
|
amount
|
103
102
|
assetId
|
@@ -135,10 +134,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
135
134
|
id
|
136
135
|
}
|
137
136
|
time
|
137
|
+
receipts {
|
138
|
+
...receiptFragment
|
139
|
+
}
|
138
140
|
programState {
|
139
141
|
returnType
|
140
142
|
data
|
141
143
|
}
|
144
|
+
receipts {
|
145
|
+
...receiptFragment
|
146
|
+
}
|
142
147
|
}
|
143
148
|
... on FailureStatus {
|
144
149
|
block {
|
@@ -146,26 +151,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
146
151
|
}
|
147
152
|
time
|
148
153
|
reason
|
154
|
+
receipts {
|
155
|
+
...receiptFragment
|
156
|
+
}
|
149
157
|
}
|
150
158
|
... on SqueezedOutStatus {
|
151
159
|
reason
|
152
160
|
}
|
153
161
|
}
|
154
|
-
`;
|
162
|
+
${ReceiptFragmentFragmentDoc}`;
|
155
163
|
var TransactionFragmentFragmentDoc = gql`
|
156
164
|
fragment transactionFragment on Transaction {
|
157
165
|
id
|
158
166
|
rawPayload
|
159
|
-
gasPrice
|
160
|
-
receipts {
|
161
|
-
...receiptFragment
|
162
|
-
}
|
163
167
|
status {
|
164
168
|
...transactionStatusFragment
|
165
169
|
}
|
166
170
|
}
|
167
|
-
${
|
168
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
171
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
169
172
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
170
173
|
fragment inputEstimatePredicatesFragment on Input {
|
171
174
|
... on InputCoin {
|
@@ -183,6 +186,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
183
186
|
}
|
184
187
|
}
|
185
188
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
189
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
190
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
191
|
+
reason
|
192
|
+
programState {
|
193
|
+
returnType
|
194
|
+
data
|
195
|
+
}
|
196
|
+
}
|
197
|
+
`;
|
198
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
199
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
200
|
+
programState {
|
201
|
+
returnType
|
202
|
+
data
|
203
|
+
}
|
204
|
+
}
|
205
|
+
`;
|
206
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
207
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
208
|
+
... on DryRunFailureStatus {
|
209
|
+
...dryRunFailureStatusFragment
|
210
|
+
}
|
211
|
+
... on DryRunSuccessStatus {
|
212
|
+
...dryRunSuccessStatusFragment
|
213
|
+
}
|
214
|
+
}
|
215
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
216
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
217
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
218
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
219
|
+
id
|
220
|
+
status {
|
221
|
+
...dryRunTransactionStatusFragment
|
222
|
+
}
|
223
|
+
receipts {
|
224
|
+
...receiptFragment
|
225
|
+
}
|
226
|
+
}
|
227
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
228
|
+
${ReceiptFragmentFragmentDoc}`;
|
186
229
|
var CoinFragmentFragmentDoc = gql`
|
187
230
|
fragment coinFragment on Coin {
|
188
231
|
__typename
|
@@ -190,7 +233,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
190
233
|
owner
|
191
234
|
amount
|
192
235
|
assetId
|
193
|
-
maturity
|
194
236
|
blockCreated
|
195
237
|
txCreatedIdx
|
196
238
|
}
|
@@ -229,26 +271,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
229
271
|
messageBlockHeader {
|
230
272
|
id
|
231
273
|
daHeight
|
274
|
+
consensusParametersVersion
|
275
|
+
stateTransitionBytecodeVersion
|
232
276
|
transactionsCount
|
277
|
+
messageReceiptCount
|
233
278
|
transactionsRoot
|
279
|
+
messageOutboxRoot
|
280
|
+
eventInboxRoot
|
234
281
|
height
|
235
282
|
prevRoot
|
236
283
|
time
|
237
284
|
applicationHash
|
238
|
-
messageReceiptRoot
|
239
|
-
messageReceiptCount
|
240
285
|
}
|
241
286
|
commitBlockHeader {
|
242
287
|
id
|
243
288
|
daHeight
|
289
|
+
consensusParametersVersion
|
290
|
+
stateTransitionBytecodeVersion
|
244
291
|
transactionsCount
|
292
|
+
messageReceiptCount
|
245
293
|
transactionsRoot
|
294
|
+
messageOutboxRoot
|
295
|
+
eventInboxRoot
|
246
296
|
height
|
247
297
|
prevRoot
|
248
298
|
time
|
249
299
|
applicationHash
|
250
|
-
messageReceiptRoot
|
251
|
-
messageReceiptCount
|
252
300
|
}
|
253
301
|
sender
|
254
302
|
recipient
|
@@ -267,8 +315,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
267
315
|
var BlockFragmentFragmentDoc = gql`
|
268
316
|
fragment blockFragment on Block {
|
269
317
|
id
|
318
|
+
height
|
270
319
|
header {
|
271
|
-
height
|
272
320
|
time
|
273
321
|
}
|
274
322
|
transactions {
|
@@ -326,6 +374,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
326
374
|
`;
|
327
375
|
var GasCostsFragmentFragmentDoc = gql`
|
328
376
|
fragment GasCostsFragment on GasCosts {
|
377
|
+
version {
|
378
|
+
... on Version {
|
379
|
+
value
|
380
|
+
}
|
381
|
+
}
|
329
382
|
add
|
330
383
|
addi
|
331
384
|
aloc
|
@@ -338,7 +391,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
338
391
|
cb
|
339
392
|
cfei
|
340
393
|
cfsi
|
341
|
-
croo
|
342
394
|
div
|
343
395
|
divi
|
344
396
|
ecr1
|
@@ -421,6 +473,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
421
473
|
ccp {
|
422
474
|
...DependentCostFragment
|
423
475
|
}
|
476
|
+
croo {
|
477
|
+
...DependentCostFragment
|
478
|
+
}
|
424
479
|
csiz {
|
425
480
|
...DependentCostFragment
|
426
481
|
}
|
@@ -480,6 +535,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
480
535
|
${DependentCostFragmentFragmentDoc}`;
|
481
536
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
482
537
|
fragment consensusParametersFragment on ConsensusParameters {
|
538
|
+
version {
|
539
|
+
... on Version {
|
540
|
+
value
|
541
|
+
}
|
542
|
+
}
|
483
543
|
txParams {
|
484
544
|
...TxParametersFragment
|
485
545
|
}
|
@@ -539,18 +599,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
539
599
|
fragment nodeInfoFragment on NodeInfo {
|
540
600
|
utxoValidation
|
541
601
|
vmBacktrace
|
542
|
-
minGasPrice
|
543
602
|
maxTx
|
544
603
|
maxDepth
|
545
604
|
nodeVersion
|
546
|
-
peers {
|
547
|
-
id
|
548
|
-
addresses
|
549
|
-
clientVersion
|
550
|
-
blockHeight
|
551
|
-
lastHeartbeatMs
|
552
|
-
appScore
|
553
|
-
}
|
554
605
|
}
|
555
606
|
`;
|
556
607
|
var GetVersionDocument = gql`
|
@@ -585,13 +636,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
585
636
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
586
637
|
transaction(id: $transactionId) {
|
587
638
|
...transactionFragment
|
588
|
-
receipts {
|
589
|
-
...receiptFragment
|
590
|
-
}
|
591
639
|
}
|
592
640
|
}
|
593
|
-
${TransactionFragmentFragmentDoc}
|
594
|
-
${ReceiptFragmentFragmentDoc}`;
|
641
|
+
${TransactionFragmentFragmentDoc}`;
|
595
642
|
var GetTransactionsDocument = gql`
|
596
643
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
597
644
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -719,6 +766,20 @@ var GetBalanceDocument = gql`
|
|
719
766
|
}
|
720
767
|
}
|
721
768
|
${BalanceFragmentFragmentDoc}`;
|
769
|
+
var GetLatestGasPriceDocument = gql`
|
770
|
+
query getLatestGasPrice {
|
771
|
+
latestGasPrice {
|
772
|
+
gasPrice
|
773
|
+
}
|
774
|
+
}
|
775
|
+
`;
|
776
|
+
var EstimateGasPriceDocument = gql`
|
777
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
778
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
779
|
+
gasPrice
|
780
|
+
}
|
781
|
+
}
|
782
|
+
`;
|
722
783
|
var GetBalancesDocument = gql`
|
723
784
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
724
785
|
balances(
|
@@ -773,12 +834,12 @@ var GetMessageStatusDocument = gql`
|
|
773
834
|
}
|
774
835
|
`;
|
775
836
|
var DryRunDocument = gql`
|
776
|
-
mutation dryRun($
|
777
|
-
dryRun(
|
778
|
-
...
|
837
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
838
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
839
|
+
...dryRunTransactionExecutionStatusFragment
|
779
840
|
}
|
780
841
|
}
|
781
|
-
${
|
842
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
782
843
|
var SubmitDocument = gql`
|
783
844
|
mutation submit($encodedTransaction: HexString!) {
|
784
845
|
submit(tx: $encodedTransaction) {
|
@@ -861,6 +922,12 @@ function getSdk(requester) {
|
|
861
922
|
getBalance(variables, options) {
|
862
923
|
return requester(GetBalanceDocument, variables, options);
|
863
924
|
},
|
925
|
+
getLatestGasPrice(variables, options) {
|
926
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
927
|
+
},
|
928
|
+
estimateGasPrice(variables, options) {
|
929
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
930
|
+
},
|
864
931
|
getBalances(variables, options) {
|
865
932
|
return requester(GetBalancesDocument, variables, options);
|
866
933
|
},
|
@@ -1054,10 +1121,9 @@ var inputify = (value) => {
|
|
1054
1121
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1055
1122
|
},
|
1056
1123
|
witnessIndex: value.witnessIndex,
|
1057
|
-
maturity: value.maturity ?? 0,
|
1058
1124
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1059
|
-
predicateLength: predicate.length,
|
1060
|
-
predicateDataLength: predicateData.length,
|
1125
|
+
predicateLength: bn2(predicate.length),
|
1126
|
+
predicateDataLength: bn2(predicateData.length),
|
1061
1127
|
predicate: hexlify3(predicate),
|
1062
1128
|
predicateData: hexlify3(predicateData)
|
1063
1129
|
};
|
@@ -1088,8 +1154,8 @@ var inputify = (value) => {
|
|
1088
1154
|
nonce: hexlify3(value.nonce),
|
1089
1155
|
witnessIndex: value.witnessIndex,
|
1090
1156
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1091
|
-
predicateLength: predicate.length,
|
1092
|
-
predicateDataLength: predicateData.length,
|
1157
|
+
predicateLength: bn2(predicate.length),
|
1158
|
+
predicateDataLength: bn2(predicateData.length),
|
1093
1159
|
predicate: hexlify3(predicate),
|
1094
1160
|
predicateData: hexlify3(predicateData),
|
1095
1161
|
data: hexlify3(data),
|
@@ -1165,7 +1231,7 @@ var outputify = (value) => {
|
|
1165
1231
|
// src/providers/transaction-request/transaction-request.ts
|
1166
1232
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1167
1233
|
import { Address, addressify } from "@fuel-ts/address";
|
1168
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1234
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1169
1235
|
import { randomBytes } from "@fuel-ts/crypto";
|
1170
1236
|
import { bn as bn7 } from "@fuel-ts/math";
|
1171
1237
|
import {
|
@@ -1219,8 +1285,8 @@ function assembleReceiptByType(receipt) {
|
|
1219
1285
|
case "CALL" /* Call */: {
|
1220
1286
|
const callReceipt = {
|
1221
1287
|
type: ReceiptType.Call,
|
1222
|
-
from: hexOrZero(receipt.
|
1223
|
-
to: hexOrZero(receipt?.to
|
1288
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1289
|
+
to: hexOrZero(receipt?.to),
|
1224
1290
|
amount: bn4(receipt.amount),
|
1225
1291
|
assetId: hexOrZero(receipt.assetId),
|
1226
1292
|
gas: bn4(receipt.gas),
|
@@ -1234,7 +1300,7 @@ function assembleReceiptByType(receipt) {
|
|
1234
1300
|
case "RETURN" /* Return */: {
|
1235
1301
|
const returnReceipt = {
|
1236
1302
|
type: ReceiptType.Return,
|
1237
|
-
id: hexOrZero(receipt.
|
1303
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1238
1304
|
val: bn4(receipt.val),
|
1239
1305
|
pc: bn4(receipt.pc),
|
1240
1306
|
is: bn4(receipt.is)
|
@@ -1244,7 +1310,7 @@ function assembleReceiptByType(receipt) {
|
|
1244
1310
|
case "RETURN_DATA" /* ReturnData */: {
|
1245
1311
|
const returnDataReceipt = {
|
1246
1312
|
type: ReceiptType.ReturnData,
|
1247
|
-
id: hexOrZero(receipt.
|
1313
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1248
1314
|
ptr: bn4(receipt.ptr),
|
1249
1315
|
len: bn4(receipt.len),
|
1250
1316
|
digest: hexOrZero(receipt.digest),
|
@@ -1256,7 +1322,7 @@ function assembleReceiptByType(receipt) {
|
|
1256
1322
|
case "PANIC" /* Panic */: {
|
1257
1323
|
const panicReceipt = {
|
1258
1324
|
type: ReceiptType.Panic,
|
1259
|
-
id: hexOrZero(receipt.
|
1325
|
+
id: hexOrZero(receipt.id),
|
1260
1326
|
reason: bn4(receipt.reason),
|
1261
1327
|
pc: bn4(receipt.pc),
|
1262
1328
|
is: bn4(receipt.is),
|
@@ -1267,7 +1333,7 @@ function assembleReceiptByType(receipt) {
|
|
1267
1333
|
case "REVERT" /* Revert */: {
|
1268
1334
|
const revertReceipt = {
|
1269
1335
|
type: ReceiptType.Revert,
|
1270
|
-
id: hexOrZero(receipt.
|
1336
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1271
1337
|
val: bn4(receipt.ra),
|
1272
1338
|
pc: bn4(receipt.pc),
|
1273
1339
|
is: bn4(receipt.is)
|
@@ -1277,7 +1343,7 @@ function assembleReceiptByType(receipt) {
|
|
1277
1343
|
case "LOG" /* Log */: {
|
1278
1344
|
const logReceipt = {
|
1279
1345
|
type: ReceiptType.Log,
|
1280
|
-
id: hexOrZero(receipt.
|
1346
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1281
1347
|
val0: bn4(receipt.ra),
|
1282
1348
|
val1: bn4(receipt.rb),
|
1283
1349
|
val2: bn4(receipt.rc),
|
@@ -1290,7 +1356,7 @@ function assembleReceiptByType(receipt) {
|
|
1290
1356
|
case "LOG_DATA" /* LogData */: {
|
1291
1357
|
const logDataReceipt = {
|
1292
1358
|
type: ReceiptType.LogData,
|
1293
|
-
id: hexOrZero(receipt.
|
1359
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1294
1360
|
val0: bn4(receipt.ra),
|
1295
1361
|
val1: bn4(receipt.rb),
|
1296
1362
|
ptr: bn4(receipt.ptr),
|
@@ -1304,8 +1370,8 @@ function assembleReceiptByType(receipt) {
|
|
1304
1370
|
case "TRANSFER" /* Transfer */: {
|
1305
1371
|
const transferReceipt = {
|
1306
1372
|
type: ReceiptType.Transfer,
|
1307
|
-
from: hexOrZero(receipt.
|
1308
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1373
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1374
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1309
1375
|
amount: bn4(receipt.amount),
|
1310
1376
|
assetId: hexOrZero(receipt.assetId),
|
1311
1377
|
pc: bn4(receipt.pc),
|
@@ -1316,8 +1382,8 @@ function assembleReceiptByType(receipt) {
|
|
1316
1382
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1317
1383
|
const transferOutReceipt = {
|
1318
1384
|
type: ReceiptType.TransferOut,
|
1319
|
-
from: hexOrZero(receipt.
|
1320
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1385
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1386
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1321
1387
|
amount: bn4(receipt.amount),
|
1322
1388
|
assetId: hexOrZero(receipt.assetId),
|
1323
1389
|
pc: bn4(receipt.pc),
|
@@ -1360,7 +1426,7 @@ function assembleReceiptByType(receipt) {
|
|
1360
1426
|
return receiptMessageOut;
|
1361
1427
|
}
|
1362
1428
|
case "MINT" /* Mint */: {
|
1363
|
-
const contractId = hexOrZero(receipt.
|
1429
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1364
1430
|
const subId = hexOrZero(receipt.subId);
|
1365
1431
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1366
1432
|
const mintReceipt = {
|
@@ -1375,7 +1441,7 @@ function assembleReceiptByType(receipt) {
|
|
1375
1441
|
return mintReceipt;
|
1376
1442
|
}
|
1377
1443
|
case "BURN" /* Burn */: {
|
1378
|
-
const contractId = hexOrZero(receipt.
|
1444
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1379
1445
|
const subId = hexOrZero(receipt.subId);
|
1380
1446
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1381
1447
|
const burnReceipt = {
|
@@ -1460,7 +1526,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1460
1526
|
import { bn as bn5 } from "@fuel-ts/math";
|
1461
1527
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1462
1528
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1463
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1464
1529
|
var getGasUsedFromReceipts = (receipts) => {
|
1465
1530
|
const scriptResult = receipts.filter(
|
1466
1531
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1481,18 +1546,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1481
1546
|
}
|
1482
1547
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1483
1548
|
const witnessCache = [];
|
1484
|
-
const
|
1549
|
+
const chargeableInputs = inputs.filter((input) => {
|
1550
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1551
|
+
if (isCoinOrMessage) {
|
1552
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1553
|
+
return true;
|
1554
|
+
}
|
1555
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1556
|
+
witnessCache.push(input.witnessIndex);
|
1557
|
+
return true;
|
1558
|
+
}
|
1559
|
+
}
|
1560
|
+
return false;
|
1561
|
+
});
|
1562
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1563
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1485
1564
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1486
1565
|
return total.add(
|
1487
|
-
|
1566
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1488
1567
|
);
|
1489
1568
|
}
|
1490
|
-
|
1491
|
-
|
1492
|
-
return total.add(gasCosts.ecr1);
|
1493
|
-
}
|
1494
|
-
return total;
|
1495
|
-
}, bn5());
|
1569
|
+
return total.add(gasCosts.ecr1);
|
1570
|
+
}, bn5(0));
|
1496
1571
|
return totalGas;
|
1497
1572
|
}
|
1498
1573
|
function getMinGas(params) {
|
@@ -1504,12 +1579,20 @@ function getMinGas(params) {
|
|
1504
1579
|
return minGas;
|
1505
1580
|
}
|
1506
1581
|
function getMaxGas(params) {
|
1507
|
-
const {
|
1582
|
+
const {
|
1583
|
+
gasPerByte,
|
1584
|
+
witnessesLength,
|
1585
|
+
witnessLimit,
|
1586
|
+
minGas,
|
1587
|
+
gasLimit = bn5(0),
|
1588
|
+
maxGasPerTx
|
1589
|
+
} = params;
|
1508
1590
|
let remainingAllowedWitnessGas = bn5(0);
|
1509
1591
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1510
1592
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1511
1593
|
}
|
1512
|
-
|
1594
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1595
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1513
1596
|
}
|
1514
1597
|
function calculateMetadataGasForTxCreate({
|
1515
1598
|
gasCosts,
|
@@ -1531,6 +1614,10 @@ function calculateMetadataGasForTxScript({
|
|
1531
1614
|
}) {
|
1532
1615
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1533
1616
|
}
|
1617
|
+
var calculateGasFee = (params) => {
|
1618
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1619
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1620
|
+
};
|
1534
1621
|
|
1535
1622
|
// src/providers/utils/json.ts
|
1536
1623
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1687,7 +1774,7 @@ var witnessify = (value) => {
|
|
1687
1774
|
// src/providers/transaction-request/transaction-request.ts
|
1688
1775
|
var BaseTransactionRequest = class {
|
1689
1776
|
/** Gas price for transaction */
|
1690
|
-
|
1777
|
+
tip;
|
1691
1778
|
/** Block until which tx cannot be included */
|
1692
1779
|
maturity;
|
1693
1780
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1700,38 +1787,34 @@ var BaseTransactionRequest = class {
|
|
1700
1787
|
outputs = [];
|
1701
1788
|
/** List of witnesses */
|
1702
1789
|
witnesses = [];
|
1703
|
-
/** Base asset ID - should be fetched from the chain */
|
1704
|
-
baseAssetId;
|
1705
1790
|
/**
|
1706
1791
|
* Constructor for initializing a base transaction request.
|
1707
1792
|
*
|
1708
1793
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1709
1794
|
*/
|
1710
1795
|
constructor({
|
1711
|
-
|
1796
|
+
tip,
|
1712
1797
|
maturity,
|
1713
1798
|
maxFee,
|
1714
1799
|
witnessLimit,
|
1715
1800
|
inputs,
|
1716
1801
|
outputs,
|
1717
|
-
witnesses
|
1718
|
-
|
1719
|
-
|
1720
|
-
this.gasPrice = bn7(gasPrice);
|
1802
|
+
witnesses
|
1803
|
+
} = {}) {
|
1804
|
+
this.tip = bn7(tip);
|
1721
1805
|
this.maturity = maturity ?? 0;
|
1722
1806
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1723
1807
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1724
1808
|
this.inputs = inputs ?? [];
|
1725
1809
|
this.outputs = outputs ?? [];
|
1726
1810
|
this.witnesses = witnesses ?? [];
|
1727
|
-
this.baseAssetId = baseAssetId;
|
1728
1811
|
}
|
1729
1812
|
static getPolicyMeta(req) {
|
1730
1813
|
let policyTypes = 0;
|
1731
1814
|
const policies = [];
|
1732
|
-
if (req.
|
1733
|
-
policyTypes += PolicyType.
|
1734
|
-
policies.push({ data: req.
|
1815
|
+
if (req.tip) {
|
1816
|
+
policyTypes += PolicyType.Tip;
|
1817
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1735
1818
|
}
|
1736
1819
|
if (req.witnessLimit) {
|
1737
1820
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1918,10 +2001,10 @@ var BaseTransactionRequest = class {
|
|
1918
2001
|
* @param predicate - Predicate bytes.
|
1919
2002
|
* @param predicateData - Predicate data bytes.
|
1920
2003
|
*/
|
1921
|
-
addCoinInput(coin
|
2004
|
+
addCoinInput(coin) {
|
1922
2005
|
const { assetId, owner, amount } = coin;
|
1923
2006
|
let witnessIndex;
|
1924
|
-
if (predicate) {
|
2007
|
+
if (coin.predicate) {
|
1925
2008
|
witnessIndex = 0;
|
1926
2009
|
} else {
|
1927
2010
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1936,8 +2019,7 @@ var BaseTransactionRequest = class {
|
|
1936
2019
|
amount,
|
1937
2020
|
assetId,
|
1938
2021
|
txPointer: "0x00000000000000000000000000000000",
|
1939
|
-
witnessIndex
|
1940
|
-
predicate: predicate?.bytes
|
2022
|
+
witnessIndex
|
1941
2023
|
};
|
1942
2024
|
this.pushInput(input);
|
1943
2025
|
this.addChangeOutput(owner, assetId);
|
@@ -1948,11 +2030,13 @@ var BaseTransactionRequest = class {
|
|
1948
2030
|
*
|
1949
2031
|
* @param message - Message resource.
|
1950
2032
|
* @param predicate - Predicate bytes.
|
2033
|
+
* @param predicateData - Predicate data bytes.
|
1951
2034
|
*/
|
1952
|
-
addMessageInput(message
|
2035
|
+
addMessageInput(message) {
|
1953
2036
|
const { recipient, sender, amount } = message;
|
2037
|
+
const assetId = BaseAssetId2;
|
1954
2038
|
let witnessIndex;
|
1955
|
-
if (predicate) {
|
2039
|
+
if (message.predicate) {
|
1956
2040
|
witnessIndex = 0;
|
1957
2041
|
} else {
|
1958
2042
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1966,11 +2050,10 @@ var BaseTransactionRequest = class {
|
|
1966
2050
|
sender: sender.toB256(),
|
1967
2051
|
recipient: recipient.toB256(),
|
1968
2052
|
amount,
|
1969
|
-
witnessIndex
|
1970
|
-
predicate: predicate?.bytes
|
2053
|
+
witnessIndex
|
1971
2054
|
};
|
1972
2055
|
this.pushInput(input);
|
1973
|
-
this.addChangeOutput(recipient,
|
2056
|
+
this.addChangeOutput(recipient, assetId);
|
1974
2057
|
}
|
1975
2058
|
/**
|
1976
2059
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1998,32 +2081,6 @@ var BaseTransactionRequest = class {
|
|
1998
2081
|
resources.forEach((resource) => this.addResource(resource));
|
1999
2082
|
return this;
|
2000
2083
|
}
|
2001
|
-
/**
|
2002
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2003
|
-
* outputs from the related assetIds.
|
2004
|
-
*
|
2005
|
-
* @param resources - The resources to add.
|
2006
|
-
* @returns This transaction.
|
2007
|
-
*/
|
2008
|
-
addPredicateResource(resource, predicate) {
|
2009
|
-
if (isCoin(resource)) {
|
2010
|
-
this.addCoinInput(resource, predicate);
|
2011
|
-
} else {
|
2012
|
-
this.addMessageInput(resource, predicate);
|
2013
|
-
}
|
2014
|
-
return this;
|
2015
|
-
}
|
2016
|
-
/**
|
2017
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2018
|
-
* from the related assetIds.
|
2019
|
-
*
|
2020
|
-
* @param resources - The resources to add.
|
2021
|
-
* @returns This transaction.
|
2022
|
-
*/
|
2023
|
-
addPredicateResources(resources, predicate) {
|
2024
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2025
|
-
return this;
|
2026
|
-
}
|
2027
2084
|
/**
|
2028
2085
|
* Adds a coin output to the transaction.
|
2029
2086
|
*
|
@@ -2031,12 +2088,12 @@ var BaseTransactionRequest = class {
|
|
2031
2088
|
* @param amount - Amount of coin.
|
2032
2089
|
* @param assetId - Asset ID of coin.
|
2033
2090
|
*/
|
2034
|
-
addCoinOutput(to, amount, assetId) {
|
2091
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
2035
2092
|
this.pushOutput({
|
2036
2093
|
type: OutputType2.Coin,
|
2037
2094
|
to: addressify(to).toB256(),
|
2038
2095
|
amount,
|
2039
|
-
assetId
|
2096
|
+
assetId
|
2040
2097
|
});
|
2041
2098
|
return this;
|
2042
2099
|
}
|
@@ -2063,7 +2120,7 @@ var BaseTransactionRequest = class {
|
|
2063
2120
|
* @param to - Address of the owner.
|
2064
2121
|
* @param assetId - Asset ID of coin.
|
2065
2122
|
*/
|
2066
|
-
addChangeOutput(to, assetId) {
|
2123
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
2067
2124
|
const changeOutput = this.getChangeOutputs().find(
|
2068
2125
|
(output) => hexlify7(output.assetId) === assetId
|
2069
2126
|
);
|
@@ -2071,7 +2128,7 @@ var BaseTransactionRequest = class {
|
|
2071
2128
|
this.pushOutput({
|
2072
2129
|
type: OutputType2.Change,
|
2073
2130
|
to: addressify(to).toB256(),
|
2074
|
-
assetId
|
2131
|
+
assetId
|
2075
2132
|
});
|
2076
2133
|
}
|
2077
2134
|
}
|
@@ -2103,7 +2160,7 @@ var BaseTransactionRequest = class {
|
|
2103
2160
|
}
|
2104
2161
|
calculateMaxGas(chainInfo, minGas) {
|
2105
2162
|
const { consensusParameters } = chainInfo;
|
2106
|
-
const { gasPerByte } = consensusParameters;
|
2163
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2107
2164
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2108
2165
|
(acc, wit) => acc + wit.dataLength,
|
2109
2166
|
0
|
@@ -2112,7 +2169,8 @@ var BaseTransactionRequest = class {
|
|
2112
2169
|
gasPerByte,
|
2113
2170
|
minGas,
|
2114
2171
|
witnessesLength,
|
2115
|
-
witnessLimit: this.witnessLimit
|
2172
|
+
witnessLimit: this.witnessLimit,
|
2173
|
+
maxGasPerTx
|
2116
2174
|
});
|
2117
2175
|
}
|
2118
2176
|
/**
|
@@ -2130,24 +2188,27 @@ var BaseTransactionRequest = class {
|
|
2130
2188
|
});
|
2131
2189
|
const updateAssetInput = (assetId, quantity) => {
|
2132
2190
|
const assetInput = findAssetInput(assetId);
|
2191
|
+
let usedQuantity = quantity;
|
2192
|
+
if (assetId === BaseAssetId2) {
|
2193
|
+
usedQuantity = bn7("1000000000000000000");
|
2194
|
+
}
|
2133
2195
|
if (assetInput && "assetId" in assetInput) {
|
2134
2196
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2135
|
-
assetInput.amount =
|
2197
|
+
assetInput.amount = usedQuantity;
|
2136
2198
|
} else {
|
2137
2199
|
this.addResources([
|
2138
2200
|
{
|
2139
2201
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2140
|
-
amount:
|
2202
|
+
amount: usedQuantity,
|
2141
2203
|
assetId,
|
2142
2204
|
owner: resourcesOwner || Address.fromRandom(),
|
2143
|
-
maturity: 0,
|
2144
2205
|
blockCreated: bn7(1),
|
2145
2206
|
txCreatedIdx: bn7(1)
|
2146
2207
|
}
|
2147
2208
|
]);
|
2148
2209
|
}
|
2149
2210
|
};
|
2150
|
-
updateAssetInput(
|
2211
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2151
2212
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2152
2213
|
}
|
2153
2214
|
/**
|
@@ -2172,7 +2233,7 @@ var BaseTransactionRequest = class {
|
|
2172
2233
|
toJSON() {
|
2173
2234
|
return normalizeJSON(this);
|
2174
2235
|
}
|
2175
|
-
|
2236
|
+
updatePredicateGasUsed(inputs) {
|
2176
2237
|
this.inputs.forEach((i) => {
|
2177
2238
|
let correspondingInput;
|
2178
2239
|
switch (i.type) {
|
@@ -2194,6 +2255,15 @@ var BaseTransactionRequest = class {
|
|
2194
2255
|
}
|
2195
2256
|
});
|
2196
2257
|
}
|
2258
|
+
shiftPredicateData() {
|
2259
|
+
this.inputs.forEach((input) => {
|
2260
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2261
|
+
input.predicateData = input.paddPredicateData(
|
2262
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2263
|
+
);
|
2264
|
+
}
|
2265
|
+
});
|
2266
|
+
}
|
2197
2267
|
};
|
2198
2268
|
|
2199
2269
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2317,7 +2387,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2317
2387
|
*
|
2318
2388
|
* @param createTransactionRequestLike - The initial values for the instance
|
2319
2389
|
*/
|
2320
|
-
constructor({
|
2390
|
+
constructor({
|
2391
|
+
bytecodeWitnessIndex,
|
2392
|
+
salt,
|
2393
|
+
storageSlots,
|
2394
|
+
...rest
|
2395
|
+
} = {}) {
|
2321
2396
|
super(rest);
|
2322
2397
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2323
2398
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2335,9 +2410,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2335
2410
|
return {
|
2336
2411
|
type: TransactionType3.Create,
|
2337
2412
|
...baseTransaction,
|
2338
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2339
2413
|
bytecodeWitnessIndex,
|
2340
|
-
storageSlotsCount: storageSlots.length,
|
2414
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2341
2415
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2342
2416
|
storageSlots
|
2343
2417
|
};
|
@@ -2441,7 +2515,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2441
2515
|
*
|
2442
2516
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2443
2517
|
*/
|
2444
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2518
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2445
2519
|
super(rest);
|
2446
2520
|
this.gasLimit = bn10(gasLimit);
|
2447
2521
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -2460,8 +2534,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2460
2534
|
type: TransactionType4.Script,
|
2461
2535
|
scriptGasLimit: this.gasLimit,
|
2462
2536
|
...super.getBaseTransaction(),
|
2463
|
-
scriptLength: script.length,
|
2464
|
-
scriptDataLength: scriptData.length,
|
2537
|
+
scriptLength: bn10(script.length),
|
2538
|
+
scriptDataLength: bn10(scriptData.length),
|
2465
2539
|
receiptsRoot: ZeroBytes327,
|
2466
2540
|
script: hexlify10(script),
|
2467
2541
|
scriptData: hexlify10(scriptData)
|
@@ -2525,7 +2599,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2525
2599
|
}
|
2526
2600
|
calculateMaxGas(chainInfo, minGas) {
|
2527
2601
|
const { consensusParameters } = chainInfo;
|
2528
|
-
const { gasPerByte } = consensusParameters;
|
2602
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2529
2603
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2530
2604
|
(acc, wit) => acc + wit.dataLength,
|
2531
2605
|
0
|
@@ -2535,7 +2609,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2535
2609
|
minGas,
|
2536
2610
|
witnessesLength,
|
2537
2611
|
witnessLimit: this.witnessLimit,
|
2538
|
-
gasLimit: this.gasLimit
|
2612
|
+
gasLimit: this.gasLimit,
|
2613
|
+
maxGasPerTx
|
2539
2614
|
});
|
2540
2615
|
}
|
2541
2616
|
/**
|
@@ -2592,7 +2667,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2592
2667
|
|
2593
2668
|
// src/providers/transaction-request/utils.ts
|
2594
2669
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2595
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2670
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2596
2671
|
var transactionRequestify = (obj) => {
|
2597
2672
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2598
2673
|
return obj;
|
@@ -2610,14 +2685,31 @@ var transactionRequestify = (obj) => {
|
|
2610
2685
|
}
|
2611
2686
|
}
|
2612
2687
|
};
|
2688
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2689
|
+
(acc, input) => {
|
2690
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2691
|
+
acc.utxos.push(input.id);
|
2692
|
+
}
|
2693
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2694
|
+
acc.messages.push(input.nonce);
|
2695
|
+
}
|
2696
|
+
return acc;
|
2697
|
+
},
|
2698
|
+
{
|
2699
|
+
utxos: [],
|
2700
|
+
messages: []
|
2701
|
+
}
|
2702
|
+
);
|
2613
2703
|
|
2614
2704
|
// src/providers/transaction-response/transaction-response.ts
|
2615
2705
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2616
|
-
import { bn as
|
2706
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2617
2707
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2618
2708
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2619
2709
|
|
2620
2710
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2711
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2712
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2621
2713
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2622
2714
|
|
2623
2715
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2626,9 +2718,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2626
2718
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2627
2719
|
var calculateTransactionFee = (params) => {
|
2628
2720
|
const {
|
2629
|
-
|
2721
|
+
gasPrice,
|
2630
2722
|
rawPayload,
|
2631
|
-
|
2723
|
+
tip,
|
2724
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2632
2725
|
} = params;
|
2633
2726
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2634
2727
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2638,8 +2731,7 @@ var calculateTransactionFee = (params) => {
|
|
2638
2731
|
return {
|
2639
2732
|
fee: bn11(0),
|
2640
2733
|
minFee: bn11(0),
|
2641
|
-
maxFee: bn11(0)
|
2642
|
-
feeFromGasUsed: bn11(0)
|
2734
|
+
maxFee: bn11(0)
|
2643
2735
|
};
|
2644
2736
|
}
|
2645
2737
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2671,7 +2763,6 @@ var calculateTransactionFee = (params) => {
|
|
2671
2763
|
metadataGas,
|
2672
2764
|
txBytesSize: transactionBytes.length
|
2673
2765
|
});
|
2674
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2675
2766
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2676
2767
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2677
2768
|
const maxGas = getMaxGas({
|
@@ -2679,17 +2770,25 @@ var calculateTransactionFee = (params) => {
|
|
2679
2770
|
minGas,
|
2680
2771
|
witnessesLength,
|
2681
2772
|
gasLimit,
|
2682
|
-
witnessLimit
|
2773
|
+
witnessLimit,
|
2774
|
+
maxGasPerTx
|
2775
|
+
});
|
2776
|
+
const minFee = calculateGasFee({
|
2777
|
+
gasPrice,
|
2778
|
+
gas: minGas,
|
2779
|
+
priceFactor: gasPriceFactor,
|
2780
|
+
tip
|
2781
|
+
});
|
2782
|
+
const maxFee = calculateGasFee({
|
2783
|
+
gasPrice,
|
2784
|
+
gas: maxGas,
|
2785
|
+
priceFactor: gasPriceFactor,
|
2786
|
+
tip
|
2683
2787
|
});
|
2684
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2685
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2686
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2687
|
-
const fee = minFee.add(feeFromGasUsed);
|
2688
2788
|
return {
|
2689
|
-
fee,
|
2690
2789
|
minFee,
|
2691
2790
|
maxFee,
|
2692
|
-
|
2791
|
+
fee: maxFee
|
2693
2792
|
};
|
2694
2793
|
};
|
2695
2794
|
|
@@ -2745,7 +2844,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2745
2844
|
|
2746
2845
|
// src/providers/transaction-summary/input.ts
|
2747
2846
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2748
|
-
import { InputType as
|
2847
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2749
2848
|
function getInputsByTypes(inputs, types) {
|
2750
2849
|
return inputs.filter((i) => types.includes(i.type));
|
2751
2850
|
}
|
@@ -2753,16 +2852,16 @@ function getInputsByType(inputs, type) {
|
|
2753
2852
|
return inputs.filter((i) => i.type === type);
|
2754
2853
|
}
|
2755
2854
|
function getInputsCoin(inputs) {
|
2756
|
-
return getInputsByType(inputs,
|
2855
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2757
2856
|
}
|
2758
2857
|
function getInputsMessage(inputs) {
|
2759
|
-
return getInputsByType(inputs,
|
2858
|
+
return getInputsByType(inputs, InputType6.Message);
|
2760
2859
|
}
|
2761
2860
|
function getInputsCoinAndMessage(inputs) {
|
2762
|
-
return getInputsByTypes(inputs, [
|
2861
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2763
2862
|
}
|
2764
2863
|
function getInputsContract(inputs) {
|
2765
|
-
return getInputsByType(inputs,
|
2864
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2766
2865
|
}
|
2767
2866
|
function getInputFromAssetId(inputs, assetId) {
|
2768
2867
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2781,7 +2880,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2781
2880
|
if (!contractInput) {
|
2782
2881
|
return void 0;
|
2783
2882
|
}
|
2784
|
-
if (contractInput.type !==
|
2883
|
+
if (contractInput.type !== InputType6.Contract) {
|
2785
2884
|
throw new FuelError9(
|
2786
2885
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2787
2886
|
`Contract input should be of type 'contract'.`
|
@@ -2790,10 +2889,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2790
2889
|
return contractInput;
|
2791
2890
|
}
|
2792
2891
|
function getInputAccountAddress(input) {
|
2793
|
-
if (input.type ===
|
2892
|
+
if (input.type === InputType6.Coin) {
|
2794
2893
|
return input.owner.toString();
|
2795
2894
|
}
|
2796
|
-
if (input.type ===
|
2895
|
+
if (input.type === InputType6.Message) {
|
2797
2896
|
return input.recipient.toString();
|
2798
2897
|
}
|
2799
2898
|
return "";
|
@@ -3303,7 +3402,9 @@ function assembleTransactionSummary(params) {
|
|
3303
3402
|
gqlTransactionStatus,
|
3304
3403
|
abiMap = {},
|
3305
3404
|
maxInputs,
|
3306
|
-
gasCosts
|
3405
|
+
gasCosts,
|
3406
|
+
maxGasPerTx,
|
3407
|
+
gasPrice
|
3307
3408
|
} = params;
|
3308
3409
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3309
3410
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3317,11 +3418,14 @@ function assembleTransactionSummary(params) {
|
|
3317
3418
|
maxInputs
|
3318
3419
|
});
|
3319
3420
|
const typeName = getTransactionTypeName(transaction.type);
|
3421
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3320
3422
|
const { fee } = calculateTransactionFee({
|
3321
|
-
|
3423
|
+
gasPrice,
|
3322
3424
|
rawPayload,
|
3425
|
+
tip,
|
3323
3426
|
consensusParameters: {
|
3324
3427
|
gasCosts,
|
3428
|
+
maxGasPerTx,
|
3325
3429
|
feeParams: {
|
3326
3430
|
gasPerByte,
|
3327
3431
|
gasPriceFactor
|
@@ -3381,7 +3485,7 @@ var TransactionResponse = class {
|
|
3381
3485
|
/** Current provider */
|
3382
3486
|
provider;
|
3383
3487
|
/** Gas used on the transaction */
|
3384
|
-
gasUsed =
|
3488
|
+
gasUsed = bn15(0);
|
3385
3489
|
/** The graphql Transaction with receipts object. */
|
3386
3490
|
gqlTransaction;
|
3387
3491
|
abis;
|
@@ -3459,8 +3563,13 @@ var TransactionResponse = class {
|
|
3459
3563
|
const decodedTransaction = this.decodeTransaction(
|
3460
3564
|
transaction
|
3461
3565
|
);
|
3462
|
-
|
3463
|
-
|
3566
|
+
let txReceipts = [];
|
3567
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3568
|
+
txReceipts = transaction.status.receipts;
|
3569
|
+
}
|
3570
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3571
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3572
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3464
3573
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3465
3574
|
const transactionSummary = assembleTransactionSummary({
|
3466
3575
|
id: this.id,
|
@@ -3472,7 +3581,9 @@ var TransactionResponse = class {
|
|
3472
3581
|
gasPriceFactor,
|
3473
3582
|
abiMap: contractsAbiMap,
|
3474
3583
|
maxInputs,
|
3475
|
-
gasCosts
|
3584
|
+
gasCosts,
|
3585
|
+
maxGasPerTx,
|
3586
|
+
gasPrice
|
3476
3587
|
});
|
3477
3588
|
return transactionSummary;
|
3478
3589
|
}
|
@@ -3599,30 +3710,29 @@ var processGqlChain = (chain) => {
|
|
3599
3710
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3600
3711
|
return {
|
3601
3712
|
name,
|
3602
|
-
baseChainHeight:
|
3713
|
+
baseChainHeight: bn16(daHeight),
|
3603
3714
|
consensusParameters: {
|
3604
|
-
contractMaxSize:
|
3605
|
-
maxInputs:
|
3606
|
-
maxOutputs:
|
3607
|
-
maxWitnesses:
|
3608
|
-
maxGasPerTx:
|
3609
|
-
maxScriptLength:
|
3610
|
-
maxScriptDataLength:
|
3611
|
-
maxStorageSlots:
|
3612
|
-
maxPredicateLength:
|
3613
|
-
maxPredicateDataLength:
|
3614
|
-
maxGasPerPredicate:
|
3615
|
-
gasPriceFactor:
|
3616
|
-
gasPerByte:
|
3617
|
-
maxMessageDataLength:
|
3618
|
-
chainId:
|
3619
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3715
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3716
|
+
maxInputs: bn16(txParams.maxInputs),
|
3717
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3718
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3719
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3720
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3721
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3722
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3723
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3724
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3725
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3726
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3727
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3728
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3729
|
+
chainId: bn16(consensusParameters.chainId),
|
3620
3730
|
gasCosts
|
3621
3731
|
},
|
3622
3732
|
gasCosts,
|
3623
3733
|
latestBlock: {
|
3624
3734
|
id: latestBlock.id,
|
3625
|
-
height:
|
3735
|
+
height: bn16(latestBlock.height),
|
3626
3736
|
time: latestBlock.header.time,
|
3627
3737
|
transactions: latestBlock.transactions.map((i) => ({
|
3628
3738
|
id: i.id
|
@@ -3716,10 +3826,8 @@ var _Provider = class {
|
|
3716
3826
|
* Returns some helpful parameters related to gas fees.
|
3717
3827
|
*/
|
3718
3828
|
getGasConfig() {
|
3719
|
-
const { minGasPrice } = this.getNode();
|
3720
3829
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3721
3830
|
return {
|
3722
|
-
minGasPrice,
|
3723
3831
|
maxGasPerTx,
|
3724
3832
|
maxGasPerPredicate,
|
3725
3833
|
gasPriceFactor,
|
@@ -3817,7 +3925,7 @@ var _Provider = class {
|
|
3817
3925
|
*/
|
3818
3926
|
async getBlockNumber() {
|
3819
3927
|
const { chain } = await this.operations.getChain();
|
3820
|
-
return
|
3928
|
+
return bn16(chain.latestBlock.height, 10);
|
3821
3929
|
}
|
3822
3930
|
/**
|
3823
3931
|
* Returns the chain information.
|
@@ -3827,13 +3935,11 @@ var _Provider = class {
|
|
3827
3935
|
async fetchNode() {
|
3828
3936
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3829
3937
|
const processedNodeInfo = {
|
3830
|
-
maxDepth:
|
3831
|
-
maxTx:
|
3832
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3938
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3939
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3833
3940
|
nodeVersion: nodeInfo.nodeVersion,
|
3834
3941
|
utxoValidation: nodeInfo.utxoValidation,
|
3835
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3836
|
-
peers: nodeInfo.peers
|
3942
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3837
3943
|
};
|
3838
3944
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3839
3945
|
return processedNodeInfo;
|
@@ -3859,17 +3965,6 @@ var _Provider = class {
|
|
3859
3965
|
} = this.getChain();
|
3860
3966
|
return chainId.toNumber();
|
3861
3967
|
}
|
3862
|
-
/**
|
3863
|
-
* Returns the base asset ID
|
3864
|
-
*
|
3865
|
-
* @returns A promise that resolves to the base asset ID
|
3866
|
-
*/
|
3867
|
-
getBaseAssetId() {
|
3868
|
-
const {
|
3869
|
-
consensusParameters: { baseAssetId }
|
3870
|
-
} = this.getChain();
|
3871
|
-
return baseAssetId;
|
3872
|
-
}
|
3873
3968
|
/**
|
3874
3969
|
* Submits a transaction to the chain to be executed.
|
3875
3970
|
*
|
@@ -3930,14 +4025,13 @@ var _Provider = class {
|
|
3930
4025
|
return this.estimateTxDependencies(transactionRequest);
|
3931
4026
|
}
|
3932
4027
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3933
|
-
const { dryRun:
|
3934
|
-
encodedTransaction,
|
4028
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4029
|
+
encodedTransactions: encodedTransaction,
|
3935
4030
|
utxoValidation: utxoValidation || false
|
3936
4031
|
});
|
3937
|
-
const receipts =
|
3938
|
-
|
3939
|
-
|
3940
|
-
};
|
4032
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4033
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4034
|
+
return { receipts, dryrunStatus: status };
|
3941
4035
|
}
|
3942
4036
|
/**
|
3943
4037
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3963,7 +4057,7 @@ var _Provider = class {
|
|
3963
4057
|
} = response;
|
3964
4058
|
if (inputs) {
|
3965
4059
|
inputs.forEach((input, index) => {
|
3966
|
-
if ("predicateGasUsed" in input &&
|
4060
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3967
4061
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3968
4062
|
}
|
3969
4063
|
});
|
@@ -3976,9 +4070,6 @@ var _Provider = class {
|
|
3976
4070
|
* If there are missing variable outputs,
|
3977
4071
|
* `addVariableOutputs` is called on the transaction.
|
3978
4072
|
*
|
3979
|
-
* @privateRemarks
|
3980
|
-
* TODO: Investigate support for missing contract IDs
|
3981
|
-
* TODO: Add support for missing output messages
|
3982
4073
|
*
|
3983
4074
|
* @param transactionRequest - The transaction request object.
|
3984
4075
|
* @returns A promise.
|
@@ -3991,16 +4082,19 @@ var _Provider = class {
|
|
3991
4082
|
missingContractIds: []
|
3992
4083
|
};
|
3993
4084
|
}
|
3994
|
-
await this.estimatePredicates(transactionRequest);
|
3995
4085
|
let receipts = [];
|
3996
4086
|
const missingContractIds = [];
|
3997
4087
|
let outputVariables = 0;
|
4088
|
+
let dryrunStatus;
|
3998
4089
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3999
|
-
const {
|
4000
|
-
|
4090
|
+
const {
|
4091
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4092
|
+
} = await this.operations.dryRun({
|
4093
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
4001
4094
|
utxoValidation: false
|
4002
4095
|
});
|
4003
|
-
receipts =
|
4096
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4097
|
+
dryrunStatus = status;
|
4004
4098
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4005
4099
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4006
4100
|
if (hasMissingOutputs) {
|
@@ -4010,6 +4104,10 @@ var _Provider = class {
|
|
4010
4104
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4011
4105
|
missingContractIds.push(contractId);
|
4012
4106
|
});
|
4107
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4108
|
+
transactionRequest
|
4109
|
+
});
|
4110
|
+
transactionRequest.maxFee = maxFee;
|
4013
4111
|
} else {
|
4014
4112
|
break;
|
4015
4113
|
}
|
@@ -4017,37 +4115,139 @@ var _Provider = class {
|
|
4017
4115
|
return {
|
4018
4116
|
receipts,
|
4019
4117
|
outputVariables,
|
4020
|
-
missingContractIds
|
4118
|
+
missingContractIds,
|
4119
|
+
dryrunStatus
|
4021
4120
|
};
|
4022
4121
|
}
|
4122
|
+
/**
|
4123
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4124
|
+
*
|
4125
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4126
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4127
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4128
|
+
*
|
4129
|
+
* @param transactionRequests - Array of transaction request objects.
|
4130
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4131
|
+
*/
|
4132
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4133
|
+
const results = transactionRequests.map(() => ({
|
4134
|
+
receipts: [],
|
4135
|
+
outputVariables: 0,
|
4136
|
+
missingContractIds: [],
|
4137
|
+
dryrunStatus: void 0
|
4138
|
+
}));
|
4139
|
+
const allRequests = clone3(transactionRequests);
|
4140
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4141
|
+
allRequests.forEach((req, index) => {
|
4142
|
+
if (req.type === TransactionType8.Script) {
|
4143
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4144
|
+
}
|
4145
|
+
});
|
4146
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4147
|
+
let attempt = 0;
|
4148
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4149
|
+
const encodedTransactions = transactionsToProcess.map(
|
4150
|
+
(index) => serializedTransactionsMap.get(index)
|
4151
|
+
);
|
4152
|
+
const dryRunResults = await this.operations.dryRun({
|
4153
|
+
encodedTransactions,
|
4154
|
+
utxoValidation: false
|
4155
|
+
});
|
4156
|
+
const nextRoundTransactions = [];
|
4157
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4158
|
+
const currentResultIndex = transactionsToProcess[i];
|
4159
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4160
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4161
|
+
results[currentResultIndex].dryrunStatus = status;
|
4162
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4163
|
+
results[currentResultIndex].receipts
|
4164
|
+
);
|
4165
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4166
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4167
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4168
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4169
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4170
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4171
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4172
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4173
|
+
});
|
4174
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4175
|
+
transactionRequest: requestToProcess
|
4176
|
+
});
|
4177
|
+
requestToProcess.maxFee = maxFee;
|
4178
|
+
serializedTransactionsMap.set(
|
4179
|
+
currentResultIndex,
|
4180
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4181
|
+
);
|
4182
|
+
nextRoundTransactions.push(currentResultIndex);
|
4183
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4184
|
+
}
|
4185
|
+
}
|
4186
|
+
transactionsToProcess = nextRoundTransactions;
|
4187
|
+
attempt += 1;
|
4188
|
+
}
|
4189
|
+
return results;
|
4190
|
+
}
|
4191
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4192
|
+
if (estimateTxDependencies) {
|
4193
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4194
|
+
}
|
4195
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4196
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4197
|
+
encodedTransactions,
|
4198
|
+
utxoValidation: utxoValidation || false
|
4199
|
+
});
|
4200
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4201
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4202
|
+
return { receipts, dryrunStatus: status };
|
4203
|
+
});
|
4204
|
+
return results;
|
4205
|
+
}
|
4023
4206
|
/**
|
4024
4207
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4025
4208
|
* @param transactionRequest - The transaction request object.
|
4026
4209
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4027
4210
|
*/
|
4028
|
-
estimateTxGasAndFee(params) {
|
4211
|
+
async estimateTxGasAndFee(params) {
|
4029
4212
|
const { transactionRequest } = params;
|
4030
|
-
|
4213
|
+
let { gasPrice } = params;
|
4031
4214
|
const chainInfo = this.getChain();
|
4032
|
-
const
|
4033
|
-
transactionRequest.gasPrice = gasPrice;
|
4215
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4034
4216
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4035
|
-
|
4217
|
+
if (!gasPrice) {
|
4218
|
+
gasPrice = await this.estimateGasPrice(10);
|
4219
|
+
}
|
4220
|
+
const minFee = calculateGasFee({
|
4221
|
+
gasPrice: bn16(gasPrice),
|
4222
|
+
gas: minGas,
|
4223
|
+
priceFactor: gasPriceFactor,
|
4224
|
+
tip: transactionRequest.tip
|
4225
|
+
}).add(1);
|
4226
|
+
let gasLimit = bn16(0);
|
4036
4227
|
if (transactionRequest.type === TransactionType8.Script) {
|
4228
|
+
gasLimit = transactionRequest.gasLimit;
|
4037
4229
|
if (transactionRequest.gasLimit.eq(0)) {
|
4038
4230
|
transactionRequest.gasLimit = minGas;
|
4039
4231
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4040
4232
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4041
4233
|
);
|
4234
|
+
gasLimit = transactionRequest.gasLimit;
|
4042
4235
|
}
|
4043
4236
|
}
|
4044
4237
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4045
|
-
const maxFee =
|
4238
|
+
const maxFee = calculateGasFee({
|
4239
|
+
gasPrice: bn16(gasPrice),
|
4240
|
+
gas: maxGas,
|
4241
|
+
priceFactor: gasPriceFactor,
|
4242
|
+
tip: transactionRequest.tip
|
4243
|
+
}).add(1);
|
4046
4244
|
return {
|
4047
4245
|
minGas,
|
4048
4246
|
minFee,
|
4049
4247
|
maxGas,
|
4050
|
-
maxFee
|
4248
|
+
maxFee,
|
4249
|
+
gasPrice,
|
4250
|
+
gasLimit
|
4051
4251
|
};
|
4052
4252
|
}
|
4053
4253
|
/**
|
@@ -4065,15 +4265,17 @@ var _Provider = class {
|
|
4065
4265
|
if (estimateTxDependencies) {
|
4066
4266
|
return this.estimateTxDependencies(transactionRequest);
|
4067
4267
|
}
|
4068
|
-
const
|
4069
|
-
const { dryRun:
|
4070
|
-
|
4268
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4269
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4270
|
+
encodedTransactions,
|
4071
4271
|
utxoValidation: true
|
4072
4272
|
});
|
4073
|
-
const
|
4074
|
-
|
4075
|
-
receipts
|
4076
|
-
|
4273
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4274
|
+
const { id, receipts, status } = dryRunStatus;
|
4275
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4276
|
+
return { id, receipts: processedReceipts, status };
|
4277
|
+
});
|
4278
|
+
return { receipts: callResult[0].receipts };
|
4077
4279
|
}
|
4078
4280
|
/**
|
4079
4281
|
* Returns a transaction cost to enable user
|
@@ -4090,77 +4292,79 @@ var _Provider = class {
|
|
4090
4292
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4091
4293
|
* @returns A promise that resolves to the transaction cost object.
|
4092
4294
|
*/
|
4093
|
-
async getTransactionCost(transactionRequestLike,
|
4094
|
-
estimateTxDependencies = true,
|
4095
|
-
estimatePredicates = true,
|
4096
|
-
resourcesOwner,
|
4097
|
-
signatureCallback
|
4098
|
-
} = {}) {
|
4295
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4099
4296
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4100
|
-
const { minGasPrice } = this.getGasConfig();
|
4101
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4102
4297
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4103
4298
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4104
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4299
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4105
4300
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4301
|
+
txRequestClone.maxFee = bn16(0);
|
4106
4302
|
if (isScriptTransaction) {
|
4107
|
-
txRequestClone.gasLimit =
|
4303
|
+
txRequestClone.gasLimit = bn16(0);
|
4108
4304
|
}
|
4109
|
-
if (
|
4110
|
-
|
4111
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4112
|
-
}
|
4113
|
-
await this.estimatePredicates(txRequestClone);
|
4305
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4306
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4114
4307
|
}
|
4308
|
+
const signedRequest = clone3(txRequestClone);
|
4309
|
+
let addedSignatures = 0;
|
4115
4310
|
if (signatureCallback && isScriptTransaction) {
|
4116
|
-
|
4311
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4312
|
+
await signatureCallback(signedRequest);
|
4313
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4117
4314
|
}
|
4118
|
-
|
4119
|
-
|
4315
|
+
await this.estimatePredicates(signedRequest);
|
4316
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4317
|
+
transactionRequest: signedRequest
|
4120
4318
|
});
|
4121
4319
|
let receipts = [];
|
4122
4320
|
let missingContractIds = [];
|
4123
4321
|
let outputVariables = 0;
|
4124
|
-
let gasUsed =
|
4125
|
-
|
4126
|
-
|
4322
|
+
let gasUsed = bn16(0);
|
4323
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4324
|
+
txRequestClone.maxFee = maxFee;
|
4325
|
+
if (isScriptTransaction) {
|
4326
|
+
txRequestClone.gasLimit = gasLimit;
|
4327
|
+
if (signatureCallback) {
|
4328
|
+
await signatureCallback(txRequestClone);
|
4329
|
+
}
|
4127
4330
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4128
4331
|
receipts = result.receipts;
|
4129
4332
|
outputVariables = result.outputVariables;
|
4130
4333
|
missingContractIds = result.missingContractIds;
|
4131
4334
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4132
4335
|
txRequestClone.gasLimit = gasUsed;
|
4133
|
-
|
4134
|
-
|
4135
|
-
|
4336
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4337
|
+
transactionRequest: txRequestClone,
|
4338
|
+
gasPrice
|
4136
4339
|
}));
|
4137
4340
|
}
|
4138
4341
|
return {
|
4139
4342
|
requiredQuantities: allQuantities,
|
4140
4343
|
receipts,
|
4141
4344
|
gasUsed,
|
4142
|
-
|
4143
|
-
gasPrice: setGasPrice,
|
4345
|
+
gasPrice,
|
4144
4346
|
minGas,
|
4145
4347
|
maxGas,
|
4146
4348
|
minFee,
|
4147
4349
|
maxFee,
|
4148
|
-
estimatedInputs: txRequestClone.inputs,
|
4149
4350
|
outputVariables,
|
4150
|
-
missingContractIds
|
4351
|
+
missingContractIds,
|
4352
|
+
addedSignatures,
|
4353
|
+
estimatedPredicates: txRequestClone.inputs
|
4151
4354
|
};
|
4152
4355
|
}
|
4153
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4356
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4154
4357
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4155
4358
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4156
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4359
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4360
|
+
quantitiesToContract
|
4361
|
+
});
|
4157
4362
|
transactionRequest.addResources(
|
4158
4363
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4159
4364
|
);
|
4160
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4161
|
-
|
4162
|
-
|
4163
|
-
);
|
4365
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4366
|
+
quantitiesToContract
|
4367
|
+
});
|
4164
4368
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4165
4369
|
return {
|
4166
4370
|
resources,
|
@@ -4182,11 +4386,10 @@ var _Provider = class {
|
|
4182
4386
|
return coins.map((coin) => ({
|
4183
4387
|
id: coin.utxoId,
|
4184
4388
|
assetId: coin.assetId,
|
4185
|
-
amount:
|
4389
|
+
amount: bn16(coin.amount),
|
4186
4390
|
owner: Address2.fromAddressOrString(coin.owner),
|
4187
|
-
|
4188
|
-
|
4189
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4391
|
+
blockCreated: bn16(coin.blockCreated),
|
4392
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4190
4393
|
}));
|
4191
4394
|
}
|
4192
4395
|
/**
|
@@ -4223,9 +4426,9 @@ var _Provider = class {
|
|
4223
4426
|
switch (coin.__typename) {
|
4224
4427
|
case "MessageCoin":
|
4225
4428
|
return {
|
4226
|
-
amount:
|
4429
|
+
amount: bn16(coin.amount),
|
4227
4430
|
assetId: coin.assetId,
|
4228
|
-
daHeight:
|
4431
|
+
daHeight: bn16(coin.daHeight),
|
4229
4432
|
sender: Address2.fromAddressOrString(coin.sender),
|
4230
4433
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4231
4434
|
nonce: coin.nonce
|
@@ -4233,12 +4436,11 @@ var _Provider = class {
|
|
4233
4436
|
case "Coin":
|
4234
4437
|
return {
|
4235
4438
|
id: coin.utxoId,
|
4236
|
-
amount:
|
4439
|
+
amount: bn16(coin.amount),
|
4237
4440
|
assetId: coin.assetId,
|
4238
4441
|
owner: Address2.fromAddressOrString(coin.owner),
|
4239
|
-
|
4240
|
-
|
4241
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4442
|
+
blockCreated: bn16(coin.blockCreated),
|
4443
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4242
4444
|
};
|
4243
4445
|
default:
|
4244
4446
|
return null;
|
@@ -4255,13 +4457,13 @@ var _Provider = class {
|
|
4255
4457
|
async getBlock(idOrHeight) {
|
4256
4458
|
let variables;
|
4257
4459
|
if (typeof idOrHeight === "number") {
|
4258
|
-
variables = { height:
|
4460
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4259
4461
|
} else if (idOrHeight === "latest") {
|
4260
4462
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4261
4463
|
} else if (idOrHeight.length === 66) {
|
4262
4464
|
variables = { blockId: idOrHeight };
|
4263
4465
|
} else {
|
4264
|
-
variables = { blockId:
|
4466
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4265
4467
|
}
|
4266
4468
|
const { block } = await this.operations.getBlock(variables);
|
4267
4469
|
if (!block) {
|
@@ -4269,7 +4471,7 @@ var _Provider = class {
|
|
4269
4471
|
}
|
4270
4472
|
return {
|
4271
4473
|
id: block.id,
|
4272
|
-
height:
|
4474
|
+
height: bn16(block.height),
|
4273
4475
|
time: block.header.time,
|
4274
4476
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4275
4477
|
};
|
@@ -4284,7 +4486,7 @@ var _Provider = class {
|
|
4284
4486
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4285
4487
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4286
4488
|
id: block.id,
|
4287
|
-
height:
|
4489
|
+
height: bn16(block.height),
|
4288
4490
|
time: block.header.time,
|
4289
4491
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4290
4492
|
}));
|
@@ -4299,7 +4501,7 @@ var _Provider = class {
|
|
4299
4501
|
async getBlockWithTransactions(idOrHeight) {
|
4300
4502
|
let variables;
|
4301
4503
|
if (typeof idOrHeight === "number") {
|
4302
|
-
variables = { blockHeight:
|
4504
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4303
4505
|
} else if (idOrHeight === "latest") {
|
4304
4506
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4305
4507
|
} else {
|
@@ -4311,7 +4513,7 @@ var _Provider = class {
|
|
4311
4513
|
}
|
4312
4514
|
return {
|
4313
4515
|
id: block.id,
|
4314
|
-
height:
|
4516
|
+
height: bn16(block.height, 10),
|
4315
4517
|
time: block.header.time,
|
4316
4518
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4317
4519
|
transactions: block.transactions.map(
|
@@ -4360,7 +4562,7 @@ var _Provider = class {
|
|
4360
4562
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4361
4563
|
asset: hexlify12(assetId)
|
4362
4564
|
});
|
4363
|
-
return
|
4565
|
+
return bn16(contractBalance.amount, 10);
|
4364
4566
|
}
|
4365
4567
|
/**
|
4366
4568
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4374,7 +4576,7 @@ var _Provider = class {
|
|
4374
4576
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4375
4577
|
assetId: hexlify12(assetId)
|
4376
4578
|
});
|
4377
|
-
return
|
4579
|
+
return bn16(balance.amount, 10);
|
4378
4580
|
}
|
4379
4581
|
/**
|
4380
4582
|
* Returns balances for the given owner.
|
@@ -4392,7 +4594,7 @@ var _Provider = class {
|
|
4392
4594
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4393
4595
|
return balances.map((balance) => ({
|
4394
4596
|
assetId: balance.assetId,
|
4395
|
-
amount:
|
4597
|
+
amount: bn16(balance.amount)
|
4396
4598
|
}));
|
4397
4599
|
}
|
4398
4600
|
/**
|
@@ -4414,15 +4616,15 @@ var _Provider = class {
|
|
4414
4616
|
sender: message.sender,
|
4415
4617
|
recipient: message.recipient,
|
4416
4618
|
nonce: message.nonce,
|
4417
|
-
amount:
|
4619
|
+
amount: bn16(message.amount),
|
4418
4620
|
data: message.data
|
4419
4621
|
}),
|
4420
4622
|
sender: Address2.fromAddressOrString(message.sender),
|
4421
4623
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4422
4624
|
nonce: message.nonce,
|
4423
|
-
amount:
|
4625
|
+
amount: bn16(message.amount),
|
4424
4626
|
data: InputMessageCoder.decodeData(message.data),
|
4425
|
-
daHeight:
|
4627
|
+
daHeight: bn16(message.daHeight)
|
4426
4628
|
}));
|
4427
4629
|
}
|
4428
4630
|
/**
|
@@ -4475,44 +4677,60 @@ var _Provider = class {
|
|
4475
4677
|
} = result.messageProof;
|
4476
4678
|
return {
|
4477
4679
|
messageProof: {
|
4478
|
-
proofIndex:
|
4680
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4479
4681
|
proofSet: messageProof.proofSet
|
4480
4682
|
},
|
4481
4683
|
blockProof: {
|
4482
|
-
proofIndex:
|
4684
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4483
4685
|
proofSet: blockProof.proofSet
|
4484
4686
|
},
|
4485
4687
|
messageBlockHeader: {
|
4486
4688
|
id: messageBlockHeader.id,
|
4487
|
-
daHeight:
|
4488
|
-
transactionsCount:
|
4689
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4690
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4489
4691
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4490
|
-
height:
|
4692
|
+
height: bn16(messageBlockHeader.height),
|
4491
4693
|
prevRoot: messageBlockHeader.prevRoot,
|
4492
4694
|
time: messageBlockHeader.time,
|
4493
4695
|
applicationHash: messageBlockHeader.applicationHash,
|
4494
|
-
|
4495
|
-
|
4696
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4697
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4698
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4699
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4700
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4496
4701
|
},
|
4497
4702
|
commitBlockHeader: {
|
4498
4703
|
id: commitBlockHeader.id,
|
4499
|
-
daHeight:
|
4500
|
-
transactionsCount:
|
4704
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4705
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4501
4706
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4502
|
-
height:
|
4707
|
+
height: bn16(commitBlockHeader.height),
|
4503
4708
|
prevRoot: commitBlockHeader.prevRoot,
|
4504
4709
|
time: commitBlockHeader.time,
|
4505
4710
|
applicationHash: commitBlockHeader.applicationHash,
|
4506
|
-
|
4507
|
-
|
4711
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4712
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4713
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4714
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4715
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4508
4716
|
},
|
4509
4717
|
sender: Address2.fromAddressOrString(sender),
|
4510
4718
|
recipient: Address2.fromAddressOrString(recipient),
|
4511
4719
|
nonce,
|
4512
|
-
amount:
|
4720
|
+
amount: bn16(amount),
|
4513
4721
|
data
|
4514
4722
|
};
|
4515
4723
|
}
|
4724
|
+
async getLatestGasPrice() {
|
4725
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4726
|
+
return bn16(latestGasPrice.gasPrice);
|
4727
|
+
}
|
4728
|
+
async estimateGasPrice(blockHorizon) {
|
4729
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4730
|
+
blockHorizon: String(blockHorizon)
|
4731
|
+
});
|
4732
|
+
return bn16(estimateGasPrice.gasPrice);
|
4733
|
+
}
|
4516
4734
|
/**
|
4517
4735
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4518
4736
|
*
|
@@ -4532,10 +4750,10 @@ var _Provider = class {
|
|
4532
4750
|
*/
|
4533
4751
|
async produceBlocks(amount, startTime) {
|
4534
4752
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4535
|
-
blocksToProduce:
|
4753
|
+
blocksToProduce: bn16(amount).toString(10),
|
4536
4754
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4537
4755
|
});
|
4538
|
-
return
|
4756
|
+
return bn16(latestBlockHeight);
|
4539
4757
|
}
|
4540
4758
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4541
4759
|
async getTransactionResponse(transactionId) {
|
@@ -4549,7 +4767,7 @@ cacheInputs_fn = function(inputs) {
|
|
4549
4767
|
return;
|
4550
4768
|
}
|
4551
4769
|
inputs.forEach((input) => {
|
4552
|
-
if (input.type ===
|
4770
|
+
if (input.type === InputType7.Coin) {
|
4553
4771
|
this.cache?.set(input.id);
|
4554
4772
|
}
|
4555
4773
|
});
|
@@ -4559,7 +4777,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4559
4777
|
|
4560
4778
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4561
4779
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4562
|
-
import { bn as
|
4780
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4563
4781
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4564
4782
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4565
4783
|
async function getTransactionSummary(params) {
|
@@ -4577,21 +4795,28 @@ async function getTransactionSummary(params) {
|
|
4577
4795
|
arrayify12(gqlTransaction.rawPayload),
|
4578
4796
|
0
|
4579
4797
|
);
|
4580
|
-
|
4798
|
+
let txReceipts = [];
|
4799
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4800
|
+
txReceipts = gqlTransaction.status.receipts;
|
4801
|
+
}
|
4802
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4581
4803
|
const {
|
4582
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4804
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4583
4805
|
} = provider.getChain();
|
4806
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4584
4807
|
const transactionInfo = assembleTransactionSummary({
|
4585
4808
|
id: gqlTransaction.id,
|
4586
4809
|
receipts,
|
4587
4810
|
transaction: decodedTransaction,
|
4588
4811
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4589
4812
|
gqlTransactionStatus: gqlTransaction.status,
|
4590
|
-
gasPerByte:
|
4591
|
-
gasPriceFactor:
|
4813
|
+
gasPerByte: bn17(gasPerByte),
|
4814
|
+
gasPriceFactor: bn17(gasPriceFactor),
|
4592
4815
|
abiMap,
|
4593
4816
|
maxInputs,
|
4594
|
-
gasCosts
|
4817
|
+
gasCosts,
|
4818
|
+
maxGasPerTx,
|
4819
|
+
gasPrice
|
4595
4820
|
});
|
4596
4821
|
return {
|
4597
4822
|
gqlTransaction,
|
@@ -4601,10 +4826,11 @@ async function getTransactionSummary(params) {
|
|
4601
4826
|
async function getTransactionSummaryFromRequest(params) {
|
4602
4827
|
const { provider, transactionRequest, abiMap } = params;
|
4603
4828
|
const { receipts } = await provider.call(transactionRequest);
|
4604
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4829
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4605
4830
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4606
4831
|
const transaction = transactionRequest.toTransaction();
|
4607
4832
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4833
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4608
4834
|
const transactionSummary = assembleTransactionSummary({
|
4609
4835
|
receipts,
|
4610
4836
|
transaction,
|
@@ -4613,7 +4839,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4613
4839
|
gasPerByte,
|
4614
4840
|
gasPriceFactor,
|
4615
4841
|
maxInputs,
|
4616
|
-
gasCosts
|
4842
|
+
gasCosts,
|
4843
|
+
maxGasPerTx,
|
4844
|
+
gasPrice
|
4617
4845
|
});
|
4618
4846
|
return transactionSummary;
|
4619
4847
|
}
|
@@ -4622,13 +4850,18 @@ async function getTransactionsSummaries(params) {
|
|
4622
4850
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4623
4851
|
const { edges, pageInfo } = transactionsByOwner;
|
4624
4852
|
const {
|
4625
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4853
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4626
4854
|
} = provider.getChain();
|
4855
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4627
4856
|
const transactions = edges.map((edge) => {
|
4628
4857
|
const { node: gqlTransaction } = edge;
|
4629
|
-
const { id, rawPayload,
|
4858
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4630
4859
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4631
|
-
|
4860
|
+
let txReceipts = [];
|
4861
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4862
|
+
txReceipts = gqlTransaction.status.receipts;
|
4863
|
+
}
|
4864
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4632
4865
|
const transactionSummary = assembleTransactionSummary({
|
4633
4866
|
id,
|
4634
4867
|
receipts,
|
@@ -4639,7 +4872,9 @@ async function getTransactionsSummaries(params) {
|
|
4639
4872
|
gasPerByte,
|
4640
4873
|
gasPriceFactor,
|
4641
4874
|
maxInputs,
|
4642
|
-
gasCosts
|
4875
|
+
gasCosts,
|
4876
|
+
maxGasPerTx,
|
4877
|
+
gasPrice
|
4643
4878
|
});
|
4644
4879
|
const output = {
|
4645
4880
|
gqlTransaction,
|
@@ -4933,9 +5168,8 @@ var Account = class extends AbstractAccount {
|
|
4933
5168
|
* @param assetId - The asset ID to check the balance for.
|
4934
5169
|
* @returns A promise that resolves to the balance amount.
|
4935
5170
|
*/
|
4936
|
-
async getBalance(assetId) {
|
4937
|
-
const
|
4938
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5171
|
+
async getBalance(assetId = BaseAssetId3) {
|
5172
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4939
5173
|
return amount;
|
4940
5174
|
}
|
4941
5175
|
/**
|
@@ -4972,37 +5206,33 @@ var Account = class extends AbstractAccount {
|
|
4972
5206
|
* @param fee - The estimated transaction fee.
|
4973
5207
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4974
5208
|
*/
|
4975
|
-
async fund(request,
|
4976
|
-
const
|
4977
|
-
const
|
4978
|
-
|
4979
|
-
|
4980
|
-
|
5209
|
+
async fund(request, params) {
|
5210
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5211
|
+
const txRequest = request;
|
5212
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5213
|
+
amount: bn18(fee),
|
5214
|
+
assetId: BaseAssetId3,
|
5215
|
+
coinQuantities: requiredQuantities
|
4981
5216
|
});
|
4982
5217
|
const quantitiesDict = {};
|
4983
|
-
|
5218
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4984
5219
|
quantitiesDict[assetId] = {
|
4985
5220
|
required: amount,
|
4986
|
-
owned:
|
5221
|
+
owned: bn18(0)
|
4987
5222
|
};
|
4988
5223
|
});
|
4989
|
-
|
4990
|
-
const cachedMessages = [];
|
4991
|
-
const owner = this.address.toB256();
|
4992
|
-
request.inputs.forEach((input) => {
|
5224
|
+
txRequest.inputs.forEach((input) => {
|
4993
5225
|
const isResource = "amount" in input;
|
4994
5226
|
if (isResource) {
|
4995
5227
|
const isCoin2 = "owner" in input;
|
4996
5228
|
if (isCoin2) {
|
4997
5229
|
const assetId = String(input.assetId);
|
4998
|
-
if (
|
4999
|
-
const amount =
|
5230
|
+
if (quantitiesDict[assetId]) {
|
5231
|
+
const amount = bn18(input.amount);
|
5000
5232
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5001
|
-
cachedUtxos.push(input.id);
|
5002
5233
|
}
|
5003
|
-
} else if (input.
|
5004
|
-
quantitiesDict[
|
5005
|
-
cachedMessages.push(input.nonce);
|
5234
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
5235
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
5006
5236
|
}
|
5007
5237
|
}
|
5008
5238
|
});
|
@@ -5017,12 +5247,23 @@ var Account = class extends AbstractAccount {
|
|
5017
5247
|
});
|
5018
5248
|
const needsToBeFunded = missingQuantities.length;
|
5019
5249
|
if (needsToBeFunded) {
|
5020
|
-
const
|
5021
|
-
|
5022
|
-
|
5023
|
-
|
5024
|
-
|
5250
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5251
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5252
|
+
txRequest.addResources(resources);
|
5253
|
+
}
|
5254
|
+
txRequest.shiftPredicateData();
|
5255
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5256
|
+
const requestToBeReEstimate = clone4(txRequest);
|
5257
|
+
if (addedSignatures) {
|
5258
|
+
Array.from({ length: addedSignatures }).forEach(
|
5259
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5260
|
+
);
|
5025
5261
|
}
|
5262
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5263
|
+
transactionRequest: requestToBeReEstimate
|
5264
|
+
});
|
5265
|
+
txRequest.maxFee = maxFee;
|
5266
|
+
return txRequest;
|
5026
5267
|
}
|
5027
5268
|
/**
|
5028
5269
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5030,30 +5271,25 @@ var Account = class extends AbstractAccount {
|
|
5030
5271
|
* @param destination - The address of the destination.
|
5031
5272
|
* @param amount - The amount of coins to transfer.
|
5032
5273
|
* @param assetId - The asset ID of the coins to transfer.
|
5033
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5274
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5034
5275
|
* @returns A promise that resolves to the prepared transaction request.
|
5035
5276
|
*/
|
5036
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5037
|
-
const
|
5038
|
-
|
5039
|
-
const
|
5040
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5041
|
-
const request = new ScriptTransactionRequest(params);
|
5042
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5043
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5277
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5278
|
+
const request = new ScriptTransactionRequest(txParams);
|
5279
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5280
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5044
5281
|
estimateTxDependencies: true,
|
5045
5282
|
resourcesOwner: this
|
5046
5283
|
});
|
5047
|
-
|
5048
|
-
|
5049
|
-
|
5050
|
-
|
5051
|
-
|
5052
|
-
|
5053
|
-
|
5054
|
-
|
5055
|
-
await this.fund(request,
|
5056
|
-
request.updatePredicateInputs(estimatedInputs);
|
5284
|
+
if ("gasLimit" in txParams) {
|
5285
|
+
this.validateGas({
|
5286
|
+
gasUsed: txCost.gasUsed,
|
5287
|
+
gasLimit: request.gasLimit
|
5288
|
+
});
|
5289
|
+
}
|
5290
|
+
request.gasLimit = txCost.gasUsed;
|
5291
|
+
request.maxFee = txCost.maxFee;
|
5292
|
+
await this.fund(request, txCost);
|
5057
5293
|
return request;
|
5058
5294
|
}
|
5059
5295
|
/**
|
@@ -5065,15 +5301,14 @@ var Account = class extends AbstractAccount {
|
|
5065
5301
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5066
5302
|
* @returns A promise that resolves to the transaction response.
|
5067
5303
|
*/
|
5068
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5069
|
-
if (
|
5304
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5305
|
+
if (bn18(amount).lte(0)) {
|
5070
5306
|
throw new FuelError15(
|
5071
5307
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5072
5308
|
"Transfer amount must be a positive number."
|
5073
5309
|
);
|
5074
5310
|
}
|
5075
|
-
const
|
5076
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5311
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5077
5312
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5078
5313
|
}
|
5079
5314
|
/**
|
@@ -5085,41 +5320,38 @@ var Account = class extends AbstractAccount {
|
|
5085
5320
|
* @param txParams - The optional transaction parameters.
|
5086
5321
|
* @returns A promise that resolves to the transaction response.
|
5087
5322
|
*/
|
5088
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5089
|
-
if (
|
5323
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5324
|
+
if (bn18(amount).lte(0)) {
|
5090
5325
|
throw new FuelError15(
|
5091
5326
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5092
5327
|
"Transfer amount must be a positive number."
|
5093
5328
|
);
|
5094
5329
|
}
|
5095
5330
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5096
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5097
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5098
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5099
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5100
5331
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5101
5332
|
hexlifiedContractId: contractAddress.toB256(),
|
5102
|
-
amountToTransfer:
|
5103
|
-
assetId
|
5333
|
+
amountToTransfer: bn18(amount),
|
5334
|
+
assetId
|
5104
5335
|
});
|
5105
5336
|
const request = new ScriptTransactionRequest({
|
5106
|
-
...
|
5337
|
+
...txParams,
|
5107
5338
|
script,
|
5108
5339
|
scriptData
|
5109
5340
|
});
|
5110
5341
|
request.addContractInputAndOutput(contractAddress);
|
5111
|
-
const
|
5112
|
-
|
5113
|
-
[{ amount:
|
5114
|
-
);
|
5115
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5116
|
-
this.validateGas({
|
5117
|
-
gasUsed,
|
5118
|
-
gasPrice: request.gasPrice,
|
5119
|
-
gasLimit: request.gasLimit,
|
5120
|
-
minGasPrice
|
5342
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5343
|
+
resourcesOwner: this,
|
5344
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
5121
5345
|
});
|
5122
|
-
|
5346
|
+
if (txParams.gasLimit) {
|
5347
|
+
this.validateGas({
|
5348
|
+
gasUsed: txCost.gasUsed,
|
5349
|
+
gasLimit: request.gasLimit
|
5350
|
+
});
|
5351
|
+
}
|
5352
|
+
request.gasLimit = txCost.gasUsed;
|
5353
|
+
request.maxFee = txCost.maxFee;
|
5354
|
+
await this.fund(request, txCost);
|
5123
5355
|
return this.sendTransaction(request);
|
5124
5356
|
}
|
5125
5357
|
/**
|
@@ -5131,40 +5363,31 @@ var Account = class extends AbstractAccount {
|
|
5131
5363
|
* @returns A promise that resolves to the transaction response.
|
5132
5364
|
*/
|
5133
5365
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5134
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5135
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5136
5366
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5137
5367
|
const recipientDataArray = arrayify14(
|
5138
5368
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5139
5369
|
);
|
5140
5370
|
const amountDataArray = arrayify14(
|
5141
|
-
"0x".concat(
|
5371
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
5142
5372
|
);
|
5143
5373
|
const script = new Uint8Array([
|
5144
5374
|
...arrayify14(withdrawScript.bytes),
|
5145
5375
|
...recipientDataArray,
|
5146
5376
|
...amountDataArray
|
5147
5377
|
]);
|
5148
|
-
const params = {
|
5149
|
-
script,
|
5150
|
-
gasPrice: minGasPrice,
|
5151
|
-
baseAssetId,
|
5152
|
-
...txParams
|
5153
|
-
};
|
5378
|
+
const params = { script, ...txParams };
|
5154
5379
|
const request = new ScriptTransactionRequest(params);
|
5155
|
-
const
|
5156
|
-
const
|
5157
|
-
|
5158
|
-
|
5159
|
-
|
5160
|
-
|
5161
|
-
|
5162
|
-
|
5163
|
-
|
5164
|
-
|
5165
|
-
|
5166
|
-
});
|
5167
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5380
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5381
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5382
|
+
if (txParams.gasLimit) {
|
5383
|
+
this.validateGas({
|
5384
|
+
gasUsed: txCost.gasUsed,
|
5385
|
+
gasLimit: request.gasLimit
|
5386
|
+
});
|
5387
|
+
}
|
5388
|
+
request.maxFee = txCost.maxFee;
|
5389
|
+
request.gasLimit = txCost.gasUsed;
|
5390
|
+
await this.fund(request, txCost);
|
5168
5391
|
return this.sendTransaction(request);
|
5169
5392
|
}
|
5170
5393
|
async signMessage(message) {
|
@@ -5222,18 +5445,7 @@ var Account = class extends AbstractAccount {
|
|
5222
5445
|
}
|
5223
5446
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5224
5447
|
}
|
5225
|
-
validateGas({
|
5226
|
-
gasUsed,
|
5227
|
-
gasPrice,
|
5228
|
-
gasLimit,
|
5229
|
-
minGasPrice
|
5230
|
-
}) {
|
5231
|
-
if (minGasPrice.gt(gasPrice)) {
|
5232
|
-
throw new FuelError15(
|
5233
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5234
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5235
|
-
);
|
5236
|
-
}
|
5448
|
+
validateGas({ gasUsed, gasLimit }) {
|
5237
5449
|
if (gasUsed.gt(gasLimit)) {
|
5238
5450
|
throw new FuelError15(
|
5239
5451
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5529,7 +5741,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5529
5741
|
* @param transactionRequestLike - The transaction request to send.
|
5530
5742
|
* @returns A promise that resolves to the TransactionResponse object.
|
5531
5743
|
*/
|
5532
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5744
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5533
5745
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5534
5746
|
if (estimateTxDependencies) {
|
5535
5747
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5570,7 +5782,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5570
5782
|
// src/hdwallet/hdwallet.ts
|
5571
5783
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5572
5784
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5573
|
-
import { bn as
|
5785
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5574
5786
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5575
5787
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5576
5788
|
|
@@ -8042,7 +8254,7 @@ var HDWallet = class {
|
|
8042
8254
|
const IR = bytes.slice(32);
|
8043
8255
|
if (privateKey) {
|
8044
8256
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8045
|
-
const ki =
|
8257
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
8046
8258
|
return new HDWallet({
|
8047
8259
|
privateKey: ki,
|
8048
8260
|
chainCode: IR,
|
@@ -8729,8 +8941,9 @@ import {
|
|
8729
8941
|
SCRIPT_FIXED_SIZE
|
8730
8942
|
} from "@fuel-ts/abi-coder";
|
8731
8943
|
import { Address as Address9 } from "@fuel-ts/address";
|
8944
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8732
8945
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8733
|
-
import { ByteArrayCoder, InputType as
|
8946
|
+
import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
|
8734
8947
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8735
8948
|
|
8736
8949
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8790,9 +9003,9 @@ var Predicate = class extends Account {
|
|
8790
9003
|
const request = transactionRequestify(transactionRequestLike);
|
8791
9004
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8792
9005
|
request.inputs?.forEach((input) => {
|
8793
|
-
if (input.type ===
|
8794
|
-
input.predicate = this.bytes;
|
8795
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9006
|
+
if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
9007
|
+
input.predicate = hexlify19(this.bytes);
|
9008
|
+
input.predicateData = hexlify19(this.getPredicateData(policies.length));
|
8796
9009
|
}
|
8797
9010
|
});
|
8798
9011
|
return request;
|
@@ -8806,10 +9019,8 @@ var Predicate = class extends Account {
|
|
8806
9019
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8807
9020
|
* @returns A promise that resolves to the prepared transaction request.
|
8808
9021
|
*/
|
8809
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8810
|
-
|
8811
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8812
|
-
return this.populateTransactionPredicateData(request);
|
9022
|
+
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
9023
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8813
9024
|
}
|
8814
9025
|
/**
|
8815
9026
|
* Sends a transaction with the populated predicate data.
|
@@ -8817,9 +9028,9 @@ var Predicate = class extends Account {
|
|
8817
9028
|
* @param transactionRequestLike - The transaction request-like object.
|
8818
9029
|
* @returns A promise that resolves to the transaction response.
|
8819
9030
|
*/
|
8820
|
-
sendTransaction(transactionRequestLike
|
8821
|
-
const transactionRequest =
|
8822
|
-
return super.sendTransaction(transactionRequest,
|
9031
|
+
sendTransaction(transactionRequestLike) {
|
9032
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9033
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8823
9034
|
}
|
8824
9035
|
/**
|
8825
9036
|
* Simulates a transaction with the populated predicate data.
|
@@ -8828,8 +9039,8 @@ var Predicate = class extends Account {
|
|
8828
9039
|
* @returns A promise that resolves to the call result.
|
8829
9040
|
*/
|
8830
9041
|
simulateTransaction(transactionRequestLike) {
|
8831
|
-
const transactionRequest =
|
8832
|
-
return super.simulateTransaction(transactionRequest);
|
9042
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9043
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8833
9044
|
}
|
8834
9045
|
getPredicateData(policiesLength) {
|
8835
9046
|
if (!this.predicateData.length) {
|
@@ -8875,6 +9086,25 @@ var Predicate = class extends Account {
|
|
8875
9086
|
predicateInterface: abiInterface
|
8876
9087
|
};
|
8877
9088
|
}
|
9089
|
+
/**
|
9090
|
+
* Retrieves resources satisfying the spend query for the account.
|
9091
|
+
*
|
9092
|
+
* @param quantities - IDs of coins to exclude.
|
9093
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9094
|
+
* @returns A promise that resolves to an array of Resources.
|
9095
|
+
*/
|
9096
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9097
|
+
const resources = await this.provider.getResourcesToSpend(
|
9098
|
+
this.address,
|
9099
|
+
quantities,
|
9100
|
+
excludedIds
|
9101
|
+
);
|
9102
|
+
return resources.map((resource) => ({
|
9103
|
+
...resource,
|
9104
|
+
predicate: hexlify19(this.bytes),
|
9105
|
+
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9106
|
+
}));
|
9107
|
+
}
|
8878
9108
|
/**
|
8879
9109
|
* Sets the configurable constants for the predicate.
|
8880
9110
|
*
|
@@ -9623,7 +9853,7 @@ export {
|
|
9623
9853
|
WalletLocked,
|
9624
9854
|
WalletManager,
|
9625
9855
|
WalletUnlocked,
|
9626
|
-
|
9856
|
+
addAmountToCoinQuantities,
|
9627
9857
|
addOperation,
|
9628
9858
|
assemblePanicError,
|
9629
9859
|
assembleReceiptByType,
|
@@ -9632,9 +9862,10 @@ export {
|
|
9632
9862
|
assets,
|
9633
9863
|
buildBlockExplorerUrl,
|
9634
9864
|
cacheFor,
|
9865
|
+
cacheTxInputsFromOwner,
|
9866
|
+
calculateGasFee,
|
9635
9867
|
calculateMetadataGasForTxCreate,
|
9636
9868
|
calculateMetadataGasForTxScript,
|
9637
|
-
calculatePriceWithFactor,
|
9638
9869
|
calculateTransactionFee,
|
9639
9870
|
coinQuantityfy,
|
9640
9871
|
deferPromise,
|