The Allo contract serves as a platform to create and manage pools with customizable strategies, allowing for decentralized and automated fund allocation and distribution. The contract includes mechanisms for handling fees, treasury management, and various access controls to ensure proper functioning and security.
- Allo.sol
- Table of Contents
- Sequence Diagrams
- Smart Contract Overview
- User Flows
- Initializer
- Create a Pool with Custom Strategy
- Create a Pool by Cloning a Cloneable Strategy
- Update Pool Metadata
- Update Registry Address
- Update Treasury Address
- Update Fee Percentage
- Update Base Fee
- Add Strategy to Cloneable Strategies
- Remove Strategy from Cloneable Strategies
- Add Pool Manager
- Remove Pool Manager
- Recover Funds
- Register Recipient
- Batch Register Recipients
- Fund a Pool
- Allocate Funds to Strategy
- Batch Allocate Funds to Strategies
- Distribute Funds to Recipients
sequenceDiagram
participant AlloOwner as Allo Owner
participant Alice as Alice
participant Registry as Registry
participant Strategy as Strategy
participant Allo as Allo Contract
participant Treasury as Treasury
participant StrategyClone as StrategyClone
AlloOwner->>Strategy: Deploy Strategy
AlloOwner->>Allo: addToCloneableStrategies()
Alice->>Allo: Create Pool using createPool()
Allo-->>Allo: Validates if strategy is cloneable
Allo->>StrategyClone: Creates clone of strategy
Allo->>Registry: Validate if Alice is Profile Member
Registry-->>Allo: returns True/False
Allo->>Treasury: Transfer Protocol Fee
Allo->>StrategyClone: Transfer Funds
Allo-->>Alice: Returns poolId
Create Pool with Custom Strategy
sequenceDiagram
participant Alice as Alice
participant Registry as Registry
participant Allo as Allo Contract
participant Treasury as Treasury
participant CustomStrategy as CustomStrategy
Alice->>CustomStrategy: Deploy Strategy
CustomStrategy-->>Alice: Success
Alice->>Allo: Create Pool using createPoolWithCustomStrategy()
Allo-->>Allo: Validates if strategy is not approved
Allo->>Registry: Validate if Alice is Profile Member
Registry-->>Allo: returns True/False
Allo->>Treasury: Transfer Protocol Fee
Allo->>CustomStrategy: Transfer Funds
Allo-->>Alice: Returns poolId
sequenceDiagram
participant Bob as Bob
participant Allo as Allo Contract
participant Treasury as Treasury
participant Strategy as Strategy
Bob->>Allo: Fund Pool
Allo-->>Allo: Deduct Protocol Fee
Allo-->>Treasury: Transfer Protocol Fee
Allo-->>Strategy: Transfer Funds to Pool
Strategy-->>Strategy: updated pool amount
sequenceDiagram
participant Alice as Alice
participant Allo as Allo Contract
participant Strategy as Strategy
Alice->>Allo: Register Recipient using registerRecipient
Allo->>Strategy: Execute Recipient Registration in Strategy
Strategy-->>Allo: returns recipientId
Allo-->>Alice: returns recipientId
sequenceDiagram
participant Bob as Bob
participant Allo as Allo Contract
participant Pool1_Strategy as Pool1_Strategy
participant Pool2_Strategy as Pool2_Strategy
Bob->>Allo: batchRegisterRecipient to pool1 and pool2
Allo-->>Allo: iterate and invoke registerRecipient
Allo->>Pool1_Strategy: registerRecipient in pool1
Allo->>Pool2_Strategy: registerRecipient to pool2
Allo-->>Bob: returns [recipientId1, recipientId2]
sequenceDiagram
participant Bob as Bob
participant Allo as Allo Contract
participant Strategy as Strategy
Bob->>Allo: Allocate Funds using allocate
Allo->>Strategy: Execute Allocation in Strategy
sequenceDiagram
participant Bob as Bob
participant Allo as Allo Contract
participant Pool1_Strategy as Pool1_Strategy
participant Pool2_Strategy as Pool2_Strategy
Bob->>Allo: batchAllocate to pool1 and pool2
Allo-->>Allo: iterate and invoke allocate
Allo->>Pool1_Strategy: allocate to pool1
Allo->>Pool2_Strategy: allocate to pool2
sequenceDiagram
participant Alice as Alice
participant Allo as Allo Contract
participant Strategy as Strategy
Alice->>Allo: Distribute Funds using distribute
Allo->>Strategy: Execute Distribution in Strategy
- License: The contract is licensed under the AGPL-3.0-only license.
- Solidity Version: The contract is written in Solidity version 0.8.19.
- Inheritance: The contract inherits from several other contracts:
Initializable
,Ownable
,AccessControl
,IAllo
,Native
, andTransfer
.
percentFee
(Private): This variable holds the fee percentage applied to transactions within pools. It's represented as a fraction of 1e18, where 1e18 equals 100%.baseFee
(Internal): An internal variable storing the base fee for transactions._poolIndex
(Private): This variable tracks the incremental index for newly created pools.treasury
(Payable Address): This is the address where fees are sent and stored.registry
(Interface): An interface to the registry of pool creators._nonces
(Mapping): A mapping from addresses to nonces, used for cloning strategies.pools
(Mapping): Maps pool IDs toPool
struct instances containing pool-specific information.cloneableStrategies
(Mapping): Maps strategy addresses to a boolean indicating whether they are cloneable.
onlyPoolManager(uint256 _poolId)
: A modifier ensuring that only pool managers of a specific pool can access a function.onlyPoolAdmin(uint256 _poolId)
: A modifier ensuring that only pool administrators of a specific pool can access a function.
-
Initializer (
initialize
) This function initializes the contract after deployment or an upgrade. It sets the owner and initializes key contract variables such as the registry address, treasury address, fee parameters, and permissions. -
Pool Creation Functions (
createPoolWithCustomStrategy
andcreatePool
) These functions allow users to create new pools. The first function creates a pool with a custom strategy, while the second creates a pool by cloning an existing strategy. The provided metadata, strategy details, and other parameters are used to create and configure the new pool. -
Update Functions (
updatePoolMetadata
,updateRegistry
,updateTreasury
,updatePercentFee
,updateBaseFee
,addToCloneableStrategies
, andremoveFromCloneableStrategies
) These functions allow the contract owner to update various parameters. For example, they can change pool metadata, the registry address, treasury address, fee percentage, base fee, and the list of cloneable strategies. -
Pool Manager Functions (
addPoolManager
andremovePoolManager
) These functions allow pool administrators to manage pool managers. Pool managers can perform actions like fund allocation and distribution within their assigned pool. -
Funds Recovery Function (
recoverFunds
) This function enables the contract owner to recover funds from the contract. It can be used to retrieve native tokens or ERC20 tokens held in the contract. -
Strategy Interaction Functions (
registerRecipient
,batchRegisterRecipient
,fundPool
,allocate
,batchAllocate
, anddistribute
) These functions interact with pool strategies to manage fund allocation and distribution. Users can register recipients, allocate funds, and distribute funds according to specific strategies. -
View Functions (
isPoolAdmin
,isPoolManager
,getStrategy
,getPercentFee
,getBaseFee
,getTreasury
,getRegistry
,isCloneableStrategy
, andgetPool
) These functions provide information about the contract, pool administrators and managers, strategies, fees, treasury address, and pool details.
-
Owner The contract owner has special privileges, including updating contract parameters, managing strategies, and recovering funds. They have ultimate control over the contract's behavior.
-
Pool Creator A user who can create new pools using custom or cloneable strategies. They can specify metadata, strategy addresses, managers, and other parameters during pool creation.
-
Pool Administrator Users with administrative control over specific pools. They can manage pool managers, enabling effective pool governance.
-
Pool Manager Users who manage funds within specific pools. They can allocate and distribute funds according to the pool's strategy.
-
Strategy Smart contracts implementing fund allocation and distribution logic for each pool. Strategies can be custom or cloneable and determine how funds are managed within a pool.
In summary, the "Allo" smart contract provides a framework for creating and managing pools with customizable fund allocation and distribution strategies. It leverages access controls, mappings, and functions to enable various actions within the protocol. The contract is designed to support a ecosystem, enhancing the efficiency and transparency of fund management in Ethereum-based applications.
- The contract has an
initialize
function that initializes the contract after an upgrade. - The function takes
_registry
,_treasury
,_percentFee
, and_baseFee
as parameters and sets various contract parameters, such as treasury, registry, percentage fee, and base fee. - This function can only be called by the contract owner.
- Users can create a new pool by calling the
createPoolWithCustomStrategy
function. - The function requires the
_profileId
,_strategy
,_initStrategyData
,_token
,_amount
,_metadata
, and_managers
as parameters. - The contract checks if the
_strategy
is not a cloneable strategy and then calls the internal_createPool
function to create the pool.
- Users can create a new pool by calling the
createPool
function. - The function requires the
_profileId
,_strategy
,_initStrategyData
,_token
,_amount
,_metadata
, and_managers
as parameters. - The contract checks if the
_strategy
is a cloneable strategy and then creates a new pool by cloning the strategy using the internal_createPool
function.
- Pool managers can update the metadata of a pool by calling the
updatePoolMetadata
function. - The function requires the
_poolId
and_metadata
as parameters. - The contract checks if the caller is a pool manager, then updates the pool's metadata.
- The contract owner can update the registry address by calling the
updateRegistry
function. - The function requires the new
_registry
address as a parameter, and it updates the registry address accordingly.
- The contract owner can update the treasury address by calling the
updateTreasury
function. - The function requires the new
_treasury
address as a parameter, and it updates the treasury address accordingly.
- The contract owner can update the fee percentage by calling the
updatePercentFee
function. - The function requires the new
_percentFee
as a parameter, and it updates the fee percentage accordingly.
- The contract owner can update the base fee by calling the
updateBaseFee
function. - The function requires the new
_baseFee
as a parameter, and it updates the base fee accordingly.
- The contract owner can add a strategy to the cloneable strategies list by calling the
addToCloneableStrategies
function. - The function requires the
_strategy
address as a parameter, and it approves the strategy for cloning.
- The contract owner can remove a strategy from the cloneable strategies list by calling the
removeFromCloneableStrategies
function. - The function requires the
_strategy
address as a parameter, and it removes the strategy from the list.
- Pool admins can add a pool manager to a pool by calling the
addPoolManager
function. - The function requires the
_poolId
and_manager
address as parameters, and it grants the pool manager role to the address.
- Pool admins can remove a pool manager from a pool by calling the
removePoolManager
function. - The function requires the
_poolId
and_manager
address as parameters, and it revokes the pool manager role from the address.
- The contract owner can recover funds from the contract by calling the
recoverFunds
function. - The function requires the
_token
address and_recipient
address as parameters. - The contract transfers the specified amount of funds (either native or ERC20) to the recipient.
- Users can register a recipient by calling the
registerRecipient
function. - The function requires the
_poolId
and_data
as parameters, and it passes the data to the strategy for registration.
- Users can register multiple recipients to multiple pools simultaneously by calling the
batchRegisterRecipient
function. - The function requires arrays of
_poolIds
and_data
as parameters, and it registers recipients for each pool.
- Users can fund a pool by calling the
fundPool
function. - The function requires the
_poolId
and_amount
as parameters, and it funds the pool with the specified amount of tokens.
- Users can allocate funds to a pool's strategy by calling the
allocate
function. - The function requires the
_poolId
and_data
as parameters, and it passes the data to the strategy for allocation.
- Users can allocate funds to strategies of multiple pools by calling the
batchAllocate
function. - The function requires arrays of
_poolIds
and_datas
as parameters, and it allocates funds to strategies for each pool.
- Users can distribute funds to recipients using a pool's distribution strategy by calling the
distribute
function. - The function requires the
_poolId
,_recipientIds
, and_data
as parameters, and it passes the data to the strategy for distribution.