all files / contracts/ xTokenRouter.sol

100% Statements 5/5
87.5% Branches 7/8
100% Functions 4/4
100% Lines 7/7
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                                                                     
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
 
//Service Contract for getting xToken/xBasket/cToken Contract
//Before using should be initialized by contract owner
 
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IxTokenRouter.sol";
 
contract xTokenRouter is IxTokenRouter, Ownable {
    struct Token {
        address xToken;
        address cToken;
    }
    mapping(string => Token) public tokens;
 
    //Add or update xToken/cToken address: tokens[SOY].xToken = '0x....'
    function setToken(
        string memory crop,
        address xToken,
        address cToken
    ) public onlyOwner {
        require(xToken != address(0), "zero address is not allowed");
        require(cToken != address(0), "zero address is not allowed");
        tokens[crop].xToken = xToken;
        tokens[crop].cToken = cToken;
    }
 
    function getXToken(string memory crop) external view returns (address) {
        return tokens[crop].xToken;
    }
 
    function getCToken(string memory crop) external view returns (address) {
        return tokens[crop].cToken;
    }
 
    function renounceOwnership() public view override EonlyOwner {
        revert ("can 't renounceOwnership here");
    }
}