contract pairToken is standardToken {
    using SafeMath for uint;

    address public pairAddress;

    bool public pairInitialized = false;

    /// @dev Set the pair token contract, can only excute once
    function initPair(address _pairAddress) public onlyOwner() {
        require(!pairInitialized, "Pair already initialized");
        pairAddress = _pairAddress;
        pairInitialized = true;
    }

    /// @dev Override
    /// @dev A special transfer function that, if the target is either this contract
    /// @dev or the pair token contract, the token will be sent to this contract, and
    /// @dev 1:1 pair tokens are sent to the sender.
    /// @dev When the target address are other than the two paired token address,
    /// @dev this function behaves exactly the same as in a standard ERC20 token.
    function transfer(address _to, uint _value) public returns (bool success) {
        require(balances[msg.sender] >= _value, "Insufficient balance");
        balances[msg.sender] = balances[msg.sender].sub(_value);
        if (_to == pairAddress || _to == address(this)) {
            balances[address(this)] = balances[address(this)].add(_value);
            pairToken(pairAddress).pairTransfer(msg.sender, _value);
            emit Exchange(msg.sender, address(this), _value);
            emit Transfer(msg.sender, _to, _value);
        } else {
            balances[_to] = balances[_to].add(_value);
            emit Transfer(msg.sender, _to, _value);
        }
        return true;
    } 

    /// @dev Function called by pair token to excute 1:1 exchange of the token.
    function pairTransfer(address _to, uint _value) external returns (bool success) {
        require(msg.sender == pairAddress, "Only token pairs can transfer");
        balances[address(this)] = balances[address(this)].sub(_value);
        balances[_to] = balances[_to].add(_value);
        return true;
    }

    event Exchange(address indexed _from, address _tokenAddress, uint _value);
}
/// @dev A standard token that is linked to another pairToken.
/// @dev The total supply of these two tokens should be the same.
/// @dev Sending one token to any of these two contract address
/// @dev using transfer method will result a receiving of 1:1 another token. 
function pairTransfer(address _to, uint _value) external returns (bool success) {
        require(msg.sender == pairAddress, "Only token pairs can transfer");
        balances[address(this)] = balances[address(this)].sub(_value);
        balances[_to] = balances[_to].add(_value);
        return true;
    }
/// @dev Function called by pair token to excute 1:1 exchange of the token.