Factory

Git Source

Inherits: IFactory

Author: typicalHuman.

Factory should be single instance for UX (finding pools for different tokens and for possible routing).

State Variables

s_owner

address immutable s_owner;

s_pools

mapping(address => mapping(address => address)) s_pools;

Functions

constructor

constructor();

createPool

Create new pool with 2 assets.

Pool should be unique (pool with these assets shouldn't be used on this factory yet).

function createPool(address token0, address token1) external returns (address poolAddress);

Parameters

NameTypeDescription
token0addressFirst asset of the pool.
token1addressSecond asset of the pool.

Returns

NameTypeDescription
poolAddressaddressAddress of newly created pool.

getPool

Get pool address based on assets.

The order matters.

function getPool(address token0, address token1) external view returns (address);

Parameters

NameTypeDescription
token0addressFirst asset of the pool.
token1addressSecond asset of the pool.

Returns

NameTypeDescription
<none>addressAddress of the pool, if not found - returns zero address.

getProtocolBeneficiary

Get address which will receive protocol fees.

function getProtocolBeneficiary() external view returns (address);

Events

PoolCreated

event PoolCreated(address pool, address token0, address token1);

Errors

TOKENS_NOT_SORTED

error TOKENS_NOT_SORTED();

POOL_ALREADY_EXISTS

error POOL_ALREADY_EXISTS();