Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pricer v2.0 #444

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/core/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ contract Oracle is Ownable {
address pricer = assetPricer[_asset];
uint256 disputePeriod = pricerDisputePeriod[pricer];

return now > price.timestamp.add(disputePeriod);
return now > _expiryTimestamp.add(disputePeriod);
}

return true;
Expand Down
33 changes: 16 additions & 17 deletions contracts/pricers/ChainlinkPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,52 @@ contract ChainLinkPricer is OpynPricerInterface {

/// @notice asset that this pricer will a get price for
address public asset;
/// @notice bot address that is allowed to call setExpiryPriceInOracle
address public bot;

/**
* @param _bot priveleged address that can call setExpiryPriceInOracle
* @param _asset asset that this pricer will get a price for
* @param _aggregator Chainlink aggregator contract for the asset
* @param _oracle Opyn Oracle address
*/
constructor(
address _bot,
address _asset,
address _aggregator,
address _oracle
) public {
require(_bot != address(0), "ChainLinkPricer: Cannot set 0 address as bot");
require(_oracle != address(0), "ChainLinkPricer: Cannot set 0 address as oracle");
require(_aggregator != address(0), "ChainLinkPricer: Cannot set 0 address as aggregator");

bot = _bot;
oracle = OracleInterface(_oracle);
aggregator = AggregatorInterface(_aggregator);
asset = _asset;

aggregatorDecimals = uint256(aggregator.decimals());
}

/**
* @notice modifier to check if sender address is equal to bot address
*/
modifier onlyBot() {
require(msg.sender == bot, "ChainLinkPricer: unauthorized sender");

_;
}

/**
* @notice set the expiry price in the oracle, can only be called by Bot address
* @dev a roundId must be provided to confirm price validity, which is the first Chainlink price provided after the expiryTimestamp
* @param _expiryTimestamp expiry to set a price for
* @param _roundId the first roundId after expiryTimestamp
*/
function setExpiryPriceInOracle(uint256 _expiryTimestamp, uint80 _roundId) external onlyBot {
function setExpiryPriceInOracle(uint256 _expiryTimestamp, uint80 _roundId) external {
(, int256 price, , uint256 roundTimestamp, ) = aggregator.getRoundData(_roundId);

require(_expiryTimestamp <= roundTimestamp, "ChainLinkPricer: invalid roundId");

bool isCorrectRoundId;
uint80 previousRoundId = _roundId--;

while (!isCorrectRoundId) {
(, int256 price, , uint256 roundTimestamp, ) = aggregator.getRoundData(previousRoundId);

if (roundTimestamp == 0) {
previousRoundId--;
} else if (roundTimestamp > _expiryTimestamp) {
revert("ChainLinkPricer: invalid roundId");
} else {
isCorrectRoundId = true;
}
}

oracle.setExpiryPrice(asset, _expiryTimestamp, uint256(price));
}

Expand Down