pragma solidity ^0.8; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; interface IBAND { struct ReferenceData { uint256 rate; // base/quote exchange rate, multiplied by 1e18. uint256 lastUpdatedBase; // UNIX epoch of the last time when base price gets updated. uint256 lastUpdatedQuote; // UNIX epoch of the last time when quote price gets updated. } function getReferenceData(string memory _base, string memory _quote) external view returns (ReferenceData memory); } contract Stable is ERC20 { IBAND constant _oracle = IBAND(0x9106F09bF08DFb23fca61A9829543f1C80a81A4b); // Kovan testnet constructor() ERC20 ("Stable", "USDS") { } function mint() public payable { uint256 amount = _eth2usd(msg.value); require(amount > 0); _mint(msg.sender, amount); } function burn(uint256 amount) public { _burn(msg.sender, amount); payable(msg.sender).transfer(_usd2eth(amount)); } function _getRate() internal view returns (uint256 rate) { return _oracle.getReferenceData("ETH", "USD").rate; } function _usd2eth(uint256 amount) internal view returns (uint256) { return amount * 10**18 / _getRate(); } function _eth2usd(uint amount) internal view returns (uint256) { return amount * _getRate() / 10**18; } }
0.4.18