@fuel-ts/account 0.0.0-rc-2021-20240415193305 → 0.0.0-rc-1976-20240416161016
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 +600 -829
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +600 -835
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +443 -677
- 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 +329 -911
- 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 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -37
- 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 +1114 -1578
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +599 -813
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +455 -669
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +22 -27
package/dist/index.mjs
CHANGED
@@ -29,15 +29,12 @@ 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) => {
|
@@ -46,11 +43,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
46
43
|
let max2;
|
47
44
|
if (Array.isArray(coinQuantityLike)) {
|
48
45
|
amount = coinQuantityLike[0];
|
49
|
-
assetId = coinQuantityLike[1]
|
50
|
-
max2 = coinQuantityLike[2]
|
46
|
+
assetId = coinQuantityLike[1];
|
47
|
+
max2 = coinQuantityLike[2];
|
51
48
|
} else {
|
52
49
|
amount = coinQuantityLike.amount;
|
53
|
-
assetId = coinQuantityLike.assetId
|
50
|
+
assetId = coinQuantityLike.assetId;
|
54
51
|
max2 = coinQuantityLike.max ?? void 0;
|
55
52
|
}
|
56
53
|
const bnAmount = bn(amount);
|
@@ -60,7 +57,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
60
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
|
}
|
@@ -271,32 +229,26 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
271
229
|
messageBlockHeader {
|
272
230
|
id
|
273
231
|
daHeight
|
274
|
-
consensusParametersVersion
|
275
|
-
stateTransitionBytecodeVersion
|
276
232
|
transactionsCount
|
277
|
-
messageReceiptCount
|
278
233
|
transactionsRoot
|
279
|
-
messageOutboxRoot
|
280
|
-
eventInboxRoot
|
281
234
|
height
|
282
235
|
prevRoot
|
283
236
|
time
|
284
237
|
applicationHash
|
238
|
+
messageReceiptRoot
|
239
|
+
messageReceiptCount
|
285
240
|
}
|
286
241
|
commitBlockHeader {
|
287
242
|
id
|
288
243
|
daHeight
|
289
|
-
consensusParametersVersion
|
290
|
-
stateTransitionBytecodeVersion
|
291
244
|
transactionsCount
|
292
|
-
messageReceiptCount
|
293
245
|
transactionsRoot
|
294
|
-
messageOutboxRoot
|
295
|
-
eventInboxRoot
|
296
246
|
height
|
297
247
|
prevRoot
|
298
248
|
time
|
299
249
|
applicationHash
|
250
|
+
messageReceiptRoot
|
251
|
+
messageReceiptCount
|
300
252
|
}
|
301
253
|
sender
|
302
254
|
recipient
|
@@ -315,8 +267,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
315
267
|
var BlockFragmentFragmentDoc = gql`
|
316
268
|
fragment blockFragment on Block {
|
317
269
|
id
|
318
|
-
height
|
319
270
|
header {
|
271
|
+
height
|
320
272
|
time
|
321
273
|
}
|
322
274
|
transactions {
|
@@ -374,11 +326,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
374
326
|
`;
|
375
327
|
var GasCostsFragmentFragmentDoc = gql`
|
376
328
|
fragment GasCostsFragment on GasCosts {
|
377
|
-
version {
|
378
|
-
... on Version {
|
379
|
-
value
|
380
|
-
}
|
381
|
-
}
|
382
329
|
add
|
383
330
|
addi
|
384
331
|
aloc
|
@@ -391,6 +338,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
391
338
|
cb
|
392
339
|
cfei
|
393
340
|
cfsi
|
341
|
+
croo
|
394
342
|
div
|
395
343
|
divi
|
396
344
|
ecr1
|
@@ -473,9 +421,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
473
421
|
ccp {
|
474
422
|
...DependentCostFragment
|
475
423
|
}
|
476
|
-
croo {
|
477
|
-
...DependentCostFragment
|
478
|
-
}
|
479
424
|
csiz {
|
480
425
|
...DependentCostFragment
|
481
426
|
}
|
@@ -535,11 +480,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
535
480
|
${DependentCostFragmentFragmentDoc}`;
|
536
481
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
537
482
|
fragment consensusParametersFragment on ConsensusParameters {
|
538
|
-
version {
|
539
|
-
... on Version {
|
540
|
-
value
|
541
|
-
}
|
542
|
-
}
|
543
483
|
txParams {
|
544
484
|
...TxParametersFragment
|
545
485
|
}
|
@@ -599,9 +539,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
599
539
|
fragment nodeInfoFragment on NodeInfo {
|
600
540
|
utxoValidation
|
601
541
|
vmBacktrace
|
542
|
+
minGasPrice
|
602
543
|
maxTx
|
603
544
|
maxDepth
|
604
545
|
nodeVersion
|
546
|
+
peers {
|
547
|
+
id
|
548
|
+
addresses
|
549
|
+
clientVersion
|
550
|
+
blockHeight
|
551
|
+
lastHeartbeatMs
|
552
|
+
appScore
|
553
|
+
}
|
605
554
|
}
|
606
555
|
`;
|
607
556
|
var GetVersionDocument = gql`
|
@@ -636,9 +585,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
636
585
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
637
586
|
transaction(id: $transactionId) {
|
638
587
|
...transactionFragment
|
588
|
+
receipts {
|
589
|
+
...receiptFragment
|
590
|
+
}
|
639
591
|
}
|
640
592
|
}
|
641
|
-
${TransactionFragmentFragmentDoc}
|
593
|
+
${TransactionFragmentFragmentDoc}
|
594
|
+
${ReceiptFragmentFragmentDoc}`;
|
642
595
|
var GetTransactionsDocument = gql`
|
643
596
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
644
597
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -766,20 +719,6 @@ var GetBalanceDocument = gql`
|
|
766
719
|
}
|
767
720
|
}
|
768
721
|
${BalanceFragmentFragmentDoc}`;
|
769
|
-
var GetLatestGasPriceDocument = gql`
|
770
|
-
query getLatestGasPrice {
|
771
|
-
latestGasPrice {
|
772
|
-
gasPrice
|
773
|
-
}
|
774
|
-
}
|
775
|
-
`;
|
776
|
-
var EstimateGasPriceDocument = gql`
|
777
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
778
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
779
|
-
gasPrice
|
780
|
-
}
|
781
|
-
}
|
782
|
-
`;
|
783
722
|
var GetBalancesDocument = gql`
|
784
723
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
785
724
|
balances(
|
@@ -834,12 +773,12 @@ var GetMessageStatusDocument = gql`
|
|
834
773
|
}
|
835
774
|
`;
|
836
775
|
var DryRunDocument = gql`
|
837
|
-
mutation dryRun($
|
838
|
-
dryRun(
|
839
|
-
...
|
776
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
777
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
778
|
+
...receiptFragment
|
840
779
|
}
|
841
780
|
}
|
842
|
-
${
|
781
|
+
${ReceiptFragmentFragmentDoc}`;
|
843
782
|
var SubmitDocument = gql`
|
844
783
|
mutation submit($encodedTransaction: HexString!) {
|
845
784
|
submit(tx: $encodedTransaction) {
|
@@ -922,12 +861,6 @@ function getSdk(requester) {
|
|
922
861
|
getBalance(variables, options) {
|
923
862
|
return requester(GetBalanceDocument, variables, options);
|
924
863
|
},
|
925
|
-
getLatestGasPrice(variables, options) {
|
926
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
927
|
-
},
|
928
|
-
estimateGasPrice(variables, options) {
|
929
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
930
|
-
},
|
931
864
|
getBalances(variables, options) {
|
932
865
|
return requester(GetBalancesDocument, variables, options);
|
933
866
|
},
|
@@ -997,14 +930,11 @@ var _FuelGraphqlSubscriber = class {
|
|
997
930
|
let data;
|
998
931
|
let errors;
|
999
932
|
try {
|
1000
|
-
|
1001
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
933
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
1002
934
|
} catch (e) {
|
1003
935
|
throw new FuelError(
|
1004
936
|
ErrorCode.STREAM_PARSING_ERROR,
|
1005
|
-
`Error while parsing stream data response: ${text}
|
1006
|
-
|
1007
|
-
Thrown error: ${e}`
|
937
|
+
`Error while parsing stream data response: ${text}`
|
1008
938
|
);
|
1009
939
|
}
|
1010
940
|
if (Array.isArray(errors)) {
|
@@ -1115,9 +1045,10 @@ var inputify = (value) => {
|
|
1115
1045
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1116
1046
|
},
|
1117
1047
|
witnessIndex: value.witnessIndex,
|
1048
|
+
maturity: value.maturity ?? 0,
|
1118
1049
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1119
|
-
predicateLength:
|
1120
|
-
predicateDataLength:
|
1050
|
+
predicateLength: predicate.length,
|
1051
|
+
predicateDataLength: predicateData.length,
|
1121
1052
|
predicate: hexlify3(predicate),
|
1122
1053
|
predicateData: hexlify3(predicateData)
|
1123
1054
|
};
|
@@ -1148,8 +1079,8 @@ var inputify = (value) => {
|
|
1148
1079
|
nonce: hexlify3(value.nonce),
|
1149
1080
|
witnessIndex: value.witnessIndex,
|
1150
1081
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1151
|
-
predicateLength:
|
1152
|
-
predicateDataLength:
|
1082
|
+
predicateLength: predicate.length,
|
1083
|
+
predicateDataLength: predicateData.length,
|
1153
1084
|
predicate: hexlify3(predicate),
|
1154
1085
|
predicateData: hexlify3(predicateData),
|
1155
1086
|
data: hexlify3(data),
|
@@ -1225,7 +1156,7 @@ var outputify = (value) => {
|
|
1225
1156
|
// src/providers/transaction-request/transaction-request.ts
|
1226
1157
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1227
1158
|
import { Address, addressify } from "@fuel-ts/address";
|
1228
|
-
import {
|
1159
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1229
1160
|
import { randomBytes } from "@fuel-ts/crypto";
|
1230
1161
|
import { bn as bn7 } from "@fuel-ts/math";
|
1231
1162
|
import {
|
@@ -1279,8 +1210,8 @@ function assembleReceiptByType(receipt) {
|
|
1279
1210
|
case "CALL" /* Call */: {
|
1280
1211
|
const callReceipt = {
|
1281
1212
|
type: ReceiptType.Call,
|
1282
|
-
from: hexOrZero(receipt.id
|
1283
|
-
to: hexOrZero(receipt?.to),
|
1213
|
+
from: hexOrZero(receipt.contract?.id),
|
1214
|
+
to: hexOrZero(receipt?.to?.id),
|
1284
1215
|
amount: bn4(receipt.amount),
|
1285
1216
|
assetId: hexOrZero(receipt.assetId),
|
1286
1217
|
gas: bn4(receipt.gas),
|
@@ -1294,7 +1225,7 @@ function assembleReceiptByType(receipt) {
|
|
1294
1225
|
case "RETURN" /* Return */: {
|
1295
1226
|
const returnReceipt = {
|
1296
1227
|
type: ReceiptType.Return,
|
1297
|
-
id: hexOrZero(receipt.id
|
1228
|
+
id: hexOrZero(receipt.contract?.id),
|
1298
1229
|
val: bn4(receipt.val),
|
1299
1230
|
pc: bn4(receipt.pc),
|
1300
1231
|
is: bn4(receipt.is)
|
@@ -1304,7 +1235,7 @@ function assembleReceiptByType(receipt) {
|
|
1304
1235
|
case "RETURN_DATA" /* ReturnData */: {
|
1305
1236
|
const returnDataReceipt = {
|
1306
1237
|
type: ReceiptType.ReturnData,
|
1307
|
-
id: hexOrZero(receipt.id
|
1238
|
+
id: hexOrZero(receipt.contract?.id),
|
1308
1239
|
ptr: bn4(receipt.ptr),
|
1309
1240
|
len: bn4(receipt.len),
|
1310
1241
|
digest: hexOrZero(receipt.digest),
|
@@ -1316,7 +1247,7 @@ function assembleReceiptByType(receipt) {
|
|
1316
1247
|
case "PANIC" /* Panic */: {
|
1317
1248
|
const panicReceipt = {
|
1318
1249
|
type: ReceiptType.Panic,
|
1319
|
-
id: hexOrZero(receipt.id),
|
1250
|
+
id: hexOrZero(receipt.contract?.id),
|
1320
1251
|
reason: bn4(receipt.reason),
|
1321
1252
|
pc: bn4(receipt.pc),
|
1322
1253
|
is: bn4(receipt.is),
|
@@ -1327,7 +1258,7 @@ function assembleReceiptByType(receipt) {
|
|
1327
1258
|
case "REVERT" /* Revert */: {
|
1328
1259
|
const revertReceipt = {
|
1329
1260
|
type: ReceiptType.Revert,
|
1330
|
-
id: hexOrZero(receipt.id
|
1261
|
+
id: hexOrZero(receipt.contract?.id),
|
1331
1262
|
val: bn4(receipt.ra),
|
1332
1263
|
pc: bn4(receipt.pc),
|
1333
1264
|
is: bn4(receipt.is)
|
@@ -1337,7 +1268,7 @@ function assembleReceiptByType(receipt) {
|
|
1337
1268
|
case "LOG" /* Log */: {
|
1338
1269
|
const logReceipt = {
|
1339
1270
|
type: ReceiptType.Log,
|
1340
|
-
id: hexOrZero(receipt.id
|
1271
|
+
id: hexOrZero(receipt.contract?.id),
|
1341
1272
|
val0: bn4(receipt.ra),
|
1342
1273
|
val1: bn4(receipt.rb),
|
1343
1274
|
val2: bn4(receipt.rc),
|
@@ -1350,7 +1281,7 @@ function assembleReceiptByType(receipt) {
|
|
1350
1281
|
case "LOG_DATA" /* LogData */: {
|
1351
1282
|
const logDataReceipt = {
|
1352
1283
|
type: ReceiptType.LogData,
|
1353
|
-
id: hexOrZero(receipt.id
|
1284
|
+
id: hexOrZero(receipt.contract?.id),
|
1354
1285
|
val0: bn4(receipt.ra),
|
1355
1286
|
val1: bn4(receipt.rb),
|
1356
1287
|
ptr: bn4(receipt.ptr),
|
@@ -1364,8 +1295,8 @@ function assembleReceiptByType(receipt) {
|
|
1364
1295
|
case "TRANSFER" /* Transfer */: {
|
1365
1296
|
const transferReceipt = {
|
1366
1297
|
type: ReceiptType.Transfer,
|
1367
|
-
from: hexOrZero(receipt.id
|
1368
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1298
|
+
from: hexOrZero(receipt.contract?.id),
|
1299
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1369
1300
|
amount: bn4(receipt.amount),
|
1370
1301
|
assetId: hexOrZero(receipt.assetId),
|
1371
1302
|
pc: bn4(receipt.pc),
|
@@ -1376,8 +1307,8 @@ function assembleReceiptByType(receipt) {
|
|
1376
1307
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1377
1308
|
const transferOutReceipt = {
|
1378
1309
|
type: ReceiptType.TransferOut,
|
1379
|
-
from: hexOrZero(receipt.id
|
1380
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1310
|
+
from: hexOrZero(receipt.contract?.id),
|
1311
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1381
1312
|
amount: bn4(receipt.amount),
|
1382
1313
|
assetId: hexOrZero(receipt.assetId),
|
1383
1314
|
pc: bn4(receipt.pc),
|
@@ -1420,7 +1351,7 @@ function assembleReceiptByType(receipt) {
|
|
1420
1351
|
return receiptMessageOut;
|
1421
1352
|
}
|
1422
1353
|
case "MINT" /* Mint */: {
|
1423
|
-
const contractId = hexOrZero(receipt.id
|
1354
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1424
1355
|
const subId = hexOrZero(receipt.subId);
|
1425
1356
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1426
1357
|
const mintReceipt = {
|
@@ -1435,7 +1366,7 @@ function assembleReceiptByType(receipt) {
|
|
1435
1366
|
return mintReceipt;
|
1436
1367
|
}
|
1437
1368
|
case "BURN" /* Burn */: {
|
1438
|
-
const contractId = hexOrZero(receipt.id
|
1369
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1439
1370
|
const subId = hexOrZero(receipt.subId);
|
1440
1371
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1441
1372
|
const burnReceipt = {
|
@@ -1520,6 +1451,7 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1520
1451
|
import { bn as bn5 } from "@fuel-ts/math";
|
1521
1452
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1522
1453
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1454
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1523
1455
|
var getGasUsedFromReceipts = (receipts) => {
|
1524
1456
|
const scriptResult = receipts.filter(
|
1525
1457
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1540,28 +1472,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1540
1472
|
}
|
1541
1473
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1542
1474
|
const witnessCache = [];
|
1543
|
-
const
|
1544
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1545
|
-
if (isCoinOrMessage) {
|
1546
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1547
|
-
return true;
|
1548
|
-
}
|
1549
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1550
|
-
witnessCache.push(input.witnessIndex);
|
1551
|
-
return true;
|
1552
|
-
}
|
1553
|
-
}
|
1554
|
-
return false;
|
1555
|
-
});
|
1556
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1557
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1475
|
+
const totalGas = inputs.reduce((total, input) => {
|
1558
1476
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1559
1477
|
return total.add(
|
1560
|
-
|
1478
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1561
1479
|
);
|
1562
1480
|
}
|
1563
|
-
|
1564
|
-
|
1481
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1482
|
+
witnessCache.push(input.witnessIndex);
|
1483
|
+
return total.add(gasCosts.ecr1);
|
1484
|
+
}
|
1485
|
+
return total;
|
1486
|
+
}, bn5());
|
1565
1487
|
return totalGas;
|
1566
1488
|
}
|
1567
1489
|
function getMinGas(params) {
|
@@ -1573,20 +1495,12 @@ function getMinGas(params) {
|
|
1573
1495
|
return minGas;
|
1574
1496
|
}
|
1575
1497
|
function getMaxGas(params) {
|
1576
|
-
const {
|
1577
|
-
gasPerByte,
|
1578
|
-
witnessesLength,
|
1579
|
-
witnessLimit,
|
1580
|
-
minGas,
|
1581
|
-
gasLimit = bn5(0),
|
1582
|
-
maxGasPerTx
|
1583
|
-
} = params;
|
1498
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1584
1499
|
let remainingAllowedWitnessGas = bn5(0);
|
1585
1500
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1586
1501
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1587
1502
|
}
|
1588
|
-
|
1589
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1503
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1590
1504
|
}
|
1591
1505
|
function calculateMetadataGasForTxCreate({
|
1592
1506
|
gasCosts,
|
@@ -1608,10 +1522,6 @@ function calculateMetadataGasForTxScript({
|
|
1608
1522
|
}) {
|
1609
1523
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1610
1524
|
}
|
1611
|
-
var calculateGasFee = (params) => {
|
1612
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1613
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1614
|
-
};
|
1615
1525
|
|
1616
1526
|
// src/providers/utils/json.ts
|
1617
1527
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1768,7 +1678,7 @@ var witnessify = (value) => {
|
|
1768
1678
|
// src/providers/transaction-request/transaction-request.ts
|
1769
1679
|
var BaseTransactionRequest = class {
|
1770
1680
|
/** Gas price for transaction */
|
1771
|
-
|
1681
|
+
gasPrice;
|
1772
1682
|
/** Block until which tx cannot be included */
|
1773
1683
|
maturity;
|
1774
1684
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1781,34 +1691,38 @@ var BaseTransactionRequest = class {
|
|
1781
1691
|
outputs = [];
|
1782
1692
|
/** List of witnesses */
|
1783
1693
|
witnesses = [];
|
1694
|
+
/** Base asset ID - should be fetched from the chain */
|
1695
|
+
baseAssetId;
|
1784
1696
|
/**
|
1785
1697
|
* Constructor for initializing a base transaction request.
|
1786
1698
|
*
|
1787
1699
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1788
1700
|
*/
|
1789
1701
|
constructor({
|
1790
|
-
|
1702
|
+
gasPrice,
|
1791
1703
|
maturity,
|
1792
1704
|
maxFee,
|
1793
1705
|
witnessLimit,
|
1794
1706
|
inputs,
|
1795
1707
|
outputs,
|
1796
|
-
witnesses
|
1797
|
-
|
1798
|
-
|
1708
|
+
witnesses,
|
1709
|
+
baseAssetId
|
1710
|
+
}) {
|
1711
|
+
this.gasPrice = bn7(gasPrice);
|
1799
1712
|
this.maturity = maturity ?? 0;
|
1800
1713
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1801
1714
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1802
1715
|
this.inputs = inputs ?? [];
|
1803
1716
|
this.outputs = outputs ?? [];
|
1804
1717
|
this.witnesses = witnesses ?? [];
|
1718
|
+
this.baseAssetId = baseAssetId;
|
1805
1719
|
}
|
1806
1720
|
static getPolicyMeta(req) {
|
1807
1721
|
let policyTypes = 0;
|
1808
1722
|
const policies = [];
|
1809
|
-
if (req.
|
1810
|
-
policyTypes += PolicyType.
|
1811
|
-
policies.push({ data: req.
|
1723
|
+
if (req.gasPrice) {
|
1724
|
+
policyTypes += PolicyType.GasPrice;
|
1725
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1812
1726
|
}
|
1813
1727
|
if (req.witnessLimit) {
|
1814
1728
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1995,10 +1909,10 @@ var BaseTransactionRequest = class {
|
|
1995
1909
|
* @param predicate - Predicate bytes.
|
1996
1910
|
* @param predicateData - Predicate data bytes.
|
1997
1911
|
*/
|
1998
|
-
addCoinInput(coin) {
|
1912
|
+
addCoinInput(coin, predicate) {
|
1999
1913
|
const { assetId, owner, amount } = coin;
|
2000
1914
|
let witnessIndex;
|
2001
|
-
if (
|
1915
|
+
if (predicate) {
|
2002
1916
|
witnessIndex = 0;
|
2003
1917
|
} else {
|
2004
1918
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2013,7 +1927,8 @@ var BaseTransactionRequest = class {
|
|
2013
1927
|
amount,
|
2014
1928
|
assetId,
|
2015
1929
|
txPointer: "0x00000000000000000000000000000000",
|
2016
|
-
witnessIndex
|
1930
|
+
witnessIndex,
|
1931
|
+
predicate: predicate?.bytes
|
2017
1932
|
};
|
2018
1933
|
this.pushInput(input);
|
2019
1934
|
this.addChangeOutput(owner, assetId);
|
@@ -2024,13 +1939,11 @@ var BaseTransactionRequest = class {
|
|
2024
1939
|
*
|
2025
1940
|
* @param message - Message resource.
|
2026
1941
|
* @param predicate - Predicate bytes.
|
2027
|
-
* @param predicateData - Predicate data bytes.
|
2028
1942
|
*/
|
2029
|
-
addMessageInput(message) {
|
1943
|
+
addMessageInput(message, predicate) {
|
2030
1944
|
const { recipient, sender, amount } = message;
|
2031
|
-
const assetId = BaseAssetId2;
|
2032
1945
|
let witnessIndex;
|
2033
|
-
if (
|
1946
|
+
if (predicate) {
|
2034
1947
|
witnessIndex = 0;
|
2035
1948
|
} else {
|
2036
1949
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2044,10 +1957,11 @@ var BaseTransactionRequest = class {
|
|
2044
1957
|
sender: sender.toB256(),
|
2045
1958
|
recipient: recipient.toB256(),
|
2046
1959
|
amount,
|
2047
|
-
witnessIndex
|
1960
|
+
witnessIndex,
|
1961
|
+
predicate: predicate?.bytes
|
2048
1962
|
};
|
2049
1963
|
this.pushInput(input);
|
2050
|
-
this.addChangeOutput(recipient,
|
1964
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
2051
1965
|
}
|
2052
1966
|
/**
|
2053
1967
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2075,6 +1989,32 @@ var BaseTransactionRequest = class {
|
|
2075
1989
|
resources.forEach((resource) => this.addResource(resource));
|
2076
1990
|
return this;
|
2077
1991
|
}
|
1992
|
+
/**
|
1993
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1994
|
+
* outputs from the related assetIds.
|
1995
|
+
*
|
1996
|
+
* @param resources - The resources to add.
|
1997
|
+
* @returns This transaction.
|
1998
|
+
*/
|
1999
|
+
addPredicateResource(resource, predicate) {
|
2000
|
+
if (isCoin(resource)) {
|
2001
|
+
this.addCoinInput(resource, predicate);
|
2002
|
+
} else {
|
2003
|
+
this.addMessageInput(resource, predicate);
|
2004
|
+
}
|
2005
|
+
return this;
|
2006
|
+
}
|
2007
|
+
/**
|
2008
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2009
|
+
* from the related assetIds.
|
2010
|
+
*
|
2011
|
+
* @param resources - The resources to add.
|
2012
|
+
* @returns This transaction.
|
2013
|
+
*/
|
2014
|
+
addPredicateResources(resources, predicate) {
|
2015
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2016
|
+
return this;
|
2017
|
+
}
|
2078
2018
|
/**
|
2079
2019
|
* Adds a coin output to the transaction.
|
2080
2020
|
*
|
@@ -2082,12 +2022,12 @@ var BaseTransactionRequest = class {
|
|
2082
2022
|
* @param amount - Amount of coin.
|
2083
2023
|
* @param assetId - Asset ID of coin.
|
2084
2024
|
*/
|
2085
|
-
addCoinOutput(to, amount, assetId
|
2025
|
+
addCoinOutput(to, amount, assetId) {
|
2086
2026
|
this.pushOutput({
|
2087
2027
|
type: OutputType2.Coin,
|
2088
2028
|
to: addressify(to).toB256(),
|
2089
2029
|
amount,
|
2090
|
-
assetId
|
2030
|
+
assetId: assetId ?? this.baseAssetId
|
2091
2031
|
});
|
2092
2032
|
return this;
|
2093
2033
|
}
|
@@ -2114,7 +2054,7 @@ var BaseTransactionRequest = class {
|
|
2114
2054
|
* @param to - Address of the owner.
|
2115
2055
|
* @param assetId - Asset ID of coin.
|
2116
2056
|
*/
|
2117
|
-
addChangeOutput(to, assetId
|
2057
|
+
addChangeOutput(to, assetId) {
|
2118
2058
|
const changeOutput = this.getChangeOutputs().find(
|
2119
2059
|
(output) => hexlify7(output.assetId) === assetId
|
2120
2060
|
);
|
@@ -2122,7 +2062,7 @@ var BaseTransactionRequest = class {
|
|
2122
2062
|
this.pushOutput({
|
2123
2063
|
type: OutputType2.Change,
|
2124
2064
|
to: addressify(to).toB256(),
|
2125
|
-
assetId
|
2065
|
+
assetId: assetId ?? this.baseAssetId
|
2126
2066
|
});
|
2127
2067
|
}
|
2128
2068
|
}
|
@@ -2154,7 +2094,7 @@ var BaseTransactionRequest = class {
|
|
2154
2094
|
}
|
2155
2095
|
calculateMaxGas(chainInfo, minGas) {
|
2156
2096
|
const { consensusParameters } = chainInfo;
|
2157
|
-
const { gasPerByte
|
2097
|
+
const { gasPerByte } = consensusParameters;
|
2158
2098
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2159
2099
|
(acc, wit) => acc + wit.dataLength,
|
2160
2100
|
0
|
@@ -2163,8 +2103,7 @@ var BaseTransactionRequest = class {
|
|
2163
2103
|
gasPerByte,
|
2164
2104
|
minGas,
|
2165
2105
|
witnessesLength,
|
2166
|
-
witnessLimit: this.witnessLimit
|
2167
|
-
maxGasPerTx
|
2106
|
+
witnessLimit: this.witnessLimit
|
2168
2107
|
});
|
2169
2108
|
}
|
2170
2109
|
/**
|
@@ -2182,27 +2121,24 @@ var BaseTransactionRequest = class {
|
|
2182
2121
|
});
|
2183
2122
|
const updateAssetInput = (assetId, quantity) => {
|
2184
2123
|
const assetInput = findAssetInput(assetId);
|
2185
|
-
let usedQuantity = quantity;
|
2186
|
-
if (assetId === BaseAssetId2) {
|
2187
|
-
usedQuantity = bn7("1000000000000000000");
|
2188
|
-
}
|
2189
2124
|
if (assetInput && "assetId" in assetInput) {
|
2190
2125
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2191
|
-
assetInput.amount =
|
2126
|
+
assetInput.amount = quantity;
|
2192
2127
|
} else {
|
2193
2128
|
this.addResources([
|
2194
2129
|
{
|
2195
2130
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2196
|
-
amount:
|
2131
|
+
amount: quantity,
|
2197
2132
|
assetId,
|
2198
2133
|
owner: resourcesOwner || Address.fromRandom(),
|
2134
|
+
maturity: 0,
|
2199
2135
|
blockCreated: bn7(1),
|
2200
2136
|
txCreatedIdx: bn7(1)
|
2201
2137
|
}
|
2202
2138
|
]);
|
2203
2139
|
}
|
2204
2140
|
};
|
2205
|
-
updateAssetInput(
|
2141
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2206
2142
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2207
2143
|
}
|
2208
2144
|
/**
|
@@ -2227,7 +2163,7 @@ var BaseTransactionRequest = class {
|
|
2227
2163
|
toJSON() {
|
2228
2164
|
return normalizeJSON(this);
|
2229
2165
|
}
|
2230
|
-
|
2166
|
+
updatePredicateInputs(inputs) {
|
2231
2167
|
this.inputs.forEach((i) => {
|
2232
2168
|
let correspondingInput;
|
2233
2169
|
switch (i.type) {
|
@@ -2249,15 +2185,6 @@ var BaseTransactionRequest = class {
|
|
2249
2185
|
}
|
2250
2186
|
});
|
2251
2187
|
}
|
2252
|
-
shiftPredicateData() {
|
2253
|
-
this.inputs.forEach((input) => {
|
2254
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2255
|
-
input.predicateData = input.paddPredicateData(
|
2256
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2257
|
-
);
|
2258
|
-
}
|
2259
|
-
});
|
2260
|
-
}
|
2261
2188
|
};
|
2262
2189
|
|
2263
2190
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2381,12 +2308,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2381
2308
|
*
|
2382
2309
|
* @param createTransactionRequestLike - The initial values for the instance
|
2383
2310
|
*/
|
2384
|
-
constructor({
|
2385
|
-
bytecodeWitnessIndex,
|
2386
|
-
salt,
|
2387
|
-
storageSlots,
|
2388
|
-
...rest
|
2389
|
-
} = {}) {
|
2311
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2390
2312
|
super(rest);
|
2391
2313
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2392
2314
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2404,8 +2326,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2404
2326
|
return {
|
2405
2327
|
type: TransactionType3.Create,
|
2406
2328
|
...baseTransaction,
|
2329
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2407
2330
|
bytecodeWitnessIndex,
|
2408
|
-
storageSlotsCount:
|
2331
|
+
storageSlotsCount: storageSlots.length,
|
2409
2332
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2410
2333
|
storageSlots
|
2411
2334
|
};
|
@@ -2509,7 +2432,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2509
2432
|
*
|
2510
2433
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2511
2434
|
*/
|
2512
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2435
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2513
2436
|
super(rest);
|
2514
2437
|
this.gasLimit = bn10(gasLimit);
|
2515
2438
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -2528,8 +2451,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2528
2451
|
type: TransactionType4.Script,
|
2529
2452
|
scriptGasLimit: this.gasLimit,
|
2530
2453
|
...super.getBaseTransaction(),
|
2531
|
-
scriptLength:
|
2532
|
-
scriptDataLength:
|
2454
|
+
scriptLength: script.length,
|
2455
|
+
scriptDataLength: scriptData.length,
|
2533
2456
|
receiptsRoot: ZeroBytes327,
|
2534
2457
|
script: hexlify10(script),
|
2535
2458
|
scriptData: hexlify10(scriptData)
|
@@ -2593,7 +2516,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2593
2516
|
}
|
2594
2517
|
calculateMaxGas(chainInfo, minGas) {
|
2595
2518
|
const { consensusParameters } = chainInfo;
|
2596
|
-
const { gasPerByte
|
2519
|
+
const { gasPerByte } = consensusParameters;
|
2597
2520
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2598
2521
|
(acc, wit) => acc + wit.dataLength,
|
2599
2522
|
0
|
@@ -2603,8 +2526,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2603
2526
|
minGas,
|
2604
2527
|
witnessesLength,
|
2605
2528
|
witnessLimit: this.witnessLimit,
|
2606
|
-
gasLimit: this.gasLimit
|
2607
|
-
maxGasPerTx
|
2529
|
+
gasLimit: this.gasLimit
|
2608
2530
|
});
|
2609
2531
|
}
|
2610
2532
|
/**
|
@@ -2661,7 +2583,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2661
2583
|
|
2662
2584
|
// src/providers/transaction-request/utils.ts
|
2663
2585
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2664
|
-
import { TransactionType as TransactionType5
|
2586
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2665
2587
|
var transactionRequestify = (obj) => {
|
2666
2588
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2667
2589
|
return obj;
|
@@ -2679,31 +2601,14 @@ var transactionRequestify = (obj) => {
|
|
2679
2601
|
}
|
2680
2602
|
}
|
2681
2603
|
};
|
2682
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2683
|
-
(acc, input) => {
|
2684
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2685
|
-
acc.utxos.push(input.id);
|
2686
|
-
}
|
2687
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2688
|
-
acc.messages.push(input.nonce);
|
2689
|
-
}
|
2690
|
-
return acc;
|
2691
|
-
},
|
2692
|
-
{
|
2693
|
-
utxos: [],
|
2694
|
-
messages: []
|
2695
|
-
}
|
2696
|
-
);
|
2697
2604
|
|
2698
2605
|
// src/providers/transaction-response/transaction-response.ts
|
2699
2606
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2700
|
-
import { bn as
|
2607
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2701
2608
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2702
2609
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2703
2610
|
|
2704
2611
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2705
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2706
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2707
2612
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2708
2613
|
|
2709
2614
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2712,10 +2617,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2712
2617
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2713
2618
|
var calculateTransactionFee = (params) => {
|
2714
2619
|
const {
|
2715
|
-
|
2620
|
+
gasUsed,
|
2716
2621
|
rawPayload,
|
2717
|
-
|
2718
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2622
|
+
consensusParameters: { gasCosts, feeParams }
|
2719
2623
|
} = params;
|
2720
2624
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2721
2625
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2725,7 +2629,8 @@ var calculateTransactionFee = (params) => {
|
|
2725
2629
|
return {
|
2726
2630
|
fee: bn11(0),
|
2727
2631
|
minFee: bn11(0),
|
2728
|
-
maxFee: bn11(0)
|
2632
|
+
maxFee: bn11(0),
|
2633
|
+
feeFromGasUsed: bn11(0)
|
2729
2634
|
};
|
2730
2635
|
}
|
2731
2636
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2757,6 +2662,7 @@ var calculateTransactionFee = (params) => {
|
|
2757
2662
|
metadataGas,
|
2758
2663
|
txBytesSize: transactionBytes.length
|
2759
2664
|
});
|
2665
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2760
2666
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2761
2667
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2762
2668
|
const maxGas = getMaxGas({
|
@@ -2764,25 +2670,17 @@ var calculateTransactionFee = (params) => {
|
|
2764
2670
|
minGas,
|
2765
2671
|
witnessesLength,
|
2766
2672
|
gasLimit,
|
2767
|
-
witnessLimit
|
2768
|
-
maxGasPerTx
|
2769
|
-
});
|
2770
|
-
const minFee = calculateGasFee({
|
2771
|
-
gasPrice,
|
2772
|
-
gas: minGas,
|
2773
|
-
priceFactor: gasPriceFactor,
|
2774
|
-
tip
|
2775
|
-
});
|
2776
|
-
const maxFee = calculateGasFee({
|
2777
|
-
gasPrice,
|
2778
|
-
gas: maxGas,
|
2779
|
-
priceFactor: gasPriceFactor,
|
2780
|
-
tip
|
2673
|
+
witnessLimit
|
2781
2674
|
});
|
2675
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2676
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2677
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2678
|
+
const fee = minFee.add(feeFromGasUsed);
|
2782
2679
|
return {
|
2680
|
+
fee,
|
2783
2681
|
minFee,
|
2784
2682
|
maxFee,
|
2785
|
-
|
2683
|
+
feeFromGasUsed
|
2786
2684
|
};
|
2787
2685
|
};
|
2788
2686
|
|
@@ -2838,7 +2736,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2838
2736
|
|
2839
2737
|
// src/providers/transaction-summary/input.ts
|
2840
2738
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2841
|
-
import { InputType as
|
2739
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2842
2740
|
function getInputsByTypes(inputs, types) {
|
2843
2741
|
return inputs.filter((i) => types.includes(i.type));
|
2844
2742
|
}
|
@@ -2846,16 +2744,16 @@ function getInputsByType(inputs, type) {
|
|
2846
2744
|
return inputs.filter((i) => i.type === type);
|
2847
2745
|
}
|
2848
2746
|
function getInputsCoin(inputs) {
|
2849
|
-
return getInputsByType(inputs,
|
2747
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2850
2748
|
}
|
2851
2749
|
function getInputsMessage(inputs) {
|
2852
|
-
return getInputsByType(inputs,
|
2750
|
+
return getInputsByType(inputs, InputType5.Message);
|
2853
2751
|
}
|
2854
2752
|
function getInputsCoinAndMessage(inputs) {
|
2855
|
-
return getInputsByTypes(inputs, [
|
2753
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2856
2754
|
}
|
2857
2755
|
function getInputsContract(inputs) {
|
2858
|
-
return getInputsByType(inputs,
|
2756
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2859
2757
|
}
|
2860
2758
|
function getInputFromAssetId(inputs, assetId) {
|
2861
2759
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2874,7 +2772,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2874
2772
|
if (!contractInput) {
|
2875
2773
|
return void 0;
|
2876
2774
|
}
|
2877
|
-
if (contractInput.type !==
|
2775
|
+
if (contractInput.type !== InputType5.Contract) {
|
2878
2776
|
throw new FuelError9(
|
2879
2777
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2880
2778
|
`Contract input should be of type 'contract'.`
|
@@ -2883,10 +2781,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2883
2781
|
return contractInput;
|
2884
2782
|
}
|
2885
2783
|
function getInputAccountAddress(input) {
|
2886
|
-
if (input.type ===
|
2784
|
+
if (input.type === InputType5.Coin) {
|
2887
2785
|
return input.owner.toString();
|
2888
2786
|
}
|
2889
|
-
if (input.type ===
|
2787
|
+
if (input.type === InputType5.Message) {
|
2890
2788
|
return input.recipient.toString();
|
2891
2789
|
}
|
2892
2790
|
return "";
|
@@ -3396,9 +3294,7 @@ function assembleTransactionSummary(params) {
|
|
3396
3294
|
gqlTransactionStatus,
|
3397
3295
|
abiMap = {},
|
3398
3296
|
maxInputs,
|
3399
|
-
gasCosts
|
3400
|
-
maxGasPerTx,
|
3401
|
-
gasPrice
|
3297
|
+
gasCosts
|
3402
3298
|
} = params;
|
3403
3299
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3404
3300
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3412,14 +3308,11 @@ function assembleTransactionSummary(params) {
|
|
3412
3308
|
maxInputs
|
3413
3309
|
});
|
3414
3310
|
const typeName = getTransactionTypeName(transaction.type);
|
3415
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3416
3311
|
const { fee } = calculateTransactionFee({
|
3417
|
-
|
3312
|
+
gasUsed,
|
3418
3313
|
rawPayload,
|
3419
|
-
tip,
|
3420
3314
|
consensusParameters: {
|
3421
3315
|
gasCosts,
|
3422
|
-
maxGasPerTx,
|
3423
3316
|
feeParams: {
|
3424
3317
|
gasPerByte,
|
3425
3318
|
gasPriceFactor
|
@@ -3479,7 +3372,7 @@ var TransactionResponse = class {
|
|
3479
3372
|
/** Current provider */
|
3480
3373
|
provider;
|
3481
3374
|
/** Gas used on the transaction */
|
3482
|
-
gasUsed =
|
3375
|
+
gasUsed = bn14(0);
|
3483
3376
|
/** The graphql Transaction with receipts object. */
|
3484
3377
|
gqlTransaction;
|
3485
3378
|
abis;
|
@@ -3557,13 +3450,8 @@ var TransactionResponse = class {
|
|
3557
3450
|
const decodedTransaction = this.decodeTransaction(
|
3558
3451
|
transaction
|
3559
3452
|
);
|
3560
|
-
|
3561
|
-
|
3562
|
-
txReceipts = transaction.status.receipts;
|
3563
|
-
}
|
3564
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3565
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3566
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3453
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3454
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3567
3455
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3568
3456
|
const transactionSummary = assembleTransactionSummary({
|
3569
3457
|
id: this.id,
|
@@ -3575,9 +3463,7 @@ var TransactionResponse = class {
|
|
3575
3463
|
gasPriceFactor,
|
3576
3464
|
abiMap: contractsAbiMap,
|
3577
3465
|
maxInputs,
|
3578
|
-
gasCosts
|
3579
|
-
maxGasPerTx,
|
3580
|
-
gasPrice
|
3466
|
+
gasCosts
|
3581
3467
|
});
|
3582
3468
|
return transactionSummary;
|
3583
3469
|
}
|
@@ -3704,29 +3590,30 @@ var processGqlChain = (chain) => {
|
|
3704
3590
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3705
3591
|
return {
|
3706
3592
|
name,
|
3707
|
-
baseChainHeight:
|
3593
|
+
baseChainHeight: bn15(daHeight),
|
3708
3594
|
consensusParameters: {
|
3709
|
-
contractMaxSize:
|
3710
|
-
maxInputs:
|
3711
|
-
maxOutputs:
|
3712
|
-
maxWitnesses:
|
3713
|
-
maxGasPerTx:
|
3714
|
-
maxScriptLength:
|
3715
|
-
maxScriptDataLength:
|
3716
|
-
maxStorageSlots:
|
3717
|
-
maxPredicateLength:
|
3718
|
-
maxPredicateDataLength:
|
3719
|
-
maxGasPerPredicate:
|
3720
|
-
gasPriceFactor:
|
3721
|
-
gasPerByte:
|
3722
|
-
maxMessageDataLength:
|
3723
|
-
chainId:
|
3595
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3596
|
+
maxInputs: bn15(txParams.maxInputs),
|
3597
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3598
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3599
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3600
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3601
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3602
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3603
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3604
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3605
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3606
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3607
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3608
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3609
|
+
chainId: bn15(consensusParameters.chainId),
|
3610
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3724
3611
|
gasCosts
|
3725
3612
|
},
|
3726
3613
|
gasCosts,
|
3727
3614
|
latestBlock: {
|
3728
3615
|
id: latestBlock.id,
|
3729
|
-
height:
|
3616
|
+
height: bn15(latestBlock.header.height),
|
3730
3617
|
time: latestBlock.header.time,
|
3731
3618
|
transactions: latestBlock.transactions.map((i) => ({
|
3732
3619
|
id: i.id
|
@@ -3820,8 +3707,10 @@ var _Provider = class {
|
|
3820
3707
|
* Returns some helpful parameters related to gas fees.
|
3821
3708
|
*/
|
3822
3709
|
getGasConfig() {
|
3710
|
+
const { minGasPrice } = this.getNode();
|
3823
3711
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3824
3712
|
return {
|
3713
|
+
minGasPrice,
|
3825
3714
|
maxGasPerTx,
|
3826
3715
|
maxGasPerPredicate,
|
3827
3716
|
gasPriceFactor,
|
@@ -3919,7 +3808,7 @@ var _Provider = class {
|
|
3919
3808
|
*/
|
3920
3809
|
async getBlockNumber() {
|
3921
3810
|
const { chain } = await this.operations.getChain();
|
3922
|
-
return
|
3811
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3923
3812
|
}
|
3924
3813
|
/**
|
3925
3814
|
* Returns the chain information.
|
@@ -3929,11 +3818,13 @@ var _Provider = class {
|
|
3929
3818
|
async fetchNode() {
|
3930
3819
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3931
3820
|
const processedNodeInfo = {
|
3932
|
-
maxDepth:
|
3933
|
-
maxTx:
|
3821
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3822
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3823
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3934
3824
|
nodeVersion: nodeInfo.nodeVersion,
|
3935
3825
|
utxoValidation: nodeInfo.utxoValidation,
|
3936
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3826
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3827
|
+
peers: nodeInfo.peers
|
3937
3828
|
};
|
3938
3829
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3939
3830
|
return processedNodeInfo;
|
@@ -3959,6 +3850,17 @@ var _Provider = class {
|
|
3959
3850
|
} = this.getChain();
|
3960
3851
|
return chainId.toNumber();
|
3961
3852
|
}
|
3853
|
+
/**
|
3854
|
+
* Returns the base asset ID
|
3855
|
+
*
|
3856
|
+
* @returns A promise that resolves to the base asset ID
|
3857
|
+
*/
|
3858
|
+
getBaseAssetId() {
|
3859
|
+
const {
|
3860
|
+
consensusParameters: { baseAssetId }
|
3861
|
+
} = this.getChain();
|
3862
|
+
return baseAssetId;
|
3863
|
+
}
|
3962
3864
|
/**
|
3963
3865
|
* Submits a transaction to the chain to be executed.
|
3964
3866
|
*
|
@@ -4019,13 +3921,14 @@ var _Provider = class {
|
|
4019
3921
|
return this.estimateTxDependencies(transactionRequest);
|
4020
3922
|
}
|
4021
3923
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
4022
|
-
const { dryRun:
|
4023
|
-
|
3924
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3925
|
+
encodedTransaction,
|
4024
3926
|
utxoValidation: utxoValidation || false
|
4025
3927
|
});
|
4026
|
-
const
|
4027
|
-
|
4028
|
-
|
3928
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3929
|
+
return {
|
3930
|
+
receipts
|
3931
|
+
};
|
4029
3932
|
}
|
4030
3933
|
/**
|
4031
3934
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4051,7 +3954,7 @@ var _Provider = class {
|
|
4051
3954
|
} = response;
|
4052
3955
|
if (inputs) {
|
4053
3956
|
inputs.forEach((input, index) => {
|
4054
|
-
if ("predicateGasUsed" in input &&
|
3957
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
4055
3958
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4056
3959
|
}
|
4057
3960
|
});
|
@@ -4064,6 +3967,9 @@ var _Provider = class {
|
|
4064
3967
|
* If there are missing variable outputs,
|
4065
3968
|
* `addVariableOutputs` is called on the transaction.
|
4066
3969
|
*
|
3970
|
+
* @privateRemarks
|
3971
|
+
* TODO: Investigate support for missing contract IDs
|
3972
|
+
* TODO: Add support for missing output messages
|
4067
3973
|
*
|
4068
3974
|
* @param transactionRequest - The transaction request object.
|
4069
3975
|
* @returns A promise.
|
@@ -4076,19 +3982,16 @@ var _Provider = class {
|
|
4076
3982
|
missingContractIds: []
|
4077
3983
|
};
|
4078
3984
|
}
|
3985
|
+
await this.estimatePredicates(transactionRequest);
|
4079
3986
|
let receipts = [];
|
4080
3987
|
const missingContractIds = [];
|
4081
3988
|
let outputVariables = 0;
|
4082
|
-
let dryrunStatus;
|
4083
3989
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4084
|
-
const {
|
4085
|
-
|
4086
|
-
} = await this.operations.dryRun({
|
4087
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3990
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3991
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
4088
3992
|
utxoValidation: false
|
4089
3993
|
});
|
4090
|
-
receipts =
|
4091
|
-
dryrunStatus = status;
|
3994
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4092
3995
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4093
3996
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4094
3997
|
if (hasMissingOutputs) {
|
@@ -4098,10 +4001,6 @@ var _Provider = class {
|
|
4098
4001
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4099
4002
|
missingContractIds.push(contractId);
|
4100
4003
|
});
|
4101
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4102
|
-
transactionRequest
|
4103
|
-
});
|
4104
|
-
transactionRequest.maxFee = maxFee;
|
4105
4004
|
} else {
|
4106
4005
|
break;
|
4107
4006
|
}
|
@@ -4109,139 +4008,37 @@ var _Provider = class {
|
|
4109
4008
|
return {
|
4110
4009
|
receipts,
|
4111
4010
|
outputVariables,
|
4112
|
-
missingContractIds
|
4113
|
-
dryrunStatus
|
4011
|
+
missingContractIds
|
4114
4012
|
};
|
4115
4013
|
}
|
4116
|
-
/**
|
4117
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4118
|
-
*
|
4119
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4120
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4121
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4122
|
-
*
|
4123
|
-
* @param transactionRequests - Array of transaction request objects.
|
4124
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4125
|
-
*/
|
4126
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4127
|
-
const results = transactionRequests.map(() => ({
|
4128
|
-
receipts: [],
|
4129
|
-
outputVariables: 0,
|
4130
|
-
missingContractIds: [],
|
4131
|
-
dryrunStatus: void 0
|
4132
|
-
}));
|
4133
|
-
const allRequests = clone3(transactionRequests);
|
4134
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4135
|
-
allRequests.forEach((req, index) => {
|
4136
|
-
if (req.type === TransactionType8.Script) {
|
4137
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4138
|
-
}
|
4139
|
-
});
|
4140
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4141
|
-
let attempt = 0;
|
4142
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4143
|
-
const encodedTransactions = transactionsToProcess.map(
|
4144
|
-
(index) => serializedTransactionsMap.get(index)
|
4145
|
-
);
|
4146
|
-
const dryRunResults = await this.operations.dryRun({
|
4147
|
-
encodedTransactions,
|
4148
|
-
utxoValidation: false
|
4149
|
-
});
|
4150
|
-
const nextRoundTransactions = [];
|
4151
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4152
|
-
const currentResultIndex = transactionsToProcess[i];
|
4153
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4154
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4155
|
-
results[currentResultIndex].dryrunStatus = status;
|
4156
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4157
|
-
results[currentResultIndex].receipts
|
4158
|
-
);
|
4159
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4160
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4161
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4162
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4163
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4164
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4165
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4166
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4167
|
-
});
|
4168
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4169
|
-
transactionRequest: requestToProcess
|
4170
|
-
});
|
4171
|
-
requestToProcess.maxFee = maxFee;
|
4172
|
-
serializedTransactionsMap.set(
|
4173
|
-
currentResultIndex,
|
4174
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4175
|
-
);
|
4176
|
-
nextRoundTransactions.push(currentResultIndex);
|
4177
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4178
|
-
}
|
4179
|
-
}
|
4180
|
-
transactionsToProcess = nextRoundTransactions;
|
4181
|
-
attempt += 1;
|
4182
|
-
}
|
4183
|
-
return results;
|
4184
|
-
}
|
4185
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4186
|
-
if (estimateTxDependencies) {
|
4187
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4188
|
-
}
|
4189
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4190
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4191
|
-
encodedTransactions,
|
4192
|
-
utxoValidation: utxoValidation || false
|
4193
|
-
});
|
4194
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4195
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4196
|
-
return { receipts, dryrunStatus: status };
|
4197
|
-
});
|
4198
|
-
return results;
|
4199
|
-
}
|
4200
4014
|
/**
|
4201
4015
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4202
4016
|
* @param transactionRequest - The transaction request object.
|
4203
4017
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4204
4018
|
*/
|
4205
|
-
|
4019
|
+
estimateTxGasAndFee(params) {
|
4206
4020
|
const { transactionRequest } = params;
|
4207
|
-
|
4021
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4208
4022
|
const chainInfo = this.getChain();
|
4209
|
-
const
|
4023
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4024
|
+
transactionRequest.gasPrice = gasPrice;
|
4210
4025
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4211
|
-
|
4212
|
-
gasPrice = await this.estimateGasPrice(10);
|
4213
|
-
}
|
4214
|
-
const minFee = calculateGasFee({
|
4215
|
-
gasPrice: bn16(gasPrice),
|
4216
|
-
gas: minGas,
|
4217
|
-
priceFactor: gasPriceFactor,
|
4218
|
-
tip: transactionRequest.tip
|
4219
|
-
}).add(1);
|
4220
|
-
let gasLimit = bn16(0);
|
4026
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4221
4027
|
if (transactionRequest.type === TransactionType8.Script) {
|
4222
|
-
gasLimit = transactionRequest.gasLimit;
|
4223
4028
|
if (transactionRequest.gasLimit.eq(0)) {
|
4224
4029
|
transactionRequest.gasLimit = minGas;
|
4225
4030
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4226
4031
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4227
4032
|
);
|
4228
|
-
gasLimit = transactionRequest.gasLimit;
|
4229
4033
|
}
|
4230
4034
|
}
|
4231
4035
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4232
|
-
const maxFee =
|
4233
|
-
gasPrice: bn16(gasPrice),
|
4234
|
-
gas: maxGas,
|
4235
|
-
priceFactor: gasPriceFactor,
|
4236
|
-
tip: transactionRequest.tip
|
4237
|
-
}).add(1);
|
4036
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4238
4037
|
return {
|
4239
4038
|
minGas,
|
4240
4039
|
minFee,
|
4241
4040
|
maxGas,
|
4242
|
-
maxFee
|
4243
|
-
gasPrice,
|
4244
|
-
gasLimit
|
4041
|
+
maxFee
|
4245
4042
|
};
|
4246
4043
|
}
|
4247
4044
|
/**
|
@@ -4259,17 +4056,15 @@ var _Provider = class {
|
|
4259
4056
|
if (estimateTxDependencies) {
|
4260
4057
|
return this.estimateTxDependencies(transactionRequest);
|
4261
4058
|
}
|
4262
|
-
const
|
4263
|
-
const { dryRun:
|
4264
|
-
|
4059
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
4060
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4061
|
+
encodedTransaction,
|
4265
4062
|
utxoValidation: true
|
4266
4063
|
});
|
4267
|
-
const
|
4268
|
-
|
4269
|
-
|
4270
|
-
|
4271
|
-
});
|
4272
|
-
return { receipts: callResult[0].receipts };
|
4064
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4065
|
+
return {
|
4066
|
+
receipts
|
4067
|
+
};
|
4273
4068
|
}
|
4274
4069
|
/**
|
4275
4070
|
* Returns a transaction cost to enable user
|
@@ -4286,79 +4081,77 @@ var _Provider = class {
|
|
4286
4081
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4287
4082
|
* @returns A promise that resolves to the transaction cost object.
|
4288
4083
|
*/
|
4289
|
-
async getTransactionCost(transactionRequestLike,
|
4084
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4085
|
+
estimateTxDependencies = true,
|
4086
|
+
estimatePredicates = true,
|
4087
|
+
resourcesOwner,
|
4088
|
+
signatureCallback
|
4089
|
+
} = {}) {
|
4290
4090
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4091
|
+
const { minGasPrice } = this.getGasConfig();
|
4092
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4291
4093
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4292
4094
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4293
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4095
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4294
4096
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4295
|
-
txRequestClone.maxFee = bn16(0);
|
4296
4097
|
if (isScriptTransaction) {
|
4297
|
-
txRequestClone.gasLimit =
|
4098
|
+
txRequestClone.gasLimit = bn15(0);
|
4298
4099
|
}
|
4299
|
-
if (
|
4300
|
-
resourcesOwner
|
4100
|
+
if (estimatePredicates) {
|
4101
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4102
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4103
|
+
}
|
4104
|
+
await this.estimatePredicates(txRequestClone);
|
4301
4105
|
}
|
4302
|
-
const signedRequest = clone3(txRequestClone);
|
4303
|
-
let addedSignatures = 0;
|
4304
4106
|
if (signatureCallback && isScriptTransaction) {
|
4305
|
-
|
4306
|
-
await signatureCallback(signedRequest);
|
4307
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4107
|
+
await signatureCallback(txRequestClone);
|
4308
4108
|
}
|
4309
|
-
|
4310
|
-
|
4311
|
-
transactionRequest: signedRequest
|
4109
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4110
|
+
transactionRequest: txRequestClone
|
4312
4111
|
});
|
4313
4112
|
let receipts = [];
|
4314
4113
|
let missingContractIds = [];
|
4315
4114
|
let outputVariables = 0;
|
4316
|
-
let gasUsed =
|
4317
|
-
|
4318
|
-
|
4319
|
-
if (isScriptTransaction) {
|
4320
|
-
txRequestClone.gasLimit = gasLimit;
|
4321
|
-
if (signatureCallback) {
|
4322
|
-
await signatureCallback(txRequestClone);
|
4323
|
-
}
|
4115
|
+
let gasUsed = bn15(0);
|
4116
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4117
|
+
txRequestClone.gasPrice = bn15(0);
|
4324
4118
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4325
4119
|
receipts = result.receipts;
|
4326
4120
|
outputVariables = result.outputVariables;
|
4327
4121
|
missingContractIds = result.missingContractIds;
|
4328
4122
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4329
4123
|
txRequestClone.gasLimit = gasUsed;
|
4330
|
-
|
4331
|
-
|
4332
|
-
|
4124
|
+
txRequestClone.gasPrice = setGasPrice;
|
4125
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4126
|
+
transactionRequest: txRequestClone
|
4333
4127
|
}));
|
4334
4128
|
}
|
4335
4129
|
return {
|
4336
4130
|
requiredQuantities: allQuantities,
|
4337
4131
|
receipts,
|
4338
4132
|
gasUsed,
|
4339
|
-
|
4133
|
+
minGasPrice,
|
4134
|
+
gasPrice: setGasPrice,
|
4340
4135
|
minGas,
|
4341
4136
|
maxGas,
|
4342
4137
|
minFee,
|
4343
4138
|
maxFee,
|
4139
|
+
estimatedInputs: txRequestClone.inputs,
|
4344
4140
|
outputVariables,
|
4345
|
-
missingContractIds
|
4346
|
-
addedSignatures,
|
4347
|
-
estimatedPredicates: txRequestClone.inputs
|
4141
|
+
missingContractIds
|
4348
4142
|
};
|
4349
4143
|
}
|
4350
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4144
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4351
4145
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4352
4146
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4353
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4354
|
-
quantitiesToContract
|
4355
|
-
});
|
4147
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4356
4148
|
transactionRequest.addResources(
|
4357
4149
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4358
4150
|
);
|
4359
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4360
|
-
|
4361
|
-
|
4151
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4152
|
+
transactionRequest,
|
4153
|
+
forwardingQuantities
|
4154
|
+
);
|
4362
4155
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4363
4156
|
return {
|
4364
4157
|
resources,
|
@@ -4380,10 +4173,11 @@ var _Provider = class {
|
|
4380
4173
|
return coins.map((coin) => ({
|
4381
4174
|
id: coin.utxoId,
|
4382
4175
|
assetId: coin.assetId,
|
4383
|
-
amount:
|
4176
|
+
amount: bn15(coin.amount),
|
4384
4177
|
owner: Address2.fromAddressOrString(coin.owner),
|
4385
|
-
|
4386
|
-
|
4178
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4179
|
+
blockCreated: bn15(coin.blockCreated),
|
4180
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4387
4181
|
}));
|
4388
4182
|
}
|
4389
4183
|
/**
|
@@ -4420,9 +4214,9 @@ var _Provider = class {
|
|
4420
4214
|
switch (coin.__typename) {
|
4421
4215
|
case "MessageCoin":
|
4422
4216
|
return {
|
4423
|
-
amount:
|
4217
|
+
amount: bn15(coin.amount),
|
4424
4218
|
assetId: coin.assetId,
|
4425
|
-
daHeight:
|
4219
|
+
daHeight: bn15(coin.daHeight),
|
4426
4220
|
sender: Address2.fromAddressOrString(coin.sender),
|
4427
4221
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4428
4222
|
nonce: coin.nonce
|
@@ -4430,11 +4224,12 @@ var _Provider = class {
|
|
4430
4224
|
case "Coin":
|
4431
4225
|
return {
|
4432
4226
|
id: coin.utxoId,
|
4433
|
-
amount:
|
4227
|
+
amount: bn15(coin.amount),
|
4434
4228
|
assetId: coin.assetId,
|
4435
4229
|
owner: Address2.fromAddressOrString(coin.owner),
|
4436
|
-
|
4437
|
-
|
4230
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4231
|
+
blockCreated: bn15(coin.blockCreated),
|
4232
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4438
4233
|
};
|
4439
4234
|
default:
|
4440
4235
|
return null;
|
@@ -4451,13 +4246,13 @@ var _Provider = class {
|
|
4451
4246
|
async getBlock(idOrHeight) {
|
4452
4247
|
let variables;
|
4453
4248
|
if (typeof idOrHeight === "number") {
|
4454
|
-
variables = { height:
|
4249
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4455
4250
|
} else if (idOrHeight === "latest") {
|
4456
4251
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4457
4252
|
} else if (idOrHeight.length === 66) {
|
4458
4253
|
variables = { blockId: idOrHeight };
|
4459
4254
|
} else {
|
4460
|
-
variables = { blockId:
|
4255
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4461
4256
|
}
|
4462
4257
|
const { block } = await this.operations.getBlock(variables);
|
4463
4258
|
if (!block) {
|
@@ -4465,7 +4260,7 @@ var _Provider = class {
|
|
4465
4260
|
}
|
4466
4261
|
return {
|
4467
4262
|
id: block.id,
|
4468
|
-
height:
|
4263
|
+
height: bn15(block.header.height),
|
4469
4264
|
time: block.header.time,
|
4470
4265
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4471
4266
|
};
|
@@ -4480,7 +4275,7 @@ var _Provider = class {
|
|
4480
4275
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4481
4276
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4482
4277
|
id: block.id,
|
4483
|
-
height:
|
4278
|
+
height: bn15(block.header.height),
|
4484
4279
|
time: block.header.time,
|
4485
4280
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4486
4281
|
}));
|
@@ -4495,7 +4290,7 @@ var _Provider = class {
|
|
4495
4290
|
async getBlockWithTransactions(idOrHeight) {
|
4496
4291
|
let variables;
|
4497
4292
|
if (typeof idOrHeight === "number") {
|
4498
|
-
variables = { blockHeight:
|
4293
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4499
4294
|
} else if (idOrHeight === "latest") {
|
4500
4295
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4501
4296
|
} else {
|
@@ -4507,7 +4302,7 @@ var _Provider = class {
|
|
4507
4302
|
}
|
4508
4303
|
return {
|
4509
4304
|
id: block.id,
|
4510
|
-
height:
|
4305
|
+
height: bn15(block.header.height, 10),
|
4511
4306
|
time: block.header.time,
|
4512
4307
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4513
4308
|
transactions: block.transactions.map(
|
@@ -4556,7 +4351,7 @@ var _Provider = class {
|
|
4556
4351
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4557
4352
|
asset: hexlify12(assetId)
|
4558
4353
|
});
|
4559
|
-
return
|
4354
|
+
return bn15(contractBalance.amount, 10);
|
4560
4355
|
}
|
4561
4356
|
/**
|
4562
4357
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4570,7 +4365,7 @@ var _Provider = class {
|
|
4570
4365
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4571
4366
|
assetId: hexlify12(assetId)
|
4572
4367
|
});
|
4573
|
-
return
|
4368
|
+
return bn15(balance.amount, 10);
|
4574
4369
|
}
|
4575
4370
|
/**
|
4576
4371
|
* Returns balances for the given owner.
|
@@ -4588,7 +4383,7 @@ var _Provider = class {
|
|
4588
4383
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4589
4384
|
return balances.map((balance) => ({
|
4590
4385
|
assetId: balance.assetId,
|
4591
|
-
amount:
|
4386
|
+
amount: bn15(balance.amount)
|
4592
4387
|
}));
|
4593
4388
|
}
|
4594
4389
|
/**
|
@@ -4610,15 +4405,15 @@ var _Provider = class {
|
|
4610
4405
|
sender: message.sender,
|
4611
4406
|
recipient: message.recipient,
|
4612
4407
|
nonce: message.nonce,
|
4613
|
-
amount:
|
4408
|
+
amount: bn15(message.amount),
|
4614
4409
|
data: message.data
|
4615
4410
|
}),
|
4616
4411
|
sender: Address2.fromAddressOrString(message.sender),
|
4617
4412
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4618
4413
|
nonce: message.nonce,
|
4619
|
-
amount:
|
4414
|
+
amount: bn15(message.amount),
|
4620
4415
|
data: InputMessageCoder.decodeData(message.data),
|
4621
|
-
daHeight:
|
4416
|
+
daHeight: bn15(message.daHeight)
|
4622
4417
|
}));
|
4623
4418
|
}
|
4624
4419
|
/**
|
@@ -4671,60 +4466,44 @@ var _Provider = class {
|
|
4671
4466
|
} = result.messageProof;
|
4672
4467
|
return {
|
4673
4468
|
messageProof: {
|
4674
|
-
proofIndex:
|
4469
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4675
4470
|
proofSet: messageProof.proofSet
|
4676
4471
|
},
|
4677
4472
|
blockProof: {
|
4678
|
-
proofIndex:
|
4473
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4679
4474
|
proofSet: blockProof.proofSet
|
4680
4475
|
},
|
4681
4476
|
messageBlockHeader: {
|
4682
4477
|
id: messageBlockHeader.id,
|
4683
|
-
daHeight:
|
4684
|
-
transactionsCount:
|
4478
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4479
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4685
4480
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4686
|
-
height:
|
4481
|
+
height: bn15(messageBlockHeader.height),
|
4687
4482
|
prevRoot: messageBlockHeader.prevRoot,
|
4688
4483
|
time: messageBlockHeader.time,
|
4689
4484
|
applicationHash: messageBlockHeader.applicationHash,
|
4690
|
-
|
4691
|
-
|
4692
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4693
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4694
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4485
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4486
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4695
4487
|
},
|
4696
4488
|
commitBlockHeader: {
|
4697
4489
|
id: commitBlockHeader.id,
|
4698
|
-
daHeight:
|
4699
|
-
transactionsCount:
|
4490
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4491
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4700
4492
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4701
|
-
height:
|
4493
|
+
height: bn15(commitBlockHeader.height),
|
4702
4494
|
prevRoot: commitBlockHeader.prevRoot,
|
4703
4495
|
time: commitBlockHeader.time,
|
4704
4496
|
applicationHash: commitBlockHeader.applicationHash,
|
4705
|
-
|
4706
|
-
|
4707
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4708
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4709
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4497
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4498
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4710
4499
|
},
|
4711
4500
|
sender: Address2.fromAddressOrString(sender),
|
4712
4501
|
recipient: Address2.fromAddressOrString(recipient),
|
4713
4502
|
nonce,
|
4714
|
-
amount:
|
4503
|
+
amount: bn15(amount),
|
4715
4504
|
data
|
4716
4505
|
};
|
4717
4506
|
}
|
4718
|
-
async getLatestGasPrice() {
|
4719
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4720
|
-
return bn16(latestGasPrice.gasPrice);
|
4721
|
-
}
|
4722
|
-
async estimateGasPrice(blockHorizon) {
|
4723
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4724
|
-
blockHorizon: String(blockHorizon)
|
4725
|
-
});
|
4726
|
-
return bn16(estimateGasPrice.gasPrice);
|
4727
|
-
}
|
4728
4507
|
/**
|
4729
4508
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4730
4509
|
*
|
@@ -4744,10 +4523,10 @@ var _Provider = class {
|
|
4744
4523
|
*/
|
4745
4524
|
async produceBlocks(amount, startTime) {
|
4746
4525
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4747
|
-
blocksToProduce:
|
4526
|
+
blocksToProduce: bn15(amount).toString(10),
|
4748
4527
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4749
4528
|
});
|
4750
|
-
return
|
4529
|
+
return bn15(latestBlockHeight);
|
4751
4530
|
}
|
4752
4531
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4753
4532
|
async getTransactionResponse(transactionId) {
|
@@ -4761,7 +4540,7 @@ cacheInputs_fn = function(inputs) {
|
|
4761
4540
|
return;
|
4762
4541
|
}
|
4763
4542
|
inputs.forEach((input) => {
|
4764
|
-
if (input.type ===
|
4543
|
+
if (input.type === InputType6.Coin) {
|
4765
4544
|
this.cache?.set(input.id);
|
4766
4545
|
}
|
4767
4546
|
});
|
@@ -4771,7 +4550,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4771
4550
|
|
4772
4551
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4773
4552
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4774
|
-
import { bn as
|
4553
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4775
4554
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4776
4555
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4777
4556
|
async function getTransactionSummary(params) {
|
@@ -4789,28 +4568,21 @@ async function getTransactionSummary(params) {
|
|
4789
4568
|
arrayify12(gqlTransaction.rawPayload),
|
4790
4569
|
0
|
4791
4570
|
);
|
4792
|
-
|
4793
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4794
|
-
txReceipts = gqlTransaction.status.receipts;
|
4795
|
-
}
|
4796
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4571
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4797
4572
|
const {
|
4798
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4573
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4799
4574
|
} = provider.getChain();
|
4800
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4801
4575
|
const transactionInfo = assembleTransactionSummary({
|
4802
4576
|
id: gqlTransaction.id,
|
4803
4577
|
receipts,
|
4804
4578
|
transaction: decodedTransaction,
|
4805
4579
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4806
4580
|
gqlTransactionStatus: gqlTransaction.status,
|
4807
|
-
gasPerByte:
|
4808
|
-
gasPriceFactor:
|
4581
|
+
gasPerByte: bn16(gasPerByte),
|
4582
|
+
gasPriceFactor: bn16(gasPriceFactor),
|
4809
4583
|
abiMap,
|
4810
4584
|
maxInputs,
|
4811
|
-
gasCosts
|
4812
|
-
maxGasPerTx,
|
4813
|
-
gasPrice
|
4585
|
+
gasCosts
|
4814
4586
|
});
|
4815
4587
|
return {
|
4816
4588
|
gqlTransaction,
|
@@ -4820,11 +4592,10 @@ async function getTransactionSummary(params) {
|
|
4820
4592
|
async function getTransactionSummaryFromRequest(params) {
|
4821
4593
|
const { provider, transactionRequest, abiMap } = params;
|
4822
4594
|
const { receipts } = await provider.call(transactionRequest);
|
4823
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4595
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4824
4596
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4825
4597
|
const transaction = transactionRequest.toTransaction();
|
4826
4598
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4827
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4828
4599
|
const transactionSummary = assembleTransactionSummary({
|
4829
4600
|
receipts,
|
4830
4601
|
transaction,
|
@@ -4833,9 +4604,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4833
4604
|
gasPerByte,
|
4834
4605
|
gasPriceFactor,
|
4835
4606
|
maxInputs,
|
4836
|
-
gasCosts
|
4837
|
-
maxGasPerTx,
|
4838
|
-
gasPrice
|
4607
|
+
gasCosts
|
4839
4608
|
});
|
4840
4609
|
return transactionSummary;
|
4841
4610
|
}
|
@@ -4844,18 +4613,13 @@ async function getTransactionsSummaries(params) {
|
|
4844
4613
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4845
4614
|
const { edges, pageInfo } = transactionsByOwner;
|
4846
4615
|
const {
|
4847
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4616
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4848
4617
|
} = provider.getChain();
|
4849
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4850
4618
|
const transactions = edges.map((edge) => {
|
4851
4619
|
const { node: gqlTransaction } = edge;
|
4852
|
-
const { id, rawPayload, status } = gqlTransaction;
|
4620
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4853
4621
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4854
|
-
|
4855
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4856
|
-
txReceipts = gqlTransaction.status.receipts;
|
4857
|
-
}
|
4858
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4622
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4859
4623
|
const transactionSummary = assembleTransactionSummary({
|
4860
4624
|
id,
|
4861
4625
|
receipts,
|
@@ -4866,9 +4630,7 @@ async function getTransactionsSummaries(params) {
|
|
4866
4630
|
gasPerByte,
|
4867
4631
|
gasPriceFactor,
|
4868
4632
|
maxInputs,
|
4869
|
-
gasCosts
|
4870
|
-
maxGasPerTx,
|
4871
|
-
gasPrice
|
4633
|
+
gasCosts
|
4872
4634
|
});
|
4873
4635
|
const output = {
|
4874
4636
|
gqlTransaction,
|
@@ -5162,8 +4924,9 @@ var Account = class extends AbstractAccount {
|
|
5162
4924
|
* @param assetId - The asset ID to check the balance for.
|
5163
4925
|
* @returns A promise that resolves to the balance amount.
|
5164
4926
|
*/
|
5165
|
-
async getBalance(assetId
|
5166
|
-
const
|
4927
|
+
async getBalance(assetId) {
|
4928
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4929
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5167
4930
|
return amount;
|
5168
4931
|
}
|
5169
4932
|
/**
|
@@ -5200,33 +4963,37 @@ var Account = class extends AbstractAccount {
|
|
5200
4963
|
* @param fee - The estimated transaction fee.
|
5201
4964
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5202
4965
|
*/
|
5203
|
-
async fund(request,
|
5204
|
-
const
|
5205
|
-
const
|
5206
|
-
|
5207
|
-
|
5208
|
-
|
5209
|
-
coinQuantities: requiredQuantities
|
4966
|
+
async fund(request, coinQuantities, fee) {
|
4967
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4968
|
+
const updatedQuantities = addAmountToAsset({
|
4969
|
+
amount: bn17(fee),
|
4970
|
+
assetId: baseAssetId,
|
4971
|
+
coinQuantities
|
5210
4972
|
});
|
5211
4973
|
const quantitiesDict = {};
|
5212
|
-
|
4974
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5213
4975
|
quantitiesDict[assetId] = {
|
5214
4976
|
required: amount,
|
5215
|
-
owned:
|
4977
|
+
owned: bn17(0)
|
5216
4978
|
};
|
5217
4979
|
});
|
5218
|
-
|
4980
|
+
const cachedUtxos = [];
|
4981
|
+
const cachedMessages = [];
|
4982
|
+
const owner = this.address.toB256();
|
4983
|
+
request.inputs.forEach((input) => {
|
5219
4984
|
const isResource = "amount" in input;
|
5220
4985
|
if (isResource) {
|
5221
4986
|
const isCoin2 = "owner" in input;
|
5222
4987
|
if (isCoin2) {
|
5223
4988
|
const assetId = String(input.assetId);
|
5224
|
-
if (quantitiesDict[assetId]) {
|
5225
|
-
const amount =
|
4989
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4990
|
+
const amount = bn17(input.amount);
|
5226
4991
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4992
|
+
cachedUtxos.push(input.id);
|
5227
4993
|
}
|
5228
|
-
} else if (input.amount && quantitiesDict[
|
5229
|
-
quantitiesDict[
|
4994
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4995
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4996
|
+
cachedMessages.push(input.nonce);
|
5230
4997
|
}
|
5231
4998
|
}
|
5232
4999
|
});
|
@@ -5241,23 +5008,12 @@ var Account = class extends AbstractAccount {
|
|
5241
5008
|
});
|
5242
5009
|
const needsToBeFunded = missingQuantities.length;
|
5243
5010
|
if (needsToBeFunded) {
|
5244
|
-
const
|
5245
|
-
|
5246
|
-
|
5247
|
-
|
5248
|
-
|
5249
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5250
|
-
const requestToBeReEstimate = clone4(txRequest);
|
5251
|
-
if (addedSignatures) {
|
5252
|
-
Array.from({ length: addedSignatures }).forEach(
|
5253
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
5254
|
-
);
|
5011
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5012
|
+
messages: cachedMessages,
|
5013
|
+
utxos: cachedUtxos
|
5014
|
+
});
|
5015
|
+
request.addResources(resources);
|
5255
5016
|
}
|
5256
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5257
|
-
transactionRequest: requestToBeReEstimate
|
5258
|
-
});
|
5259
|
-
txRequest.maxFee = maxFee;
|
5260
|
-
return txRequest;
|
5261
5017
|
}
|
5262
5018
|
/**
|
5263
5019
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5265,25 +5021,30 @@ var Account = class extends AbstractAccount {
|
|
5265
5021
|
* @param destination - The address of the destination.
|
5266
5022
|
* @param amount - The amount of coins to transfer.
|
5267
5023
|
* @param assetId - The asset ID of the coins to transfer.
|
5268
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5024
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5269
5025
|
* @returns A promise that resolves to the prepared transaction request.
|
5270
5026
|
*/
|
5271
|
-
async createTransfer(destination, amount, assetId
|
5272
|
-
const
|
5273
|
-
|
5274
|
-
const
|
5027
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5028
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5029
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5030
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5031
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5032
|
+
const request = new ScriptTransactionRequest(params);
|
5033
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5034
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5275
5035
|
estimateTxDependencies: true,
|
5276
5036
|
resourcesOwner: this
|
5277
5037
|
});
|
5278
|
-
|
5279
|
-
|
5280
|
-
|
5281
|
-
|
5282
|
-
|
5283
|
-
|
5284
|
-
|
5285
|
-
|
5286
|
-
await this.fund(request,
|
5038
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
5039
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
5040
|
+
this.validateGas({
|
5041
|
+
gasUsed,
|
5042
|
+
gasPrice: request.gasPrice,
|
5043
|
+
gasLimit: request.gasLimit,
|
5044
|
+
minGasPrice
|
5045
|
+
});
|
5046
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5047
|
+
request.updatePredicateInputs(estimatedInputs);
|
5287
5048
|
return request;
|
5288
5049
|
}
|
5289
5050
|
/**
|
@@ -5295,14 +5056,15 @@ var Account = class extends AbstractAccount {
|
|
5295
5056
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5296
5057
|
* @returns A promise that resolves to the transaction response.
|
5297
5058
|
*/
|
5298
|
-
async transfer(destination, amount, assetId
|
5299
|
-
if (
|
5059
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5060
|
+
if (bn17(amount).lte(0)) {
|
5300
5061
|
throw new FuelError15(
|
5301
5062
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5302
5063
|
"Transfer amount must be a positive number."
|
5303
5064
|
);
|
5304
5065
|
}
|
5305
|
-
const
|
5066
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5067
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5306
5068
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5307
5069
|
}
|
5308
5070
|
/**
|
@@ -5314,38 +5076,41 @@ var Account = class extends AbstractAccount {
|
|
5314
5076
|
* @param txParams - The optional transaction parameters.
|
5315
5077
|
* @returns A promise that resolves to the transaction response.
|
5316
5078
|
*/
|
5317
|
-
async transferToContract(contractId, amount, assetId
|
5318
|
-
if (
|
5079
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5080
|
+
if (bn17(amount).lte(0)) {
|
5319
5081
|
throw new FuelError15(
|
5320
5082
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5321
5083
|
"Transfer amount must be a positive number."
|
5322
5084
|
);
|
5323
5085
|
}
|
5324
5086
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5087
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5088
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5089
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5090
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5325
5091
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5326
5092
|
hexlifiedContractId: contractAddress.toB256(),
|
5327
|
-
amountToTransfer:
|
5328
|
-
assetId
|
5093
|
+
amountToTransfer: bn17(amount),
|
5094
|
+
assetId: assetIdToTransfer
|
5329
5095
|
});
|
5330
5096
|
const request = new ScriptTransactionRequest({
|
5331
|
-
...
|
5097
|
+
...params,
|
5332
5098
|
script,
|
5333
5099
|
scriptData
|
5334
5100
|
});
|
5335
5101
|
request.addContractInputAndOutput(contractAddress);
|
5336
|
-
const
|
5337
|
-
|
5338
|
-
|
5102
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5103
|
+
request,
|
5104
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
5105
|
+
);
|
5106
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5107
|
+
this.validateGas({
|
5108
|
+
gasUsed,
|
5109
|
+
gasPrice: request.gasPrice,
|
5110
|
+
gasLimit: request.gasLimit,
|
5111
|
+
minGasPrice
|
5339
5112
|
});
|
5340
|
-
|
5341
|
-
this.validateGas({
|
5342
|
-
gasUsed: txCost.gasUsed,
|
5343
|
-
gasLimit: request.gasLimit
|
5344
|
-
});
|
5345
|
-
}
|
5346
|
-
request.gasLimit = txCost.gasUsed;
|
5347
|
-
request.maxFee = txCost.maxFee;
|
5348
|
-
await this.fund(request, txCost);
|
5113
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5349
5114
|
return this.sendTransaction(request);
|
5350
5115
|
}
|
5351
5116
|
/**
|
@@ -5357,31 +5122,40 @@ var Account = class extends AbstractAccount {
|
|
5357
5122
|
* @returns A promise that resolves to the transaction response.
|
5358
5123
|
*/
|
5359
5124
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5125
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5126
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5360
5127
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5361
5128
|
const recipientDataArray = arrayify14(
|
5362
5129
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5363
5130
|
);
|
5364
5131
|
const amountDataArray = arrayify14(
|
5365
|
-
"0x".concat(
|
5132
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5366
5133
|
);
|
5367
5134
|
const script = new Uint8Array([
|
5368
5135
|
...arrayify14(withdrawScript.bytes),
|
5369
5136
|
...recipientDataArray,
|
5370
5137
|
...amountDataArray
|
5371
5138
|
]);
|
5372
|
-
const params = {
|
5139
|
+
const params = {
|
5140
|
+
script,
|
5141
|
+
gasPrice: minGasPrice,
|
5142
|
+
baseAssetId,
|
5143
|
+
...txParams
|
5144
|
+
};
|
5373
5145
|
const request = new ScriptTransactionRequest(params);
|
5374
|
-
const
|
5375
|
-
const
|
5376
|
-
|
5377
|
-
|
5378
|
-
|
5379
|
-
|
5380
|
-
|
5381
|
-
|
5382
|
-
|
5383
|
-
|
5384
|
-
|
5146
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
5147
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5148
|
+
request,
|
5149
|
+
forwardingQuantities
|
5150
|
+
);
|
5151
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5152
|
+
this.validateGas({
|
5153
|
+
gasUsed,
|
5154
|
+
gasPrice: request.gasPrice,
|
5155
|
+
gasLimit: request.gasLimit,
|
5156
|
+
minGasPrice
|
5157
|
+
});
|
5158
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5385
5159
|
return this.sendTransaction(request);
|
5386
5160
|
}
|
5387
5161
|
async signMessage(message) {
|
@@ -5439,7 +5213,18 @@ var Account = class extends AbstractAccount {
|
|
5439
5213
|
}
|
5440
5214
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5441
5215
|
}
|
5442
|
-
validateGas({
|
5216
|
+
validateGas({
|
5217
|
+
gasUsed,
|
5218
|
+
gasPrice,
|
5219
|
+
gasLimit,
|
5220
|
+
minGasPrice
|
5221
|
+
}) {
|
5222
|
+
if (minGasPrice.gt(gasPrice)) {
|
5223
|
+
throw new FuelError15(
|
5224
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5225
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5226
|
+
);
|
5227
|
+
}
|
5443
5228
|
if (gasUsed.gt(gasLimit)) {
|
5444
5229
|
throw new FuelError15(
|
5445
5230
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5735,7 +5520,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5735
5520
|
* @param transactionRequestLike - The transaction request to send.
|
5736
5521
|
* @returns A promise that resolves to the TransactionResponse object.
|
5737
5522
|
*/
|
5738
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5523
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5739
5524
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5740
5525
|
if (estimateTxDependencies) {
|
5741
5526
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5776,7 +5561,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5776
5561
|
// src/hdwallet/hdwallet.ts
|
5777
5562
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5778
5563
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5779
|
-
import { bn as
|
5564
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5780
5565
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5781
5566
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5782
5567
|
|
@@ -8248,7 +8033,7 @@ var HDWallet = class {
|
|
8248
8033
|
const IR = bytes.slice(32);
|
8249
8034
|
if (privateKey) {
|
8250
8035
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8251
|
-
const ki =
|
8036
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
8252
8037
|
return new HDWallet({
|
8253
8038
|
privateKey: ki,
|
8254
8039
|
chainCode: IR,
|
@@ -8935,9 +8720,8 @@ import {
|
|
8935
8720
|
SCRIPT_FIXED_SIZE
|
8936
8721
|
} from "@fuel-ts/abi-coder";
|
8937
8722
|
import { Address as Address9 } from "@fuel-ts/address";
|
8938
|
-
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8939
8723
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8940
|
-
import { ByteArrayCoder, InputType as
|
8724
|
+
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8941
8725
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8942
8726
|
|
8943
8727
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8997,9 +8781,9 @@ var Predicate = class extends Account {
|
|
8997
8781
|
const request = transactionRequestify(transactionRequestLike);
|
8998
8782
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8999
8783
|
request.inputs?.forEach((input) => {
|
9000
|
-
if (input.type ===
|
9001
|
-
input.predicate =
|
9002
|
-
input.predicateData =
|
8784
|
+
if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
8785
|
+
input.predicate = this.bytes;
|
8786
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9003
8787
|
}
|
9004
8788
|
});
|
9005
8789
|
return request;
|
@@ -9013,8 +8797,10 @@ var Predicate = class extends Account {
|
|
9013
8797
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
9014
8798
|
* @returns A promise that resolves to the prepared transaction request.
|
9015
8799
|
*/
|
9016
|
-
async createTransfer(destination, amount, assetId
|
9017
|
-
|
8800
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8801
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8802
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8803
|
+
return this.populateTransactionPredicateData(request);
|
9018
8804
|
}
|
9019
8805
|
/**
|
9020
8806
|
* Sends a transaction with the populated predicate data.
|
@@ -9022,9 +8808,9 @@ var Predicate = class extends Account {
|
|
9022
8808
|
* @param transactionRequestLike - The transaction request-like object.
|
9023
8809
|
* @returns A promise that resolves to the transaction response.
|
9024
8810
|
*/
|
9025
|
-
sendTransaction(transactionRequestLike) {
|
9026
|
-
const transactionRequest =
|
9027
|
-
return super.sendTransaction(transactionRequest,
|
8811
|
+
sendTransaction(transactionRequestLike, options) {
|
8812
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8813
|
+
return super.sendTransaction(transactionRequest, options);
|
9028
8814
|
}
|
9029
8815
|
/**
|
9030
8816
|
* Simulates a transaction with the populated predicate data.
|
@@ -9033,8 +8819,8 @@ var Predicate = class extends Account {
|
|
9033
8819
|
* @returns A promise that resolves to the call result.
|
9034
8820
|
*/
|
9035
8821
|
simulateTransaction(transactionRequestLike) {
|
9036
|
-
const transactionRequest =
|
9037
|
-
return super.simulateTransaction(transactionRequest
|
8822
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8823
|
+
return super.simulateTransaction(transactionRequest);
|
9038
8824
|
}
|
9039
8825
|
getPredicateData(policiesLength) {
|
9040
8826
|
if (!this.predicateData.length) {
|
@@ -9080,25 +8866,6 @@ var Predicate = class extends Account {
|
|
9080
8866
|
predicateInterface: abiInterface
|
9081
8867
|
};
|
9082
8868
|
}
|
9083
|
-
/**
|
9084
|
-
* Retrieves resources satisfying the spend query for the account.
|
9085
|
-
*
|
9086
|
-
* @param quantities - IDs of coins to exclude.
|
9087
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9088
|
-
* @returns A promise that resolves to an array of Resources.
|
9089
|
-
*/
|
9090
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9091
|
-
const resources = await this.provider.getResourcesToSpend(
|
9092
|
-
this.address,
|
9093
|
-
quantities,
|
9094
|
-
excludedIds
|
9095
|
-
);
|
9096
|
-
return resources.map((resource) => ({
|
9097
|
-
...resource,
|
9098
|
-
predicate: hexlify19(this.bytes),
|
9099
|
-
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9100
|
-
}));
|
9101
|
-
}
|
9102
8869
|
/**
|
9103
8870
|
* Sets the configurable constants for the predicate.
|
9104
8871
|
*
|
@@ -9847,7 +9614,7 @@ export {
|
|
9847
9614
|
WalletLocked,
|
9848
9615
|
WalletManager,
|
9849
9616
|
WalletUnlocked,
|
9850
|
-
|
9617
|
+
addAmountToAsset,
|
9851
9618
|
addOperation,
|
9852
9619
|
assemblePanicError,
|
9853
9620
|
assembleReceiptByType,
|
@@ -9856,10 +9623,9 @@ export {
|
|
9856
9623
|
assets,
|
9857
9624
|
buildBlockExplorerUrl,
|
9858
9625
|
cacheFor,
|
9859
|
-
cacheTxInputsFromOwner,
|
9860
|
-
calculateGasFee,
|
9861
9626
|
calculateMetadataGasForTxCreate,
|
9862
9627
|
calculateMetadataGasForTxScript,
|
9628
|
+
calculatePriceWithFactor,
|
9863
9629
|
calculateTransactionFee,
|
9864
9630
|
coinQuantityfy,
|
9865
9631
|
deferPromise,
|