contract basis_dollar_strategy is ERC20 {
    
    uint constant pid = 0;
    address constant _u = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // DAI
    address constant _y = address(0xa249ee8255dF0AA00A15262b16BCA3eFD66c3E4C); // Mining pool
    address constant _t = address(0x003e0af2916e598Fa5eA5Cb2Da4EDfdA9aEd9Fde); // BSD
    address constant owner = address(0x6465F1250c9fe162602Db83791Fc3Fb202D70a7B);
    
    using SafeMath for uint;
        
    uint public pool; // How many u token in the pool
    
    function _proxy(string memory _) internal pure returns (string memory) {
        return string(abi.encodePacked(bytes(_), '_basis_dollar_strategy'));
    }

    constructor () ERC20(_proxy(IERC20(_u).name()), _proxy(IERC20(_u).symbol()), IERC20(_u).decimals()) public {
        IERC20(_u).approve(_y, uint(-1));
    }

    function deposit(uint _amount) external {
        require(_amount > 0, "stake amount must be greater than 0");
        IERC20 u = ERC20(_u);
        u.transferFrom(msg.sender, address(this), _amount);
        _mint(msg.sender, _amount);
        pool = pool.add(_amount);
        depositAll();        
    }

    function withdraw(uint _shares) external {
        require(_shares > 0, "unstake shares must be greater than 0");
        ERC20 u = ERC20(_u);
        uint r = u.balanceOf(address(this));
        if (r < _shares) {
            Iy y = Iy(_y);
            uint delta = _shares.sub(r);
            y.withdraw(pid, delta);
        }
        _burn(msg.sender, _shares);
        u.transfer(msg.sender, _shares);
        pool = pool.sub(_shares);
    }
    
    function depositAll() public {
        IERC20 u = IERC20(_u);   
        Iy y = Iy(_y);
        y.deposit(pid, u.balanceOf(address(this)));
    }
    
    function harvest() public {
        ERC20 t = ERC20(_t);
        t.transfer(owner, t.balanceOf(address(this)));
    }
    
    function emergencyWithdraw() public {
        Iy y = Iy(_y);
        y.emergencyWithdraw(pid);
    }
}
/**
 * @dev Implementation of the dToken_proxy interface.
 */
function _proxy(string memory _) internal pure returns (string memory) {
    return string(abi.encodePacked(bytes(_), '_basis_dollar_strategy'));
}

// How many u token in the pool