Skip to content

Commit

Permalink
Cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oldchili committed Dec 5, 2023
1 parent 18e0bda commit 3793b3e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/dss-test
15 changes: 7 additions & 8 deletions src/StickyOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions test/StickyOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 3793b3e

Please sign in to comment.