Skip to content

Commit

Permalink
Changed SimplePriceOracle so ETH price can be set on testnets (#151)
Browse files Browse the repository at this point in the history
* Changed SimplePriceOracle so ETH price can be set on testnets

* fix lens test
  • Loading branch information
ajb413 authored Nov 16, 2021
1 parent 9e93e85 commit ecc4ab8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions contracts/SimplePriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ contract SimplePriceOracle is PriceOracle {
mapping(address => uint) prices;
event PricePosted(address asset, uint previousPriceMantissa, uint requestedPriceMantissa, uint newPriceMantissa);

function getUnderlyingPrice(CToken cToken) public view returns (uint) {
function _getUnderlyingAddress(CToken cToken) private view returns (address) {
address asset;
if (compareStrings(cToken.symbol(), "cETH")) {
return 1e18;
asset = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
} else {
return prices[address(CErc20(address(cToken)).underlying())];
asset = address(CErc20(address(cToken)).underlying());
}
return asset;
}

function getUnderlyingPrice(CToken cToken) public view returns (uint) {
return prices[_getUnderlyingAddress(cToken)];
}

function setUnderlyingPrice(CToken cToken, uint underlyingPriceMantissa) public {
address asset = address(CErc20(address(cToken)).underlying());
address asset = _getUnderlyingAddress(cToken);
emit PricePosted(asset, prices[asset], underlyingPriceMantissa, underlyingPriceMantissa);
prices[asset] = underlyingPriceMantissa;
}
Expand Down
3 changes: 2 additions & 1 deletion networks/ropsten.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"cZRX": "0x6B8b0D7875B4182Fb126877023fB93b934dD302A",
"cWBTC": "0x541c9cB0E97b77F142684cc33E8AC9aC17B1990F",
"USDC": "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
"ComptrollerRopsten": "0x1435b33741523dd5BB99f8FD8Dc00cF926fE96Fb"
"ComptrollerRopsten": "0x1435b33741523dd5BB99f8FD8Dc00cF926fE96Fb",
"SimplePriceOracle": "0x7BBF806F69ea21Ea9B8Af061AD0C1c41913063A1"
},
"Blocks": {
"ComptrollerG8": 10279074,
Expand Down
4 changes: 2 additions & 2 deletions tests/Lens/CompoundLensTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe('CompoundLens', () => {
).toEqual(
{
cToken: cEth._address,
underlyingPrice: "1000000000000000000",
underlyingPrice: "0",
}
);
});
Expand All @@ -264,7 +264,7 @@ describe('CompoundLens', () => {
},
{
cToken: cEth._address,
underlyingPrice: "1000000000000000000",
underlyingPrice: "0",
}
]);
});
Expand Down

0 comments on commit ecc4ab8

Please sign in to comment.