-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #804 from ebtc-protocol/release-0.8
Release 0.8
- Loading branch information
Showing
15 changed files
with
489 additions
and
58 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import {IPriceFetcher} from "./Interfaces/IOracleCaller.sol"; | ||
import {IChronicle} from "./Interfaces/IChronicle.sol"; | ||
|
||
/// @notice Chronicle oracle adapter for EbtcFeed | ||
/// @notice https://etherscan.io/address/0x02238bb0085395ae52cd4755456891fc2fd5934d | ||
contract ChronicleAdapter is IPriceFetcher { | ||
uint256 public constant MAX_STALENESS = 24 hours; | ||
uint256 public constant ADAPTER_PRECISION = 1e18; | ||
|
||
address public immutable BTC_STETH_FEED; | ||
uint256 public immutable FEED_PRECISION; | ||
|
||
constructor(address _btcStEthFeed) { | ||
BTC_STETH_FEED = _btcStEthFeed; | ||
|
||
uint256 feedDecimals = IChronicle(BTC_STETH_FEED).decimals(); | ||
require(feedDecimals > 0 && feedDecimals <= 18); | ||
|
||
FEED_PRECISION = 10 ** feedDecimals; | ||
} | ||
|
||
function fetchPrice() external returns (uint256) { | ||
(uint256 price, uint256 age) = IChronicle(BTC_STETH_FEED).readWithAge(); | ||
uint256 staleness = block.timestamp - age; | ||
if (staleness > MAX_STALENESS) revert("ChronicleAdapter: stale price"); | ||
|
||
return (price * ADAPTER_PRECISION) / FEED_PRECISION; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
/// @title IChronicle | ||
/// @author chronicleprotocol (https://github.com/chronicleprotocol/chronicle-std/blob/ea9afe78a1d33245afcdbcc3f530ee9cbd7cde28/src/IChronicle.sol) | ||
/// @notice Partial interface for Chronicle Protocol's oracle products. | ||
interface IChronicle { | ||
/// @notice Returns the oracle's current value and its age. | ||
/// @dev Reverts if no value set. | ||
/// @return value The oracle's current value. | ||
/// @return age The value's age. | ||
function readWithAge() external view returns (uint256 value, uint256 age); | ||
|
||
/// @notice Returns the oracle's decimals. | ||
/// @return The decimals of the oracle. | ||
function decimals() external view returns (uint8); | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.17; | ||
|
||
import "forge-std/Test.sol"; | ||
import {MockAggregator} from "../contracts/TestContracts/MockAggregator.sol"; | ||
import {ChronicleAdapter} from "../contracts/ChronicleAdapter.sol"; | ||
|
||
contract ChainlinkAdapterTest is Test { | ||
MockAggregator internal stEthBtcAggregator; | ||
ChronicleAdapter internal chronicleAdapter; | ||
|
||
constructor() {} | ||
|
||
function testSuccessPrecision8() public { | ||
stEthBtcAggregator = new MockAggregator(8); | ||
chronicleAdapter = new ChronicleAdapter(address(stEthBtcAggregator)); | ||
|
||
stEthBtcAggregator.setUpdateTime(block.timestamp); | ||
stEthBtcAggregator.setPrice(5341495); | ||
|
||
assertEq(chronicleAdapter.fetchPrice(), 53414950000000000); | ||
} | ||
|
||
function testSuccessPrecision18() public { | ||
stEthBtcAggregator = new MockAggregator(18); | ||
chronicleAdapter = new ChronicleAdapter(address(stEthBtcAggregator)); | ||
|
||
stEthBtcAggregator.setUpdateTime(block.timestamp); | ||
stEthBtcAggregator.setPrice(53414952714851023); | ||
|
||
assertEq(chronicleAdapter.fetchPrice(), 53414952714851023); | ||
} | ||
|
||
function testFailureFreshness() public { | ||
stEthBtcAggregator = new MockAggregator(18); | ||
chronicleAdapter = new ChronicleAdapter(address(stEthBtcAggregator)); | ||
|
||
stEthBtcAggregator.setUpdateTime(block.timestamp - 24 hours - 1); | ||
stEthBtcAggregator.setPrice(100e18); | ||
|
||
vm.expectRevert("ChronicleAdapter: stale price"); | ||
chronicleAdapter.fetchPrice(); | ||
} | ||
} |
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
Oops, something went wrong.