all files / contracts/ cToken.sol

100% Statements 10/10
81.25% Branches 13/16
100% Functions 7/7
100% Lines 15/15
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 55 56 57 58                                    48× 48× 48× 48× 48×                                                  
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
 
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "./interfaces/IcToken.sol";
import "./interfaces/IxTokenRouter.sol";
import "./interfaces/IRentFoundation.sol";
 
contract CToken is IcToken, Context, ERC20Burnable, Ownable {
    IRentFoundation public rentFoundation;
    IxTokenRouter public xTokenRouter; // address of xTokenRouter
    string public crop;
 
    constructor(address _rentFoundation, address _xTokenRouter, string memory _crop)
        ERC20("LandX cToken", string(abi.encodePacked('c', _crop)))
    {
        Erequire(_rentFoundation != address(0), "zero address is not allowed");
        Erequire(_xTokenRouter != address(0), "zero address is not allowed");
        rentFoundation = IRentFoundation(_rentFoundation);
        xTokenRouter = IxTokenRouter(_xTokenRouter);
        crop = _crop;
    }
 
    // only minter can mint cTokens, for example xToken contract
    function mint(address account, uint256 amount) public {
        require(
            msg.sender == xTokenRouter.getXToken(crop),
            "action is not allowed"
        );
        _mint(account, amount);
    }
 
    function burn(uint256 amount) public override {
        rentFoundation.sellCToken(msg.sender, amount);
        _burn(msg.sender, amount);
    }
 
    function setRentFoundation(address _address) public onlyOwner {
        require(_address != address(0), "zero address is not allowed");
        rentFoundation = IRentFoundation(_address);
    }
 
    function setXTokenRouter(address _router) public onlyOwner {
        require(_router != address(0), "zero address is not allowed");
        xTokenRouter = IxTokenRouter(_router);
    }
 
    function decimals() public pure override returns (uint8) {
        return 6;
    }
 
     function renounceOwnership() public view override EonlyOwner {
        revert ("can 't renounceOwnership here");
    }
}