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