# CapsuleFactory.sol

## The CapsuleFactory Contract

The CapsuleFactory contract allows users to deploy their own Capsule Collections. While the CapsuleMinter contract can be thought of as a database for Capsule NFTs, the CapsuleFactory contract can be thought of as a database for Capsule Collections.

> [View CapsuleFactory.sol verified contract code on Etherscan](https://etherscan.io/address/0x68df2bb8515b32819f0592f277af6ec0cd85ae08)
>
> [View CapsuleFactory.sol verified proxy contract code on Etherscan](https://etherscan.io/address/0x4ced59c19f1f3a9eebd670f746b737acf504d1eb)

### User Interactable Methods

#### createCapsuleCollection

```solidity
function createCapsuleCollection(string _name, string _symbol, address _tokenURIOwner, bool _isCollectionPrivate) external payable returns (address)
```

**Usage**: The main method which creates a Capsule NFT Collection for a user. Creation of a Capsule Collection MUST go through the CapsuleFactory in order to ensure ecosystem safety - this ensures that no Capsule contract is able to exploit the CapsuleMinter's token storing/redeeming methods.

**Parameters**:

* `_name`: (string) - the name of the Capsule Collection
* `_symbol`: (string) - the symbol of the Capsule Collection
* `_tokenURIOwner`: (address) - the address of the Capsule Collection tokenURIOwner (also known as the Metamaster)
* `_isCollectionPrivate`: (boolean) - whether the Capsule Collection is designated as private

**Returns**: (address) - The address of the newly deployed Capsule Collection.

#### getAllCapsuleCollections

```solidity
function getAllCapsuleCollections() external view returns (address[])
```

**Usage**: Get a list of all Capsule Collections created.

**Parameters**: (none)

**Returns**: (address\[]) - An array of addresses of all Capsule Collections created.

#### getCapsuleCollectionsOf

```solidity
function getCapsuleCollectionsOf(address _owner) external view returns (address[])
```

**Usage**: Get list of all Capsule Collections created by an input owner address `_owner`.

**Parameters**:

* `_owner`: (address) - the address of the owner

**Returns**: (address\[]) - An array of addresses of all Capsule Collections created by `_owner`.

### User Non-Interactable Methods

#### updateCapsuleCollectionOwner

```solidity
function updateCapsuleCollectionOwner(address _previousOwner, address _newOwner) external
```

**Usage**: A helper method which updates owner of a Capsule Collection. This is called when the `transferOwnership` method is called by the Capsule NFT in order to update the Capsule's owner information in the CapsuleFactory. Only a Capsule NFT may call this method.

**Parameters**:

* `_previousOwner`: (address) - the address of the old owner (the caller)
* `_newOwner`: (address) - the address of the new owner

### Lesser Interesting Methods

#### initialize

```solidity
function initialize() external
```

#### addToWhitelist

```solidity
function addToWhitelist(address _user) external
```

#### removeFromWhitelist

```solidity
function removeFromWhitelist(address _user) external
```

#### addToBlacklist

```solidity
function addToBlacklist(address _user) external
```

#### removeFromBlacklist

```solidity
function removeFromBlacklist(address _user) external
```

#### flushTaxAmount

```solidity
function flushTaxAmount() external
```

The owner or tax collector can call this function to withdraw all ETH stored in this contract

#### getWhitelist

```solidity
function getWhitelist() external view returns (address[])
```

Get a list of all whitelisted addresses

#### getBlacklist

```solidity
function getBlacklist() external view returns (address[])
```

Get a list of all blacklisted addresses

#### isBlacklisted

```solidity
function isBlacklisted(address _user) external view returns (bool)
```

Return whether a given address is blacklisted or not

#### isWhitelisted

```solidity
function isWhitelisted(address _user) external view returns (bool)
```

Return whether a given address is whitelisted or not

#### setCapsuleMinter

```solidity
function setCapsuleMinter(address _newCapsuleMinter) external
```

Set CapsuleMinter address

#### updateCapsuleCollectionTax

```solidity
function updateCapsuleCollectionTax(uint256 _newTax) external
```

Update Capsule Collection creation tax

#### updateTaxCollector

```solidity
function updateTaxCollector(address _newTaxCollector) external
```

Update tax collector

### Key Constants

#### VERSION

```solidity
string VERSION
```

### Key Events

#### CapsuleCollectionTaxUpdated

```solidity
event CapsuleCollectionTaxUpdated(uint256 oldTax, uint256 newTax)
```

#### CapsuleCollectionCreated

```solidity
event CapsuleCollectionCreated(address caller, address capsule)
```

#### CapsuleOwnerUpdated

```solidity
event CapsuleOwnerUpdated(address capsule, address previousOwner, address newOwner)
```

#### TaxCollectorUpdated

```solidity
event TaxCollectorUpdated(address oldTaxCollector, address newTaxCollector)
```

### CapsuleFactoryStorage

#### capsuleCollectionTax

```solidity
uint256 capsuleCollectionTax
```

#### taxCollector

```solidity
address taxCollector
```

#### capsuleMinter

```solidity
address capsuleMinter
```

#### capsules

```solidity
address[] capsules
```

#### capsulesOf

```solidity
mapping(address => struct EnumerableSet.AddressSet) capsulesOf
```

#### isCapsule

```solidity
mapping(address => bool) isCapsule
```

#### whitelist

```solidity
struct EnumerableSet.AddressSet whitelist
```

#### blacklist

```solidity
struct EnumerableSet.AddressSet blacklist
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.capsulelabs.xyz/capsulenft/developer-walkthroughs/contracts/capsulefactory.sol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
