velodrome-finance / v1

Velodrome Finance v1 Smart Contracts
https://v1.velodrome.finance
47 stars 81 forks source link

fix sample calc in library, add getTradeDiffs #10

Open ethzoomer opened 1 year ago

ethzoomer commented 1 year ago

Deployed here https://optimistic.etherscan.io/address/0x82959edf06499c3c931c39ebca8737f0b5551bec and being used in nightride UI

Makes _getAmountOut account for differences in the amount of decimals for tokenA and tokenB, instead of just assuming both tokenA and tokenB have the same amount of decimals.

In getTradeDiff(uint,address,address,bool), sample was rounding to 0 in certain cases incorrectly, e.g. if the pool had 0.1 WBTC and 1e9 OptiDoge, sample would be 0, because 0.1 1e8 1e18/ ( 1e9 * 1e18 ) rounds to 0, so we just directly calculate the derivative instead for volatile pairs in getTradeDiff.

Added a getTradeDiffs function just for convenience to be able to bundle many getTradeDiff calls at once (used by v2 UI).

ethzoomer commented 1 year ago

Deployed newest version at https://optimistic.etherscan.io/address/0x10fC5e227C1E0705AF5931489c42c4791F81b1E5#code