-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathCoreSaltyFeed.sol
54 lines (40 loc) · 1.47 KB
/
CoreSaltyFeed.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
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IExchangeConfig.sol";
import "../pools/interfaces/IPools.sol";
import "./interfaces/IPriceFeed.sol";
import "../pools/PoolUtils.sol";
// Uses the Salty.IO pools to retrieve prices for BTC and ETH.
// Prices are returned with 18 decimals.
contract CoreSaltyFeed is IPriceFeed
{
IPools immutable public pools;
IERC20 immutable public wbtc;
IERC20 immutable public weth;
IERC20 immutable public usds;
constructor( IPools _pools, IExchangeConfig _exchangeConfig )
{
pools = _pools;
wbtc = _exchangeConfig.wbtc();
weth = _exchangeConfig.weth();
usds = _exchangeConfig.usds();
}
// Returns zero for an invalid price
function getPriceBTC() external view returns (uint256)
{
(uint256 reservesWBTC, uint256 reservesUSDS) = pools.getPoolReserves(wbtc, usds);
if ( ( reservesWBTC < PoolUtils.DUST ) || ( reservesUSDS < PoolUtils.DUST ) )
return 0;
// reservesWBTC has 8 decimals, keep the 18 decimals of reservesUSDS
return ( reservesUSDS * 10**8 ) / reservesWBTC;
}
// Returns zero for an invalid price
function getPriceETH() external view returns (uint256)
{
(uint256 reservesWETH, uint256 reservesUSDS) = pools.getPoolReserves(weth, usds);
if ( ( reservesWETH < PoolUtils.DUST ) || ( reservesUSDS < PoolUtils.DUST ) )
return 0;
return ( reservesUSDS * 10**18 ) / reservesWETH;
}
}