library SafeERC20Ex {
    using SafeERC20 for IERC20;

    /**
     * @dev ensures that the spender has sufficient allowance
     *
     * @param token the address of the token to ensure
     * @param spender the address allowed to spend
     * @param amount the allowed amount to spend
     */
    function ensureApprove(
        IERC20 token,
        address spender,
        uint256 amount
    ) internal {
        if (amount == 0) {
            return;
        }

        uint256 allowance = token.allowance(address(this), spender);
        if (allowance >= amount) {
            return;
        }

        if (allowance > 0) {
            token.safeApprove(spender, 0);
        }
        token.safeApprove(spender, amount);
    }
}
/**
 * @dev Extends the SafeERC20 library with additional operations
 */
function ensureApprove(
    IERC20 token,
    address spender,
    uint256 amount
) internal {
    if (amount == 0) {
        return;
    }

    uint256 allowance = token.allowance(address(this), spender);
    if (allowance >= amount) {
        return;
    }

    if (allowance > 0) {
        token.safeApprove(spender, 0);
    }
    token.safeApprove(spender, amount);
}

/**
 * @dev ensures that the spender has sufficient allowance
 *
 * @param token the address of the token to ensure
 * @param spender the address allowed to spend
 * @param amount the allowed amount to spend
 */