Here is my price oracle token contract. I would appreciate any feedback on it to make sure its secure:
| // SPDX-License-Identifier: MIT | |
|---|---|
| pragma solidity 0.6.12; | |
| import "@openzeppelin/contracts/access/Ownable.sol"; | |
| import "@openzeppelin/contracts/math/SafeMath.sol"; | |
| interface IMyToken { | |
| function mintCost(uint256 amount) external view returns (uint256); | |
| } | |
| contract MyTokenPriceOracle is Ownable { | |
| using SafeMath for uint256; | |
| address public MyToken; | |
| event MyTokenUpdated(address indexed MyToken, address indexed oldMyToken); | |
| constructor(address _myToken) public { | |
| require(_myToken != address(0), "invalid my token address"); | |
| myToken = _myToken; | |
| } | |
| function updateMyToken(address _newMyToken) external onlyOwner { | |
| require(_newMyToken != address(0), "invalid my token address"); | |
| require(_newMyToken != myToken, "invalid my token address"); | |
| address oldMyToken = myToken; | |
| myToken = _newMyToken; | |
| emit MyTokenUpdated(myToken, oldMyToken); | |
| } | |
| function latestAnswer() public view returns (int256) { | |
| uint256 ethPerMTK = IMyToken(myToken).mintCost(1e18); | |
| return int256(ethPerMTK.div(1e10)); |