Last active
June 20, 2020 21:49
-
-
Save epheph/0b115f9f1961c3ac84866ee06a94426c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract UniswapV2Pair { | |
// Contract Storage Variables: | |
uint public price0CumulativeLast; | |
uint public price1CumulativeLast; | |
... | |
// The only place these storage variables are updated: | |
function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private { | |
uint32 timeElapsed = blockTimestamp - blockTimestampLast; | |
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) { | |
price0CumulativeLast += uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed; | |
price1CumulativeLast += uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed; | |
} | |
blockTimestampLast = blockTimestamp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment