@fuel-ts/account 0.0.0-rc-2021-20240411141803 → 0.0.0-rc-1976-20240411153008
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +625 -876
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +619 -856
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +462 -698
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +328 -894
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -45
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +29 -9
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1128 -1593
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +618 -834
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +476 -692
- 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/test-utils.mjs
CHANGED
@@ -24,38 +24,35 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
29
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
31
30
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
-
import { clone as clone4 } from "ramda";
|
33
31
|
|
34
32
|
// src/providers/coin-quantity.ts
|
35
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
36
33
|
import { bn } from "@fuel-ts/math";
|
37
34
|
import { hexlify } from "@fuel-ts/utils";
|
38
35
|
var coinQuantityfy = (coinQuantityLike) => {
|
39
36
|
let assetId;
|
40
37
|
let amount;
|
41
|
-
let
|
38
|
+
let max2;
|
42
39
|
if (Array.isArray(coinQuantityLike)) {
|
43
40
|
amount = coinQuantityLike[0];
|
44
|
-
assetId = coinQuantityLike[1]
|
45
|
-
|
41
|
+
assetId = coinQuantityLike[1];
|
42
|
+
max2 = coinQuantityLike[2];
|
46
43
|
} else {
|
47
44
|
amount = coinQuantityLike.amount;
|
48
|
-
assetId = coinQuantityLike.assetId
|
49
|
-
|
45
|
+
assetId = coinQuantityLike.assetId;
|
46
|
+
max2 = coinQuantityLike.max ?? void 0;
|
50
47
|
}
|
51
48
|
const bnAmount = bn(amount);
|
52
49
|
return {
|
53
50
|
assetId: hexlify(assetId),
|
54
51
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
55
|
-
max:
|
52
|
+
max: max2 ? bn(max2) : void 0
|
56
53
|
};
|
57
54
|
};
|
58
|
-
var
|
55
|
+
var addAmountToAsset = (params) => {
|
59
56
|
const { amount, assetId } = params;
|
60
57
|
const coinQuantities = [...params.coinQuantities];
|
61
58
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -70,9 +67,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
70
67
|
// src/providers/provider.ts
|
71
68
|
import { Address as Address2 } from "@fuel-ts/address";
|
72
69
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
73
|
-
import { BN, bn as
|
70
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
74
71
|
import {
|
75
|
-
InputType as
|
72
|
+
InputType as InputType6,
|
76
73
|
TransactionType as TransactionType8,
|
77
74
|
InputMessageCoder,
|
78
75
|
TransactionCoder as TransactionCoder5
|
@@ -88,10 +85,14 @@ import { clone as clone3 } from "ramda";
|
|
88
85
|
import gql from "graphql-tag";
|
89
86
|
var ReceiptFragmentFragmentDoc = gql`
|
90
87
|
fragment receiptFragment on Receipt {
|
91
|
-
|
88
|
+
contract {
|
89
|
+
id
|
90
|
+
}
|
92
91
|
pc
|
93
92
|
is
|
94
|
-
to
|
93
|
+
to {
|
94
|
+
id
|
95
|
+
}
|
95
96
|
toAddress
|
96
97
|
amount
|
97
98
|
assetId
|
@@ -129,16 +130,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
129
130
|
id
|
130
131
|
}
|
131
132
|
time
|
132
|
-
receipts {
|
133
|
-
...receiptFragment
|
134
|
-
}
|
135
133
|
programState {
|
136
134
|
returnType
|
137
135
|
data
|
138
136
|
}
|
139
|
-
receipts {
|
140
|
-
...receiptFragment
|
141
|
-
}
|
142
137
|
}
|
143
138
|
... on FailureStatus {
|
144
139
|
block {
|
@@ -146,24 +141,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
146
141
|
}
|
147
142
|
time
|
148
143
|
reason
|
149
|
-
receipts {
|
150
|
-
...receiptFragment
|
151
|
-
}
|
152
144
|
}
|
153
145
|
... on SqueezedOutStatus {
|
154
146
|
reason
|
155
147
|
}
|
156
148
|
}
|
157
|
-
|
149
|
+
`;
|
158
150
|
var TransactionFragmentFragmentDoc = gql`
|
159
151
|
fragment transactionFragment on Transaction {
|
160
152
|
id
|
161
153
|
rawPayload
|
154
|
+
gasPrice
|
155
|
+
receipts {
|
156
|
+
...receiptFragment
|
157
|
+
}
|
162
158
|
status {
|
163
159
|
...transactionStatusFragment
|
164
160
|
}
|
165
161
|
}
|
166
|
-
${
|
162
|
+
${ReceiptFragmentFragmentDoc}
|
163
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
167
164
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
168
165
|
fragment inputEstimatePredicatesFragment on Input {
|
169
166
|
... on InputCoin {
|
@@ -181,46 +178,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
181
178
|
}
|
182
179
|
}
|
183
180
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
184
|
-
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
185
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
186
|
-
reason
|
187
|
-
programState {
|
188
|
-
returnType
|
189
|
-
data
|
190
|
-
}
|
191
|
-
}
|
192
|
-
`;
|
193
|
-
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
194
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
195
|
-
programState {
|
196
|
-
returnType
|
197
|
-
data
|
198
|
-
}
|
199
|
-
}
|
200
|
-
`;
|
201
|
-
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
202
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
203
|
-
... on DryRunFailureStatus {
|
204
|
-
...dryRunFailureStatusFragment
|
205
|
-
}
|
206
|
-
... on DryRunSuccessStatus {
|
207
|
-
...dryRunSuccessStatusFragment
|
208
|
-
}
|
209
|
-
}
|
210
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
211
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
212
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
213
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
214
|
-
id
|
215
|
-
status {
|
216
|
-
...dryRunTransactionStatusFragment
|
217
|
-
}
|
218
|
-
receipts {
|
219
|
-
...receiptFragment
|
220
|
-
}
|
221
|
-
}
|
222
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
223
|
-
${ReceiptFragmentFragmentDoc}`;
|
224
181
|
var CoinFragmentFragmentDoc = gql`
|
225
182
|
fragment coinFragment on Coin {
|
226
183
|
__typename
|
@@ -228,6 +185,7 @@ var CoinFragmentFragmentDoc = gql`
|
|
228
185
|
owner
|
229
186
|
amount
|
230
187
|
assetId
|
188
|
+
maturity
|
231
189
|
blockCreated
|
232
190
|
txCreatedIdx
|
233
191
|
}
|
@@ -272,6 +230,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
272
230
|
prevRoot
|
273
231
|
time
|
274
232
|
applicationHash
|
233
|
+
messageReceiptRoot
|
275
234
|
messageReceiptCount
|
276
235
|
}
|
277
236
|
commitBlockHeader {
|
@@ -283,6 +242,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
283
242
|
prevRoot
|
284
243
|
time
|
285
244
|
applicationHash
|
245
|
+
messageReceiptRoot
|
286
246
|
messageReceiptCount
|
287
247
|
}
|
288
248
|
sender
|
@@ -302,8 +262,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
302
262
|
var BlockFragmentFragmentDoc = gql`
|
303
263
|
fragment blockFragment on Block {
|
304
264
|
id
|
305
|
-
height
|
306
265
|
header {
|
266
|
+
height
|
307
267
|
time
|
308
268
|
}
|
309
269
|
transactions {
|
@@ -361,11 +321,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
361
321
|
`;
|
362
322
|
var GasCostsFragmentFragmentDoc = gql`
|
363
323
|
fragment GasCostsFragment on GasCosts {
|
364
|
-
version {
|
365
|
-
... on Version {
|
366
|
-
value
|
367
|
-
}
|
368
|
-
}
|
369
324
|
add
|
370
325
|
addi
|
371
326
|
aloc
|
@@ -378,6 +333,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
378
333
|
cb
|
379
334
|
cfei
|
380
335
|
cfsi
|
336
|
+
croo
|
381
337
|
div
|
382
338
|
divi
|
383
339
|
ecr1
|
@@ -460,9 +416,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
460
416
|
ccp {
|
461
417
|
...DependentCostFragment
|
462
418
|
}
|
463
|
-
croo {
|
464
|
-
...DependentCostFragment
|
465
|
-
}
|
466
419
|
csiz {
|
467
420
|
...DependentCostFragment
|
468
421
|
}
|
@@ -522,11 +475,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
522
475
|
${DependentCostFragmentFragmentDoc}`;
|
523
476
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
524
477
|
fragment consensusParametersFragment on ConsensusParameters {
|
525
|
-
version {
|
526
|
-
... on Version {
|
527
|
-
value
|
528
|
-
}
|
529
|
-
}
|
530
478
|
txParams {
|
531
479
|
...TxParametersFragment
|
532
480
|
}
|
@@ -586,9 +534,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
586
534
|
fragment nodeInfoFragment on NodeInfo {
|
587
535
|
utxoValidation
|
588
536
|
vmBacktrace
|
537
|
+
minGasPrice
|
589
538
|
maxTx
|
590
539
|
maxDepth
|
591
540
|
nodeVersion
|
541
|
+
peers {
|
542
|
+
id
|
543
|
+
addresses
|
544
|
+
clientVersion
|
545
|
+
blockHeight
|
546
|
+
lastHeartbeatMs
|
547
|
+
appScore
|
548
|
+
}
|
592
549
|
}
|
593
550
|
`;
|
594
551
|
var GetVersionDocument = gql`
|
@@ -623,9 +580,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
623
580
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
624
581
|
transaction(id: $transactionId) {
|
625
582
|
...transactionFragment
|
583
|
+
receipts {
|
584
|
+
...receiptFragment
|
585
|
+
}
|
626
586
|
}
|
627
587
|
}
|
628
|
-
${TransactionFragmentFragmentDoc}
|
588
|
+
${TransactionFragmentFragmentDoc}
|
589
|
+
${ReceiptFragmentFragmentDoc}`;
|
629
590
|
var GetTransactionsDocument = gql`
|
630
591
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
631
592
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -753,20 +714,6 @@ var GetBalanceDocument = gql`
|
|
753
714
|
}
|
754
715
|
}
|
755
716
|
${BalanceFragmentFragmentDoc}`;
|
756
|
-
var GetLatestGasPriceDocument = gql`
|
757
|
-
query getLatestGasPrice {
|
758
|
-
latestGasPrice {
|
759
|
-
gasPrice
|
760
|
-
}
|
761
|
-
}
|
762
|
-
`;
|
763
|
-
var EstimateGasPriceDocument = gql`
|
764
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
765
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
766
|
-
gasPrice
|
767
|
-
}
|
768
|
-
}
|
769
|
-
`;
|
770
717
|
var GetBalancesDocument = gql`
|
771
718
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
772
719
|
balances(
|
@@ -821,12 +768,12 @@ var GetMessageStatusDocument = gql`
|
|
821
768
|
}
|
822
769
|
`;
|
823
770
|
var DryRunDocument = gql`
|
824
|
-
mutation dryRun($
|
825
|
-
dryRun(
|
826
|
-
...
|
771
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
772
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
773
|
+
...receiptFragment
|
827
774
|
}
|
828
775
|
}
|
829
|
-
${
|
776
|
+
${ReceiptFragmentFragmentDoc}`;
|
830
777
|
var SubmitDocument = gql`
|
831
778
|
mutation submit($encodedTransaction: HexString!) {
|
832
779
|
submit(tx: $encodedTransaction) {
|
@@ -909,12 +856,6 @@ function getSdk(requester) {
|
|
909
856
|
getBalance(variables, options) {
|
910
857
|
return requester(GetBalanceDocument, variables, options);
|
911
858
|
},
|
912
|
-
getLatestGasPrice(variables, options) {
|
913
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
914
|
-
},
|
915
|
-
estimateGasPrice(variables, options) {
|
916
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
917
|
-
},
|
918
859
|
getBalances(variables, options) {
|
919
860
|
return requester(GetBalancesDocument, variables, options);
|
920
861
|
},
|
@@ -984,14 +925,11 @@ var _FuelGraphqlSubscriber = class {
|
|
984
925
|
let data;
|
985
926
|
let errors;
|
986
927
|
try {
|
987
|
-
|
988
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
928
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
989
929
|
} catch (e) {
|
990
930
|
throw new FuelError(
|
991
931
|
ErrorCode.STREAM_PARSING_ERROR,
|
992
|
-
`Error while parsing stream data response: ${text}
|
993
|
-
|
994
|
-
Thrown error: ${e}`
|
932
|
+
`Error while parsing stream data response: ${text}`
|
995
933
|
);
|
996
934
|
}
|
997
935
|
if (Array.isArray(errors)) {
|
@@ -1092,7 +1030,7 @@ var inputify = (value) => {
|
|
1092
1030
|
return {
|
1093
1031
|
type: InputType.Coin,
|
1094
1032
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1095
|
-
outputIndex:
|
1033
|
+
outputIndex: arrayify(value.id)[32],
|
1096
1034
|
owner: hexlify3(value.owner),
|
1097
1035
|
amount: bn2(value.amount),
|
1098
1036
|
assetId: hexlify3(value.assetId),
|
@@ -1101,9 +1039,10 @@ var inputify = (value) => {
|
|
1101
1039
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1102
1040
|
},
|
1103
1041
|
witnessIndex: value.witnessIndex,
|
1042
|
+
maturity: value.maturity ?? 0,
|
1104
1043
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1105
|
-
predicateLength:
|
1106
|
-
predicateDataLength:
|
1044
|
+
predicateLength: predicate.length,
|
1045
|
+
predicateDataLength: predicateData.length,
|
1107
1046
|
predicate: hexlify3(predicate),
|
1108
1047
|
predicateData: hexlify3(predicateData)
|
1109
1048
|
};
|
@@ -1134,8 +1073,8 @@ var inputify = (value) => {
|
|
1134
1073
|
nonce: hexlify3(value.nonce),
|
1135
1074
|
witnessIndex: value.witnessIndex,
|
1136
1075
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1137
|
-
predicateLength:
|
1138
|
-
predicateDataLength:
|
1076
|
+
predicateLength: predicate.length,
|
1077
|
+
predicateDataLength: predicateData.length,
|
1139
1078
|
predicate: hexlify3(predicate),
|
1140
1079
|
predicateData: hexlify3(predicateData),
|
1141
1080
|
data: hexlify3(data),
|
@@ -1210,7 +1149,7 @@ var outputify = (value) => {
|
|
1210
1149
|
|
1211
1150
|
// src/providers/transaction-request/transaction-request.ts
|
1212
1151
|
import { Address, addressify } from "@fuel-ts/address";
|
1213
|
-
import {
|
1152
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1214
1153
|
import { bn as bn7 } from "@fuel-ts/math";
|
1215
1154
|
import {
|
1216
1155
|
PolicyType,
|
@@ -1220,7 +1159,6 @@ import {
|
|
1220
1159
|
TransactionType
|
1221
1160
|
} from "@fuel-ts/transactions";
|
1222
1161
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1223
|
-
import { randomBytes } from "ethers";
|
1224
1162
|
|
1225
1163
|
// src/providers/resource.ts
|
1226
1164
|
var isCoin = (resource) => "id" in resource;
|
@@ -1261,8 +1199,8 @@ function assembleReceiptByType(receipt) {
|
|
1261
1199
|
case "CALL" /* Call */: {
|
1262
1200
|
const callReceipt = {
|
1263
1201
|
type: ReceiptType.Call,
|
1264
|
-
from: hexOrZero(receipt.id
|
1265
|
-
to: hexOrZero(receipt?.to),
|
1202
|
+
from: hexOrZero(receipt.contract?.id),
|
1203
|
+
to: hexOrZero(receipt?.to?.id),
|
1266
1204
|
amount: bn4(receipt.amount),
|
1267
1205
|
assetId: hexOrZero(receipt.assetId),
|
1268
1206
|
gas: bn4(receipt.gas),
|
@@ -1276,7 +1214,7 @@ function assembleReceiptByType(receipt) {
|
|
1276
1214
|
case "RETURN" /* Return */: {
|
1277
1215
|
const returnReceipt = {
|
1278
1216
|
type: ReceiptType.Return,
|
1279
|
-
id: hexOrZero(receipt.id
|
1217
|
+
id: hexOrZero(receipt.contract?.id),
|
1280
1218
|
val: bn4(receipt.val),
|
1281
1219
|
pc: bn4(receipt.pc),
|
1282
1220
|
is: bn4(receipt.is)
|
@@ -1286,7 +1224,7 @@ function assembleReceiptByType(receipt) {
|
|
1286
1224
|
case "RETURN_DATA" /* ReturnData */: {
|
1287
1225
|
const returnDataReceipt = {
|
1288
1226
|
type: ReceiptType.ReturnData,
|
1289
|
-
id: hexOrZero(receipt.id
|
1227
|
+
id: hexOrZero(receipt.contract?.id),
|
1290
1228
|
ptr: bn4(receipt.ptr),
|
1291
1229
|
len: bn4(receipt.len),
|
1292
1230
|
digest: hexOrZero(receipt.digest),
|
@@ -1298,7 +1236,7 @@ function assembleReceiptByType(receipt) {
|
|
1298
1236
|
case "PANIC" /* Panic */: {
|
1299
1237
|
const panicReceipt = {
|
1300
1238
|
type: ReceiptType.Panic,
|
1301
|
-
id: hexOrZero(receipt.id),
|
1239
|
+
id: hexOrZero(receipt.contract?.id),
|
1302
1240
|
reason: bn4(receipt.reason),
|
1303
1241
|
pc: bn4(receipt.pc),
|
1304
1242
|
is: bn4(receipt.is),
|
@@ -1309,7 +1247,7 @@ function assembleReceiptByType(receipt) {
|
|
1309
1247
|
case "REVERT" /* Revert */: {
|
1310
1248
|
const revertReceipt = {
|
1311
1249
|
type: ReceiptType.Revert,
|
1312
|
-
id: hexOrZero(receipt.id
|
1250
|
+
id: hexOrZero(receipt.contract?.id),
|
1313
1251
|
val: bn4(receipt.ra),
|
1314
1252
|
pc: bn4(receipt.pc),
|
1315
1253
|
is: bn4(receipt.is)
|
@@ -1319,7 +1257,7 @@ function assembleReceiptByType(receipt) {
|
|
1319
1257
|
case "LOG" /* Log */: {
|
1320
1258
|
const logReceipt = {
|
1321
1259
|
type: ReceiptType.Log,
|
1322
|
-
id: hexOrZero(receipt.id
|
1260
|
+
id: hexOrZero(receipt.contract?.id),
|
1323
1261
|
val0: bn4(receipt.ra),
|
1324
1262
|
val1: bn4(receipt.rb),
|
1325
1263
|
val2: bn4(receipt.rc),
|
@@ -1332,7 +1270,7 @@ function assembleReceiptByType(receipt) {
|
|
1332
1270
|
case "LOG_DATA" /* LogData */: {
|
1333
1271
|
const logDataReceipt = {
|
1334
1272
|
type: ReceiptType.LogData,
|
1335
|
-
id: hexOrZero(receipt.id
|
1273
|
+
id: hexOrZero(receipt.contract?.id),
|
1336
1274
|
val0: bn4(receipt.ra),
|
1337
1275
|
val1: bn4(receipt.rb),
|
1338
1276
|
ptr: bn4(receipt.ptr),
|
@@ -1346,8 +1284,8 @@ function assembleReceiptByType(receipt) {
|
|
1346
1284
|
case "TRANSFER" /* Transfer */: {
|
1347
1285
|
const transferReceipt = {
|
1348
1286
|
type: ReceiptType.Transfer,
|
1349
|
-
from: hexOrZero(receipt.id
|
1350
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1287
|
+
from: hexOrZero(receipt.contract?.id),
|
1288
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1351
1289
|
amount: bn4(receipt.amount),
|
1352
1290
|
assetId: hexOrZero(receipt.assetId),
|
1353
1291
|
pc: bn4(receipt.pc),
|
@@ -1358,8 +1296,8 @@ function assembleReceiptByType(receipt) {
|
|
1358
1296
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1359
1297
|
const transferOutReceipt = {
|
1360
1298
|
type: ReceiptType.TransferOut,
|
1361
|
-
from: hexOrZero(receipt.id
|
1362
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1299
|
+
from: hexOrZero(receipt.contract?.id),
|
1300
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1363
1301
|
amount: bn4(receipt.amount),
|
1364
1302
|
assetId: hexOrZero(receipt.assetId),
|
1365
1303
|
pc: bn4(receipt.pc),
|
@@ -1402,7 +1340,7 @@ function assembleReceiptByType(receipt) {
|
|
1402
1340
|
return receiptMessageOut;
|
1403
1341
|
}
|
1404
1342
|
case "MINT" /* Mint */: {
|
1405
|
-
const contractId = hexOrZero(receipt.id
|
1343
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1406
1344
|
const subId = hexOrZero(receipt.subId);
|
1407
1345
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1408
1346
|
const mintReceipt = {
|
@@ -1417,7 +1355,7 @@ function assembleReceiptByType(receipt) {
|
|
1417
1355
|
return mintReceipt;
|
1418
1356
|
}
|
1419
1357
|
case "BURN" /* Burn */: {
|
1420
|
-
const contractId = hexOrZero(receipt.id
|
1358
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1421
1359
|
const subId = hexOrZero(receipt.subId);
|
1422
1360
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1423
1361
|
const burnReceipt = {
|
@@ -1443,6 +1381,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1443
1381
|
import { bn as bn5 } from "@fuel-ts/math";
|
1444
1382
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1445
1383
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1384
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1446
1385
|
var getGasUsedFromReceipts = (receipts) => {
|
1447
1386
|
const scriptResult = receipts.filter(
|
1448
1387
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1463,28 +1402,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1463
1402
|
}
|
1464
1403
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1465
1404
|
const witnessCache = [];
|
1466
|
-
const
|
1467
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1468
|
-
if (isCoinOrMessage) {
|
1469
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1470
|
-
return true;
|
1471
|
-
}
|
1472
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1473
|
-
witnessCache.push(input.witnessIndex);
|
1474
|
-
return true;
|
1475
|
-
}
|
1476
|
-
}
|
1477
|
-
return false;
|
1478
|
-
});
|
1479
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1480
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1405
|
+
const totalGas = inputs.reduce((total, input) => {
|
1481
1406
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1482
1407
|
return total.add(
|
1483
|
-
|
1408
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1484
1409
|
);
|
1485
1410
|
}
|
1486
|
-
|
1487
|
-
|
1411
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1412
|
+
witnessCache.push(input.witnessIndex);
|
1413
|
+
return total.add(gasCosts.ecr1);
|
1414
|
+
}
|
1415
|
+
return total;
|
1416
|
+
}, bn5());
|
1488
1417
|
return totalGas;
|
1489
1418
|
}
|
1490
1419
|
function getMinGas(params) {
|
@@ -1496,20 +1425,12 @@ function getMinGas(params) {
|
|
1496
1425
|
return minGas;
|
1497
1426
|
}
|
1498
1427
|
function getMaxGas(params) {
|
1499
|
-
const {
|
1500
|
-
gasPerByte,
|
1501
|
-
witnessesLength,
|
1502
|
-
witnessLimit,
|
1503
|
-
minGas,
|
1504
|
-
gasLimit = bn5(0),
|
1505
|
-
maxGasPerTx
|
1506
|
-
} = params;
|
1428
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1507
1429
|
let remainingAllowedWitnessGas = bn5(0);
|
1508
1430
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1509
1431
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1510
1432
|
}
|
1511
|
-
|
1512
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1433
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1513
1434
|
}
|
1514
1435
|
function calculateMetadataGasForTxCreate({
|
1515
1436
|
gasCosts,
|
@@ -1531,10 +1452,6 @@ function calculateMetadataGasForTxScript({
|
|
1531
1452
|
}) {
|
1532
1453
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1533
1454
|
}
|
1534
|
-
var calculateGasFee = (params) => {
|
1535
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1536
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1537
|
-
};
|
1538
1455
|
|
1539
1456
|
// src/providers/utils/json.ts
|
1540
1457
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1679,7 +1596,7 @@ var witnessify = (value) => {
|
|
1679
1596
|
// src/providers/transaction-request/transaction-request.ts
|
1680
1597
|
var BaseTransactionRequest = class {
|
1681
1598
|
/** Gas price for transaction */
|
1682
|
-
|
1599
|
+
gasPrice;
|
1683
1600
|
/** Block until which tx cannot be included */
|
1684
1601
|
maturity;
|
1685
1602
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1692,34 +1609,38 @@ var BaseTransactionRequest = class {
|
|
1692
1609
|
outputs = [];
|
1693
1610
|
/** List of witnesses */
|
1694
1611
|
witnesses = [];
|
1612
|
+
/** Base asset ID - should be fetched from the chain */
|
1613
|
+
baseAssetId;
|
1695
1614
|
/**
|
1696
1615
|
* Constructor for initializing a base transaction request.
|
1697
1616
|
*
|
1698
1617
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1699
1618
|
*/
|
1700
1619
|
constructor({
|
1701
|
-
|
1620
|
+
gasPrice,
|
1702
1621
|
maturity,
|
1703
1622
|
maxFee,
|
1704
1623
|
witnessLimit,
|
1705
1624
|
inputs,
|
1706
1625
|
outputs,
|
1707
|
-
witnesses
|
1708
|
-
|
1709
|
-
|
1626
|
+
witnesses,
|
1627
|
+
baseAssetId
|
1628
|
+
}) {
|
1629
|
+
this.gasPrice = bn7(gasPrice);
|
1710
1630
|
this.maturity = maturity ?? 0;
|
1711
1631
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1712
1632
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1713
1633
|
this.inputs = inputs ?? [];
|
1714
1634
|
this.outputs = outputs ?? [];
|
1715
1635
|
this.witnesses = witnesses ?? [];
|
1636
|
+
this.baseAssetId = baseAssetId;
|
1716
1637
|
}
|
1717
1638
|
static getPolicyMeta(req) {
|
1718
1639
|
let policyTypes = 0;
|
1719
1640
|
const policies = [];
|
1720
|
-
if (req.
|
1721
|
-
policyTypes += PolicyType.
|
1722
|
-
policies.push({ data: req.
|
1641
|
+
if (req.gasPrice) {
|
1642
|
+
policyTypes += PolicyType.GasPrice;
|
1643
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1723
1644
|
}
|
1724
1645
|
if (req.witnessLimit) {
|
1725
1646
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1906,10 +1827,10 @@ var BaseTransactionRequest = class {
|
|
1906
1827
|
* @param predicate - Predicate bytes.
|
1907
1828
|
* @param predicateData - Predicate data bytes.
|
1908
1829
|
*/
|
1909
|
-
addCoinInput(coin) {
|
1830
|
+
addCoinInput(coin, predicate) {
|
1910
1831
|
const { assetId, owner, amount } = coin;
|
1911
1832
|
let witnessIndex;
|
1912
|
-
if (
|
1833
|
+
if (predicate) {
|
1913
1834
|
witnessIndex = 0;
|
1914
1835
|
} else {
|
1915
1836
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1924,7 +1845,8 @@ var BaseTransactionRequest = class {
|
|
1924
1845
|
amount,
|
1925
1846
|
assetId,
|
1926
1847
|
txPointer: "0x00000000000000000000000000000000",
|
1927
|
-
witnessIndex
|
1848
|
+
witnessIndex,
|
1849
|
+
predicate: predicate?.bytes
|
1928
1850
|
};
|
1929
1851
|
this.pushInput(input);
|
1930
1852
|
this.addChangeOutput(owner, assetId);
|
@@ -1935,13 +1857,11 @@ var BaseTransactionRequest = class {
|
|
1935
1857
|
*
|
1936
1858
|
* @param message - Message resource.
|
1937
1859
|
* @param predicate - Predicate bytes.
|
1938
|
-
* @param predicateData - Predicate data bytes.
|
1939
1860
|
*/
|
1940
|
-
addMessageInput(message) {
|
1861
|
+
addMessageInput(message, predicate) {
|
1941
1862
|
const { recipient, sender, amount } = message;
|
1942
|
-
const assetId = BaseAssetId2;
|
1943
1863
|
let witnessIndex;
|
1944
|
-
if (
|
1864
|
+
if (predicate) {
|
1945
1865
|
witnessIndex = 0;
|
1946
1866
|
} else {
|
1947
1867
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1955,10 +1875,11 @@ var BaseTransactionRequest = class {
|
|
1955
1875
|
sender: sender.toB256(),
|
1956
1876
|
recipient: recipient.toB256(),
|
1957
1877
|
amount,
|
1958
|
-
witnessIndex
|
1878
|
+
witnessIndex,
|
1879
|
+
predicate: predicate?.bytes
|
1959
1880
|
};
|
1960
1881
|
this.pushInput(input);
|
1961
|
-
this.addChangeOutput(recipient,
|
1882
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1962
1883
|
}
|
1963
1884
|
/**
|
1964
1885
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1986,6 +1907,32 @@ var BaseTransactionRequest = class {
|
|
1986
1907
|
resources.forEach((resource) => this.addResource(resource));
|
1987
1908
|
return this;
|
1988
1909
|
}
|
1910
|
+
/**
|
1911
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1912
|
+
* outputs from the related assetIds.
|
1913
|
+
*
|
1914
|
+
* @param resources - The resources to add.
|
1915
|
+
* @returns This transaction.
|
1916
|
+
*/
|
1917
|
+
addPredicateResource(resource, predicate) {
|
1918
|
+
if (isCoin(resource)) {
|
1919
|
+
this.addCoinInput(resource, predicate);
|
1920
|
+
} else {
|
1921
|
+
this.addMessageInput(resource, predicate);
|
1922
|
+
}
|
1923
|
+
return this;
|
1924
|
+
}
|
1925
|
+
/**
|
1926
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1927
|
+
* from the related assetIds.
|
1928
|
+
*
|
1929
|
+
* @param resources - The resources to add.
|
1930
|
+
* @returns This transaction.
|
1931
|
+
*/
|
1932
|
+
addPredicateResources(resources, predicate) {
|
1933
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1934
|
+
return this;
|
1935
|
+
}
|
1989
1936
|
/**
|
1990
1937
|
* Adds a coin output to the transaction.
|
1991
1938
|
*
|
@@ -1993,12 +1940,12 @@ var BaseTransactionRequest = class {
|
|
1993
1940
|
* @param amount - Amount of coin.
|
1994
1941
|
* @param assetId - Asset ID of coin.
|
1995
1942
|
*/
|
1996
|
-
addCoinOutput(to, amount, assetId
|
1943
|
+
addCoinOutput(to, amount, assetId) {
|
1997
1944
|
this.pushOutput({
|
1998
1945
|
type: OutputType2.Coin,
|
1999
1946
|
to: addressify(to).toB256(),
|
2000
1947
|
amount,
|
2001
|
-
assetId
|
1948
|
+
assetId: assetId ?? this.baseAssetId
|
2002
1949
|
});
|
2003
1950
|
return this;
|
2004
1951
|
}
|
@@ -2025,7 +1972,7 @@ var BaseTransactionRequest = class {
|
|
2025
1972
|
* @param to - Address of the owner.
|
2026
1973
|
* @param assetId - Asset ID of coin.
|
2027
1974
|
*/
|
2028
|
-
addChangeOutput(to, assetId
|
1975
|
+
addChangeOutput(to, assetId) {
|
2029
1976
|
const changeOutput = this.getChangeOutputs().find(
|
2030
1977
|
(output) => hexlify7(output.assetId) === assetId
|
2031
1978
|
);
|
@@ -2033,7 +1980,7 @@ var BaseTransactionRequest = class {
|
|
2033
1980
|
this.pushOutput({
|
2034
1981
|
type: OutputType2.Change,
|
2035
1982
|
to: addressify(to).toB256(),
|
2036
|
-
assetId
|
1983
|
+
assetId: assetId ?? this.baseAssetId
|
2037
1984
|
});
|
2038
1985
|
}
|
2039
1986
|
}
|
@@ -2065,7 +2012,7 @@ var BaseTransactionRequest = class {
|
|
2065
2012
|
}
|
2066
2013
|
calculateMaxGas(chainInfo, minGas) {
|
2067
2014
|
const { consensusParameters } = chainInfo;
|
2068
|
-
const { gasPerByte
|
2015
|
+
const { gasPerByte } = consensusParameters;
|
2069
2016
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2070
2017
|
(acc, wit) => acc + wit.dataLength,
|
2071
2018
|
0
|
@@ -2074,8 +2021,7 @@ var BaseTransactionRequest = class {
|
|
2074
2021
|
gasPerByte,
|
2075
2022
|
minGas,
|
2076
2023
|
witnessesLength,
|
2077
|
-
witnessLimit: this.witnessLimit
|
2078
|
-
maxGasPerTx
|
2024
|
+
witnessLimit: this.witnessLimit
|
2079
2025
|
});
|
2080
2026
|
}
|
2081
2027
|
/**
|
@@ -2085,6 +2031,12 @@ var BaseTransactionRequest = class {
|
|
2085
2031
|
* @param quantities - CoinQuantity Array.
|
2086
2032
|
*/
|
2087
2033
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2034
|
+
let idCounter = 0;
|
2035
|
+
const generateId = () => {
|
2036
|
+
const counterString = String(idCounter++);
|
2037
|
+
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2038
|
+
return id;
|
2039
|
+
};
|
2088
2040
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2089
2041
|
if ("assetId" in input) {
|
2090
2042
|
return input.assetId === assetId;
|
@@ -2093,27 +2045,24 @@ var BaseTransactionRequest = class {
|
|
2093
2045
|
});
|
2094
2046
|
const updateAssetInput = (assetId, quantity) => {
|
2095
2047
|
const assetInput = findAssetInput(assetId);
|
2096
|
-
let usedQuantity = quantity;
|
2097
|
-
if (assetId === BaseAssetId2) {
|
2098
|
-
usedQuantity = bn7("1000000000000000000");
|
2099
|
-
}
|
2100
2048
|
if (assetInput && "assetId" in assetInput) {
|
2101
|
-
assetInput.id =
|
2102
|
-
assetInput.amount =
|
2049
|
+
assetInput.id = generateId();
|
2050
|
+
assetInput.amount = quantity;
|
2103
2051
|
} else {
|
2104
2052
|
this.addResources([
|
2105
2053
|
{
|
2106
|
-
id:
|
2107
|
-
amount:
|
2054
|
+
id: generateId(),
|
2055
|
+
amount: quantity,
|
2108
2056
|
assetId,
|
2109
2057
|
owner: resourcesOwner || Address.fromRandom(),
|
2058
|
+
maturity: 0,
|
2110
2059
|
blockCreated: bn7(1),
|
2111
2060
|
txCreatedIdx: bn7(1)
|
2112
2061
|
}
|
2113
2062
|
]);
|
2114
2063
|
}
|
2115
2064
|
};
|
2116
|
-
updateAssetInput(
|
2065
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2117
2066
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2118
2067
|
}
|
2119
2068
|
/**
|
@@ -2138,7 +2087,7 @@ var BaseTransactionRequest = class {
|
|
2138
2087
|
toJSON() {
|
2139
2088
|
return normalizeJSON(this);
|
2140
2089
|
}
|
2141
|
-
|
2090
|
+
updatePredicateInputs(inputs) {
|
2142
2091
|
this.inputs.forEach((i) => {
|
2143
2092
|
let correspondingInput;
|
2144
2093
|
switch (i.type) {
|
@@ -2160,15 +2109,6 @@ var BaseTransactionRequest = class {
|
|
2160
2109
|
}
|
2161
2110
|
});
|
2162
2111
|
}
|
2163
|
-
shiftPredicateData() {
|
2164
|
-
this.inputs.forEach((input) => {
|
2165
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2166
|
-
input.predicateData = input.paddPredicateData(
|
2167
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2168
|
-
);
|
2169
|
-
}
|
2170
|
-
});
|
2171
|
-
}
|
2172
2112
|
};
|
2173
2113
|
|
2174
2114
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2292,12 +2232,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2292
2232
|
*
|
2293
2233
|
* @param createTransactionRequestLike - The initial values for the instance
|
2294
2234
|
*/
|
2295
|
-
constructor({
|
2296
|
-
bytecodeWitnessIndex,
|
2297
|
-
salt,
|
2298
|
-
storageSlots,
|
2299
|
-
...rest
|
2300
|
-
} = {}) {
|
2235
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2301
2236
|
super(rest);
|
2302
2237
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2303
2238
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2315,8 +2250,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2315
2250
|
return {
|
2316
2251
|
type: TransactionType3.Create,
|
2317
2252
|
...baseTransaction,
|
2253
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2318
2254
|
bytecodeWitnessIndex,
|
2319
|
-
storageSlotsCount:
|
2255
|
+
storageSlotsCount: storageSlots.length,
|
2320
2256
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2321
2257
|
storageSlots
|
2322
2258
|
};
|
@@ -2420,7 +2356,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2420
2356
|
*
|
2421
2357
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2422
2358
|
*/
|
2423
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2359
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2424
2360
|
super(rest);
|
2425
2361
|
this.gasLimit = bn10(gasLimit);
|
2426
2362
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -2439,8 +2375,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2439
2375
|
type: TransactionType4.Script,
|
2440
2376
|
scriptGasLimit: this.gasLimit,
|
2441
2377
|
...super.getBaseTransaction(),
|
2442
|
-
scriptLength:
|
2443
|
-
scriptDataLength:
|
2378
|
+
scriptLength: script.length,
|
2379
|
+
scriptDataLength: scriptData.length,
|
2444
2380
|
receiptsRoot: ZeroBytes327,
|
2445
2381
|
script: hexlify10(script),
|
2446
2382
|
scriptData: hexlify10(scriptData)
|
@@ -2504,7 +2440,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2504
2440
|
}
|
2505
2441
|
calculateMaxGas(chainInfo, minGas) {
|
2506
2442
|
const { consensusParameters } = chainInfo;
|
2507
|
-
const { gasPerByte
|
2443
|
+
const { gasPerByte } = consensusParameters;
|
2508
2444
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2509
2445
|
(acc, wit) => acc + wit.dataLength,
|
2510
2446
|
0
|
@@ -2514,8 +2450,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2514
2450
|
minGas,
|
2515
2451
|
witnessesLength,
|
2516
2452
|
witnessLimit: this.witnessLimit,
|
2517
|
-
gasLimit: this.gasLimit
|
2518
|
-
maxGasPerTx
|
2453
|
+
gasLimit: this.gasLimit
|
2519
2454
|
});
|
2520
2455
|
}
|
2521
2456
|
/**
|
@@ -2572,7 +2507,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2572
2507
|
|
2573
2508
|
// src/providers/transaction-request/utils.ts
|
2574
2509
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2575
|
-
import { TransactionType as TransactionType5
|
2510
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2576
2511
|
var transactionRequestify = (obj) => {
|
2577
2512
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2578
2513
|
return obj;
|
@@ -2590,31 +2525,14 @@ var transactionRequestify = (obj) => {
|
|
2590
2525
|
}
|
2591
2526
|
}
|
2592
2527
|
};
|
2593
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2594
|
-
(acc, input) => {
|
2595
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2596
|
-
acc.utxos.push(input.id);
|
2597
|
-
}
|
2598
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2599
|
-
acc.messages.push(input.nonce);
|
2600
|
-
}
|
2601
|
-
return acc;
|
2602
|
-
},
|
2603
|
-
{
|
2604
|
-
utxos: [],
|
2605
|
-
messages: []
|
2606
|
-
}
|
2607
|
-
);
|
2608
2528
|
|
2609
2529
|
// src/providers/transaction-response/transaction-response.ts
|
2610
2530
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2611
|
-
import { bn as
|
2531
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2612
2532
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2613
2533
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2614
2534
|
|
2615
2535
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2616
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2617
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2618
2536
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2619
2537
|
|
2620
2538
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2623,10 +2541,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2623
2541
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2624
2542
|
var calculateTransactionFee = (params) => {
|
2625
2543
|
const {
|
2626
|
-
|
2544
|
+
gasUsed,
|
2627
2545
|
rawPayload,
|
2628
|
-
|
2629
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2546
|
+
consensusParameters: { gasCosts, feeParams }
|
2630
2547
|
} = params;
|
2631
2548
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2632
2549
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2636,7 +2553,8 @@ var calculateTransactionFee = (params) => {
|
|
2636
2553
|
return {
|
2637
2554
|
fee: bn11(0),
|
2638
2555
|
minFee: bn11(0),
|
2639
|
-
maxFee: bn11(0)
|
2556
|
+
maxFee: bn11(0),
|
2557
|
+
feeFromGasUsed: bn11(0)
|
2640
2558
|
};
|
2641
2559
|
}
|
2642
2560
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2668,6 +2586,7 @@ var calculateTransactionFee = (params) => {
|
|
2668
2586
|
metadataGas,
|
2669
2587
|
txBytesSize: transactionBytes.length
|
2670
2588
|
});
|
2589
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2671
2590
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2672
2591
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2673
2592
|
const maxGas = getMaxGas({
|
@@ -2675,25 +2594,17 @@ var calculateTransactionFee = (params) => {
|
|
2675
2594
|
minGas,
|
2676
2595
|
witnessesLength,
|
2677
2596
|
gasLimit,
|
2678
|
-
witnessLimit
|
2679
|
-
maxGasPerTx
|
2680
|
-
});
|
2681
|
-
const minFee = calculateGasFee({
|
2682
|
-
gasPrice,
|
2683
|
-
gas: minGas,
|
2684
|
-
priceFactor: gasPriceFactor,
|
2685
|
-
tip
|
2686
|
-
});
|
2687
|
-
const maxFee = calculateGasFee({
|
2688
|
-
gasPrice,
|
2689
|
-
gas: maxGas,
|
2690
|
-
priceFactor: gasPriceFactor,
|
2691
|
-
tip
|
2597
|
+
witnessLimit
|
2692
2598
|
});
|
2599
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2600
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2601
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2602
|
+
const fee = minFee.add(feeFromGasUsed);
|
2693
2603
|
return {
|
2604
|
+
fee,
|
2694
2605
|
minFee,
|
2695
2606
|
maxFee,
|
2696
|
-
|
2607
|
+
feeFromGasUsed
|
2697
2608
|
};
|
2698
2609
|
};
|
2699
2610
|
|
@@ -2749,7 +2660,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2749
2660
|
|
2750
2661
|
// src/providers/transaction-summary/input.ts
|
2751
2662
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2752
|
-
import { InputType as
|
2663
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2753
2664
|
function getInputsByTypes(inputs, types) {
|
2754
2665
|
return inputs.filter((i) => types.includes(i.type));
|
2755
2666
|
}
|
@@ -2757,16 +2668,16 @@ function getInputsByType(inputs, type) {
|
|
2757
2668
|
return inputs.filter((i) => i.type === type);
|
2758
2669
|
}
|
2759
2670
|
function getInputsCoin(inputs) {
|
2760
|
-
return getInputsByType(inputs,
|
2671
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2761
2672
|
}
|
2762
2673
|
function getInputsMessage(inputs) {
|
2763
|
-
return getInputsByType(inputs,
|
2674
|
+
return getInputsByType(inputs, InputType5.Message);
|
2764
2675
|
}
|
2765
2676
|
function getInputsCoinAndMessage(inputs) {
|
2766
|
-
return getInputsByTypes(inputs, [
|
2677
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2767
2678
|
}
|
2768
2679
|
function getInputsContract(inputs) {
|
2769
|
-
return getInputsByType(inputs,
|
2680
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2770
2681
|
}
|
2771
2682
|
function getInputFromAssetId(inputs, assetId) {
|
2772
2683
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2785,7 +2696,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2785
2696
|
if (!contractInput) {
|
2786
2697
|
return void 0;
|
2787
2698
|
}
|
2788
|
-
if (contractInput.type !==
|
2699
|
+
if (contractInput.type !== InputType5.Contract) {
|
2789
2700
|
throw new FuelError9(
|
2790
2701
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2791
2702
|
`Contract input should be of type 'contract'.`
|
@@ -2794,10 +2705,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2794
2705
|
return contractInput;
|
2795
2706
|
}
|
2796
2707
|
function getInputAccountAddress(input) {
|
2797
|
-
if (input.type ===
|
2708
|
+
if (input.type === InputType5.Coin) {
|
2798
2709
|
return input.owner.toString();
|
2799
2710
|
}
|
2800
|
-
if (input.type ===
|
2711
|
+
if (input.type === InputType5.Message) {
|
2801
2712
|
return input.recipient.toString();
|
2802
2713
|
}
|
2803
2714
|
return "";
|
@@ -3260,9 +3171,7 @@ function assembleTransactionSummary(params) {
|
|
3260
3171
|
gqlTransactionStatus,
|
3261
3172
|
abiMap = {},
|
3262
3173
|
maxInputs,
|
3263
|
-
gasCosts
|
3264
|
-
maxGasPerTx,
|
3265
|
-
gasPrice
|
3174
|
+
gasCosts
|
3266
3175
|
} = params;
|
3267
3176
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3268
3177
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3276,14 +3185,11 @@ function assembleTransactionSummary(params) {
|
|
3276
3185
|
maxInputs
|
3277
3186
|
});
|
3278
3187
|
const typeName = getTransactionTypeName(transaction.type);
|
3279
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3280
3188
|
const { fee } = calculateTransactionFee({
|
3281
|
-
|
3189
|
+
gasUsed,
|
3282
3190
|
rawPayload,
|
3283
|
-
tip,
|
3284
3191
|
consensusParameters: {
|
3285
3192
|
gasCosts,
|
3286
|
-
maxGasPerTx,
|
3287
3193
|
feeParams: {
|
3288
3194
|
gasPerByte,
|
3289
3195
|
gasPriceFactor
|
@@ -3343,7 +3249,7 @@ var TransactionResponse = class {
|
|
3343
3249
|
/** Current provider */
|
3344
3250
|
provider;
|
3345
3251
|
/** Gas used on the transaction */
|
3346
|
-
gasUsed =
|
3252
|
+
gasUsed = bn14(0);
|
3347
3253
|
/** The graphql Transaction with receipts object. */
|
3348
3254
|
gqlTransaction;
|
3349
3255
|
abis;
|
@@ -3421,13 +3327,8 @@ var TransactionResponse = class {
|
|
3421
3327
|
const decodedTransaction = this.decodeTransaction(
|
3422
3328
|
transaction
|
3423
3329
|
);
|
3424
|
-
|
3425
|
-
|
3426
|
-
txReceipts = transaction.status.receipts;
|
3427
|
-
}
|
3428
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3429
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3430
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3330
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3331
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3431
3332
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3432
3333
|
const transactionSummary = assembleTransactionSummary({
|
3433
3334
|
id: this.id,
|
@@ -3439,9 +3340,7 @@ var TransactionResponse = class {
|
|
3439
3340
|
gasPriceFactor,
|
3440
3341
|
abiMap: contractsAbiMap,
|
3441
3342
|
maxInputs,
|
3442
|
-
gasCosts
|
3443
|
-
maxGasPerTx,
|
3444
|
-
gasPrice
|
3343
|
+
gasCosts
|
3445
3344
|
});
|
3446
3345
|
return transactionSummary;
|
3447
3346
|
}
|
@@ -3568,29 +3467,30 @@ var processGqlChain = (chain) => {
|
|
3568
3467
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3569
3468
|
return {
|
3570
3469
|
name,
|
3571
|
-
baseChainHeight:
|
3470
|
+
baseChainHeight: bn15(daHeight),
|
3572
3471
|
consensusParameters: {
|
3573
|
-
contractMaxSize:
|
3574
|
-
maxInputs:
|
3575
|
-
maxOutputs:
|
3576
|
-
maxWitnesses:
|
3577
|
-
maxGasPerTx:
|
3578
|
-
maxScriptLength:
|
3579
|
-
maxScriptDataLength:
|
3580
|
-
maxStorageSlots:
|
3581
|
-
maxPredicateLength:
|
3582
|
-
maxPredicateDataLength:
|
3583
|
-
maxGasPerPredicate:
|
3584
|
-
gasPriceFactor:
|
3585
|
-
gasPerByte:
|
3586
|
-
maxMessageDataLength:
|
3587
|
-
chainId:
|
3472
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3473
|
+
maxInputs: bn15(txParams.maxInputs),
|
3474
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3475
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3476
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3477
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3478
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3479
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3480
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3481
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3482
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3483
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3484
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3485
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3486
|
+
chainId: bn15(consensusParameters.chainId),
|
3487
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3588
3488
|
gasCosts
|
3589
3489
|
},
|
3590
3490
|
gasCosts,
|
3591
3491
|
latestBlock: {
|
3592
3492
|
id: latestBlock.id,
|
3593
|
-
height:
|
3493
|
+
height: bn15(latestBlock.header.height),
|
3594
3494
|
time: latestBlock.header.time,
|
3595
3495
|
transactions: latestBlock.transactions.map((i) => ({
|
3596
3496
|
id: i.id
|
@@ -3684,8 +3584,10 @@ var _Provider = class {
|
|
3684
3584
|
* Returns some helpful parameters related to gas fees.
|
3685
3585
|
*/
|
3686
3586
|
getGasConfig() {
|
3587
|
+
const { minGasPrice } = this.getNode();
|
3687
3588
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3688
3589
|
return {
|
3590
|
+
minGasPrice,
|
3689
3591
|
maxGasPerTx,
|
3690
3592
|
maxGasPerPredicate,
|
3691
3593
|
gasPriceFactor,
|
@@ -3783,7 +3685,7 @@ var _Provider = class {
|
|
3783
3685
|
*/
|
3784
3686
|
async getBlockNumber() {
|
3785
3687
|
const { chain } = await this.operations.getChain();
|
3786
|
-
return
|
3688
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3787
3689
|
}
|
3788
3690
|
/**
|
3789
3691
|
* Returns the chain information.
|
@@ -3793,11 +3695,13 @@ var _Provider = class {
|
|
3793
3695
|
async fetchNode() {
|
3794
3696
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3795
3697
|
const processedNodeInfo = {
|
3796
|
-
maxDepth:
|
3797
|
-
maxTx:
|
3698
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3699
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3700
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3798
3701
|
nodeVersion: nodeInfo.nodeVersion,
|
3799
3702
|
utxoValidation: nodeInfo.utxoValidation,
|
3800
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3703
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3704
|
+
peers: nodeInfo.peers
|
3801
3705
|
};
|
3802
3706
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3803
3707
|
return processedNodeInfo;
|
@@ -3823,6 +3727,17 @@ var _Provider = class {
|
|
3823
3727
|
} = this.getChain();
|
3824
3728
|
return chainId.toNumber();
|
3825
3729
|
}
|
3730
|
+
/**
|
3731
|
+
* Returns the base asset ID
|
3732
|
+
*
|
3733
|
+
* @returns A promise that resolves to the base asset ID
|
3734
|
+
*/
|
3735
|
+
getBaseAssetId() {
|
3736
|
+
const {
|
3737
|
+
consensusParameters: { baseAssetId }
|
3738
|
+
} = this.getChain();
|
3739
|
+
return baseAssetId;
|
3740
|
+
}
|
3826
3741
|
/**
|
3827
3742
|
* Submits a transaction to the chain to be executed.
|
3828
3743
|
*
|
@@ -3883,13 +3798,14 @@ var _Provider = class {
|
|
3883
3798
|
return this.estimateTxDependencies(transactionRequest);
|
3884
3799
|
}
|
3885
3800
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3886
|
-
const { dryRun:
|
3887
|
-
|
3801
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3802
|
+
encodedTransaction,
|
3888
3803
|
utxoValidation: utxoValidation || false
|
3889
3804
|
});
|
3890
|
-
const
|
3891
|
-
|
3892
|
-
|
3805
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3806
|
+
return {
|
3807
|
+
receipts
|
3808
|
+
};
|
3893
3809
|
}
|
3894
3810
|
/**
|
3895
3811
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3915,7 +3831,7 @@ var _Provider = class {
|
|
3915
3831
|
} = response;
|
3916
3832
|
if (inputs) {
|
3917
3833
|
inputs.forEach((input, index) => {
|
3918
|
-
if ("predicateGasUsed" in input &&
|
3834
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3919
3835
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3920
3836
|
}
|
3921
3837
|
});
|
@@ -3928,6 +3844,9 @@ var _Provider = class {
|
|
3928
3844
|
* If there are missing variable outputs,
|
3929
3845
|
* `addVariableOutputs` is called on the transaction.
|
3930
3846
|
*
|
3847
|
+
* @privateRemarks
|
3848
|
+
* TODO: Investigate support for missing contract IDs
|
3849
|
+
* TODO: Add support for missing output messages
|
3931
3850
|
*
|
3932
3851
|
* @param transactionRequest - The transaction request object.
|
3933
3852
|
* @returns A promise.
|
@@ -3940,19 +3859,16 @@ var _Provider = class {
|
|
3940
3859
|
missingContractIds: []
|
3941
3860
|
};
|
3942
3861
|
}
|
3862
|
+
await this.estimatePredicates(transactionRequest);
|
3943
3863
|
let receipts = [];
|
3944
3864
|
const missingContractIds = [];
|
3945
3865
|
let outputVariables = 0;
|
3946
|
-
let dryrunStatus;
|
3947
3866
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3948
|
-
const {
|
3949
|
-
|
3950
|
-
} = await this.operations.dryRun({
|
3951
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3867
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3868
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3952
3869
|
utxoValidation: false
|
3953
3870
|
});
|
3954
|
-
receipts =
|
3955
|
-
dryrunStatus = status;
|
3871
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3956
3872
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3957
3873
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3958
3874
|
if (hasMissingOutputs) {
|
@@ -3962,11 +3878,6 @@ var _Provider = class {
|
|
3962
3878
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3963
3879
|
missingContractIds.push(contractId);
|
3964
3880
|
});
|
3965
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3966
|
-
transactionRequest,
|
3967
|
-
optimizeGas: false
|
3968
|
-
});
|
3969
|
-
transactionRequest.maxFee = maxFee;
|
3970
3881
|
} else {
|
3971
3882
|
break;
|
3972
3883
|
}
|
@@ -3974,133 +3885,7 @@ var _Provider = class {
|
|
3974
3885
|
return {
|
3975
3886
|
receipts,
|
3976
3887
|
outputVariables,
|
3977
|
-
missingContractIds
|
3978
|
-
dryrunStatus
|
3979
|
-
};
|
3980
|
-
}
|
3981
|
-
/**
|
3982
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3983
|
-
*
|
3984
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3985
|
-
* further modifications are identified. The method iteratively updates these transactions
|
3986
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3987
|
-
*
|
3988
|
-
* @param transactionRequests - Array of transaction request objects.
|
3989
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
3990
|
-
*/
|
3991
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
3992
|
-
const results = transactionRequests.map(() => ({
|
3993
|
-
receipts: [],
|
3994
|
-
outputVariables: 0,
|
3995
|
-
missingContractIds: [],
|
3996
|
-
dryrunStatus: void 0
|
3997
|
-
}));
|
3998
|
-
const allRequests = clone3(transactionRequests);
|
3999
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4000
|
-
allRequests.forEach((req, index) => {
|
4001
|
-
if (req.type === TransactionType8.Script) {
|
4002
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4003
|
-
}
|
4004
|
-
});
|
4005
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4006
|
-
let attempt = 0;
|
4007
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4008
|
-
const encodedTransactions = transactionsToProcess.map(
|
4009
|
-
(index) => serializedTransactionsMap.get(index)
|
4010
|
-
);
|
4011
|
-
const dryRunResults = await this.operations.dryRun({
|
4012
|
-
encodedTransactions,
|
4013
|
-
utxoValidation: false
|
4014
|
-
});
|
4015
|
-
const nextRoundTransactions = [];
|
4016
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4017
|
-
const currentResultIndex = transactionsToProcess[i];
|
4018
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4019
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4020
|
-
results[currentResultIndex].dryrunStatus = status;
|
4021
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4022
|
-
results[currentResultIndex].receipts
|
4023
|
-
);
|
4024
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4025
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4026
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4027
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4028
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4029
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4030
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4031
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4032
|
-
});
|
4033
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4034
|
-
transactionRequest: requestToProcess,
|
4035
|
-
optimizeGas: false
|
4036
|
-
});
|
4037
|
-
requestToProcess.maxFee = maxFee;
|
4038
|
-
serializedTransactionsMap.set(
|
4039
|
-
currentResultIndex,
|
4040
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4041
|
-
);
|
4042
|
-
nextRoundTransactions.push(currentResultIndex);
|
4043
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4044
|
-
}
|
4045
|
-
}
|
4046
|
-
transactionsToProcess = nextRoundTransactions;
|
4047
|
-
attempt += 1;
|
4048
|
-
}
|
4049
|
-
return results;
|
4050
|
-
}
|
4051
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4052
|
-
if (estimateTxDependencies) {
|
4053
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4054
|
-
}
|
4055
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4056
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4057
|
-
encodedTransactions,
|
4058
|
-
utxoValidation: utxoValidation || false
|
4059
|
-
});
|
4060
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4061
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4062
|
-
return { receipts, dryrunStatus: status };
|
4063
|
-
});
|
4064
|
-
return results;
|
4065
|
-
}
|
4066
|
-
async estimateTxGasAndFee(params) {
|
4067
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4068
|
-
let { gasPrice } = params;
|
4069
|
-
const chainInfo = this.getChain();
|
4070
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4071
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4072
|
-
if (!gasPrice) {
|
4073
|
-
gasPrice = await this.estimateGasPrice(10);
|
4074
|
-
}
|
4075
|
-
const minFee = calculateGasFee({
|
4076
|
-
gasPrice: bn16(gasPrice),
|
4077
|
-
gas: minGas,
|
4078
|
-
priceFactor: gasPriceFactor,
|
4079
|
-
tip: transactionRequest.tip
|
4080
|
-
}).add(1);
|
4081
|
-
let gasLimit = bn16(0);
|
4082
|
-
if (transactionRequest.type === TransactionType8.Script) {
|
4083
|
-
gasLimit = transactionRequest.gasLimit;
|
4084
|
-
if (!optimizeGas) {
|
4085
|
-
transactionRequest.gasLimit = minGas;
|
4086
|
-
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4087
|
-
transactionRequest.gasLimit = gasLimit;
|
4088
|
-
}
|
4089
|
-
}
|
4090
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4091
|
-
const maxFee = calculateGasFee({
|
4092
|
-
gasPrice: bn16(gasPrice),
|
4093
|
-
gas: maxGas,
|
4094
|
-
priceFactor: gasPriceFactor,
|
4095
|
-
tip: transactionRequest.tip
|
4096
|
-
}).add(1);
|
4097
|
-
return {
|
4098
|
-
minGas,
|
4099
|
-
minFee,
|
4100
|
-
maxGas,
|
4101
|
-
maxFee,
|
4102
|
-
gasPrice,
|
4103
|
-
gasLimit
|
3888
|
+
missingContractIds
|
4104
3889
|
};
|
4105
3890
|
}
|
4106
3891
|
/**
|
@@ -4118,17 +3903,15 @@ var _Provider = class {
|
|
4118
3903
|
if (estimateTxDependencies) {
|
4119
3904
|
return this.estimateTxDependencies(transactionRequest);
|
4120
3905
|
}
|
4121
|
-
const
|
4122
|
-
const { dryRun:
|
4123
|
-
|
3906
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3907
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3908
|
+
encodedTransaction,
|
4124
3909
|
utxoValidation: true
|
4125
3910
|
});
|
4126
|
-
const
|
4127
|
-
|
4128
|
-
|
4129
|
-
|
4130
|
-
});
|
4131
|
-
return { receipts: callResult[0].receipts };
|
3911
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3912
|
+
return {
|
3913
|
+
receipts
|
3914
|
+
};
|
4132
3915
|
}
|
4133
3916
|
/**
|
4134
3917
|
* Returns a transaction cost to enable user
|
@@ -4145,80 +3928,80 @@ var _Provider = class {
|
|
4145
3928
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4146
3929
|
* @returns A promise that resolves to the transaction cost object.
|
4147
3930
|
*/
|
4148
|
-
async getTransactionCost(transactionRequestLike,
|
3931
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3932
|
+
estimateTxDependencies = true,
|
3933
|
+
estimatePredicates = true,
|
3934
|
+
resourcesOwner,
|
3935
|
+
signatureCallback
|
3936
|
+
} = {}) {
|
4149
3937
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3938
|
+
const chainInfo = this.getChain();
|
3939
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3940
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4150
3941
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4151
3942
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4152
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3943
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4153
3944
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
3945
|
+
if (estimatePredicates) {
|
3946
|
+
if (isScriptTransaction) {
|
3947
|
+
txRequestClone.gasLimit = bn15(0);
|
3948
|
+
}
|
3949
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3950
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3951
|
+
}
|
3952
|
+
await this.estimatePredicates(txRequestClone);
|
4160
3953
|
}
|
4161
|
-
const signedRequest = clone3(txRequestClone);
|
4162
|
-
let addedSignatures = 0;
|
4163
3954
|
if (signatureCallback && isScriptTransaction) {
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
await this.estimatePredicates(signedRequest);
|
4169
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4170
|
-
transactionRequest: signedRequest,
|
4171
|
-
optimizeGas: false
|
4172
|
-
});
|
4173
|
-
txRequestClone.maxFee = maxFee;
|
3955
|
+
await signatureCallback(txRequestClone);
|
3956
|
+
}
|
3957
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3958
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4174
3959
|
let receipts = [];
|
4175
3960
|
let missingContractIds = [];
|
4176
3961
|
let outputVariables = 0;
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
if (signatureCallback) {
|
4181
|
-
await signatureCallback(txRequestClone);
|
4182
|
-
}
|
4183
|
-
txRequestClone.gasLimit = gasLimit;
|
3962
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3963
|
+
txRequestClone.gasPrice = bn15(0);
|
3964
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4184
3965
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4185
3966
|
receipts = result.receipts;
|
4186
3967
|
outputVariables = result.outputVariables;
|
4187
3968
|
missingContractIds = result.missingContractIds;
|
4188
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4189
|
-
txRequestClone.gasLimit = gasUsed;
|
4190
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4191
|
-
transactionRequest: txRequestClone,
|
4192
|
-
gasPrice
|
4193
|
-
}));
|
4194
3969
|
}
|
3970
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3971
|
+
const usedFee = calculatePriceWithFactor(
|
3972
|
+
gasUsed,
|
3973
|
+
gasPrice,
|
3974
|
+
gasPriceFactor
|
3975
|
+
).normalizeZeroToOne();
|
3976
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3977
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4195
3978
|
return {
|
4196
3979
|
requiredQuantities: allQuantities,
|
4197
3980
|
receipts,
|
4198
3981
|
gasUsed,
|
3982
|
+
minGasPrice,
|
4199
3983
|
gasPrice,
|
4200
3984
|
minGas,
|
4201
3985
|
maxGas,
|
3986
|
+
usedFee,
|
4202
3987
|
minFee,
|
4203
3988
|
maxFee,
|
3989
|
+
estimatedInputs: txRequestClone.inputs,
|
4204
3990
|
outputVariables,
|
4205
|
-
missingContractIds
|
4206
|
-
addedSignatures,
|
4207
|
-
estimatedPredicates: txRequestClone.inputs
|
3991
|
+
missingContractIds
|
4208
3992
|
};
|
4209
3993
|
}
|
4210
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
3994
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4211
3995
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4212
3996
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4213
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4214
|
-
quantitiesToContract
|
4215
|
-
});
|
3997
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4216
3998
|
transactionRequest.addResources(
|
4217
3999
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4218
4000
|
);
|
4219
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4220
|
-
|
4221
|
-
|
4001
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4002
|
+
transactionRequest,
|
4003
|
+
forwardingQuantities
|
4004
|
+
);
|
4222
4005
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4223
4006
|
return {
|
4224
4007
|
resources,
|
@@ -4240,10 +4023,11 @@ var _Provider = class {
|
|
4240
4023
|
return coins.map((coin) => ({
|
4241
4024
|
id: coin.utxoId,
|
4242
4025
|
assetId: coin.assetId,
|
4243
|
-
amount:
|
4026
|
+
amount: bn15(coin.amount),
|
4244
4027
|
owner: Address2.fromAddressOrString(coin.owner),
|
4245
|
-
|
4246
|
-
|
4028
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4029
|
+
blockCreated: bn15(coin.blockCreated),
|
4030
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4247
4031
|
}));
|
4248
4032
|
}
|
4249
4033
|
/**
|
@@ -4280,9 +4064,9 @@ var _Provider = class {
|
|
4280
4064
|
switch (coin.__typename) {
|
4281
4065
|
case "MessageCoin":
|
4282
4066
|
return {
|
4283
|
-
amount:
|
4067
|
+
amount: bn15(coin.amount),
|
4284
4068
|
assetId: coin.assetId,
|
4285
|
-
daHeight:
|
4069
|
+
daHeight: bn15(coin.daHeight),
|
4286
4070
|
sender: Address2.fromAddressOrString(coin.sender),
|
4287
4071
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4288
4072
|
nonce: coin.nonce
|
@@ -4290,11 +4074,12 @@ var _Provider = class {
|
|
4290
4074
|
case "Coin":
|
4291
4075
|
return {
|
4292
4076
|
id: coin.utxoId,
|
4293
|
-
amount:
|
4077
|
+
amount: bn15(coin.amount),
|
4294
4078
|
assetId: coin.assetId,
|
4295
4079
|
owner: Address2.fromAddressOrString(coin.owner),
|
4296
|
-
|
4297
|
-
|
4080
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4081
|
+
blockCreated: bn15(coin.blockCreated),
|
4082
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4298
4083
|
};
|
4299
4084
|
default:
|
4300
4085
|
return null;
|
@@ -4311,13 +4096,13 @@ var _Provider = class {
|
|
4311
4096
|
async getBlock(idOrHeight) {
|
4312
4097
|
let variables;
|
4313
4098
|
if (typeof idOrHeight === "number") {
|
4314
|
-
variables = { height:
|
4099
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4315
4100
|
} else if (idOrHeight === "latest") {
|
4316
4101
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4317
4102
|
} else if (idOrHeight.length === 66) {
|
4318
4103
|
variables = { blockId: idOrHeight };
|
4319
4104
|
} else {
|
4320
|
-
variables = { blockId:
|
4105
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4321
4106
|
}
|
4322
4107
|
const { block } = await this.operations.getBlock(variables);
|
4323
4108
|
if (!block) {
|
@@ -4325,7 +4110,7 @@ var _Provider = class {
|
|
4325
4110
|
}
|
4326
4111
|
return {
|
4327
4112
|
id: block.id,
|
4328
|
-
height:
|
4113
|
+
height: bn15(block.header.height),
|
4329
4114
|
time: block.header.time,
|
4330
4115
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4331
4116
|
};
|
@@ -4340,7 +4125,7 @@ var _Provider = class {
|
|
4340
4125
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4341
4126
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4342
4127
|
id: block.id,
|
4343
|
-
height:
|
4128
|
+
height: bn15(block.header.height),
|
4344
4129
|
time: block.header.time,
|
4345
4130
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4346
4131
|
}));
|
@@ -4355,7 +4140,7 @@ var _Provider = class {
|
|
4355
4140
|
async getBlockWithTransactions(idOrHeight) {
|
4356
4141
|
let variables;
|
4357
4142
|
if (typeof idOrHeight === "number") {
|
4358
|
-
variables = { blockHeight:
|
4143
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4359
4144
|
} else if (idOrHeight === "latest") {
|
4360
4145
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4361
4146
|
} else {
|
@@ -4367,7 +4152,7 @@ var _Provider = class {
|
|
4367
4152
|
}
|
4368
4153
|
return {
|
4369
4154
|
id: block.id,
|
4370
|
-
height:
|
4155
|
+
height: bn15(block.header.height, 10),
|
4371
4156
|
time: block.header.time,
|
4372
4157
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4373
4158
|
transactions: block.transactions.map(
|
@@ -4416,7 +4201,7 @@ var _Provider = class {
|
|
4416
4201
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4417
4202
|
asset: hexlify12(assetId)
|
4418
4203
|
});
|
4419
|
-
return
|
4204
|
+
return bn15(contractBalance.amount, 10);
|
4420
4205
|
}
|
4421
4206
|
/**
|
4422
4207
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4430,7 +4215,7 @@ var _Provider = class {
|
|
4430
4215
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4431
4216
|
assetId: hexlify12(assetId)
|
4432
4217
|
});
|
4433
|
-
return
|
4218
|
+
return bn15(balance.amount, 10);
|
4434
4219
|
}
|
4435
4220
|
/**
|
4436
4221
|
* Returns balances for the given owner.
|
@@ -4448,7 +4233,7 @@ var _Provider = class {
|
|
4448
4233
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4449
4234
|
return balances.map((balance) => ({
|
4450
4235
|
assetId: balance.assetId,
|
4451
|
-
amount:
|
4236
|
+
amount: bn15(balance.amount)
|
4452
4237
|
}));
|
4453
4238
|
}
|
4454
4239
|
/**
|
@@ -4470,15 +4255,15 @@ var _Provider = class {
|
|
4470
4255
|
sender: message.sender,
|
4471
4256
|
recipient: message.recipient,
|
4472
4257
|
nonce: message.nonce,
|
4473
|
-
amount:
|
4258
|
+
amount: bn15(message.amount),
|
4474
4259
|
data: message.data
|
4475
4260
|
}),
|
4476
4261
|
sender: Address2.fromAddressOrString(message.sender),
|
4477
4262
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4478
4263
|
nonce: message.nonce,
|
4479
|
-
amount:
|
4264
|
+
amount: bn15(message.amount),
|
4480
4265
|
data: InputMessageCoder.decodeData(message.data),
|
4481
|
-
daHeight:
|
4266
|
+
daHeight: bn15(message.daHeight)
|
4482
4267
|
}));
|
4483
4268
|
}
|
4484
4269
|
/**
|
@@ -4531,52 +4316,44 @@ var _Provider = class {
|
|
4531
4316
|
} = result.messageProof;
|
4532
4317
|
return {
|
4533
4318
|
messageProof: {
|
4534
|
-
proofIndex:
|
4319
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4535
4320
|
proofSet: messageProof.proofSet
|
4536
4321
|
},
|
4537
4322
|
blockProof: {
|
4538
|
-
proofIndex:
|
4323
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4539
4324
|
proofSet: blockProof.proofSet
|
4540
4325
|
},
|
4541
4326
|
messageBlockHeader: {
|
4542
4327
|
id: messageBlockHeader.id,
|
4543
|
-
daHeight:
|
4544
|
-
transactionsCount:
|
4328
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4329
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4545
4330
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4546
|
-
height:
|
4331
|
+
height: bn15(messageBlockHeader.height),
|
4547
4332
|
prevRoot: messageBlockHeader.prevRoot,
|
4548
4333
|
time: messageBlockHeader.time,
|
4549
4334
|
applicationHash: messageBlockHeader.applicationHash,
|
4550
|
-
|
4335
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4336
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4551
4337
|
},
|
4552
4338
|
commitBlockHeader: {
|
4553
4339
|
id: commitBlockHeader.id,
|
4554
|
-
daHeight:
|
4555
|
-
transactionsCount:
|
4340
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4341
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4556
4342
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4557
|
-
height:
|
4343
|
+
height: bn15(commitBlockHeader.height),
|
4558
4344
|
prevRoot: commitBlockHeader.prevRoot,
|
4559
4345
|
time: commitBlockHeader.time,
|
4560
4346
|
applicationHash: commitBlockHeader.applicationHash,
|
4561
|
-
|
4347
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4348
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4562
4349
|
},
|
4563
4350
|
sender: Address2.fromAddressOrString(sender),
|
4564
4351
|
recipient: Address2.fromAddressOrString(recipient),
|
4565
4352
|
nonce,
|
4566
|
-
amount:
|
4353
|
+
amount: bn15(amount),
|
4567
4354
|
data
|
4568
4355
|
};
|
4569
4356
|
}
|
4570
|
-
async getLatestGasPrice() {
|
4571
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4572
|
-
return bn16(latestGasPrice.gasPrice);
|
4573
|
-
}
|
4574
|
-
async estimateGasPrice(blockHorizon) {
|
4575
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4576
|
-
blockHorizon: String(blockHorizon)
|
4577
|
-
});
|
4578
|
-
return bn16(estimateGasPrice.gasPrice);
|
4579
|
-
}
|
4580
4357
|
/**
|
4581
4358
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4582
4359
|
*
|
@@ -4596,10 +4373,10 @@ var _Provider = class {
|
|
4596
4373
|
*/
|
4597
4374
|
async produceBlocks(amount, startTime) {
|
4598
4375
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4599
|
-
blocksToProduce:
|
4376
|
+
blocksToProduce: bn15(amount).toString(10),
|
4600
4377
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4601
4378
|
});
|
4602
|
-
return
|
4379
|
+
return bn15(latestBlockHeight);
|
4603
4380
|
}
|
4604
4381
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4605
4382
|
async getTransactionResponse(transactionId) {
|
@@ -4613,7 +4390,7 @@ cacheInputs_fn = function(inputs) {
|
|
4613
4390
|
return;
|
4614
4391
|
}
|
4615
4392
|
inputs.forEach((input) => {
|
4616
|
-
if (input.type ===
|
4393
|
+
if (input.type === InputType6.Coin) {
|
4617
4394
|
this.cache?.set(input.id);
|
4618
4395
|
}
|
4619
4396
|
});
|
@@ -4623,7 +4400,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4623
4400
|
|
4624
4401
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4625
4402
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4626
|
-
import { bn as
|
4403
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4627
4404
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4628
4405
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4629
4406
|
|
@@ -4831,8 +4608,9 @@ var Account = class extends AbstractAccount {
|
|
4831
4608
|
* @param assetId - The asset ID to check the balance for.
|
4832
4609
|
* @returns A promise that resolves to the balance amount.
|
4833
4610
|
*/
|
4834
|
-
async getBalance(assetId
|
4835
|
-
const
|
4611
|
+
async getBalance(assetId) {
|
4612
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4613
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4836
4614
|
return amount;
|
4837
4615
|
}
|
4838
4616
|
/**
|
@@ -4869,33 +4647,37 @@ var Account = class extends AbstractAccount {
|
|
4869
4647
|
* @param fee - The estimated transaction fee.
|
4870
4648
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4871
4649
|
*/
|
4872
|
-
async fund(request,
|
4873
|
-
const
|
4874
|
-
const
|
4875
|
-
|
4876
|
-
|
4877
|
-
|
4878
|
-
coinQuantities: requiredQuantities
|
4650
|
+
async fund(request, coinQuantities, fee) {
|
4651
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4652
|
+
const updatedQuantities = addAmountToAsset({
|
4653
|
+
amount: bn17(fee),
|
4654
|
+
assetId: baseAssetId,
|
4655
|
+
coinQuantities
|
4879
4656
|
});
|
4880
4657
|
const quantitiesDict = {};
|
4881
|
-
|
4658
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4882
4659
|
quantitiesDict[assetId] = {
|
4883
4660
|
required: amount,
|
4884
|
-
owned:
|
4661
|
+
owned: bn17(0)
|
4885
4662
|
};
|
4886
4663
|
});
|
4887
|
-
|
4664
|
+
const cachedUtxos = [];
|
4665
|
+
const cachedMessages = [];
|
4666
|
+
const owner = this.address.toB256();
|
4667
|
+
request.inputs.forEach((input) => {
|
4888
4668
|
const isResource = "amount" in input;
|
4889
4669
|
if (isResource) {
|
4890
4670
|
const isCoin2 = "owner" in input;
|
4891
4671
|
if (isCoin2) {
|
4892
4672
|
const assetId = String(input.assetId);
|
4893
|
-
if (quantitiesDict[assetId]) {
|
4894
|
-
const amount =
|
4673
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4674
|
+
const amount = bn17(input.amount);
|
4895
4675
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4676
|
+
cachedUtxos.push(input.id);
|
4896
4677
|
}
|
4897
|
-
} else if (input.amount && quantitiesDict[
|
4898
|
-
quantitiesDict[
|
4678
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4679
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4680
|
+
cachedMessages.push(input.nonce);
|
4899
4681
|
}
|
4900
4682
|
}
|
4901
4683
|
});
|
@@ -4910,23 +4692,12 @@ var Account = class extends AbstractAccount {
|
|
4910
4692
|
});
|
4911
4693
|
const needsToBeFunded = missingQuantities.length;
|
4912
4694
|
if (needsToBeFunded) {
|
4913
|
-
const
|
4914
|
-
|
4915
|
-
|
4916
|
-
|
4917
|
-
|
4918
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4919
|
-
const requestToBeReEstimate = clone4(txRequest);
|
4920
|
-
if (addedSignatures) {
|
4921
|
-
Array.from({ length: addedSignatures }).forEach(
|
4922
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4923
|
-
);
|
4695
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4696
|
+
messages: cachedMessages,
|
4697
|
+
utxos: cachedUtxos
|
4698
|
+
});
|
4699
|
+
request.addResources(resources);
|
4924
4700
|
}
|
4925
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4926
|
-
transactionRequest: requestToBeReEstimate
|
4927
|
-
});
|
4928
|
-
txRequest.maxFee = maxFee;
|
4929
|
-
return txRequest;
|
4930
4701
|
}
|
4931
4702
|
/**
|
4932
4703
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4934,25 +4705,30 @@ var Account = class extends AbstractAccount {
|
|
4934
4705
|
* @param destination - The address of the destination.
|
4935
4706
|
* @param amount - The amount of coins to transfer.
|
4936
4707
|
* @param assetId - The asset ID of the coins to transfer.
|
4937
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4708
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4938
4709
|
* @returns A promise that resolves to the prepared transaction request.
|
4939
4710
|
*/
|
4940
|
-
async createTransfer(destination, amount, assetId
|
4941
|
-
const
|
4942
|
-
|
4943
|
-
const
|
4711
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4712
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4713
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4714
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4715
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4716
|
+
const request = new ScriptTransactionRequest(params);
|
4717
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4718
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4944
4719
|
estimateTxDependencies: true,
|
4945
4720
|
resourcesOwner: this
|
4946
4721
|
});
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
await this.fund(request,
|
4722
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4723
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4724
|
+
this.validateGas({
|
4725
|
+
gasUsed,
|
4726
|
+
gasPrice: request.gasPrice,
|
4727
|
+
gasLimit: request.gasLimit,
|
4728
|
+
minGasPrice
|
4729
|
+
});
|
4730
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4731
|
+
request.updatePredicateInputs(estimatedInputs);
|
4956
4732
|
return request;
|
4957
4733
|
}
|
4958
4734
|
/**
|
@@ -4964,14 +4740,15 @@ var Account = class extends AbstractAccount {
|
|
4964
4740
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4965
4741
|
* @returns A promise that resolves to the transaction response.
|
4966
4742
|
*/
|
4967
|
-
async transfer(destination, amount, assetId
|
4968
|
-
if (
|
4743
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4744
|
+
if (bn17(amount).lte(0)) {
|
4969
4745
|
throw new FuelError15(
|
4970
4746
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4971
4747
|
"Transfer amount must be a positive number."
|
4972
4748
|
);
|
4973
4749
|
}
|
4974
|
-
const
|
4750
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4751
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4975
4752
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4976
4753
|
}
|
4977
4754
|
/**
|
@@ -4983,38 +4760,41 @@ var Account = class extends AbstractAccount {
|
|
4983
4760
|
* @param txParams - The optional transaction parameters.
|
4984
4761
|
* @returns A promise that resolves to the transaction response.
|
4985
4762
|
*/
|
4986
|
-
async transferToContract(contractId, amount, assetId
|
4987
|
-
if (
|
4763
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4764
|
+
if (bn17(amount).lte(0)) {
|
4988
4765
|
throw new FuelError15(
|
4989
4766
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4990
4767
|
"Transfer amount must be a positive number."
|
4991
4768
|
);
|
4992
4769
|
}
|
4993
4770
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4771
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4772
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4773
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4774
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4994
4775
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4995
4776
|
hexlifiedContractId: contractAddress.toB256(),
|
4996
|
-
amountToTransfer:
|
4997
|
-
assetId
|
4777
|
+
amountToTransfer: bn17(amount),
|
4778
|
+
assetId: assetIdToTransfer
|
4998
4779
|
});
|
4999
4780
|
const request = new ScriptTransactionRequest({
|
5000
|
-
...
|
4781
|
+
...params,
|
5001
4782
|
script,
|
5002
4783
|
scriptData
|
5003
4784
|
});
|
5004
4785
|
request.addContractInputAndOutput(contractAddress);
|
5005
|
-
const
|
5006
|
-
|
5007
|
-
|
4786
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4787
|
+
request,
|
4788
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4789
|
+
);
|
4790
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4791
|
+
this.validateGas({
|
4792
|
+
gasUsed,
|
4793
|
+
gasPrice: request.gasPrice,
|
4794
|
+
gasLimit: request.gasLimit,
|
4795
|
+
minGasPrice
|
5008
4796
|
});
|
5009
|
-
|
5010
|
-
this.validateGas({
|
5011
|
-
gasUsed: txCost.gasUsed,
|
5012
|
-
gasLimit: request.gasLimit
|
5013
|
-
});
|
5014
|
-
}
|
5015
|
-
request.gasLimit = txCost.gasUsed;
|
5016
|
-
request.maxFee = txCost.maxFee;
|
5017
|
-
await this.fund(request, txCost);
|
4797
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5018
4798
|
return this.sendTransaction(request);
|
5019
4799
|
}
|
5020
4800
|
/**
|
@@ -5026,31 +4806,40 @@ var Account = class extends AbstractAccount {
|
|
5026
4806
|
* @returns A promise that resolves to the transaction response.
|
5027
4807
|
*/
|
5028
4808
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4809
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4810
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5029
4811
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5030
4812
|
const recipientDataArray = arrayify14(
|
5031
4813
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5032
4814
|
);
|
5033
4815
|
const amountDataArray = arrayify14(
|
5034
|
-
"0x".concat(
|
4816
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5035
4817
|
);
|
5036
4818
|
const script = new Uint8Array([
|
5037
4819
|
...arrayify14(withdrawScript.bytes),
|
5038
4820
|
...recipientDataArray,
|
5039
4821
|
...amountDataArray
|
5040
4822
|
]);
|
5041
|
-
const params = {
|
4823
|
+
const params = {
|
4824
|
+
script,
|
4825
|
+
gasPrice: minGasPrice,
|
4826
|
+
baseAssetId,
|
4827
|
+
...txParams
|
4828
|
+
};
|
5042
4829
|
const request = new ScriptTransactionRequest(params);
|
5043
|
-
const
|
5044
|
-
const
|
5045
|
-
|
5046
|
-
|
5047
|
-
|
5048
|
-
|
5049
|
-
|
5050
|
-
|
5051
|
-
|
5052
|
-
|
5053
|
-
|
4830
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4831
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4832
|
+
request,
|
4833
|
+
forwardingQuantities
|
4834
|
+
);
|
4835
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4836
|
+
this.validateGas({
|
4837
|
+
gasUsed,
|
4838
|
+
gasPrice: request.gasPrice,
|
4839
|
+
gasLimit: request.gasLimit,
|
4840
|
+
minGasPrice
|
4841
|
+
});
|
4842
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5054
4843
|
return this.sendTransaction(request);
|
5055
4844
|
}
|
5056
4845
|
async signMessage(message) {
|
@@ -5108,7 +4897,18 @@ var Account = class extends AbstractAccount {
|
|
5108
4897
|
}
|
5109
4898
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5110
4899
|
}
|
5111
|
-
validateGas({
|
4900
|
+
validateGas({
|
4901
|
+
gasUsed,
|
4902
|
+
gasPrice,
|
4903
|
+
gasLimit,
|
4904
|
+
minGasPrice
|
4905
|
+
}) {
|
4906
|
+
if (minGasPrice.gt(gasPrice)) {
|
4907
|
+
throw new FuelError15(
|
4908
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4909
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4910
|
+
);
|
4911
|
+
}
|
5112
4912
|
if (gasUsed.gt(gasLimit)) {
|
5113
4913
|
throw new FuelError15(
|
5114
4914
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5120,7 +4920,7 @@ var Account = class extends AbstractAccount {
|
|
5120
4920
|
|
5121
4921
|
// src/signer/signer.ts
|
5122
4922
|
import { Address as Address4 } from "@fuel-ts/address";
|
5123
|
-
import { randomBytes
|
4923
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5124
4924
|
import { hash } from "@fuel-ts/hasher";
|
5125
4925
|
import { toBytes } from "@fuel-ts/math";
|
5126
4926
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5213,7 +5013,7 @@ var Signer = class {
|
|
5213
5013
|
* @returns random 32-byte hashed
|
5214
5014
|
*/
|
5215
5015
|
static generatePrivateKey(entropy) {
|
5216
|
-
return entropy ? hash(concat3([
|
5016
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5217
5017
|
}
|
5218
5018
|
/**
|
5219
5019
|
* Extended publicKey from a compact publicKey
|
@@ -5232,7 +5032,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5232
5032
|
import {
|
5233
5033
|
bufferFromString,
|
5234
5034
|
keccak256,
|
5235
|
-
randomBytes as
|
5035
|
+
randomBytes as randomBytes2,
|
5236
5036
|
scrypt,
|
5237
5037
|
stringFromBuffer,
|
5238
5038
|
decryptJsonWalletData,
|
@@ -5255,7 +5055,7 @@ var removeHexPrefix = (hexString) => {
|
|
5255
5055
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5256
5056
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5257
5057
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5258
|
-
const salt =
|
5058
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5259
5059
|
const key = scrypt({
|
5260
5060
|
password: bufferFromString(password),
|
5261
5061
|
salt,
|
@@ -5264,7 +5064,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5264
5064
|
r: DEFAULT_KDF_PARAMS_R,
|
5265
5065
|
p: DEFAULT_KDF_PARAMS_P
|
5266
5066
|
});
|
5267
|
-
const iv =
|
5067
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5268
5068
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5269
5069
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5270
5070
|
const macHashUint8Array = keccak256(data);
|
@@ -5400,7 +5200,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5400
5200
|
* @param transactionRequestLike - The transaction request to send.
|
5401
5201
|
* @returns A promise that resolves to the TransactionResponse object.
|
5402
5202
|
*/
|
5403
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5203
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5404
5204
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5405
5205
|
if (estimateTxDependencies) {
|
5406
5206
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5441,12 +5241,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5441
5241
|
// src/hdwallet/hdwallet.ts
|
5442
5242
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5443
5243
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5444
|
-
import { bn as
|
5244
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5445
5245
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5446
5246
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5447
5247
|
|
5448
5248
|
// src/mnemonic/mnemonic.ts
|
5449
|
-
import { randomBytes as
|
5249
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5450
5250
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5451
5251
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5452
5252
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7801,7 +7601,7 @@ var Mnemonic = class {
|
|
7801
7601
|
* @returns A randomly generated mnemonic
|
7802
7602
|
*/
|
7803
7603
|
static generate(size = 32, extraEntropy = "") {
|
7804
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7604
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7805
7605
|
return Mnemonic.entropyToMnemonic(entropy);
|
7806
7606
|
}
|
7807
7607
|
};
|
@@ -7907,7 +7707,7 @@ var HDWallet = class {
|
|
7907
7707
|
const IR = bytes.slice(32);
|
7908
7708
|
if (privateKey) {
|
7909
7709
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7910
|
-
const ki =
|
7710
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7911
7711
|
return new HDWallet({
|
7912
7712
|
privateKey: ki,
|
7913
7713
|
chainCode: IR,
|
@@ -8172,21 +7972,22 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
8172
7972
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
8173
7973
|
|
8174
7974
|
// src/test-utils/seedTestWallet.ts
|
8175
|
-
import { randomBytes as
|
7975
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
8176
7976
|
var seedTestWallet = async (wallet, quantities) => {
|
8177
7977
|
const genesisWallet = new WalletUnlocked(
|
8178
|
-
process.env.GENESIS_SECRET ||
|
7978
|
+
process.env.GENESIS_SECRET || randomBytes4(32),
|
8179
7979
|
wallet.provider
|
8180
7980
|
);
|
8181
|
-
const
|
8182
|
-
|
8183
|
-
|
8184
|
-
|
7981
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7982
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7983
|
+
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
7984
|
+
const request = new ScriptTransactionRequest({
|
7985
|
+
baseAssetId,
|
7986
|
+
gasLimit: 1e4,
|
7987
|
+
gasPrice: minGasPrice
|
8185
7988
|
});
|
8186
|
-
|
8187
|
-
request.
|
8188
|
-
request.maxFee = txCost.maxFee;
|
8189
|
-
await genesisWallet.fund(request, txCost);
|
7989
|
+
request.addResources(resources);
|
7990
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8190
7991
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8191
7992
|
};
|
8192
7993
|
|
@@ -8200,12 +8001,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8200
8001
|
};
|
8201
8002
|
|
8202
8003
|
// src/test-utils/launchNode.ts
|
8203
|
-
import {
|
8204
|
-
import {
|
8004
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8005
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8006
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8205
8007
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8206
8008
|
import { spawn } from "child_process";
|
8207
8009
|
import { randomUUID } from "crypto";
|
8208
|
-
import { randomBytes as randomBytes6 } from "ethers";
|
8209
8010
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8210
8011
|
import os from "os";
|
8211
8012
|
import path from "path";
|
@@ -8254,12 +8055,12 @@ var launchNode = async ({
|
|
8254
8055
|
// eslint-disable-next-line no-async-promise-executor
|
8255
8056
|
new Promise(async (resolve, reject) => {
|
8256
8057
|
const remainingArgs = extractRemainingArgs(args, [
|
8257
|
-
"--
|
8058
|
+
"--chain",
|
8258
8059
|
"--consensus-key",
|
8259
8060
|
"--db-type",
|
8260
8061
|
"--poa-instant"
|
8261
8062
|
]);
|
8262
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8063
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8263
8064
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8264
8065
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8265
8066
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8278,54 +8079,36 @@ var launchNode = async ({
|
|
8278
8079
|
let chainConfigPathToUse;
|
8279
8080
|
const prefix = basePath || os.tmpdir();
|
8280
8081
|
const suffix = basePath ? "" : randomUUID();
|
8281
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8082
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8282
8083
|
if (chainConfigPath) {
|
8283
8084
|
chainConfigPathToUse = chainConfigPath;
|
8284
8085
|
} else {
|
8285
8086
|
if (!existsSync(tempDirPath)) {
|
8286
8087
|
mkdirSync(tempDirPath, { recursive: true });
|
8287
8088
|
}
|
8288
|
-
|
8289
|
-
|
8290
|
-
stateConfigJson = {
|
8291
|
-
...stateConfigJson,
|
8292
|
-
coins: [
|
8293
|
-
...stateConfigJson.coins.map((coin) => ({
|
8294
|
-
...coin,
|
8295
|
-
amount: "18446744073709551615"
|
8296
|
-
}))
|
8297
|
-
],
|
8298
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8299
|
-
...message,
|
8300
|
-
amount: "18446744073709551615"
|
8301
|
-
}))
|
8302
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8303
|
-
};
|
8089
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8090
|
+
let chainConfig = defaultChainConfig;
|
8304
8091
|
if (!process.env.GENESIS_SECRET) {
|
8305
8092
|
const pk = Signer.generatePrivateKey();
|
8306
8093
|
const signer = new Signer(pk);
|
8307
8094
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8308
|
-
|
8309
|
-
|
8310
|
-
|
8311
|
-
|
8312
|
-
|
8313
|
-
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8095
|
+
chainConfig = {
|
8096
|
+
...defaultChainConfig,
|
8097
|
+
initial_state: {
|
8098
|
+
...defaultChainConfig.initial_state,
|
8099
|
+
coins: [
|
8100
|
+
...defaultChainConfig.initial_state.coins,
|
8101
|
+
{
|
8102
|
+
owner: signer.address.toHexString(),
|
8103
|
+
amount: toHex2(1e9),
|
8104
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8105
|
+
}
|
8106
|
+
]
|
8107
|
+
}
|
8108
|
+
};
|
8318
8109
|
}
|
8319
|
-
|
8320
|
-
|
8321
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8322
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8323
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8324
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8325
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8326
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8327
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8328
|
-
chainConfigPathToUse = tempDirPath;
|
8110
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8111
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8329
8112
|
}
|
8330
8113
|
const child = spawn(
|
8331
8114
|
command,
|
@@ -8334,10 +8117,10 @@ var launchNode = async ({
|
|
8334
8117
|
["--ip", ipToUse],
|
8335
8118
|
["--port", portToUse],
|
8336
8119
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8337
|
-
["--min-gas-price", "
|
8120
|
+
["--min-gas-price", "0"],
|
8338
8121
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8339
8122
|
["--consensus-key", consensusKey],
|
8340
|
-
["--
|
8123
|
+
["--chain", chainConfigPathToUse],
|
8341
8124
|
"--vm-backtrace",
|
8342
8125
|
"--utxo-validation",
|
8343
8126
|
"--debug",
|
@@ -8384,9 +8167,10 @@ var launchNode = async ({
|
|
8384
8167
|
})
|
8385
8168
|
);
|
8386
8169
|
var generateWallets = async (count, provider) => {
|
8170
|
+
const baseAssetId = provider.getBaseAssetId();
|
8387
8171
|
const wallets = [];
|
8388
8172
|
for (let i = 0; i < count; i += 1) {
|
8389
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8173
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8390
8174
|
wallets.push(wallet);
|
8391
8175
|
}
|
8392
8176
|
return wallets;
|
@@ -8396,7 +8180,7 @@ var launchNodeAndGetWallets = async ({
|
|
8396
8180
|
walletCount = 10
|
8397
8181
|
} = {}) => {
|
8398
8182
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8399
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8183
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8400
8184
|
const wallets = await generateWallets(walletCount, provider);
|
8401
8185
|
const cleanup = () => {
|
8402
8186
|
closeNode();
|