From 3793b3e83f2cba1bce95160dba1becb440178e12 Mon Sep 17 00:00:00 2001 From: oldchili <130549691+oldchili@users.noreply.github.com> Date: Tue, 5 Dec 2023 21:40:44 +0200 Subject: [PATCH] Cosmetic changes --- lib/dss-test | 2 +- src/StickyOracle.sol | 15 +++++++-------- test/StickyOracle.t.sol | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/dss-test b/lib/dss-test index df7b13ea..28000a0e 160000 --- a/lib/dss-test +++ b/lib/dss-test @@ -1 +1 @@ -Subproject commit df7b13ead253f4b831df2464f7d74f28a091a790 +Subproject commit 28000a0ea3602c887f2fdc22dea591789d1b4971 diff --git a/src/StickyOracle.sol b/src/StickyOracle.sol index 76b82ea6..b182ba27 100644 --- a/src/StickyOracle.sol +++ b/src/StickyOracle.sol @@ -46,8 +46,8 @@ contract StickyOracle { event Kiss(address indexed usr); event Diss(address indexed usr); event File(bytes32 indexed what, uint256 data); - event Init(uint256 days_, uint128 cur); - event Poke(uint256 indexed day, uint128 cap, uint128 pokePrice); + event Init(uint256 days_, uint128 pokePrice_); + event Poke(uint256 indexed day, uint128 cap, uint128 pokePrice_); constructor(address _pip) { pip = PipLike(_pip); @@ -104,24 +104,22 @@ contract StickyOracle { // if the initiated timespan is shorter than the [lo, hi] window the initial cap will just be used for longer function init(uint256 days_) external auth { require(cap == 0, "StickyOracle/already-init"); - uint128 cur = cap = pokePrice = pip.read(); + uint128 pokePrice_ = pokePrice = cap = pip.read(); uint256 pokeDay_ = pokeDay = block.timestamp / 1 days; - uint256 firstDay = pokeDay_ - days_; - uint256 accumulatedVal = 0; uint32 accumulatedTs = uint32(block.timestamp - days_ * 1 days); - for (uint256 day = firstDay; day <= pokeDay_;) { + for (uint256 day = pokeDay_ - days_; day <= pokeDay_;) { accumulators[day].val = accumulatedVal; accumulators[day].ts = accumulatedTs; - accumulatedVal += cur * 1 days; + accumulatedVal += pokePrice_ * 1 days; accumulatedTs += 1 days; unchecked { ++day; } } - emit Init(days_, cur); + emit Init(days_, pokePrice_); } function poke() external { @@ -137,6 +135,7 @@ contract StickyOracle { accumulators[today].val = accumulators[pokeDay].val + pokePrice * (block.timestamp - accumulators[pokeDay].ts); accumulators[today].ts = uint32(block.timestamp); + // store for next accumulator calc uint128 pokePrice_ = pokePrice = _min(pip.read(), cap_); pokeDay = today; diff --git a/test/StickyOracle.t.sol b/test/StickyOracle.t.sol index 514ffa16..42d89b3e 100644 --- a/test/StickyOracle.t.sol +++ b/test/StickyOracle.t.sol @@ -69,8 +69,8 @@ contract StickyOracleTest is Test { address PAUSE_PROXY; address PIP_MKR; - event Init(uint256 days_, uint128 cur); - event Poke(uint256 indexed day, uint128 cap, uint128 pokePrice); + event Init(uint256 days_, uint128 pokePrice_); + event Poke(uint256 indexed day, uint128 cap, uint128 pokePrice_); function setMedianizerPrice(uint256 newPrice) internal { vm.store(address(medianizer), bytes32(uint256(1)), bytes32(block.timestamp << 128 | newPrice));