Split Risk Pool Factory

The Split Risk Pool Factory is responsible for creating and managing all Split Risk Pool instances in the YieldShield protocol. It implements the factory pattern to ensure consistent pool initialization and maintains a registry of all active pools.

Overview

The Factory contract serves as the entry point for pool creation. It validates parameters, enforces token whitelisting, and deploys pools as upgradeable proxies. The Factory also manages the token whitelist, which controls which tokens can be used in pools.

Pool Creation Process

When creating a pool, the Factory performs the following steps:

  1. Parameter Validation: Validates all input parameters using PoolValidationLib

    • Basic validation (addresses, symbols)
    • Pool parameter validation (commission rate, pool fee, collateral ratio)
    • Whitelist validation (both tokens must be whitelisted)
  2. Token Info Retrieval: Retrieves TokenInfo structs for both tokens from the whitelist

    • Each whitelisted token has associated metadata (name, symbol, vault address, token type)
  3. Pool Deployment: Uses PoolCreationLib to deploy the pool

    • Creates an ERC1967Proxy pointing to the pool implementation
    • Initializes the pool with all required parameters
    • Creates receipt token contracts (Tranche) for insured and underwriter tokens
  4. Registry Update: Stores pool information and adds to the pools array

    • Creates a PoolInfo struct with pool metadata
    • Stores mapping from pool address to PoolInfo
    • Adds pool address to the pools array
  5. Event Emission: Emits PoolCreated event for off-chain indexing

Token Whitelisting

The Factory manages which tokens can be used in pools through a whitelist system:

TokenWhitelistLib

The TokenWhitelistLib library provides functions for managing the whitelist:

  • addToken: Adds a token to the whitelist (governance only)
  • addTokenInitial: Adds a token during initial deployment (owner only)
  • removeToken: Removes a token from the whitelist (governance only)

TokenInfo

Each whitelisted token has associated metadata:

  • name: Token name
  • symbol: Token symbol
  • token: Token contract address
  • vault: Vault/pool address (for Aave tokens, can be address(0) for others)
  • tokenType: Type identifier (0: Mock, 1: ERC4626, 2: Aave, etc.)

Whitelist Enforcement

The Factory enforces that both insured and underwriter tokens must be whitelisted before a pool can be created. This ensures:

  • Only approved tokens are used
  • Token metadata is available for pool initialization
  • Integration with the adapter system is possible

Validation Library

The PoolValidationLib provides three validation functions:

validateBasicParams

Validates basic pool creation parameters:

  • Ensures token addresses are not zero or equal
  • Validates token symbols are not empty
  • Ensures symbol length is within limits

validatePoolParams

Validates pool configuration parameters:

  • Commission rate must be within bounds (1% to 50%)
  • Pool fee must be within bounds (0% to 20%)
  • Collateral ratio must be within bounds (100% to 500%)

validateWhitelist

Enforces whitelist requirements:

  • Both tokens must be whitelisted
  • Tokens must be different addresses

Pool Creation Library

The PoolCreationLib handles the actual pool deployment:

createAndStorePool

Deploys a new pool proxy and creates the PoolInfo struct:

  • Creates ERC1967Proxy with pool implementation
  • Generates receipt token names and symbols (prefixed with "i" and "u")
  • Returns pool address and PoolInfo struct

emitPoolCreated

Emits the PoolCreated event with all relevant pool information for off-chain indexing.

Pool Registry

The Factory maintains a registry of all created pools:

  • pools: Array of all pool addresses (for iteration)
  • _poolInfo: Mapping from pool address to PoolInfo struct
  • getAllPools: Returns all pool addresses
  • getPoolInfo: Returns PoolInfo for a specific pool

PoolInfo Structure

Each pool's metadata is stored in a PoolInfo struct:

  • insuredToken: Address of the insured token
  • underwriteToken: Address of the underwriter token
  • insuredTokenSymbol: Symbol of insured token
  • underwriteTokenSymbol: Symbol of underwriter token
  • commissionRate: Commission rate (basis points)
  • poolFee: Pool creator fee rate (basis points)
  • colleteralRatio: Collateral ratio (basis points)
  • createdAt: Timestamp of pool creation
  • creator: Address of the pool creator

Governance Functions

The Factory provides governance-controlled functions:

  • setPoolImplementation: Updates the pool implementation contract (for upgrades)
  • addToken: Adds a token to the whitelist (governance only)
  • removeToken: Removes a token from the whitelist (governance only)
  • setGovernanceTimelock: Updates the governance timelock address

Owner Functions

During initial deployment, the owner can:

  • addTokenInitial: Add tokens to the whitelist without governance (for bootstrap)

Base Contract

The Factory inherits from ProtocolAccessControlUpgradeable, providing:

  • Governance timelock controls
  • Pausable functionality
  • Reentrancy protection
  • Upgradeability (UUPS pattern)

Interface

The Factory implements ISplitRiskPoolFactory, which defines:

  • State variable getters
  • Pool creation function
  • View functions for pool registry
  • Governance functions

Integration with Pools

When a pool is created, the Factory:

  • Sets itself as the initial owner of the pool (for upgrade authority)
  • Passes the governance timelock to the pool
  • Ensures proper initialization of all pool parameters
  • Maintains the registry for discovery and iteration