TWAMM icon indicating copy to clipboard operation
TWAMM copied to clipboard

Tokens received after LongTermSwap greatly varies from expected values for certain parameters

Open corddry opened this issue 3 years ago • 2 comments

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.

corddry avatar Dec 01 '21 02:12 corddry

Forked repository to work toward fixing: https://github.com/corddry/TWAMM

corddry avatar Dec 01 '21 03:12 corddry

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

corddry avatar Dec 14 '21 04:12 corddry