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/price fixes ci fix #448

Closed
Closed
26 changes: 13 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1
orbs:
coveralls: coveralls/[email protected]
node: circleci/node@1.1.6
node: circleci/node@5.0.0

workflows:
build-test-report:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
checkout_and_install:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: circleci/node:16.13.1
steps:
- checkout
- restore_cache:
Expand All @@ -64,7 +64,7 @@ jobs:
lint:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: circleci/node:16.13.1
steps:
- checkout
- restore_cache:
Expand All @@ -79,7 +79,7 @@ jobs:
build:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: circleci/node:16.13.1
steps:
- checkout
- restore_cache:
Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
size-check:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: circleci/node:16.13.1
steps:
- restore_cache:
key: gamma-contracts-build-{{ .Environment.CIRCLE_SHA1 }}
Expand All @@ -166,8 +166,8 @@ jobs:
unit-test:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: trufflesuite/ganache-cli:v6.10.1
- image: circleci/node:16.13.1
- image: trufflesuite/ganache-cli:v6.12.2
command: ganache-cli -d --port 8545 --defaultBalanceEther 500
steps:
- restore_cache:
Expand All @@ -183,8 +183,8 @@ jobs:
integration-test:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: trufflesuite/ganache-cli:v6.10.1
- image: circleci/node:16.13.1
- image: trufflesuite/ganache-cli:v6.12.2
command: ganache-cli -d --port 8545 --defaultBalanceEther 500
steps:
- restore_cache:
Expand All @@ -200,7 +200,7 @@ jobs:
e2e-test:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: circleci/node:16.13.1
steps:
- restore_cache:
key: gamma-contracts-build-{{ .Environment.CIRCLE_SHA1 }}
Expand All @@ -219,8 +219,8 @@ jobs:
gas-report:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: trufflesuite/ganache-cli:v6.10.1
- image: circleci/node:16.13.1
- image: trufflesuite/ganache-cli:v6.12.2
steps:
- restore_cache:
key: gamma-contracts-build-{{ .Environment.CIRCLE_SHA1 }}
Expand All @@ -233,7 +233,7 @@ jobs:
coverage:
working_directory: ~/gammaprotocol
docker:
- image: circleci/node:10.18.0
- image: circleci/node:16.13.1
steps:
- checkout
- restore_cache:
Expand Down
32 changes: 21 additions & 11 deletions contracts/pricers/ChainlinkPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,35 @@ contract ChainLinkPricer is OpynPricerInterface {
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");
require(_expiryTimestamp <= roundTimestamp, "ChainLinkPricer: roundId not first after expiry");
require(price >= 0, "ChainLinkPricer: invalid price");

if (msg.sender != bot) {
bool isCorrectRoundId;
uint80 previousRoundId = uint80(uint256(_roundId).sub(1));

while (!isCorrectRoundId) {
(, , , uint256 previousRoundTimestamp, ) = aggregator.getRoundData(previousRoundId);

if (previousRoundTimestamp == 0) {
require(previousRoundId > 0, "ChainLinkPricer: Invalid previousRoundId");
previousRoundId = previousRoundId - 1;
} else if (previousRoundTimestamp > _expiryTimestamp) {
revert("ChainLinkPricer: previousRoundId not last before expiry");
} else {
isCorrectRoundId = true;
}
}
}

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