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