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