cowprotocol/solver-rewards

Formula for volume based fees might be wrong

Closed this issue · 1 comments

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

Closing as we don't compute protocol fees any more but fetch them directly from the backend db