forked from unitprotocol/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 34x4p08 <[email protected]>
- Loading branch information
1 parent
73a8215
commit 3775077
Showing
16 changed files
with
198 additions
and
100 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
3 changes: 2 additions & 1 deletion
3
.../interfaces/IBearingAssetOracleSimple.sol → contracts/interfaces/IBearingAssetOracle.sol
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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
interface IOracleEth { | ||
|
||
// returns Q112-encoded value | ||
function assetToEth(address asset, uint amount) external view returns (uint); | ||
|
||
// returns the value "as is" | ||
function ethToUsd(uint amount) external view returns (uint); | ||
|
||
// returns the value "as is" | ||
function usdToEth(uint amount) external view returns (uint); | ||
} |
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,8 @@ | ||
interface IOracleForAsset { | ||
|
||
// returns Q112-encoded value | ||
function assetToUsd(address asset, uint amount) external view returns (uint); | ||
|
||
// returns Q112-encoded value | ||
function assetToEth(address asset, uint amount) external view returns (uint); | ||
} |
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 |
---|---|---|
@@ -1,12 +1,25 @@ | ||
pragma abicoder v2; | ||
|
||
|
||
interface IOracleRegistry { | ||
function getOracles ( ) external view returns ( address[] memory oracles ); | ||
|
||
struct Oracle { | ||
uint oracleType; | ||
address oracleAddress; | ||
bool quoteInEth; | ||
} | ||
|
||
function WETH ( ) external view returns ( address ); | ||
function getOracles ( ) external view returns ( Oracle[] memory foundOracles ); | ||
function maxOracleType ( ) external view returns ( uint256 ); | ||
function oracleByAsset ( address asset ) external view returns ( address ); | ||
function oracleByType ( uint256 ) external view returns ( address ); | ||
function oracleTypeByAsset ( address ) external view returns ( uint256 ); | ||
function setOracle ( uint256 oracleType, address oracle ) external; | ||
function oracleTypeByOracle ( address ) external view returns ( uint256 ); | ||
function quoteInEthSupportByOracle ( address oracle ) external view returns ( bool ); | ||
function quoteInEthSupported ( uint256 ) external view returns ( bool ); | ||
function setOracle ( uint256 oracleType, address oracle, bool _quoteInEthSupported ) external; | ||
function setOracleTypeToAsset ( address asset, uint256 oracleType ) external; | ||
function setOracleTypeToAssets ( address[] memory assets, uint256 oracleType ) external; | ||
function typeByOracle ( address ) external view returns ( uint256 ); | ||
function vaultParameters ( ) external view returns ( address ); | ||
} |
4 changes: 3 additions & 1 deletion
4
contracts/interfaces/IOracleSimple.sol → contracts/interfaces/IOracleUsd.sol
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
interface IOracleSimple { | ||
interface IOracleUsd { | ||
|
||
// returns Q112-encoded value | ||
function assetToUsd(address asset, uint amount) external view returns (uint); | ||
} |
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 |
---|---|---|
|
@@ -4,27 +4,40 @@ | |
Copyright 2020 Unit Protocol: Artem Zakharov ([email protected]). | ||
*/ | ||
pragma solidity 0.7.6; | ||
pragma abicoder v2; | ||
|
||
import "../VaultParameters.sol"; | ||
|
||
contract OracleRegistry is Auth { | ||
|
||
struct Oracle { | ||
uint oracleType; | ||
address oracleAddress; | ||
bool quoteInEth; | ||
} | ||
|
||
uint public maxOracleType; | ||
|
||
// map token to oracle address | ||
address public immutable WETH; | ||
|
||
// map asset to oracle type ID | ||
mapping(address => uint) public oracleTypeByAsset; | ||
|
||
// map oracle ID to oracle address | ||
// map oracle type ID to oracle address | ||
mapping(uint => address) public oracleByType; | ||
|
||
// map oracle address to oracle ID | ||
mapping(address => uint) public typeByOracle; | ||
// whether quote in ETH supported for an oracle type ID | ||
mapping(uint => bool) public quoteInEthSupported; | ||
|
||
// map oracle address to oracle type ID | ||
mapping(address => uint) public oracleTypeByOracle; | ||
|
||
event AssetOracle(address indexed asset, uint indexed oracleType); | ||
event OracleType(uint indexed oracleType, address indexed oracle); | ||
event OracleType(uint indexed oracleType, address indexed oracle, bool quoteInEthSupported); | ||
|
||
constructor(address vaultParameters) Auth(vaultParameters) { | ||
require(vaultParameters != address(0), "Unit Protocol: ZERO_ADDRESS"); | ||
constructor(address vaultParameters, address _weth) Auth(vaultParameters) { | ||
require(vaultParameters != address(0) && _weth != address(0), "Unit Protocol: ZERO_ADDRESS"); | ||
WETH = _weth; | ||
} | ||
|
||
function setOracleTypeToAsset(address asset, uint oracleType) public onlyManager { | ||
|
@@ -33,17 +46,18 @@ contract OracleRegistry is Auth { | |
emit AssetOracle(asset, oracleType); | ||
} | ||
|
||
function setOracle(uint oracleType, address oracle) public onlyManager { | ||
function setOracle(uint oracleType, address oracle, bool _quoteInEthSupported) public onlyManager { | ||
require(oracleType != 0, "Unit Protocol: INVALID_ARGS"); | ||
|
||
if (oracleType > maxOracleType) { | ||
maxOracleType = oracleType; | ||
} | ||
|
||
oracleByType[oracleType] = oracle; | ||
typeByOracle[oracle] = oracleType; | ||
|
||
emit OracleType(oracleType, oracle); | ||
oracleTypeByOracle[oracle] = oracleType; | ||
quoteInEthSupported[oracleType] = _quoteInEthSupported; | ||
|
||
emit OracleType(oracleType, oracle, _quoteInEthSupported); | ||
} | ||
|
||
function setOracleTypeToAssets(address[] calldata assets, uint oracleType) public onlyManager { | ||
|
@@ -56,26 +70,21 @@ contract OracleRegistry is Auth { | |
} | ||
} | ||
|
||
function getOracles() external view returns (address[] memory oracles) { | ||
function getOracles() external view returns (Oracle[] memory foundOracles) { | ||
|
||
// Memory arrays can't be reallocated so we'll overprovision | ||
address[] memory foundOracles = new address[](maxOracleType - 1); | ||
uint actualOraclesCount = 0; | ||
foundOracles = new Oracle[](maxOracleType); | ||
|
||
for (uint _type = 1; _type <= maxOracleType; ++_type) { | ||
if (oracleByType[_type] != address(0)) { | ||
foundOracles[actualOraclesCount++] = oracleByType[_type]; | ||
} | ||
} | ||
|
||
oracles = new address[](actualOraclesCount); | ||
for (uint i = 0; i < actualOraclesCount; ++i) { | ||
oracles[i] = foundOracles[i]; | ||
for (uint _type = 0; _type < maxOracleType; ++_type) { | ||
foundOracles[_type] = Oracle(_type, oracleByType[_type], quoteInEthSupported[_type]); | ||
} | ||
} | ||
|
||
function oracleByAsset(address asset) external view returns (address) { | ||
return oracleByType[oracleTypeByAsset[asset]]; | ||
} | ||
|
||
function quoteInEthSupportByOracle(address oracle) external view returns (bool) { | ||
return quoteInEthSupported[oracleTypeByOracle[oracle]]; | ||
} | ||
|
||
} |
Oops, something went wrong.