This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUniswapPriceAdaptor.sol
66 lines (55 loc) · 2.2 KB
/
UniswapPriceAdaptor.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Copyright 2022 JOJO Exchange
SPDX-License-Identifier: BUSL-1.1
*/
pragma solidity 0.8.9;
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@JOJO/contracts/adaptor/emergencyOracle.sol";
import "@mean-finance/solidity/interfaces/IStaticOracle.sol";
contract UniswapPriceAdaptor is Ownable{
IStaticOracle public immutable UNISWAP_V3_ORACLE;
uint8 public immutable decimal;
address public immutable baseToken;
address public immutable quoteToken;
// query period
uint32 public period;
address public priceFeedOracle;
uint256 public impact;
event UpdatePools(address[] oldPools, address[] newPools);
event UpdatePeriod(uint32 oldPeriod, uint32 newPeriod);
event UpdateImpact(uint256 oldImpact, uint256 newImpact);
constructor(
address _uniswapAdaptor,
uint8 _decimal,
address _baseToken,
address _quoteToken,
uint32 _period,
address _priceFeedOracle,
uint256 _impact
) {
UNISWAP_V3_ORACLE = IStaticOracle(_uniswapAdaptor);
decimal = _decimal;
baseToken = _baseToken;
quoteToken = _quoteToken;
period = _period;
priceFeedOracle = _priceFeedOracle;
impact = _impact;
}
function getAssetPrice() external view returns (uint256) {
(uint256 uniswapPriceFeed,) = IStaticOracle(UNISWAP_V3_ORACLE).quoteAllAvailablePoolsWithTimePeriod(uint128(10**decimal), baseToken, quoteToken, period);
uint256 JOJOPriceFeed = EmergencyOracle(priceFeedOracle).getMarkPrice();
uint256 diff = JOJOPriceFeed >= uniswapPriceFeed ? JOJOPriceFeed - uniswapPriceFeed : uniswapPriceFeed - JOJOPriceFeed;
//JOJOPriceFeed(1 - impact) <= uniswapPriceFeed <= JOJOPriceFeed(1 + impact)
require(diff * 1e18 / JOJOPriceFeed <= impact, "deviation is too big");
return uniswapPriceFeed;
}
function updatePeriod(uint32 newPeriod) external onlyOwner {
emit UpdatePeriod(period, newPeriod);
period = newPeriod;
}
function updateImpact(uint32 newImpact) external onlyOwner {
emit UpdateImpact(impact, newImpact);
impact = newImpact;
}
}