Skip to content

[Rosetta] Use fee estimator in tx construction #1298

Closed
@zone117x

Description

@zone117x

Context from #1295

The Rosetta construction code still uses the legacy fee calculation method of essentially fee = someConstant * tx.byteLength. There's a new-ish RPC endpoint /v2/fees/transaction which can return more accurate fees based on network conditions.

Keep in mind the new fee estimator endpoint can return an error NoEstimateAvailable, in which case the Rosetta code should fallback to the previous estimation logic.

Relevant code at:

const feeInfo = await new StacksCoreRpcClient().getEstimatedTransferFee();
if (feeInfo === undefined || feeInfo === '0') {
res.status(400).json(RosettaErrors[RosettaErrorsTypes.invalidFee]);
return;
}
if (!options.size) {
res.status(400).json(RosettaErrorsTypes.missingTransactionSize);
return;
}
const feeValue = (BigInt(feeInfo) * BigInt(options.size)).toString();
const currency: RosettaCurrency = {
symbol: RosettaConstants.symbol,
decimals: RosettaConstants.decimals,
};
const fee: RosettaAmount = {
value: feeValue,
currency,
};
response.suggested_fee = [fee];

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions