Function: _fetchPrice(uint256 lastPrice)
Fetches the latest price from Chainlink and Tellor oracles and determines the appropriate price to use based on various conditions.
Branches and code coverage (including function calls)
Intended branches
If Chainlink is working and the response is not stale, return the last stored price.
If Chainlink is broken and Tellor is working, switch to Tellor and return the current Tellor price.
If Chainlink is frozen, try using Tellor and handle different scenarios accordingly:
If Tellor is broken too, remember Tellor broke and return the last good price.
If Tellor is frozen but otherwise returning valid data, just return the last good price (Tellor may need to be tipped to return current data).
If Tellor is working, switch to Tellor and return the current Tellor price.
If Chainlink's price change is above the maximum allowed, compare it to Tellor's price:
If Tellor is broken and both oracles are untrusted, return the last good price.
If Tellor is frozen, switch to Tellor and return the last good price.
If Tellor is live and both oracles have a similar price, conclude that Chainlink's large price deviation between two consecutive rounds was likely a legitimate market price movement, and continue using Chainlink.
If Tellor is live but the oracles differ too much in price, distrust Chainlink, switch to Tellor, and return the current Tellor price.
If both oracles are untrusted, handle the situation accordingly:
If both oracles are now live, unbroken, and reporting similar prices, assume they are reporting accurately and switch back to Chainlink.
Otherwise, return the last good price since both oracles are still untrusted.
If using Tellor and Chainlink is frozen, switch to using Tellor and handle the situation accordingly:
If both oracles are broken, return the last good price.
If Chainlink is broken, remember it and switch to using Tellor.
If Tellor is frozen, return the last good price.
If Tellor is working, return the current Tellor price.
If using Chainlink and Tellor is untrusted, handle the situation accordingly:
If Chainlink breaks, and now both oracles are untrusted, return the last good price.
If Chainlink is frozen, return the last good price.
If both Chainlink and Tellor are live, unbroken, and reporting similar prices, switch back to
chainlinkWorking
and return the current Chainlink price.If Chainlink is live but deviated >50% from its previous price and Tellor is still untrusted, switch to
bothOraclesUntrusted
and return the last good price.Otherwise, if Chainlink is live and deviated <50% from its previous price and Tellor is still untrusted, return the current Chainlink price.