contract HORSEMigrator {
    /// Address of the old token contract
    IERC20Burnable public legacyToken = IERC20Burnable(0x5B0751713b2527d7f002c0c4e2a37e1219610A6B);

    /// Address of the TRIBE token contract
    IERC20Mintable public TRIBEToken;

    /// Address of the DECENT token contract
    IERC20Mintable public DECENTToken;

    uint256 horseToTribeRatio = 0.1 ether; // you'll get 1 tribe for 10 horse
    uint256 horseToDecentRatio = 0.000001 ether; //you'll get 1 DECENT for 1M HORSE

    uint256 public migrationTime = 5 weeks;
    uint256 public migrationEnds;

    /**
     * @dev Begins the migration by setting both tokens to be
     * minted. This contract must be a minter for the new tokens.
     * @param tribeContract the tribe token to be minted
     * @param decentContract the decent token to be minted
     */
    function beginMigration(IERC20Mintable tribeContract, IERC20Mintable decentContract) public {
        require(migrationEnds == 0, "migration already started");
        require((address(tribeContract) != address(0)) && (address(decentContract) != address(0)), "new token is the zero address");

        require(tribeContract.isMinter(address(this)), "not a minter for tribe");
        require(decentContract.isMinter(address(this)), "not a minter for decent");

        migrationEnds = now + migrationTime;

        TRIBEToken = tribeContract;
        DECENTToken = decentContract;
    }

    /**
     * @dev Transfers part of an account's balance in the old token to this
     * contract, and mints the corrent amount of new tokens for that account.
     * @param account whose tokens will be migrated
     * @param amount amount of tokens to be migrated
     */
    function migrate(address account, uint256 amount) notEnded() public {
        require(address(TRIBEToken) != address(0), "migration not started");
        legacyToken.transferFrom(account, address(this), amount);
        legacyToken.burn(amount);
        TRIBEToken.mint(account, amount * horseToTribeRatio / 1 ether);
        DECENTToken.mint(account, amount * horseToDecentRatio / 1 ether);
    }

    /**
     * @dev Transfers all of an account's allowed balance in the old token to
     * this contract, and mints the same amount of new tokens for that account.
     * @param account whose tokens will be migrated
     */
    function migrateAll(address account) public {
        uint256 balance = legacyToken.balanceOf(account);
        uint256 allowance = legacyToken.allowance(account, address(this));
        uint256 amount = Math.min(balance, allowance);
        migrate(account, amount);
    }

    modifier notEnded() {
        require(now < migrationEnds, "Swapping ended");
        _;
    }
}
/// heavily inspired by ERC20Migrator in openzeppelin-solidity/contracts/drafts
function beginMigration(IERC20Mintable tribeContract, IERC20Mintable decentContract) public {
    require(migrationEnds == 0, "migration already started");
    require((address(tribeContract) != address(0)) && (address(decentContract) != address(0)), "new token is the zero address");

    require(tribeContract.isMinter(address(this)), "not a minter for tribe");
    require(decentContract.isMinter(address(this)), "not a minter for decent");

    migrationEnds = now + migrationTime;

    TRIBEToken = tribeContract;
    DECENTToken = decentContract;
}

/**
 * @dev Begins the migration by setting both tokens to be
 * minted. This contract must be a minter for the new tokens.
 * @param tribeContract the tribe token to be minted
 * @param decentContract the decent token to be minted
 */