From d10f0de89c232bb78417c8a5fd79182cf861cbd5 Mon Sep 17 00:00:00 2001 From: oldchili <130549691+oldchili@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:35:51 +0200 Subject: [PATCH] Return false on init if no price --- src/StickyOracle.sol | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/StickyOracle.sol b/src/StickyOracle.sol index 169d315f..a58bf40b 100644 --- a/src/StickyOracle.sol +++ b/src/StickyOracle.sol @@ -104,10 +104,13 @@ contract StickyOracle { // days_ == N will fill up a window corresponding to [lo == N, hi == 1] along with the current day // days_ should be selected carefully as too many iterations can cause the transaction to run out of gas // 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 { + function init(uint256 days_) external auth returns(bool) { require(cap == 0, "StickyOracle/already-init"); - uint128 pokePrice_ = pokePrice = cap = pip.read(); // TODO: should this use peek() and return true/false instead of reverting? it will be called from a spell so we don't want it to revert + (uint128 pokePrice_, bool has) = pip.peek(); // non-reverting to support calling from a spell + if (!has) return false; + + pokePrice = cap = pokePrice_; uint256 pokeDay_ = pokeDay = block.timestamp / 1 days; uint256 accumulatedVal = 0; uint32 accumulatedTs = uint32(block.timestamp - days_ * 1 days); @@ -122,6 +125,7 @@ contract StickyOracle { } emit Init(days_, pokePrice_); + return true; } function void() external auth {