Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formula for volume based fees might be wrong #336

Open
fhenneke opened this issue Feb 5, 2024 · 0 comments
Open

Formula for volume based fees might be wrong #336

fhenneke opened this issue Feb 5, 2024 · 0 comments

Comments

@fhenneke
Copy link
Contributor

fhenneke commented Feb 5, 2024

I think the code in this repo (and in dune-sync) for the computation of protocol fees based on volume contains an error.

WHEN fp.kind = 'volume'
THEN fp.volume_factor / (1 + fp.volume_factor) * os.sell_amount

The formula is probably correct for buy orders: Suppose the volume without fees is Y. Then after adding a fee of X = 0.0015 * Y the sell amount is os.sell_amount = Y + X = (1 + 0.0015) * Y. From this observable amount we can reconstruct the fee as X = 0.0015 * Y = 0.0015 / (1 + 0.0015) * os.sell_amount.

For sell orders the formula is probably incorrect: If the sell amount without fees is Y then the fee is X = 0.0015 Y. The user still sends os.sell_amount = Y for a sell order. Thus the correct fee is reconstucted as X = 0.0015 * Y = 0.0015 * os.sell_amount.

Is this how the driver implements volume based fees @sunce86? If so, sell and buy orders could be treated in different cases (using a CASE statement) as is done for surplus based fees.

cc @harisang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant