@@ -37,6 +37,7 @@ import {
37
37
MessageSignature ,
38
38
noneCV ,
39
39
OptionalCV ,
40
+ principalCV ,
40
41
someCV ,
41
42
StacksTransaction ,
42
43
standardPrincipalCV ,
@@ -310,6 +311,8 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
310
311
const request : RosettaConstructionMetadataRequest = req . body ;
311
312
const options : RosettaOptions = request . options ;
312
313
314
+ let dummyTransaction : StacksTransaction ;
315
+
313
316
if ( options ?. sender_address && ! isValidC32Address ( options . sender_address ) ) {
314
317
res . status ( 400 ) . json ( RosettaErrors [ RosettaErrorsTypes . invalidSender ] ) ;
315
318
return ;
@@ -337,6 +340,20 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
337
340
res . status ( 400 ) . json ( RosettaErrors [ RosettaErrorsTypes . invalidRecipient ] ) ;
338
341
return ;
339
342
}
343
+
344
+ // dummy transaction to calculate fee
345
+ const dummyTokenTransferTx : UnsignedTokenTransferOptions = {
346
+ recipient : recipientAddress ,
347
+ amount : 1n , // placeholder
348
+ publicKey : '000000000000000000000000000000000000000000000000000000000000000000' , // placeholder
349
+ network : getStacksNetwork ( ) ,
350
+ nonce : 0 , // placeholder
351
+ memo : '123456' , // placeholder
352
+ anchorMode : AnchorMode . Any ,
353
+ } ;
354
+ // Do not set fee so that the fee is calculated
355
+ dummyTransaction = await makeUnsignedSTXTokenTransfer ( dummyTokenTransferTx ) ;
356
+
340
357
break ;
341
358
case RosettaOperationType . StackStx : {
342
359
// Getting PoX info
@@ -353,6 +370,27 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
353
370
options . contract_address = contractAddress ;
354
371
options . contract_name = contractName ;
355
372
options . burn_block_height = burnBlockHeight ;
373
+
374
+ // dummy transaction to calculate fee
375
+ const dummyStackingTx : UnsignedContractCallOptions = {
376
+ publicKey : '000000000000000000000000000000000000000000000000000000000000000000' ,
377
+ contractAddress : contractAddress ,
378
+ contractName : contractName ,
379
+ functionName : 'stack-stx' ,
380
+ functionArgs : [
381
+ uintCV ( 0 ) ,
382
+ poxAddressToTuple ( 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4' ) , // placeholder
383
+ uintCV ( 0 ) ,
384
+ uintCV ( 1 ) ,
385
+ ] ,
386
+ validateWithAbi : false ,
387
+ network : getStacksNetwork ( ) ,
388
+ nonce : 0 ,
389
+ anchorMode : AnchorMode . Any ,
390
+ } ;
391
+ // Do not set fee so that the fee is calculated
392
+ dummyTransaction = await makeUnsignedContractCall ( dummyStackingTx ) ;
393
+
356
394
break ;
357
395
}
358
396
case RosettaOperationType . DelegateStx : {
@@ -361,6 +399,27 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
361
399
const [ contractAddress , contractName ] = contract . split ( '.' ) ;
362
400
options . contract_address = contractAddress ;
363
401
options . contract_name = contractName ;
402
+
403
+ // dummy transaction to calculate fee
404
+ const dummyDelegateStxTx : UnsignedContractCallOptions = {
405
+ publicKey : '000000000000000000000000000000000000000000000000000000000000000000' ,
406
+ contractAddress : 'ST000000000000000000002AMW42H' ,
407
+ contractName : 'pox' ,
408
+ functionName : 'delegate-stx' ,
409
+ functionArgs : [
410
+ uintCV ( 1 ) , // placeholder
411
+ principalCV ( 'SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159.some-contract-name-v1-2-3-4' ) , // placeholder,
412
+ someCV ( uintCV ( 1 ) ) , // placeholder
413
+ someCV ( poxAddressToTuple ( 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4' ) ) , // placeholder
414
+ ] ,
415
+ validateWithAbi : false ,
416
+ network : getStacksNetwork ( ) ,
417
+ nonce : 0 ,
418
+ anchorMode : AnchorMode . Any ,
419
+ } ;
420
+ // Do not set fee so that the fee is calculated
421
+ dummyTransaction = await makeUnsignedContractCall ( dummyDelegateStxTx ) ;
422
+
364
423
break ;
365
424
}
366
425
default :
@@ -392,8 +451,8 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
392
451
} ;
393
452
394
453
// Getting fee info if not operation fee was given in /preprocess
395
- const feeInfo = await new StacksCoreRpcClient ( ) . getEstimatedTransferFee ( ) ;
396
- if ( feeInfo === undefined || feeInfo === '0' ) {
454
+ const feeValue = dummyTransaction . auth . spendingCondition . fee . toString ( ) ;
455
+ if ( feeValue === undefined || feeValue === '0' ) {
397
456
res . status ( 400 ) . json ( RosettaErrors [ RosettaErrorsTypes . invalidFee ] ) ;
398
457
return ;
399
458
}
@@ -402,7 +461,7 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
402
461
res . status ( 400 ) . json ( RosettaErrorsTypes . missingTransactionSize ) ;
403
462
return ;
404
463
}
405
- const feeValue = Math . round ( Number ( feeInfo ) * Number ( options . size ) * 1.5 ) . toString ( ) ;
464
+
406
465
const currency : RosettaCurrency = {
407
466
symbol : RosettaConstants . symbol ,
408
467
decimals : RosettaConstants . decimals ,
0 commit comments