AllocationMechanismFactory
Title: Allocation Mechanism Factory
Author: Golem Foundation
Factory for deploying voting/allocation mechanisms with shared implementation
Follows Yearn V3 proxy pattern: lightweight proxies + shared logic ARCHITECTURE:
- One TokenizedAllocationMechanism implementation (shared)
- Multiple mechanism proxies (QuadraticVotingMechanism, etc.)
- Each proxy delegates to shared implementation
- Custom behavior via hooks in proxy contracts DEPLOYMENT:
- CREATE2 for deterministic addresses
- Parameters hashed for uniqueness
- Duplicate prevention via address check
- Registry tracking of all deployments
Notes:
-
security-contact: [email protected]
-
security: CREATE2 salt includes all parameters to prevent collisions
-
security: Duplicate deployments revert to prevent parameter confusion
State Variables
tokenizedAllocationImplementation
Shared TokenizedAllocationMechanism implementation address
All deployed mechanisms delegate to this for common logic
address public immutable tokenizedAllocationImplementation
deployedMechanisms
Array of all deployed mechanism addresses
Used for enumeration and tracking
address[] public deployedMechanisms
isMechanism
Mapping to quickly check if address is a deployed mechanism
Set to true when mechanism is deployed
mapping(address => bool) public isMechanism
Functions
constructor
Deploys the factory and shared TokenizedAllocationMechanism implementation
Implementation is deployed once and shared by all proxy mechanisms This saves significant gas on subsequent deployments (~300k → ~50k gas)
constructor() ;
predictMechanismAddress
Predict the deployment address of a QuadraticVotingMechanism
Uses CREATE2 address computation with same salt generation as deployment Address prediction is deterministic and guaranteed to match deployment
function predictMechanismAddress(
AllocationConfig memory _config,
uint256 _alphaNumerator,
uint256 _alphaDenominator,
address deployer
) public view returns (address predicted);
Parameters
| Name | Type | Description |
|---|---|---|
_config | AllocationConfig | Configuration struct containing all mechanism parameters |
_alphaNumerator | uint256 | Alpha numerator for ProperQF weighting (dimensionless ratio, 0 to _alphaDenominator) |
_alphaDenominator | uint256 | Alpha denominator for ProperQF weighting (dimensionless ratio) |
deployer | address | Address that will deploy the mechanism (used in salt) |
Returns
| Name | Type | Description |
|---|---|---|
predicted | address | Deterministic CREATE2 address where mechanism will be deployed |
deployQuadraticVotingMechanism
Deploy a new QuadraticVotingMechanism with deterministic address
Uses CREATE2 for deterministic deployment address Reverts if mechanism with same parameters already exists DEPLOYMENT STEPS:
- Set msg.sender as mechanism owner
- Generate deterministic salt from all parameters
- Compute expected address via CREATE2
- Check for existing deployment (revert if exists)
- Deploy via CREATE2
- Track in registry
- Emit deployment event
Notes:
-
security: Caller becomes mechanism owner with admin privileges
-
security: CREATE2 ensures same parameters always deploy to same address
function deployQuadraticVotingMechanism(
AllocationConfig memory _config,
uint256 _alphaNumerator,
uint256 _alphaDenominator
) external returns (address mechanism);
Parameters
| Name | Type | Description |
|---|---|---|
_config | AllocationConfig | Configuration struct containing mechanism parameters |
_alphaNumerator | uint256 | Alpha numerator for ProperQF weighting (dimensionless ratio, 0 to _alphaDenominator) |
_alphaDenominator | uint256 | Alpha denominator for ProperQF weighting (dimensionless ratio) |
Returns
| Name | Type | Description |
|---|---|---|
mechanism | address | Address of the deployed QuadraticVotingMechanism contract |
predictOctantQFMechanismAddress
Predict the deployment address of an OctantQFMechanism
Uses CREATE2 address computation with same salt generation as deployment Address prediction is deterministic and guaranteed to match deployment
function predictOctantQFMechanismAddress(
AllocationConfig memory _config,
uint256 _alphaNumerator,
uint256 _alphaDenominator,
IAddressSet _allowset,
IAddressSet _blockset,
AccessMode _accessMode,
address deployer
) public view returns (address predicted);
Parameters
| Name | Type | Description |
|---|---|---|
_config | AllocationConfig | Configuration struct containing all mechanism parameters |
_alphaNumerator | uint256 | Alpha numerator for ProperQF weighting |
_alphaDenominator | uint256 | Alpha denominator for ProperQF weighting |
_allowset | IAddressSet | Allowset contract used in ALLOWSET mode |
_blockset | IAddressSet | Blockset contract used in BLOCKSET mode |
_accessMode | AccessMode | Initial access mode (NONE, ALLOWSET, BLOCKSET) |
deployer | address | Address that will deploy the mechanism (used in salt) |
Returns
| Name | Type | Description |
|---|---|---|
predicted | address | Deterministic CREATE2 address where mechanism will be deployed |
deployOctantQFMechanism
Deploy a new OctantQFMechanism with deterministic address
Uses CREATE2 for deterministic deployment address Reverts if mechanism with same parameters already exists DEPLOYMENT STEPS:
- Set msg.sender as mechanism owner
- Generate deterministic salt from all parameters
- Compute expected address via CREATE2
- Check for existing deployment (revert if exists)
- Deploy via CREATE2
- Track in registry
- Emit deployment event
Notes:
-
security: Caller becomes mechanism owner with admin privileges
-
security: CREATE2 ensures same parameters always deploy to same address
function deployOctantQFMechanism(
AllocationConfig memory _config,
uint256 _alphaNumerator,
uint256 _alphaDenominator,
IAddressSet _allowset,
IAddressSet _blockset,
AccessMode _accessMode
) external returns (address mechanism);
Parameters
| Name | Type | Description |
|---|---|---|
_config | AllocationConfig | Configuration struct containing mechanism parameters |
_alphaNumerator | uint256 | Alpha numerator for ProperQF weighting |
_alphaDenominator | uint256 | Alpha denominator for ProperQF weighting |
_allowset | IAddressSet | Allowset contract used in ALLOWSET mode (address(0) if unused) |
_blockset | IAddressSet | Blockset contract used in BLOCKSET mode (address(0) if unused) |
_accessMode | AccessMode | Initial access mode (NONE, ALLOWSET, or BLOCKSET) |
Returns
| Name | Type | Description |
|---|---|---|
mechanism | address | Address of the deployed OctantQFMechanism contract |
_octantQFSalt
function _octantQFSalt(
AllocationConfig memory _config,
uint256 _alphaNumerator,
uint256 _alphaDenominator,
IAddressSet _allowset,
IAddressSet _blockset,
AccessMode _accessMode,
address deployer
) internal view returns (bytes32);
_octantQFBytecode
function _octantQFBytecode(
AllocationConfig memory _config,
uint256 _alphaNumerator,
uint256 _alphaDenominator,
IAddressSet _allowset,
IAddressSet _blockset,
AccessMode _accessMode
) internal view returns (bytes memory);
getDeployedCount
Get the total number of deployed mechanisms
Used for enumeration and pagination
function getDeployedCount() external view returns (uint256 count);
Returns
| Name | Type | Description |
|---|---|---|
count | uint256 | Number of mechanisms deployed by this factory |
getAllDeployedMechanisms
Get all deployed mechanism addresses
May be expensive for large arrays; consider pagination via getDeployedMechanism()
function getAllDeployedMechanisms() external view returns (address[] memory mechanisms);
Returns
| Name | Type | Description |
|---|---|---|
mechanisms | address[] | Array of all deployed mechanism addresses |
getDeployedMechanism
Get a specific deployed mechanism by array index
Reverts if index out of bounds
Use with getDeployedCount() for pagination
function getDeployedMechanism(uint256 index) external view returns (address mechanism);
Parameters
| Name | Type | Description |
|---|---|---|
index | uint256 | Zero-based index in the deployedMechanisms array |
Returns
| Name | Type | Description |
|---|---|---|
mechanism | address | Address of the mechanism at given index |
Events
AllocationMechanismDeployed
Emitted when a new allocation mechanism is deployed
event AllocationMechanismDeployed(
address indexed mechanism, address indexed asset, string name, string symbol, address indexed deployer
);
Parameters
| Name | Type | Description |
|---|---|---|
mechanism | address | Address of the deployed mechanism contract |
asset | address | Address of the ERC20 token used for voting |
name | string | Human-readable name of the mechanism |
symbol | string | Token symbol for the mechanism shares |
deployer | address | Address that deployed the mechanism (becomes owner) |
Errors
MechanismAlreadyExists
error MechanismAlreadyExists(address existingMechanism);