TWAMM
TWAMM copied to clipboard
Tokens received after LongTermSwap greatly varies from expected values for certain parameters
Increasing the length of the long term swaps causes most tests to fail. For example, setting blockInterval to 500 causes the received values to differ from the expected by as much as 30%.
I believe this to be a result of sellingRate being casted to an integer value.
uint256 sellingRate = amount / (orderExpiry - currentBlock);
In cases where amount is close to the number of blocks the order is selling over, this results in a drastic effect.
For example, selling 10,000 tokens over 5,000 blocks results in a sellingRate of 1.977, which is cast to 1, resulting in the user only receiving around half as many tokens as expected.
Forked repository to work toward fixing: https://github.com/corddry/TWAMM
This is only an issue for extremely small amounts of tokens, as 10,000 is a tiny fraction of an erc-20 that has say, 18 decimals