@@ -37,6 +37,7 @@ import {
3737 MessageSignature ,
3838 noneCV ,
3939 OptionalCV ,
40+ principalCV ,
4041 someCV ,
4142 StacksTransaction ,
4243 standardPrincipalCV ,
@@ -310,6 +311,8 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
310311 const request : RosettaConstructionMetadataRequest = req . body ;
311312 const options : RosettaOptions = request . options ;
312313
314+ let dummyTransaction : StacksTransaction ;
315+
313316 if ( options ?. sender_address && ! isValidC32Address ( options . sender_address ) ) {
314317 res . status ( 400 ) . json ( RosettaErrors [ RosettaErrorsTypes . invalidSender ] ) ;
315318 return ;
@@ -337,6 +340,20 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
337340 res . status ( 400 ) . json ( RosettaErrors [ RosettaErrorsTypes . invalidRecipient ] ) ;
338341 return ;
339342 }
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+
340357 break ;
341358 case RosettaOperationType . StackStx : {
342359 // Getting PoX info
@@ -353,6 +370,27 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
353370 options . contract_address = contractAddress ;
354371 options . contract_name = contractName ;
355372 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+
356394 break ;
357395 }
358396 case RosettaOperationType . DelegateStx : {
@@ -361,6 +399,27 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
361399 const [ contractAddress , contractName ] = contract . split ( '.' ) ;
362400 options . contract_address = contractAddress ;
363401 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+
364423 break ;
365424 }
366425 default :
@@ -392,8 +451,8 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
392451 } ;
393452
394453 // 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' ) {
397456 res . status ( 400 ) . json ( RosettaErrors [ RosettaErrorsTypes . invalidFee ] ) ;
398457 return ;
399458 }
@@ -402,7 +461,7 @@ export function createRosettaConstructionRouter(db: PgStore, chainId: ChainID):
402461 res . status ( 400 ) . json ( RosettaErrorsTypes . missingTransactionSize ) ;
403462 return ;
404463 }
405- const feeValue = Math . round ( Number ( feeInfo ) * Number ( options . size ) * 1.5 ) . toString ( ) ;
464+
406465 const currency : RosettaCurrency = {
407466 symbol : RosettaConstants . symbol ,
408467 decimals : RosettaConstants . decimals ,
0 commit comments