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