primitivefinance / portfolio

Portfolio is an automated market making protocol for implementing custom strategies at the lowest cost possible.

Home Page:https://www.primitive.xyz/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix: Swap fees are truncated to 0 on small swaps

Alexangelj opened this issue · comments

Description

A small input amount for a swap that is less than the fee percentage would lead to a truncated fee amount of zero. For example, if the swap input is 10, and the fee is 1 / 100, the fee amount is 0.1 which is truncated to zero. This can lead to path independence for small swaps, but path dependence on larger swaps, a discrepancy that can be used to manipulate the pool to extract profits.

Fix

  • Round fee amount up if the remainder of the computation is non-zero.

Should we also apply the rounding to the protocol fee amount?