contract InstanceRegistry is IInstanceRegistry {
    using EnumerableSet for EnumerableSet.AddressSet;

    /* storage */

    EnumerableSet.AddressSet private _instanceSet;

    /* view functions */

    function isInstance(address instance) external view override returns (bool validity) {
        return _instanceSet.contains(instance);
    }

    function instanceCount() external view override returns (uint256 count) {
        return _instanceSet.length();
    }

    function instanceAt(uint256 index) external view override returns (address instance) {
        return _instanceSet.at(index);
    }

    /* admin functions */

    function _register(address instance) internal {
        require(_instanceSet.add(instance), "InstanceRegistry: already registered");
        emit InstanceAdded(instance);
    }

    function _deregister(address instance) internal {
        require(_instanceSet.remove(instance), "InstanceRegistry: not registered");
        emit InstanceRemoved(instance);
    }
}
/// @title InstanceRegistry
/// @dev Security contact: dev-support@ampleforth.org
function isInstance(address instance) external view override returns (bool validity) {
    return _instanceSet.contains(instance);
}

/* view functions */