@fuel-ts/account 0.0.0-rc-1976-20240406124842 → 0.0.0-rc-2021-20240408141516
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 +865 -615
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +845 -609
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +687 -452
- 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 +888 -322
- 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/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +3 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +45 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +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.global.js +1580 -1116
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +821 -606
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +679 -464
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/index.mjs
CHANGED
@@ -29,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
|
}
|
@@ -235,7 +277,6 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
235
277
|
prevRoot
|
236
278
|
time
|
237
279
|
applicationHash
|
238
|
-
messageReceiptRoot
|
239
280
|
messageReceiptCount
|
240
281
|
}
|
241
282
|
commitBlockHeader {
|
@@ -247,7 +288,6 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
247
288
|
prevRoot
|
248
289
|
time
|
249
290
|
applicationHash
|
250
|
-
messageReceiptRoot
|
251
291
|
messageReceiptCount
|
252
292
|
}
|
253
293
|
sender
|
@@ -267,8 +307,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
267
307
|
var BlockFragmentFragmentDoc = gql`
|
268
308
|
fragment blockFragment on Block {
|
269
309
|
id
|
310
|
+
height
|
270
311
|
header {
|
271
|
-
height
|
272
312
|
time
|
273
313
|
}
|
274
314
|
transactions {
|
@@ -326,6 +366,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
326
366
|
`;
|
327
367
|
var GasCostsFragmentFragmentDoc = gql`
|
328
368
|
fragment GasCostsFragment on GasCosts {
|
369
|
+
version {
|
370
|
+
... on Version {
|
371
|
+
value
|
372
|
+
}
|
373
|
+
}
|
329
374
|
add
|
330
375
|
addi
|
331
376
|
aloc
|
@@ -338,7 +383,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
338
383
|
cb
|
339
384
|
cfei
|
340
385
|
cfsi
|
341
|
-
croo
|
342
386
|
div
|
343
387
|
divi
|
344
388
|
ecr1
|
@@ -421,6 +465,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
421
465
|
ccp {
|
422
466
|
...DependentCostFragment
|
423
467
|
}
|
468
|
+
croo {
|
469
|
+
...DependentCostFragment
|
470
|
+
}
|
424
471
|
csiz {
|
425
472
|
...DependentCostFragment
|
426
473
|
}
|
@@ -480,6 +527,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
480
527
|
${DependentCostFragmentFragmentDoc}`;
|
481
528
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
482
529
|
fragment consensusParametersFragment on ConsensusParameters {
|
530
|
+
version {
|
531
|
+
... on Version {
|
532
|
+
value
|
533
|
+
}
|
534
|
+
}
|
483
535
|
txParams {
|
484
536
|
...TxParametersFragment
|
485
537
|
}
|
@@ -539,18 +591,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
539
591
|
fragment nodeInfoFragment on NodeInfo {
|
540
592
|
utxoValidation
|
541
593
|
vmBacktrace
|
542
|
-
minGasPrice
|
543
594
|
maxTx
|
544
595
|
maxDepth
|
545
596
|
nodeVersion
|
546
|
-
peers {
|
547
|
-
id
|
548
|
-
addresses
|
549
|
-
clientVersion
|
550
|
-
blockHeight
|
551
|
-
lastHeartbeatMs
|
552
|
-
appScore
|
553
|
-
}
|
554
597
|
}
|
555
598
|
`;
|
556
599
|
var GetVersionDocument = gql`
|
@@ -585,13 +628,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
585
628
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
586
629
|
transaction(id: $transactionId) {
|
587
630
|
...transactionFragment
|
588
|
-
receipts {
|
589
|
-
...receiptFragment
|
590
|
-
}
|
591
631
|
}
|
592
632
|
}
|
593
|
-
${TransactionFragmentFragmentDoc}
|
594
|
-
${ReceiptFragmentFragmentDoc}`;
|
633
|
+
${TransactionFragmentFragmentDoc}`;
|
595
634
|
var GetTransactionsDocument = gql`
|
596
635
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
597
636
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -719,6 +758,20 @@ var GetBalanceDocument = gql`
|
|
719
758
|
}
|
720
759
|
}
|
721
760
|
${BalanceFragmentFragmentDoc}`;
|
761
|
+
var GetLatestGasPriceDocument = gql`
|
762
|
+
query getLatestGasPrice {
|
763
|
+
latestGasPrice {
|
764
|
+
gasPrice
|
765
|
+
}
|
766
|
+
}
|
767
|
+
`;
|
768
|
+
var EstimateGasPriceDocument = gql`
|
769
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
770
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
771
|
+
gasPrice
|
772
|
+
}
|
773
|
+
}
|
774
|
+
`;
|
722
775
|
var GetBalancesDocument = gql`
|
723
776
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
724
777
|
balances(
|
@@ -773,12 +826,12 @@ var GetMessageStatusDocument = gql`
|
|
773
826
|
}
|
774
827
|
`;
|
775
828
|
var DryRunDocument = gql`
|
776
|
-
mutation dryRun($
|
777
|
-
dryRun(
|
778
|
-
...
|
829
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
830
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
831
|
+
...dryRunTransactionExecutionStatusFragment
|
779
832
|
}
|
780
833
|
}
|
781
|
-
${
|
834
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
782
835
|
var SubmitDocument = gql`
|
783
836
|
mutation submit($encodedTransaction: HexString!) {
|
784
837
|
submit(tx: $encodedTransaction) {
|
@@ -861,6 +914,12 @@ function getSdk(requester) {
|
|
861
914
|
getBalance(variables, options) {
|
862
915
|
return requester(GetBalanceDocument, variables, options);
|
863
916
|
},
|
917
|
+
getLatestGasPrice(variables, options) {
|
918
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
919
|
+
},
|
920
|
+
estimateGasPrice(variables, options) {
|
921
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
922
|
+
},
|
864
923
|
getBalances(variables, options) {
|
865
924
|
return requester(GetBalancesDocument, variables, options);
|
866
925
|
},
|
@@ -1035,7 +1094,7 @@ var inputify = (value) => {
|
|
1035
1094
|
return {
|
1036
1095
|
type: InputType.Coin,
|
1037
1096
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1038
|
-
outputIndex: arrayify(value.id)
|
1097
|
+
outputIndex: toNumber(arrayify(value.id).slice(32, 34)),
|
1039
1098
|
owner: hexlify3(value.owner),
|
1040
1099
|
amount: bn2(value.amount),
|
1041
1100
|
assetId: hexlify3(value.assetId),
|
@@ -1044,10 +1103,9 @@ var inputify = (value) => {
|
|
1044
1103
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1045
1104
|
},
|
1046
1105
|
witnessIndex: value.witnessIndex,
|
1047
|
-
maturity: value.maturity ?? 0,
|
1048
1106
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1049
|
-
predicateLength: predicate.length,
|
1050
|
-
predicateDataLength: predicateData.length,
|
1107
|
+
predicateLength: bn2(predicate.length),
|
1108
|
+
predicateDataLength: bn2(predicateData.length),
|
1051
1109
|
predicate: hexlify3(predicate),
|
1052
1110
|
predicateData: hexlify3(predicateData)
|
1053
1111
|
};
|
@@ -1078,8 +1136,8 @@ var inputify = (value) => {
|
|
1078
1136
|
nonce: hexlify3(value.nonce),
|
1079
1137
|
witnessIndex: value.witnessIndex,
|
1080
1138
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1081
|
-
predicateLength: predicate.length,
|
1082
|
-
predicateDataLength: predicateData.length,
|
1139
|
+
predicateLength: bn2(predicate.length),
|
1140
|
+
predicateDataLength: bn2(predicateData.length),
|
1083
1141
|
predicate: hexlify3(predicate),
|
1084
1142
|
predicateData: hexlify3(predicateData),
|
1085
1143
|
data: hexlify3(data),
|
@@ -1154,7 +1212,7 @@ var outputify = (value) => {
|
|
1154
1212
|
|
1155
1213
|
// src/providers/transaction-request/transaction-request.ts
|
1156
1214
|
import { Address, addressify } from "@fuel-ts/address";
|
1157
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1215
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1158
1216
|
import { bn as bn7 } from "@fuel-ts/math";
|
1159
1217
|
import {
|
1160
1218
|
PolicyType,
|
@@ -1164,6 +1222,7 @@ import {
|
|
1164
1222
|
TransactionType
|
1165
1223
|
} from "@fuel-ts/transactions";
|
1166
1224
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1225
|
+
import { randomBytes } from "ethers";
|
1167
1226
|
|
1168
1227
|
// src/providers/resource.ts
|
1169
1228
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1207,8 +1266,8 @@ function assembleReceiptByType(receipt) {
|
|
1207
1266
|
case "CALL" /* Call */: {
|
1208
1267
|
const callReceipt = {
|
1209
1268
|
type: ReceiptType.Call,
|
1210
|
-
from: hexOrZero(receipt.
|
1211
|
-
to: hexOrZero(receipt?.to
|
1269
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1270
|
+
to: hexOrZero(receipt?.to),
|
1212
1271
|
amount: bn4(receipt.amount),
|
1213
1272
|
assetId: hexOrZero(receipt.assetId),
|
1214
1273
|
gas: bn4(receipt.gas),
|
@@ -1222,7 +1281,7 @@ function assembleReceiptByType(receipt) {
|
|
1222
1281
|
case "RETURN" /* Return */: {
|
1223
1282
|
const returnReceipt = {
|
1224
1283
|
type: ReceiptType.Return,
|
1225
|
-
id: hexOrZero(receipt.
|
1284
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1226
1285
|
val: bn4(receipt.val),
|
1227
1286
|
pc: bn4(receipt.pc),
|
1228
1287
|
is: bn4(receipt.is)
|
@@ -1232,7 +1291,7 @@ function assembleReceiptByType(receipt) {
|
|
1232
1291
|
case "RETURN_DATA" /* ReturnData */: {
|
1233
1292
|
const returnDataReceipt = {
|
1234
1293
|
type: ReceiptType.ReturnData,
|
1235
|
-
id: hexOrZero(receipt.
|
1294
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1236
1295
|
ptr: bn4(receipt.ptr),
|
1237
1296
|
len: bn4(receipt.len),
|
1238
1297
|
digest: hexOrZero(receipt.digest),
|
@@ -1244,7 +1303,7 @@ function assembleReceiptByType(receipt) {
|
|
1244
1303
|
case "PANIC" /* Panic */: {
|
1245
1304
|
const panicReceipt = {
|
1246
1305
|
type: ReceiptType.Panic,
|
1247
|
-
id: hexOrZero(receipt.
|
1306
|
+
id: hexOrZero(receipt.id),
|
1248
1307
|
reason: bn4(receipt.reason),
|
1249
1308
|
pc: bn4(receipt.pc),
|
1250
1309
|
is: bn4(receipt.is),
|
@@ -1255,7 +1314,7 @@ function assembleReceiptByType(receipt) {
|
|
1255
1314
|
case "REVERT" /* Revert */: {
|
1256
1315
|
const revertReceipt = {
|
1257
1316
|
type: ReceiptType.Revert,
|
1258
|
-
id: hexOrZero(receipt.
|
1317
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1259
1318
|
val: bn4(receipt.ra),
|
1260
1319
|
pc: bn4(receipt.pc),
|
1261
1320
|
is: bn4(receipt.is)
|
@@ -1265,7 +1324,7 @@ function assembleReceiptByType(receipt) {
|
|
1265
1324
|
case "LOG" /* Log */: {
|
1266
1325
|
const logReceipt = {
|
1267
1326
|
type: ReceiptType.Log,
|
1268
|
-
id: hexOrZero(receipt.
|
1327
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1269
1328
|
val0: bn4(receipt.ra),
|
1270
1329
|
val1: bn4(receipt.rb),
|
1271
1330
|
val2: bn4(receipt.rc),
|
@@ -1278,7 +1337,7 @@ function assembleReceiptByType(receipt) {
|
|
1278
1337
|
case "LOG_DATA" /* LogData */: {
|
1279
1338
|
const logDataReceipt = {
|
1280
1339
|
type: ReceiptType.LogData,
|
1281
|
-
id: hexOrZero(receipt.
|
1340
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1282
1341
|
val0: bn4(receipt.ra),
|
1283
1342
|
val1: bn4(receipt.rb),
|
1284
1343
|
ptr: bn4(receipt.ptr),
|
@@ -1292,8 +1351,8 @@ function assembleReceiptByType(receipt) {
|
|
1292
1351
|
case "TRANSFER" /* Transfer */: {
|
1293
1352
|
const transferReceipt = {
|
1294
1353
|
type: ReceiptType.Transfer,
|
1295
|
-
from: hexOrZero(receipt.
|
1296
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1354
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1355
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1297
1356
|
amount: bn4(receipt.amount),
|
1298
1357
|
assetId: hexOrZero(receipt.assetId),
|
1299
1358
|
pc: bn4(receipt.pc),
|
@@ -1304,8 +1363,8 @@ function assembleReceiptByType(receipt) {
|
|
1304
1363
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1305
1364
|
const transferOutReceipt = {
|
1306
1365
|
type: ReceiptType.TransferOut,
|
1307
|
-
from: hexOrZero(receipt.
|
1308
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1366
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1367
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1309
1368
|
amount: bn4(receipt.amount),
|
1310
1369
|
assetId: hexOrZero(receipt.assetId),
|
1311
1370
|
pc: bn4(receipt.pc),
|
@@ -1348,7 +1407,7 @@ function assembleReceiptByType(receipt) {
|
|
1348
1407
|
return receiptMessageOut;
|
1349
1408
|
}
|
1350
1409
|
case "MINT" /* Mint */: {
|
1351
|
-
const contractId = hexOrZero(receipt.
|
1410
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1352
1411
|
const subId = hexOrZero(receipt.subId);
|
1353
1412
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1354
1413
|
const mintReceipt = {
|
@@ -1363,7 +1422,7 @@ function assembleReceiptByType(receipt) {
|
|
1363
1422
|
return mintReceipt;
|
1364
1423
|
}
|
1365
1424
|
case "BURN" /* Burn */: {
|
1366
|
-
const contractId = hexOrZero(receipt.
|
1425
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1367
1426
|
const subId = hexOrZero(receipt.subId);
|
1368
1427
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1369
1428
|
const burnReceipt = {
|
@@ -1448,7 +1507,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1448
1507
|
import { bn as bn5 } from "@fuel-ts/math";
|
1449
1508
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1450
1509
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1451
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1452
1510
|
var getGasUsedFromReceipts = (receipts) => {
|
1453
1511
|
const scriptResult = receipts.filter(
|
1454
1512
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1469,18 +1527,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1469
1527
|
}
|
1470
1528
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1471
1529
|
const witnessCache = [];
|
1472
|
-
const
|
1530
|
+
const chargeableInputs = inputs.filter((input) => {
|
1531
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1532
|
+
if (isCoinOrMessage) {
|
1533
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1534
|
+
return true;
|
1535
|
+
}
|
1536
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1537
|
+
witnessCache.push(input.witnessIndex);
|
1538
|
+
return true;
|
1539
|
+
}
|
1540
|
+
}
|
1541
|
+
return false;
|
1542
|
+
});
|
1543
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1544
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1473
1545
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1474
1546
|
return total.add(
|
1475
|
-
|
1547
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1476
1548
|
);
|
1477
1549
|
}
|
1478
|
-
|
1479
|
-
|
1480
|
-
return total.add(gasCosts.ecr1);
|
1481
|
-
}
|
1482
|
-
return total;
|
1483
|
-
}, bn5());
|
1550
|
+
return total.add(gasCosts.ecr1);
|
1551
|
+
}, bn5(0));
|
1484
1552
|
return totalGas;
|
1485
1553
|
}
|
1486
1554
|
function getMinGas(params) {
|
@@ -1492,12 +1560,20 @@ function getMinGas(params) {
|
|
1492
1560
|
return minGas;
|
1493
1561
|
}
|
1494
1562
|
function getMaxGas(params) {
|
1495
|
-
const {
|
1563
|
+
const {
|
1564
|
+
gasPerByte,
|
1565
|
+
witnessesLength,
|
1566
|
+
witnessLimit,
|
1567
|
+
minGas,
|
1568
|
+
gasLimit = bn5(0),
|
1569
|
+
maxGasPerTx
|
1570
|
+
} = params;
|
1496
1571
|
let remainingAllowedWitnessGas = bn5(0);
|
1497
1572
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1498
1573
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1499
1574
|
}
|
1500
|
-
|
1575
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1576
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1501
1577
|
}
|
1502
1578
|
function calculateMetadataGasForTxCreate({
|
1503
1579
|
gasCosts,
|
@@ -1519,6 +1595,10 @@ function calculateMetadataGasForTxScript({
|
|
1519
1595
|
}) {
|
1520
1596
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1521
1597
|
}
|
1598
|
+
var calculateGasFee = (params) => {
|
1599
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1600
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1601
|
+
};
|
1522
1602
|
|
1523
1603
|
// src/providers/utils/json.ts
|
1524
1604
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1675,7 +1755,7 @@ var witnessify = (value) => {
|
|
1675
1755
|
// src/providers/transaction-request/transaction-request.ts
|
1676
1756
|
var BaseTransactionRequest = class {
|
1677
1757
|
/** Gas price for transaction */
|
1678
|
-
|
1758
|
+
tip;
|
1679
1759
|
/** Block until which tx cannot be included */
|
1680
1760
|
maturity;
|
1681
1761
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1688,38 +1768,34 @@ var BaseTransactionRequest = class {
|
|
1688
1768
|
outputs = [];
|
1689
1769
|
/** List of witnesses */
|
1690
1770
|
witnesses = [];
|
1691
|
-
/** Base asset ID - should be fetched from the chain */
|
1692
|
-
baseAssetId = ZeroBytes324;
|
1693
1771
|
/**
|
1694
1772
|
* Constructor for initializing a base transaction request.
|
1695
1773
|
*
|
1696
1774
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1697
1775
|
*/
|
1698
1776
|
constructor({
|
1699
|
-
|
1777
|
+
tip,
|
1700
1778
|
maturity,
|
1701
1779
|
maxFee,
|
1702
1780
|
witnessLimit,
|
1703
1781
|
inputs,
|
1704
1782
|
outputs,
|
1705
|
-
witnesses
|
1706
|
-
baseAssetId
|
1783
|
+
witnesses
|
1707
1784
|
} = {}) {
|
1708
|
-
this.
|
1785
|
+
this.tip = bn7(tip);
|
1709
1786
|
this.maturity = maturity ?? 0;
|
1710
1787
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1711
1788
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1712
1789
|
this.inputs = inputs ?? [];
|
1713
1790
|
this.outputs = outputs ?? [];
|
1714
1791
|
this.witnesses = witnesses ?? [];
|
1715
|
-
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1716
1792
|
}
|
1717
1793
|
static getPolicyMeta(req) {
|
1718
1794
|
let policyTypes = 0;
|
1719
1795
|
const policies = [];
|
1720
|
-
if (req.
|
1721
|
-
policyTypes += PolicyType.
|
1722
|
-
policies.push({ data: req.
|
1796
|
+
if (req.tip) {
|
1797
|
+
policyTypes += PolicyType.Tip;
|
1798
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1723
1799
|
}
|
1724
1800
|
if (req.witnessLimit) {
|
1725
1801
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1906,10 +1982,10 @@ var BaseTransactionRequest = class {
|
|
1906
1982
|
* @param predicate - Predicate bytes.
|
1907
1983
|
* @param predicateData - Predicate data bytes.
|
1908
1984
|
*/
|
1909
|
-
addCoinInput(coin
|
1985
|
+
addCoinInput(coin) {
|
1910
1986
|
const { assetId, owner, amount } = coin;
|
1911
1987
|
let witnessIndex;
|
1912
|
-
if (predicate) {
|
1988
|
+
if (coin.predicate) {
|
1913
1989
|
witnessIndex = 0;
|
1914
1990
|
} else {
|
1915
1991
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1924,9 +2000,7 @@ var BaseTransactionRequest = class {
|
|
1924
2000
|
amount,
|
1925
2001
|
assetId,
|
1926
2002
|
txPointer: "0x00000000000000000000000000000000",
|
1927
|
-
witnessIndex
|
1928
|
-
predicate: predicate?.bytes,
|
1929
|
-
predicateData: predicate?.predicateDataBytes
|
2003
|
+
witnessIndex
|
1930
2004
|
};
|
1931
2005
|
this.pushInput(input);
|
1932
2006
|
this.addChangeOutput(owner, assetId);
|
@@ -1937,11 +2011,13 @@ var BaseTransactionRequest = class {
|
|
1937
2011
|
*
|
1938
2012
|
* @param message - Message resource.
|
1939
2013
|
* @param predicate - Predicate bytes.
|
2014
|
+
* @param predicateData - Predicate data bytes.
|
1940
2015
|
*/
|
1941
|
-
addMessageInput(message
|
2016
|
+
addMessageInput(message) {
|
1942
2017
|
const { recipient, sender, amount } = message;
|
2018
|
+
const assetId = BaseAssetId2;
|
1943
2019
|
let witnessIndex;
|
1944
|
-
if (predicate) {
|
2020
|
+
if (message.predicate) {
|
1945
2021
|
witnessIndex = 0;
|
1946
2022
|
} else {
|
1947
2023
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1955,12 +2031,10 @@ var BaseTransactionRequest = class {
|
|
1955
2031
|
sender: sender.toB256(),
|
1956
2032
|
recipient: recipient.toB256(),
|
1957
2033
|
amount,
|
1958
|
-
witnessIndex
|
1959
|
-
predicate: predicate?.bytes,
|
1960
|
-
predicateData: predicate?.predicateDataBytes
|
2034
|
+
witnessIndex
|
1961
2035
|
};
|
1962
2036
|
this.pushInput(input);
|
1963
|
-
this.addChangeOutput(recipient,
|
2037
|
+
this.addChangeOutput(recipient, assetId);
|
1964
2038
|
}
|
1965
2039
|
/**
|
1966
2040
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1988,32 +2062,6 @@ var BaseTransactionRequest = class {
|
|
1988
2062
|
resources.forEach((resource) => this.addResource(resource));
|
1989
2063
|
return this;
|
1990
2064
|
}
|
1991
|
-
/**
|
1992
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1993
|
-
* outputs from the related assetIds.
|
1994
|
-
*
|
1995
|
-
* @param resources - The resources to add.
|
1996
|
-
* @returns This transaction.
|
1997
|
-
*/
|
1998
|
-
addPredicateResource(resource, predicate) {
|
1999
|
-
if (isCoin(resource)) {
|
2000
|
-
this.addCoinInput(resource, predicate);
|
2001
|
-
} else {
|
2002
|
-
this.addMessageInput(resource, predicate);
|
2003
|
-
}
|
2004
|
-
return this;
|
2005
|
-
}
|
2006
|
-
/**
|
2007
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2008
|
-
* from the related assetIds.
|
2009
|
-
*
|
2010
|
-
* @param resources - The resources to add.
|
2011
|
-
* @returns This transaction.
|
2012
|
-
*/
|
2013
|
-
addPredicateResources(resources, predicate) {
|
2014
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2015
|
-
return this;
|
2016
|
-
}
|
2017
2065
|
/**
|
2018
2066
|
* Adds a coin output to the transaction.
|
2019
2067
|
*
|
@@ -2021,12 +2069,12 @@ var BaseTransactionRequest = class {
|
|
2021
2069
|
* @param amount - Amount of coin.
|
2022
2070
|
* @param assetId - Asset ID of coin.
|
2023
2071
|
*/
|
2024
|
-
addCoinOutput(to, amount, assetId) {
|
2072
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
2025
2073
|
this.pushOutput({
|
2026
2074
|
type: OutputType2.Coin,
|
2027
2075
|
to: addressify(to).toB256(),
|
2028
2076
|
amount,
|
2029
|
-
assetId
|
2077
|
+
assetId
|
2030
2078
|
});
|
2031
2079
|
return this;
|
2032
2080
|
}
|
@@ -2053,7 +2101,7 @@ var BaseTransactionRequest = class {
|
|
2053
2101
|
* @param to - Address of the owner.
|
2054
2102
|
* @param assetId - Asset ID of coin.
|
2055
2103
|
*/
|
2056
|
-
addChangeOutput(to, assetId) {
|
2104
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
2057
2105
|
const changeOutput = this.getChangeOutputs().find(
|
2058
2106
|
(output) => hexlify7(output.assetId) === assetId
|
2059
2107
|
);
|
@@ -2061,7 +2109,7 @@ var BaseTransactionRequest = class {
|
|
2061
2109
|
this.pushOutput({
|
2062
2110
|
type: OutputType2.Change,
|
2063
2111
|
to: addressify(to).toB256(),
|
2064
|
-
assetId
|
2112
|
+
assetId
|
2065
2113
|
});
|
2066
2114
|
}
|
2067
2115
|
}
|
@@ -2093,7 +2141,7 @@ var BaseTransactionRequest = class {
|
|
2093
2141
|
}
|
2094
2142
|
calculateMaxGas(chainInfo, minGas) {
|
2095
2143
|
const { consensusParameters } = chainInfo;
|
2096
|
-
const { gasPerByte } = consensusParameters;
|
2144
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2097
2145
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2098
2146
|
(acc, wit) => acc + wit.dataLength,
|
2099
2147
|
0
|
@@ -2102,7 +2150,8 @@ var BaseTransactionRequest = class {
|
|
2102
2150
|
gasPerByte,
|
2103
2151
|
minGas,
|
2104
2152
|
witnessesLength,
|
2105
|
-
witnessLimit: this.witnessLimit
|
2153
|
+
witnessLimit: this.witnessLimit,
|
2154
|
+
maxGasPerTx
|
2106
2155
|
});
|
2107
2156
|
}
|
2108
2157
|
/**
|
@@ -2112,12 +2161,6 @@ var BaseTransactionRequest = class {
|
|
2112
2161
|
* @param quantities - CoinQuantity Array.
|
2113
2162
|
*/
|
2114
2163
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2115
|
-
let idCounter = 0;
|
2116
|
-
const generateId = () => {
|
2117
|
-
const counterString = String(idCounter++);
|
2118
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2119
|
-
return id;
|
2120
|
-
};
|
2121
2164
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2122
2165
|
if ("assetId" in input) {
|
2123
2166
|
return input.assetId === assetId;
|
@@ -2126,24 +2169,27 @@ var BaseTransactionRequest = class {
|
|
2126
2169
|
});
|
2127
2170
|
const updateAssetInput = (assetId, quantity) => {
|
2128
2171
|
const assetInput = findAssetInput(assetId);
|
2172
|
+
let usedQuantity = quantity;
|
2173
|
+
if (assetId === BaseAssetId2) {
|
2174
|
+
usedQuantity = bn7("1000000000000000000");
|
2175
|
+
}
|
2129
2176
|
if (assetInput && "assetId" in assetInput) {
|
2130
|
-
assetInput.id =
|
2131
|
-
assetInput.amount =
|
2177
|
+
assetInput.id = hexlify7(randomBytes(34));
|
2178
|
+
assetInput.amount = usedQuantity;
|
2132
2179
|
} else {
|
2133
2180
|
this.addResources([
|
2134
2181
|
{
|
2135
|
-
id:
|
2136
|
-
amount:
|
2182
|
+
id: hexlify7(randomBytes(34)),
|
2183
|
+
amount: usedQuantity,
|
2137
2184
|
assetId,
|
2138
2185
|
owner: resourcesOwner || Address.fromRandom(),
|
2139
|
-
maturity: 0,
|
2140
2186
|
blockCreated: bn7(1),
|
2141
2187
|
txCreatedIdx: bn7(1)
|
2142
2188
|
}
|
2143
2189
|
]);
|
2144
2190
|
}
|
2145
2191
|
};
|
2146
|
-
updateAssetInput(
|
2192
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2147
2193
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2148
2194
|
}
|
2149
2195
|
/**
|
@@ -2168,7 +2214,7 @@ var BaseTransactionRequest = class {
|
|
2168
2214
|
toJSON() {
|
2169
2215
|
return normalizeJSON(this);
|
2170
2216
|
}
|
2171
|
-
|
2217
|
+
updatePredicateGasUsed(inputs) {
|
2172
2218
|
this.inputs.forEach((i) => {
|
2173
2219
|
let correspondingInput;
|
2174
2220
|
switch (i.type) {
|
@@ -2190,6 +2236,15 @@ var BaseTransactionRequest = class {
|
|
2190
2236
|
}
|
2191
2237
|
});
|
2192
2238
|
}
|
2239
|
+
shiftPredicateData() {
|
2240
|
+
this.inputs.forEach((input) => {
|
2241
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2242
|
+
input.predicateData = input.paddPredicateData(
|
2243
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2244
|
+
);
|
2245
|
+
}
|
2246
|
+
});
|
2247
|
+
}
|
2193
2248
|
};
|
2194
2249
|
|
2195
2250
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2336,9 +2391,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2336
2391
|
return {
|
2337
2392
|
type: TransactionType3.Create,
|
2338
2393
|
...baseTransaction,
|
2339
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2340
2394
|
bytecodeWitnessIndex,
|
2341
|
-
storageSlotsCount: storageSlots.length,
|
2395
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2342
2396
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2343
2397
|
storageSlots
|
2344
2398
|
};
|
@@ -2461,8 +2515,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2461
2515
|
type: TransactionType4.Script,
|
2462
2516
|
scriptGasLimit: this.gasLimit,
|
2463
2517
|
...super.getBaseTransaction(),
|
2464
|
-
scriptLength: script.length,
|
2465
|
-
scriptDataLength: scriptData.length,
|
2518
|
+
scriptLength: bn10(script.length),
|
2519
|
+
scriptDataLength: bn10(scriptData.length),
|
2466
2520
|
receiptsRoot: ZeroBytes327,
|
2467
2521
|
script: hexlify10(script),
|
2468
2522
|
scriptData: hexlify10(scriptData)
|
@@ -2526,7 +2580,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2526
2580
|
}
|
2527
2581
|
calculateMaxGas(chainInfo, minGas) {
|
2528
2582
|
const { consensusParameters } = chainInfo;
|
2529
|
-
const { gasPerByte } = consensusParameters;
|
2583
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2530
2584
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2531
2585
|
(acc, wit) => acc + wit.dataLength,
|
2532
2586
|
0
|
@@ -2536,7 +2590,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2536
2590
|
minGas,
|
2537
2591
|
witnessesLength,
|
2538
2592
|
witnessLimit: this.witnessLimit,
|
2539
|
-
gasLimit: this.gasLimit
|
2593
|
+
gasLimit: this.gasLimit,
|
2594
|
+
maxGasPerTx
|
2540
2595
|
});
|
2541
2596
|
}
|
2542
2597
|
/**
|
@@ -2593,7 +2648,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2593
2648
|
|
2594
2649
|
// src/providers/transaction-request/utils.ts
|
2595
2650
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2596
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2651
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2597
2652
|
var transactionRequestify = (obj) => {
|
2598
2653
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2599
2654
|
return obj;
|
@@ -2611,14 +2666,31 @@ var transactionRequestify = (obj) => {
|
|
2611
2666
|
}
|
2612
2667
|
}
|
2613
2668
|
};
|
2669
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2670
|
+
(acc, input) => {
|
2671
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2672
|
+
acc.utxos.push(input.id);
|
2673
|
+
}
|
2674
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2675
|
+
acc.messages.push(input.nonce);
|
2676
|
+
}
|
2677
|
+
return acc;
|
2678
|
+
},
|
2679
|
+
{
|
2680
|
+
utxos: [],
|
2681
|
+
messages: []
|
2682
|
+
}
|
2683
|
+
);
|
2614
2684
|
|
2615
2685
|
// src/providers/transaction-response/transaction-response.ts
|
2616
2686
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2617
|
-
import { bn as
|
2687
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2618
2688
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2619
2689
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2620
2690
|
|
2621
2691
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2692
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2693
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2622
2694
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2623
2695
|
|
2624
2696
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2627,9 +2699,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2627
2699
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2628
2700
|
var calculateTransactionFee = (params) => {
|
2629
2701
|
const {
|
2630
|
-
|
2702
|
+
gasPrice,
|
2631
2703
|
rawPayload,
|
2632
|
-
|
2704
|
+
tip,
|
2705
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2633
2706
|
} = params;
|
2634
2707
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2635
2708
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2639,8 +2712,7 @@ var calculateTransactionFee = (params) => {
|
|
2639
2712
|
return {
|
2640
2713
|
fee: bn11(0),
|
2641
2714
|
minFee: bn11(0),
|
2642
|
-
maxFee: bn11(0)
|
2643
|
-
feeFromGasUsed: bn11(0)
|
2715
|
+
maxFee: bn11(0)
|
2644
2716
|
};
|
2645
2717
|
}
|
2646
2718
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2672,7 +2744,6 @@ var calculateTransactionFee = (params) => {
|
|
2672
2744
|
metadataGas,
|
2673
2745
|
txBytesSize: transactionBytes.length
|
2674
2746
|
});
|
2675
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2676
2747
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2677
2748
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2678
2749
|
const maxGas = getMaxGas({
|
@@ -2680,17 +2751,25 @@ var calculateTransactionFee = (params) => {
|
|
2680
2751
|
minGas,
|
2681
2752
|
witnessesLength,
|
2682
2753
|
gasLimit,
|
2683
|
-
witnessLimit
|
2754
|
+
witnessLimit,
|
2755
|
+
maxGasPerTx
|
2756
|
+
});
|
2757
|
+
const minFee = calculateGasFee({
|
2758
|
+
gasPrice,
|
2759
|
+
gas: minGas,
|
2760
|
+
priceFactor: gasPriceFactor,
|
2761
|
+
tip
|
2762
|
+
});
|
2763
|
+
const maxFee = calculateGasFee({
|
2764
|
+
gasPrice,
|
2765
|
+
gas: maxGas,
|
2766
|
+
priceFactor: gasPriceFactor,
|
2767
|
+
tip
|
2684
2768
|
});
|
2685
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2686
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2687
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2688
|
-
const fee = minFee.add(feeFromGasUsed);
|
2689
2769
|
return {
|
2690
|
-
fee,
|
2691
2770
|
minFee,
|
2692
2771
|
maxFee,
|
2693
|
-
|
2772
|
+
fee: maxFee
|
2694
2773
|
};
|
2695
2774
|
};
|
2696
2775
|
|
@@ -2746,7 +2825,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2746
2825
|
|
2747
2826
|
// src/providers/transaction-summary/input.ts
|
2748
2827
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2749
|
-
import { InputType as
|
2828
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2750
2829
|
function getInputsByTypes(inputs, types) {
|
2751
2830
|
return inputs.filter((i) => types.includes(i.type));
|
2752
2831
|
}
|
@@ -2754,16 +2833,16 @@ function getInputsByType(inputs, type) {
|
|
2754
2833
|
return inputs.filter((i) => i.type === type);
|
2755
2834
|
}
|
2756
2835
|
function getInputsCoin(inputs) {
|
2757
|
-
return getInputsByType(inputs,
|
2836
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2758
2837
|
}
|
2759
2838
|
function getInputsMessage(inputs) {
|
2760
|
-
return getInputsByType(inputs,
|
2839
|
+
return getInputsByType(inputs, InputType6.Message);
|
2761
2840
|
}
|
2762
2841
|
function getInputsCoinAndMessage(inputs) {
|
2763
|
-
return getInputsByTypes(inputs, [
|
2842
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2764
2843
|
}
|
2765
2844
|
function getInputsContract(inputs) {
|
2766
|
-
return getInputsByType(inputs,
|
2845
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2767
2846
|
}
|
2768
2847
|
function getInputFromAssetId(inputs, assetId) {
|
2769
2848
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2782,7 +2861,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2782
2861
|
if (!contractInput) {
|
2783
2862
|
return void 0;
|
2784
2863
|
}
|
2785
|
-
if (contractInput.type !==
|
2864
|
+
if (contractInput.type !== InputType6.Contract) {
|
2786
2865
|
throw new FuelError9(
|
2787
2866
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2788
2867
|
`Contract input should be of type 'contract'.`
|
@@ -2791,10 +2870,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2791
2870
|
return contractInput;
|
2792
2871
|
}
|
2793
2872
|
function getInputAccountAddress(input) {
|
2794
|
-
if (input.type ===
|
2873
|
+
if (input.type === InputType6.Coin) {
|
2795
2874
|
return input.owner.toString();
|
2796
2875
|
}
|
2797
|
-
if (input.type ===
|
2876
|
+
if (input.type === InputType6.Message) {
|
2798
2877
|
return input.recipient.toString();
|
2799
2878
|
}
|
2800
2879
|
return "";
|
@@ -3304,7 +3383,9 @@ function assembleTransactionSummary(params) {
|
|
3304
3383
|
gqlTransactionStatus,
|
3305
3384
|
abiMap = {},
|
3306
3385
|
maxInputs,
|
3307
|
-
gasCosts
|
3386
|
+
gasCosts,
|
3387
|
+
maxGasPerTx,
|
3388
|
+
gasPrice
|
3308
3389
|
} = params;
|
3309
3390
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3310
3391
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3318,11 +3399,14 @@ function assembleTransactionSummary(params) {
|
|
3318
3399
|
maxInputs
|
3319
3400
|
});
|
3320
3401
|
const typeName = getTransactionTypeName(transaction.type);
|
3402
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3321
3403
|
const { fee } = calculateTransactionFee({
|
3322
|
-
|
3404
|
+
gasPrice,
|
3323
3405
|
rawPayload,
|
3406
|
+
tip,
|
3324
3407
|
consensusParameters: {
|
3325
3408
|
gasCosts,
|
3409
|
+
maxGasPerTx,
|
3326
3410
|
feeParams: {
|
3327
3411
|
gasPerByte,
|
3328
3412
|
gasPriceFactor
|
@@ -3382,7 +3466,7 @@ var TransactionResponse = class {
|
|
3382
3466
|
/** Current provider */
|
3383
3467
|
provider;
|
3384
3468
|
/** Gas used on the transaction */
|
3385
|
-
gasUsed =
|
3469
|
+
gasUsed = bn15(0);
|
3386
3470
|
/** The graphql Transaction with receipts object. */
|
3387
3471
|
gqlTransaction;
|
3388
3472
|
abis;
|
@@ -3460,8 +3544,13 @@ var TransactionResponse = class {
|
|
3460
3544
|
const decodedTransaction = this.decodeTransaction(
|
3461
3545
|
transaction
|
3462
3546
|
);
|
3463
|
-
|
3464
|
-
|
3547
|
+
let txReceipts = [];
|
3548
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3549
|
+
txReceipts = transaction.status.receipts;
|
3550
|
+
}
|
3551
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3552
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3553
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3465
3554
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3466
3555
|
const transactionSummary = assembleTransactionSummary({
|
3467
3556
|
id: this.id,
|
@@ -3473,7 +3562,9 @@ var TransactionResponse = class {
|
|
3473
3562
|
gasPriceFactor,
|
3474
3563
|
abiMap: contractsAbiMap,
|
3475
3564
|
maxInputs,
|
3476
|
-
gasCosts
|
3565
|
+
gasCosts,
|
3566
|
+
maxGasPerTx,
|
3567
|
+
gasPrice
|
3477
3568
|
});
|
3478
3569
|
return transactionSummary;
|
3479
3570
|
}
|
@@ -3600,30 +3691,29 @@ var processGqlChain = (chain) => {
|
|
3600
3691
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3601
3692
|
return {
|
3602
3693
|
name,
|
3603
|
-
baseChainHeight:
|
3694
|
+
baseChainHeight: bn16(daHeight),
|
3604
3695
|
consensusParameters: {
|
3605
|
-
contractMaxSize:
|
3606
|
-
maxInputs:
|
3607
|
-
maxOutputs:
|
3608
|
-
maxWitnesses:
|
3609
|
-
maxGasPerTx:
|
3610
|
-
maxScriptLength:
|
3611
|
-
maxScriptDataLength:
|
3612
|
-
maxStorageSlots:
|
3613
|
-
maxPredicateLength:
|
3614
|
-
maxPredicateDataLength:
|
3615
|
-
maxGasPerPredicate:
|
3616
|
-
gasPriceFactor:
|
3617
|
-
gasPerByte:
|
3618
|
-
maxMessageDataLength:
|
3619
|
-
chainId:
|
3620
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3696
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3697
|
+
maxInputs: bn16(txParams.maxInputs),
|
3698
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3699
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3700
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3701
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3702
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3703
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3704
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3705
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3706
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3707
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3708
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3709
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3710
|
+
chainId: bn16(consensusParameters.chainId),
|
3621
3711
|
gasCosts
|
3622
3712
|
},
|
3623
3713
|
gasCosts,
|
3624
3714
|
latestBlock: {
|
3625
3715
|
id: latestBlock.id,
|
3626
|
-
height:
|
3716
|
+
height: bn16(latestBlock.height),
|
3627
3717
|
time: latestBlock.header.time,
|
3628
3718
|
transactions: latestBlock.transactions.map((i) => ({
|
3629
3719
|
id: i.id
|
@@ -3717,10 +3807,8 @@ var _Provider = class {
|
|
3717
3807
|
* Returns some helpful parameters related to gas fees.
|
3718
3808
|
*/
|
3719
3809
|
getGasConfig() {
|
3720
|
-
const { minGasPrice } = this.getNode();
|
3721
3810
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3722
3811
|
return {
|
3723
|
-
minGasPrice,
|
3724
3812
|
maxGasPerTx,
|
3725
3813
|
maxGasPerPredicate,
|
3726
3814
|
gasPriceFactor,
|
@@ -3818,7 +3906,7 @@ var _Provider = class {
|
|
3818
3906
|
*/
|
3819
3907
|
async getBlockNumber() {
|
3820
3908
|
const { chain } = await this.operations.getChain();
|
3821
|
-
return
|
3909
|
+
return bn16(chain.latestBlock.height, 10);
|
3822
3910
|
}
|
3823
3911
|
/**
|
3824
3912
|
* Returns the chain information.
|
@@ -3828,13 +3916,11 @@ var _Provider = class {
|
|
3828
3916
|
async fetchNode() {
|
3829
3917
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3830
3918
|
const processedNodeInfo = {
|
3831
|
-
maxDepth:
|
3832
|
-
maxTx:
|
3833
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3919
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3920
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3834
3921
|
nodeVersion: nodeInfo.nodeVersion,
|
3835
3922
|
utxoValidation: nodeInfo.utxoValidation,
|
3836
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3837
|
-
peers: nodeInfo.peers
|
3923
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3838
3924
|
};
|
3839
3925
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3840
3926
|
return processedNodeInfo;
|
@@ -3860,17 +3946,6 @@ var _Provider = class {
|
|
3860
3946
|
} = this.getChain();
|
3861
3947
|
return chainId.toNumber();
|
3862
3948
|
}
|
3863
|
-
/**
|
3864
|
-
* Returns the base asset ID
|
3865
|
-
*
|
3866
|
-
* @returns A promise that resolves to the base asset ID
|
3867
|
-
*/
|
3868
|
-
getBaseAssetId() {
|
3869
|
-
const {
|
3870
|
-
consensusParameters: { baseAssetId }
|
3871
|
-
} = this.getChain();
|
3872
|
-
return baseAssetId;
|
3873
|
-
}
|
3874
3949
|
/**
|
3875
3950
|
* Submits a transaction to the chain to be executed.
|
3876
3951
|
*
|
@@ -3931,14 +4006,13 @@ var _Provider = class {
|
|
3931
4006
|
return this.estimateTxDependencies(transactionRequest);
|
3932
4007
|
}
|
3933
4008
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3934
|
-
const { dryRun:
|
3935
|
-
encodedTransaction,
|
4009
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4010
|
+
encodedTransactions: encodedTransaction,
|
3936
4011
|
utxoValidation: utxoValidation || false
|
3937
4012
|
});
|
3938
|
-
const receipts =
|
3939
|
-
|
3940
|
-
|
3941
|
-
};
|
4013
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4014
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4015
|
+
return { receipts, dryrunStatus: status };
|
3942
4016
|
}
|
3943
4017
|
/**
|
3944
4018
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3964,7 +4038,7 @@ var _Provider = class {
|
|
3964
4038
|
} = response;
|
3965
4039
|
if (inputs) {
|
3966
4040
|
inputs.forEach((input, index) => {
|
3967
|
-
if ("predicateGasUsed" in input &&
|
4041
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3968
4042
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3969
4043
|
}
|
3970
4044
|
});
|
@@ -3977,9 +4051,6 @@ var _Provider = class {
|
|
3977
4051
|
* If there are missing variable outputs,
|
3978
4052
|
* `addVariableOutputs` is called on the transaction.
|
3979
4053
|
*
|
3980
|
-
* @privateRemarks
|
3981
|
-
* TODO: Investigate support for missing contract IDs
|
3982
|
-
* TODO: Add support for missing output messages
|
3983
4054
|
*
|
3984
4055
|
* @param transactionRequest - The transaction request object.
|
3985
4056
|
* @returns A promise.
|
@@ -3992,16 +4063,19 @@ var _Provider = class {
|
|
3992
4063
|
missingContractIds: []
|
3993
4064
|
};
|
3994
4065
|
}
|
3995
|
-
await this.estimatePredicates(transactionRequest);
|
3996
4066
|
let receipts = [];
|
3997
4067
|
const missingContractIds = [];
|
3998
4068
|
let outputVariables = 0;
|
4069
|
+
let dryrunStatus;
|
3999
4070
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4000
|
-
const {
|
4001
|
-
|
4071
|
+
const {
|
4072
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4073
|
+
} = await this.operations.dryRun({
|
4074
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
4002
4075
|
utxoValidation: false
|
4003
4076
|
});
|
4004
|
-
receipts =
|
4077
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4078
|
+
dryrunStatus = status;
|
4005
4079
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4006
4080
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4007
4081
|
if (hasMissingOutputs) {
|
@@ -4011,6 +4085,11 @@ var _Provider = class {
|
|
4011
4085
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4012
4086
|
missingContractIds.push(contractId);
|
4013
4087
|
});
|
4088
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4089
|
+
transactionRequest,
|
4090
|
+
optimizeGas: false
|
4091
|
+
});
|
4092
|
+
transactionRequest.maxFee = maxFee;
|
4014
4093
|
} else {
|
4015
4094
|
break;
|
4016
4095
|
}
|
@@ -4018,7 +4097,133 @@ var _Provider = class {
|
|
4018
4097
|
return {
|
4019
4098
|
receipts,
|
4020
4099
|
outputVariables,
|
4021
|
-
missingContractIds
|
4100
|
+
missingContractIds,
|
4101
|
+
dryrunStatus
|
4102
|
+
};
|
4103
|
+
}
|
4104
|
+
/**
|
4105
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4106
|
+
*
|
4107
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4108
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4109
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4110
|
+
*
|
4111
|
+
* @param transactionRequests - Array of transaction request objects.
|
4112
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4113
|
+
*/
|
4114
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4115
|
+
const results = transactionRequests.map(() => ({
|
4116
|
+
receipts: [],
|
4117
|
+
outputVariables: 0,
|
4118
|
+
missingContractIds: [],
|
4119
|
+
dryrunStatus: void 0
|
4120
|
+
}));
|
4121
|
+
const allRequests = clone3(transactionRequests);
|
4122
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4123
|
+
allRequests.forEach((req, index) => {
|
4124
|
+
if (req.type === TransactionType8.Script) {
|
4125
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4126
|
+
}
|
4127
|
+
});
|
4128
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4129
|
+
let attempt = 0;
|
4130
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4131
|
+
const encodedTransactions = transactionsToProcess.map(
|
4132
|
+
(index) => serializedTransactionsMap.get(index)
|
4133
|
+
);
|
4134
|
+
const dryRunResults = await this.operations.dryRun({
|
4135
|
+
encodedTransactions,
|
4136
|
+
utxoValidation: false
|
4137
|
+
});
|
4138
|
+
const nextRoundTransactions = [];
|
4139
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4140
|
+
const currentResultIndex = transactionsToProcess[i];
|
4141
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4142
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4143
|
+
results[currentResultIndex].dryrunStatus = status;
|
4144
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4145
|
+
results[currentResultIndex].receipts
|
4146
|
+
);
|
4147
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4148
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4149
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4150
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4151
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4152
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4153
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4154
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4155
|
+
});
|
4156
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4157
|
+
transactionRequest: requestToProcess,
|
4158
|
+
optimizeGas: false
|
4159
|
+
});
|
4160
|
+
requestToProcess.maxFee = maxFee;
|
4161
|
+
serializedTransactionsMap.set(
|
4162
|
+
currentResultIndex,
|
4163
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4164
|
+
);
|
4165
|
+
nextRoundTransactions.push(currentResultIndex);
|
4166
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4167
|
+
}
|
4168
|
+
}
|
4169
|
+
transactionsToProcess = nextRoundTransactions;
|
4170
|
+
attempt += 1;
|
4171
|
+
}
|
4172
|
+
return results;
|
4173
|
+
}
|
4174
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4175
|
+
if (estimateTxDependencies) {
|
4176
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4177
|
+
}
|
4178
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4179
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4180
|
+
encodedTransactions,
|
4181
|
+
utxoValidation: utxoValidation || false
|
4182
|
+
});
|
4183
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4184
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4185
|
+
return { receipts, dryrunStatus: status };
|
4186
|
+
});
|
4187
|
+
return results;
|
4188
|
+
}
|
4189
|
+
async estimateTxGasAndFee(params) {
|
4190
|
+
const { transactionRequest, optimizeGas = true } = params;
|
4191
|
+
let { gasPrice } = params;
|
4192
|
+
const chainInfo = this.getChain();
|
4193
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4194
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4195
|
+
if (!gasPrice) {
|
4196
|
+
gasPrice = await this.estimateGasPrice(10);
|
4197
|
+
}
|
4198
|
+
const minFee = calculateGasFee({
|
4199
|
+
gasPrice: bn16(gasPrice),
|
4200
|
+
gas: minGas,
|
4201
|
+
priceFactor: gasPriceFactor,
|
4202
|
+
tip: transactionRequest.tip
|
4203
|
+
}).add(1);
|
4204
|
+
let gasLimit = bn16(0);
|
4205
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
4206
|
+
gasLimit = transactionRequest.gasLimit;
|
4207
|
+
if (!optimizeGas) {
|
4208
|
+
transactionRequest.gasLimit = minGas;
|
4209
|
+
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4210
|
+
transactionRequest.gasLimit = gasLimit;
|
4211
|
+
}
|
4212
|
+
}
|
4213
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4214
|
+
const maxFee = calculateGasFee({
|
4215
|
+
gasPrice: bn16(gasPrice),
|
4216
|
+
gas: maxGas,
|
4217
|
+
priceFactor: gasPriceFactor,
|
4218
|
+
tip: transactionRequest.tip
|
4219
|
+
}).add(1);
|
4220
|
+
return {
|
4221
|
+
minGas,
|
4222
|
+
minFee,
|
4223
|
+
maxGas,
|
4224
|
+
maxFee,
|
4225
|
+
gasPrice,
|
4226
|
+
gasLimit
|
4022
4227
|
};
|
4023
4228
|
}
|
4024
4229
|
/**
|
@@ -4036,15 +4241,17 @@ var _Provider = class {
|
|
4036
4241
|
if (estimateTxDependencies) {
|
4037
4242
|
return this.estimateTxDependencies(transactionRequest);
|
4038
4243
|
}
|
4039
|
-
const
|
4040
|
-
const { dryRun:
|
4041
|
-
|
4244
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4245
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4246
|
+
encodedTransactions,
|
4042
4247
|
utxoValidation: true
|
4043
4248
|
});
|
4044
|
-
const
|
4045
|
-
|
4046
|
-
receipts
|
4047
|
-
|
4249
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4250
|
+
const { id, receipts, status } = dryRunStatus;
|
4251
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4252
|
+
return { id, receipts: processedReceipts, status };
|
4253
|
+
});
|
4254
|
+
return { receipts: callResult[0].receipts };
|
4048
4255
|
}
|
4049
4256
|
/**
|
4050
4257
|
* Returns a transaction cost to enable user
|
@@ -4061,80 +4268,80 @@ var _Provider = class {
|
|
4061
4268
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4062
4269
|
* @returns A promise that resolves to the transaction cost object.
|
4063
4270
|
*/
|
4064
|
-
async getTransactionCost(transactionRequestLike,
|
4065
|
-
estimateTxDependencies = true,
|
4066
|
-
estimatePredicates = true,
|
4067
|
-
resourcesOwner,
|
4068
|
-
signatureCallback
|
4069
|
-
} = {}) {
|
4271
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4070
4272
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4071
|
-
const chainInfo = this.getChain();
|
4072
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4073
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4074
4273
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4075
4274
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4076
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4275
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4077
4276
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4078
|
-
|
4079
|
-
|
4080
|
-
|
4081
|
-
}
|
4082
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4083
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4084
|
-
}
|
4085
|
-
await this.estimatePredicates(txRequestClone);
|
4277
|
+
txRequestClone.maxFee = bn16(0);
|
4278
|
+
if (isScriptTransaction) {
|
4279
|
+
txRequestClone.gasLimit = bn16(0);
|
4086
4280
|
}
|
4087
|
-
if (
|
4088
|
-
|
4281
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4282
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4089
4283
|
}
|
4090
|
-
const
|
4091
|
-
|
4284
|
+
const signedRequest = clone3(txRequestClone);
|
4285
|
+
let addedSignatures = 0;
|
4286
|
+
if (signatureCallback && isScriptTransaction) {
|
4287
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4288
|
+
await signatureCallback(signedRequest);
|
4289
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4290
|
+
}
|
4291
|
+
await this.estimatePredicates(signedRequest);
|
4292
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4293
|
+
transactionRequest: signedRequest,
|
4294
|
+
optimizeGas: false
|
4295
|
+
});
|
4296
|
+
txRequestClone.maxFee = maxFee;
|
4092
4297
|
let receipts = [];
|
4093
4298
|
let missingContractIds = [];
|
4094
4299
|
let outputVariables = 0;
|
4095
|
-
|
4096
|
-
|
4097
|
-
|
4300
|
+
let gasUsed = bn16(0);
|
4301
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4302
|
+
if (isScriptTransaction) {
|
4303
|
+
if (signatureCallback) {
|
4304
|
+
await signatureCallback(txRequestClone);
|
4305
|
+
}
|
4306
|
+
txRequestClone.gasLimit = gasLimit;
|
4098
4307
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4099
4308
|
receipts = result.receipts;
|
4100
4309
|
outputVariables = result.outputVariables;
|
4101
4310
|
missingContractIds = result.missingContractIds;
|
4311
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4312
|
+
txRequestClone.gasLimit = gasUsed;
|
4313
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4314
|
+
transactionRequest: txRequestClone,
|
4315
|
+
gasPrice
|
4316
|
+
}));
|
4102
4317
|
}
|
4103
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4104
|
-
const usedFee = calculatePriceWithFactor(
|
4105
|
-
gasUsed,
|
4106
|
-
gasPrice,
|
4107
|
-
gasPriceFactor
|
4108
|
-
).normalizeZeroToOne();
|
4109
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4110
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4111
4318
|
return {
|
4112
4319
|
requiredQuantities: allQuantities,
|
4113
4320
|
receipts,
|
4114
4321
|
gasUsed,
|
4115
|
-
minGasPrice,
|
4116
4322
|
gasPrice,
|
4117
4323
|
minGas,
|
4118
4324
|
maxGas,
|
4119
|
-
usedFee,
|
4120
4325
|
minFee,
|
4121
4326
|
maxFee,
|
4122
|
-
estimatedInputs: txRequestClone.inputs,
|
4123
4327
|
outputVariables,
|
4124
|
-
missingContractIds
|
4328
|
+
missingContractIds,
|
4329
|
+
addedSignatures,
|
4330
|
+
estimatedPredicates: txRequestClone.inputs
|
4125
4331
|
};
|
4126
4332
|
}
|
4127
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4333
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4128
4334
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4129
4335
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4130
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4336
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4337
|
+
quantitiesToContract
|
4338
|
+
});
|
4131
4339
|
transactionRequest.addResources(
|
4132
4340
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4133
4341
|
);
|
4134
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4135
|
-
|
4136
|
-
|
4137
|
-
);
|
4342
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4343
|
+
quantitiesToContract
|
4344
|
+
});
|
4138
4345
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4139
4346
|
return {
|
4140
4347
|
resources,
|
@@ -4156,11 +4363,10 @@ var _Provider = class {
|
|
4156
4363
|
return coins.map((coin) => ({
|
4157
4364
|
id: coin.utxoId,
|
4158
4365
|
assetId: coin.assetId,
|
4159
|
-
amount:
|
4366
|
+
amount: bn16(coin.amount),
|
4160
4367
|
owner: Address2.fromAddressOrString(coin.owner),
|
4161
|
-
|
4162
|
-
|
4163
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4368
|
+
blockCreated: bn16(coin.blockCreated),
|
4369
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4164
4370
|
}));
|
4165
4371
|
}
|
4166
4372
|
/**
|
@@ -4197,9 +4403,9 @@ var _Provider = class {
|
|
4197
4403
|
switch (coin.__typename) {
|
4198
4404
|
case "MessageCoin":
|
4199
4405
|
return {
|
4200
|
-
amount:
|
4406
|
+
amount: bn16(coin.amount),
|
4201
4407
|
assetId: coin.assetId,
|
4202
|
-
daHeight:
|
4408
|
+
daHeight: bn16(coin.daHeight),
|
4203
4409
|
sender: Address2.fromAddressOrString(coin.sender),
|
4204
4410
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4205
4411
|
nonce: coin.nonce
|
@@ -4207,12 +4413,11 @@ var _Provider = class {
|
|
4207
4413
|
case "Coin":
|
4208
4414
|
return {
|
4209
4415
|
id: coin.utxoId,
|
4210
|
-
amount:
|
4416
|
+
amount: bn16(coin.amount),
|
4211
4417
|
assetId: coin.assetId,
|
4212
4418
|
owner: Address2.fromAddressOrString(coin.owner),
|
4213
|
-
|
4214
|
-
|
4215
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4419
|
+
blockCreated: bn16(coin.blockCreated),
|
4420
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4216
4421
|
};
|
4217
4422
|
default:
|
4218
4423
|
return null;
|
@@ -4229,13 +4434,13 @@ var _Provider = class {
|
|
4229
4434
|
async getBlock(idOrHeight) {
|
4230
4435
|
let variables;
|
4231
4436
|
if (typeof idOrHeight === "number") {
|
4232
|
-
variables = { height:
|
4437
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4233
4438
|
} else if (idOrHeight === "latest") {
|
4234
4439
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4235
4440
|
} else if (idOrHeight.length === 66) {
|
4236
4441
|
variables = { blockId: idOrHeight };
|
4237
4442
|
} else {
|
4238
|
-
variables = { blockId:
|
4443
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4239
4444
|
}
|
4240
4445
|
const { block } = await this.operations.getBlock(variables);
|
4241
4446
|
if (!block) {
|
@@ -4243,7 +4448,7 @@ var _Provider = class {
|
|
4243
4448
|
}
|
4244
4449
|
return {
|
4245
4450
|
id: block.id,
|
4246
|
-
height:
|
4451
|
+
height: bn16(block.height),
|
4247
4452
|
time: block.header.time,
|
4248
4453
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4249
4454
|
};
|
@@ -4258,7 +4463,7 @@ var _Provider = class {
|
|
4258
4463
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4259
4464
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4260
4465
|
id: block.id,
|
4261
|
-
height:
|
4466
|
+
height: bn16(block.height),
|
4262
4467
|
time: block.header.time,
|
4263
4468
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4264
4469
|
}));
|
@@ -4273,7 +4478,7 @@ var _Provider = class {
|
|
4273
4478
|
async getBlockWithTransactions(idOrHeight) {
|
4274
4479
|
let variables;
|
4275
4480
|
if (typeof idOrHeight === "number") {
|
4276
|
-
variables = { blockHeight:
|
4481
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4277
4482
|
} else if (idOrHeight === "latest") {
|
4278
4483
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4279
4484
|
} else {
|
@@ -4285,7 +4490,7 @@ var _Provider = class {
|
|
4285
4490
|
}
|
4286
4491
|
return {
|
4287
4492
|
id: block.id,
|
4288
|
-
height:
|
4493
|
+
height: bn16(block.height, 10),
|
4289
4494
|
time: block.header.time,
|
4290
4495
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4291
4496
|
transactions: block.transactions.map(
|
@@ -4334,7 +4539,7 @@ var _Provider = class {
|
|
4334
4539
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4335
4540
|
asset: hexlify12(assetId)
|
4336
4541
|
});
|
4337
|
-
return
|
4542
|
+
return bn16(contractBalance.amount, 10);
|
4338
4543
|
}
|
4339
4544
|
/**
|
4340
4545
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4348,7 +4553,7 @@ var _Provider = class {
|
|
4348
4553
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4349
4554
|
assetId: hexlify12(assetId)
|
4350
4555
|
});
|
4351
|
-
return
|
4556
|
+
return bn16(balance.amount, 10);
|
4352
4557
|
}
|
4353
4558
|
/**
|
4354
4559
|
* Returns balances for the given owner.
|
@@ -4366,7 +4571,7 @@ var _Provider = class {
|
|
4366
4571
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4367
4572
|
return balances.map((balance) => ({
|
4368
4573
|
assetId: balance.assetId,
|
4369
|
-
amount:
|
4574
|
+
amount: bn16(balance.amount)
|
4370
4575
|
}));
|
4371
4576
|
}
|
4372
4577
|
/**
|
@@ -4388,15 +4593,15 @@ var _Provider = class {
|
|
4388
4593
|
sender: message.sender,
|
4389
4594
|
recipient: message.recipient,
|
4390
4595
|
nonce: message.nonce,
|
4391
|
-
amount:
|
4596
|
+
amount: bn16(message.amount),
|
4392
4597
|
data: message.data
|
4393
4598
|
}),
|
4394
4599
|
sender: Address2.fromAddressOrString(message.sender),
|
4395
4600
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4396
4601
|
nonce: message.nonce,
|
4397
|
-
amount:
|
4602
|
+
amount: bn16(message.amount),
|
4398
4603
|
data: InputMessageCoder.decodeData(message.data),
|
4399
|
-
daHeight:
|
4604
|
+
daHeight: bn16(message.daHeight)
|
4400
4605
|
}));
|
4401
4606
|
}
|
4402
4607
|
/**
|
@@ -4449,44 +4654,52 @@ var _Provider = class {
|
|
4449
4654
|
} = result.messageProof;
|
4450
4655
|
return {
|
4451
4656
|
messageProof: {
|
4452
|
-
proofIndex:
|
4657
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4453
4658
|
proofSet: messageProof.proofSet
|
4454
4659
|
},
|
4455
4660
|
blockProof: {
|
4456
|
-
proofIndex:
|
4661
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4457
4662
|
proofSet: blockProof.proofSet
|
4458
4663
|
},
|
4459
4664
|
messageBlockHeader: {
|
4460
4665
|
id: messageBlockHeader.id,
|
4461
|
-
daHeight:
|
4462
|
-
transactionsCount:
|
4666
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4667
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4463
4668
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4464
|
-
height:
|
4669
|
+
height: bn16(messageBlockHeader.height),
|
4465
4670
|
prevRoot: messageBlockHeader.prevRoot,
|
4466
4671
|
time: messageBlockHeader.time,
|
4467
4672
|
applicationHash: messageBlockHeader.applicationHash,
|
4468
|
-
|
4469
|
-
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4673
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount)
|
4470
4674
|
},
|
4471
4675
|
commitBlockHeader: {
|
4472
4676
|
id: commitBlockHeader.id,
|
4473
|
-
daHeight:
|
4474
|
-
transactionsCount:
|
4677
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4678
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4475
4679
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4476
|
-
height:
|
4680
|
+
height: bn16(commitBlockHeader.height),
|
4477
4681
|
prevRoot: commitBlockHeader.prevRoot,
|
4478
4682
|
time: commitBlockHeader.time,
|
4479
4683
|
applicationHash: commitBlockHeader.applicationHash,
|
4480
|
-
|
4481
|
-
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4684
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount)
|
4482
4685
|
},
|
4483
4686
|
sender: Address2.fromAddressOrString(sender),
|
4484
4687
|
recipient: Address2.fromAddressOrString(recipient),
|
4485
4688
|
nonce,
|
4486
|
-
amount:
|
4689
|
+
amount: bn16(amount),
|
4487
4690
|
data
|
4488
4691
|
};
|
4489
4692
|
}
|
4693
|
+
async getLatestGasPrice() {
|
4694
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4695
|
+
return bn16(latestGasPrice.gasPrice);
|
4696
|
+
}
|
4697
|
+
async estimateGasPrice(blockHorizon) {
|
4698
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4699
|
+
blockHorizon: String(blockHorizon)
|
4700
|
+
});
|
4701
|
+
return bn16(estimateGasPrice.gasPrice);
|
4702
|
+
}
|
4490
4703
|
/**
|
4491
4704
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4492
4705
|
*
|
@@ -4506,10 +4719,10 @@ var _Provider = class {
|
|
4506
4719
|
*/
|
4507
4720
|
async produceBlocks(amount, startTime) {
|
4508
4721
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4509
|
-
blocksToProduce:
|
4722
|
+
blocksToProduce: bn16(amount).toString(10),
|
4510
4723
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4511
4724
|
});
|
4512
|
-
return
|
4725
|
+
return bn16(latestBlockHeight);
|
4513
4726
|
}
|
4514
4727
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4515
4728
|
async getTransactionResponse(transactionId) {
|
@@ -4523,7 +4736,7 @@ cacheInputs_fn = function(inputs) {
|
|
4523
4736
|
return;
|
4524
4737
|
}
|
4525
4738
|
inputs.forEach((input) => {
|
4526
|
-
if (input.type ===
|
4739
|
+
if (input.type === InputType7.Coin) {
|
4527
4740
|
this.cache?.set(input.id);
|
4528
4741
|
}
|
4529
4742
|
});
|
@@ -4533,7 +4746,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4533
4746
|
|
4534
4747
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4535
4748
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4536
|
-
import { bn as
|
4749
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4537
4750
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4538
4751
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4539
4752
|
async function getTransactionSummary(params) {
|
@@ -4551,21 +4764,28 @@ async function getTransactionSummary(params) {
|
|
4551
4764
|
arrayify12(gqlTransaction.rawPayload),
|
4552
4765
|
0
|
4553
4766
|
);
|
4554
|
-
|
4767
|
+
let txReceipts = [];
|
4768
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4769
|
+
txReceipts = gqlTransaction.status.receipts;
|
4770
|
+
}
|
4771
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4555
4772
|
const {
|
4556
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4773
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4557
4774
|
} = provider.getChain();
|
4775
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4558
4776
|
const transactionInfo = assembleTransactionSummary({
|
4559
4777
|
id: gqlTransaction.id,
|
4560
4778
|
receipts,
|
4561
4779
|
transaction: decodedTransaction,
|
4562
4780
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4563
4781
|
gqlTransactionStatus: gqlTransaction.status,
|
4564
|
-
gasPerByte:
|
4565
|
-
gasPriceFactor:
|
4782
|
+
gasPerByte: bn17(gasPerByte),
|
4783
|
+
gasPriceFactor: bn17(gasPriceFactor),
|
4566
4784
|
abiMap,
|
4567
4785
|
maxInputs,
|
4568
|
-
gasCosts
|
4786
|
+
gasCosts,
|
4787
|
+
maxGasPerTx,
|
4788
|
+
gasPrice
|
4569
4789
|
});
|
4570
4790
|
return {
|
4571
4791
|
gqlTransaction,
|
@@ -4575,10 +4795,11 @@ async function getTransactionSummary(params) {
|
|
4575
4795
|
async function getTransactionSummaryFromRequest(params) {
|
4576
4796
|
const { provider, transactionRequest, abiMap } = params;
|
4577
4797
|
const { receipts } = await provider.call(transactionRequest);
|
4578
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4798
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4579
4799
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4580
4800
|
const transaction = transactionRequest.toTransaction();
|
4581
4801
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4802
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4582
4803
|
const transactionSummary = assembleTransactionSummary({
|
4583
4804
|
receipts,
|
4584
4805
|
transaction,
|
@@ -4587,7 +4808,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4587
4808
|
gasPerByte,
|
4588
4809
|
gasPriceFactor,
|
4589
4810
|
maxInputs,
|
4590
|
-
gasCosts
|
4811
|
+
gasCosts,
|
4812
|
+
maxGasPerTx,
|
4813
|
+
gasPrice
|
4591
4814
|
});
|
4592
4815
|
return transactionSummary;
|
4593
4816
|
}
|
@@ -4596,13 +4819,18 @@ async function getTransactionsSummaries(params) {
|
|
4596
4819
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4597
4820
|
const { edges, pageInfo } = transactionsByOwner;
|
4598
4821
|
const {
|
4599
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4822
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4600
4823
|
} = provider.getChain();
|
4824
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4601
4825
|
const transactions = edges.map((edge) => {
|
4602
4826
|
const { node: gqlTransaction } = edge;
|
4603
|
-
const { id, rawPayload,
|
4827
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4604
4828
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4605
|
-
|
4829
|
+
let txReceipts = [];
|
4830
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4831
|
+
txReceipts = gqlTransaction.status.receipts;
|
4832
|
+
}
|
4833
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4606
4834
|
const transactionSummary = assembleTransactionSummary({
|
4607
4835
|
id,
|
4608
4836
|
receipts,
|
@@ -4613,7 +4841,9 @@ async function getTransactionsSummaries(params) {
|
|
4613
4841
|
gasPerByte,
|
4614
4842
|
gasPriceFactor,
|
4615
4843
|
maxInputs,
|
4616
|
-
gasCosts
|
4844
|
+
gasCosts,
|
4845
|
+
maxGasPerTx,
|
4846
|
+
gasPrice
|
4617
4847
|
});
|
4618
4848
|
const output = {
|
4619
4849
|
gqlTransaction,
|
@@ -4907,9 +5137,8 @@ var Account = class extends AbstractAccount {
|
|
4907
5137
|
* @param assetId - The asset ID to check the balance for.
|
4908
5138
|
* @returns A promise that resolves to the balance amount.
|
4909
5139
|
*/
|
4910
|
-
async getBalance(assetId) {
|
4911
|
-
const
|
4912
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5140
|
+
async getBalance(assetId = BaseAssetId3) {
|
5141
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4913
5142
|
return amount;
|
4914
5143
|
}
|
4915
5144
|
/**
|
@@ -4946,37 +5175,33 @@ var Account = class extends AbstractAccount {
|
|
4946
5175
|
* @param fee - The estimated transaction fee.
|
4947
5176
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4948
5177
|
*/
|
4949
|
-
async fund(request,
|
4950
|
-
const
|
4951
|
-
const
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
5178
|
+
async fund(request, params) {
|
5179
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5180
|
+
const txRequest = request;
|
5181
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5182
|
+
amount: bn18(fee),
|
5183
|
+
assetId: BaseAssetId3,
|
5184
|
+
coinQuantities: requiredQuantities
|
4955
5185
|
});
|
4956
5186
|
const quantitiesDict = {};
|
4957
|
-
|
5187
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4958
5188
|
quantitiesDict[assetId] = {
|
4959
5189
|
required: amount,
|
4960
|
-
owned:
|
5190
|
+
owned: bn18(0)
|
4961
5191
|
};
|
4962
5192
|
});
|
4963
|
-
|
4964
|
-
const cachedMessages = [];
|
4965
|
-
const owner = this.address.toB256();
|
4966
|
-
request.inputs.forEach((input) => {
|
5193
|
+
txRequest.inputs.forEach((input) => {
|
4967
5194
|
const isResource = "amount" in input;
|
4968
5195
|
if (isResource) {
|
4969
5196
|
const isCoin2 = "owner" in input;
|
4970
5197
|
if (isCoin2) {
|
4971
5198
|
const assetId = String(input.assetId);
|
4972
|
-
if (
|
4973
|
-
const amount =
|
5199
|
+
if (quantitiesDict[assetId]) {
|
5200
|
+
const amount = bn18(input.amount);
|
4974
5201
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4975
|
-
cachedUtxos.push(input.id);
|
4976
5202
|
}
|
4977
|
-
} else if (input.
|
4978
|
-
quantitiesDict[
|
4979
|
-
cachedMessages.push(input.nonce);
|
5203
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
5204
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4980
5205
|
}
|
4981
5206
|
}
|
4982
5207
|
});
|
@@ -4991,12 +5216,23 @@ var Account = class extends AbstractAccount {
|
|
4991
5216
|
});
|
4992
5217
|
const needsToBeFunded = missingQuantities.length;
|
4993
5218
|
if (needsToBeFunded) {
|
4994
|
-
const
|
4995
|
-
|
4996
|
-
|
4997
|
-
|
4998
|
-
|
5219
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5220
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5221
|
+
txRequest.addResources(resources);
|
5222
|
+
}
|
5223
|
+
txRequest.shiftPredicateData();
|
5224
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5225
|
+
const requestToBeReEstimate = clone4(txRequest);
|
5226
|
+
if (addedSignatures) {
|
5227
|
+
Array.from({ length: addedSignatures }).forEach(
|
5228
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5229
|
+
);
|
4999
5230
|
}
|
5231
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5232
|
+
transactionRequest: requestToBeReEstimate
|
5233
|
+
});
|
5234
|
+
txRequest.maxFee = maxFee;
|
5235
|
+
return txRequest;
|
5000
5236
|
}
|
5001
5237
|
/**
|
5002
5238
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5004,29 +5240,25 @@ var Account = class extends AbstractAccount {
|
|
5004
5240
|
* @param destination - The address of the destination.
|
5005
5241
|
* @param amount - The amount of coins to transfer.
|
5006
5242
|
* @param assetId - The asset ID of the coins to transfer.
|
5007
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5243
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5008
5244
|
* @returns A promise that resolves to the prepared transaction request.
|
5009
5245
|
*/
|
5010
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5011
|
-
const
|
5012
|
-
|
5013
|
-
const
|
5014
|
-
const request = new ScriptTransactionRequest(params);
|
5015
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5016
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5246
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5247
|
+
const request = new ScriptTransactionRequest(txParams);
|
5248
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5249
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5017
5250
|
estimateTxDependencies: true,
|
5018
5251
|
resourcesOwner: this
|
5019
5252
|
});
|
5020
|
-
|
5021
|
-
|
5022
|
-
|
5023
|
-
|
5024
|
-
|
5025
|
-
|
5026
|
-
|
5027
|
-
|
5028
|
-
await this.fund(request,
|
5029
|
-
request.updatePredicateInputs(estimatedInputs);
|
5253
|
+
if ("gasLimit" in txParams) {
|
5254
|
+
this.validateGas({
|
5255
|
+
gasUsed: txCost.gasUsed,
|
5256
|
+
gasLimit: request.gasLimit
|
5257
|
+
});
|
5258
|
+
}
|
5259
|
+
request.gasLimit = txCost.gasUsed;
|
5260
|
+
request.maxFee = txCost.maxFee;
|
5261
|
+
await this.fund(request, txCost);
|
5030
5262
|
return request;
|
5031
5263
|
}
|
5032
5264
|
/**
|
@@ -5038,15 +5270,14 @@ var Account = class extends AbstractAccount {
|
|
5038
5270
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5039
5271
|
* @returns A promise that resolves to the transaction response.
|
5040
5272
|
*/
|
5041
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5042
|
-
if (
|
5273
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5274
|
+
if (bn18(amount).lte(0)) {
|
5043
5275
|
throw new FuelError15(
|
5044
5276
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5045
5277
|
"Transfer amount must be a positive number."
|
5046
5278
|
);
|
5047
5279
|
}
|
5048
|
-
const
|
5049
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5280
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5050
5281
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5051
5282
|
}
|
5052
5283
|
/**
|
@@ -5058,40 +5289,38 @@ var Account = class extends AbstractAccount {
|
|
5058
5289
|
* @param txParams - The optional transaction parameters.
|
5059
5290
|
* @returns A promise that resolves to the transaction response.
|
5060
5291
|
*/
|
5061
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5062
|
-
if (
|
5292
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5293
|
+
if (bn18(amount).lte(0)) {
|
5063
5294
|
throw new FuelError15(
|
5064
5295
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5065
5296
|
"Transfer amount must be a positive number."
|
5066
5297
|
);
|
5067
5298
|
}
|
5068
5299
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5069
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5070
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5071
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5072
5300
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5073
5301
|
hexlifiedContractId: contractAddress.toB256(),
|
5074
|
-
amountToTransfer:
|
5075
|
-
assetId
|
5302
|
+
amountToTransfer: bn18(amount),
|
5303
|
+
assetId
|
5076
5304
|
});
|
5077
5305
|
const request = new ScriptTransactionRequest({
|
5078
|
-
...
|
5306
|
+
...txParams,
|
5079
5307
|
script,
|
5080
5308
|
scriptData
|
5081
5309
|
});
|
5082
5310
|
request.addContractInputAndOutput(contractAddress);
|
5083
|
-
const
|
5084
|
-
|
5085
|
-
[{ amount:
|
5086
|
-
);
|
5087
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5088
|
-
this.validateGas({
|
5089
|
-
gasUsed,
|
5090
|
-
gasPrice: request.gasPrice,
|
5091
|
-
gasLimit: request.gasLimit,
|
5092
|
-
minGasPrice
|
5311
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5312
|
+
resourcesOwner: this,
|
5313
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
5093
5314
|
});
|
5094
|
-
|
5315
|
+
if (txParams.gasLimit) {
|
5316
|
+
this.validateGas({
|
5317
|
+
gasUsed: txCost.gasUsed,
|
5318
|
+
gasLimit: request.gasLimit
|
5319
|
+
});
|
5320
|
+
}
|
5321
|
+
request.gasLimit = txCost.gasUsed;
|
5322
|
+
request.maxFee = txCost.maxFee;
|
5323
|
+
await this.fund(request, txCost);
|
5095
5324
|
return this.sendTransaction(request);
|
5096
5325
|
}
|
5097
5326
|
/**
|
@@ -5103,35 +5332,31 @@ var Account = class extends AbstractAccount {
|
|
5103
5332
|
* @returns A promise that resolves to the transaction response.
|
5104
5333
|
*/
|
5105
5334
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5106
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5107
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5108
5335
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5109
5336
|
const recipientDataArray = arrayify14(
|
5110
5337
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5111
5338
|
);
|
5112
5339
|
const amountDataArray = arrayify14(
|
5113
|
-
"0x".concat(
|
5340
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
5114
5341
|
);
|
5115
5342
|
const script = new Uint8Array([
|
5116
5343
|
...arrayify14(withdrawScript.bytes),
|
5117
5344
|
...recipientDataArray,
|
5118
5345
|
...amountDataArray
|
5119
5346
|
]);
|
5120
|
-
const params = { script,
|
5347
|
+
const params = { script, ...txParams };
|
5121
5348
|
const request = new ScriptTransactionRequest(params);
|
5122
|
-
const
|
5123
|
-
const
|
5124
|
-
|
5125
|
-
|
5126
|
-
|
5127
|
-
|
5128
|
-
|
5129
|
-
|
5130
|
-
|
5131
|
-
|
5132
|
-
|
5133
|
-
});
|
5134
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5349
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5350
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5351
|
+
if (txParams.gasLimit) {
|
5352
|
+
this.validateGas({
|
5353
|
+
gasUsed: txCost.gasUsed,
|
5354
|
+
gasLimit: request.gasLimit
|
5355
|
+
});
|
5356
|
+
}
|
5357
|
+
request.maxFee = txCost.maxFee;
|
5358
|
+
request.gasLimit = txCost.gasUsed;
|
5359
|
+
await this.fund(request, txCost);
|
5135
5360
|
return this.sendTransaction(request);
|
5136
5361
|
}
|
5137
5362
|
async signMessage(message) {
|
@@ -5189,18 +5414,7 @@ var Account = class extends AbstractAccount {
|
|
5189
5414
|
}
|
5190
5415
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5191
5416
|
}
|
5192
|
-
validateGas({
|
5193
|
-
gasUsed,
|
5194
|
-
gasPrice,
|
5195
|
-
gasLimit,
|
5196
|
-
minGasPrice
|
5197
|
-
}) {
|
5198
|
-
if (minGasPrice.gt(gasPrice)) {
|
5199
|
-
throw new FuelError15(
|
5200
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5201
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5202
|
-
);
|
5203
|
-
}
|
5417
|
+
validateGas({ gasUsed, gasLimit }) {
|
5204
5418
|
if (gasUsed.gt(gasLimit)) {
|
5205
5419
|
throw new FuelError15(
|
5206
5420
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5216,7 +5430,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5216
5430
|
|
5217
5431
|
// src/signer/signer.ts
|
5218
5432
|
import { Address as Address4 } from "@fuel-ts/address";
|
5219
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5433
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
5220
5434
|
import { hash } from "@fuel-ts/hasher";
|
5221
5435
|
import { toBytes } from "@fuel-ts/math";
|
5222
5436
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5309,7 +5523,7 @@ var Signer = class {
|
|
5309
5523
|
* @returns random 32-byte hashed
|
5310
5524
|
*/
|
5311
5525
|
static generatePrivateKey(entropy) {
|
5312
|
-
return entropy ? hash(concat3([
|
5526
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5313
5527
|
}
|
5314
5528
|
/**
|
5315
5529
|
* Extended publicKey from a compact publicKey
|
@@ -5328,7 +5542,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5328
5542
|
import {
|
5329
5543
|
bufferFromString,
|
5330
5544
|
keccak256,
|
5331
|
-
randomBytes as
|
5545
|
+
randomBytes as randomBytes3,
|
5332
5546
|
scrypt,
|
5333
5547
|
stringFromBuffer,
|
5334
5548
|
decryptJsonWalletData,
|
@@ -5351,7 +5565,7 @@ var removeHexPrefix = (hexString) => {
|
|
5351
5565
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5352
5566
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5353
5567
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5354
|
-
const salt =
|
5568
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5355
5569
|
const key = scrypt({
|
5356
5570
|
password: bufferFromString(password),
|
5357
5571
|
salt,
|
@@ -5360,7 +5574,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5360
5574
|
r: DEFAULT_KDF_PARAMS_R,
|
5361
5575
|
p: DEFAULT_KDF_PARAMS_P
|
5362
5576
|
});
|
5363
|
-
const iv =
|
5577
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5364
5578
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5365
5579
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5366
5580
|
const macHashUint8Array = keccak256(data);
|
@@ -5496,7 +5710,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5496
5710
|
* @param transactionRequestLike - The transaction request to send.
|
5497
5711
|
* @returns A promise that resolves to the TransactionResponse object.
|
5498
5712
|
*/
|
5499
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5713
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5500
5714
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5501
5715
|
if (estimateTxDependencies) {
|
5502
5716
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5537,12 +5751,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5537
5751
|
// src/hdwallet/hdwallet.ts
|
5538
5752
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5539
5753
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5540
|
-
import { bn as
|
5754
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5541
5755
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5542
5756
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5543
5757
|
|
5544
5758
|
// src/mnemonic/mnemonic.ts
|
5545
|
-
import { randomBytes as
|
5759
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5546
5760
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5547
5761
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5548
5762
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7903,7 +8117,7 @@ var Mnemonic = class {
|
|
7903
8117
|
* @returns A randomly generated mnemonic
|
7904
8118
|
*/
|
7905
8119
|
static generate(size = 32, extraEntropy = "") {
|
7906
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
8120
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7907
8121
|
return Mnemonic.entropyToMnemonic(entropy);
|
7908
8122
|
}
|
7909
8123
|
};
|
@@ -8009,7 +8223,7 @@ var HDWallet = class {
|
|
8009
8223
|
const IR = bytes.slice(32);
|
8010
8224
|
if (privateKey) {
|
8011
8225
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8012
|
-
const ki =
|
8226
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
8013
8227
|
return new HDWallet({
|
8014
8228
|
privateKey: ki,
|
8015
8229
|
chainCode: IR,
|
@@ -8696,8 +8910,9 @@ import {
|
|
8696
8910
|
SCRIPT_FIXED_SIZE
|
8697
8911
|
} from "@fuel-ts/abi-coder";
|
8698
8912
|
import { Address as Address9 } from "@fuel-ts/address";
|
8913
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8699
8914
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8700
|
-
import { ByteArrayCoder, InputType as
|
8915
|
+
import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
|
8701
8916
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8702
8917
|
|
8703
8918
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8746,6 +8961,7 @@ var Predicate = class extends Account {
|
|
8746
8961
|
this.interface = predicateInterface;
|
8747
8962
|
if (inputData !== void 0 && inputData.length > 0) {
|
8748
8963
|
this.predicateData = inputData;
|
8964
|
+
this.predicateDataBytes = this.getPredicateData(0);
|
8749
8965
|
}
|
8750
8966
|
}
|
8751
8967
|
/**
|
@@ -8758,9 +8974,9 @@ var Predicate = class extends Account {
|
|
8758
8974
|
const request = transactionRequestify(transactionRequestLike);
|
8759
8975
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8760
8976
|
request.inputs?.forEach((input) => {
|
8761
|
-
if (input.type ===
|
8762
|
-
input.predicate = this.bytes;
|
8763
|
-
input.predicateData = this.getPredicateData(policies.length);
|
8977
|
+
if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
8978
|
+
input.predicate = hexlify19(this.bytes);
|
8979
|
+
input.predicateData = hexlify19(this.getPredicateData(policies.length));
|
8764
8980
|
}
|
8765
8981
|
});
|
8766
8982
|
return request;
|
@@ -8774,10 +8990,8 @@ var Predicate = class extends Account {
|
|
8774
8990
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8775
8991
|
* @returns A promise that resolves to the prepared transaction request.
|
8776
8992
|
*/
|
8777
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8778
|
-
|
8779
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8780
|
-
return this.populateTransactionPredicateData(request);
|
8993
|
+
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8994
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8781
8995
|
}
|
8782
8996
|
/**
|
8783
8997
|
* Sends a transaction with the populated predicate data.
|
@@ -8785,9 +8999,9 @@ var Predicate = class extends Account {
|
|
8785
8999
|
* @param transactionRequestLike - The transaction request-like object.
|
8786
9000
|
* @returns A promise that resolves to the transaction response.
|
8787
9001
|
*/
|
8788
|
-
sendTransaction(transactionRequestLike
|
8789
|
-
const transactionRequest =
|
8790
|
-
return super.sendTransaction(transactionRequest,
|
9002
|
+
sendTransaction(transactionRequestLike) {
|
9003
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9004
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8791
9005
|
}
|
8792
9006
|
/**
|
8793
9007
|
* Simulates a transaction with the populated predicate data.
|
@@ -8796,8 +9010,8 @@ var Predicate = class extends Account {
|
|
8796
9010
|
* @returns A promise that resolves to the call result.
|
8797
9011
|
*/
|
8798
9012
|
simulateTransaction(transactionRequestLike) {
|
8799
|
-
const transactionRequest =
|
8800
|
-
return super.simulateTransaction(transactionRequest);
|
9013
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9014
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8801
9015
|
}
|
8802
9016
|
getPredicateData(policiesLength) {
|
8803
9017
|
if (!this.predicateData.length) {
|
@@ -8843,6 +9057,26 @@ var Predicate = class extends Account {
|
|
8843
9057
|
predicateInterface: abiInterface
|
8844
9058
|
};
|
8845
9059
|
}
|
9060
|
+
/**
|
9061
|
+
* Retrieves resources satisfying the spend query for the account.
|
9062
|
+
*
|
9063
|
+
* @param quantities - IDs of coins to exclude.
|
9064
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9065
|
+
* @returns A promise that resolves to an array of Resources.
|
9066
|
+
*/
|
9067
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9068
|
+
const resources = await this.provider.getResourcesToSpend(
|
9069
|
+
this.address,
|
9070
|
+
quantities,
|
9071
|
+
excludedIds
|
9072
|
+
);
|
9073
|
+
return resources.map((resource) => ({
|
9074
|
+
...resource,
|
9075
|
+
predicate: hexlify19(this.bytes),
|
9076
|
+
predicateData: hexlify19(this.predicateDataBytes),
|
9077
|
+
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9078
|
+
}));
|
9079
|
+
}
|
8846
9080
|
/**
|
8847
9081
|
* Sets the configurable constants for the predicate.
|
8848
9082
|
*
|
@@ -9591,7 +9825,7 @@ export {
|
|
9591
9825
|
WalletLocked,
|
9592
9826
|
WalletManager,
|
9593
9827
|
WalletUnlocked,
|
9594
|
-
|
9828
|
+
addAmountToCoinQuantities,
|
9595
9829
|
addOperation,
|
9596
9830
|
assemblePanicError,
|
9597
9831
|
assembleReceiptByType,
|
@@ -9600,9 +9834,10 @@ export {
|
|
9600
9834
|
assets,
|
9601
9835
|
buildBlockExplorerUrl,
|
9602
9836
|
cacheFor,
|
9837
|
+
cacheTxInputsFromOwner,
|
9838
|
+
calculateGasFee,
|
9603
9839
|
calculateMetadataGasForTxCreate,
|
9604
9840
|
calculateMetadataGasForTxScript,
|
9605
|
-
calculatePriceWithFactor,
|
9606
9841
|
calculateTransactionFee,
|
9607
9842
|
coinQuantityfy,
|
9608
9843
|
deferPromise,
|