BaseStrategyFactory
Title: BaseStrategyFactory
Author: Golem Foundation
Base contract for strategy factories with deterministic deployment
Uses CREATE2 with parameter-based hashing to prevent duplicate deployments Security Considerations:
- Strategy parameters are hashed to create a unique salt
- Same parameters always result in the same deployment address
- Duplicate strategy deployments are automatically prevented
- Addresses are deterministic and predictable based on parameters
Note: security-contact: [email protected]
State Variables
strategies
Mapping from deployer address to their deployed strategies Used for tracking deployed strategies
mapping(address => StrategyInfo[]) public strategies
Functions
computeStrategyAddress
Compute the deterministic address where a strategy will be deployed
Must be implemented by child factories using their own bytecode
function computeStrategyAddress(
address _vault,
address _asset,
string memory _name,
string memory _symbol,
address _management,
address _keeper,
address _emergencyAdmin,
address _donationAddress,
bool _enableBurning,
address _tokenizedStrategyAddress,
address _deployer
) public view virtual returns (address);
Parameters
| Name | Type | Description |
|---|---|---|
_vault | address | Vault address (e.g., Yearn vault, or factory constant for hardcoded vaults) |
_asset | address | Underlying asset address (or factory constant for hardcoded assets) |
_name | string | Strategy share token name |
_symbol | string | Strategy share token symbol |
_management | address | Management address |
_keeper | address | Keeper address |
_emergencyAdmin | address | Emergency admin address |
_donationAddress | address | Donation address |
_enableBurning | bool | Enable burning flag |
_tokenizedStrategyAddress | address | TokenizedStrategy implementation |
_deployer | address | Address that will deploy the strategy |
Returns
| Name | Type | Description |
|---|---|---|
<none> | address | Predicted strategy address |
_predictStrategyAddress
Internal helper to predict deterministic deployment address
Single source of truth for salt computation - used by child factories' computeStrategyAddress
function _predictStrategyAddress(bytes32 _parameterHash, address _deployer, bytes memory _bytecode)
internal
view
returns (address);
Parameters
| Name | Type | Description |
|---|---|---|
_parameterHash | bytes32 | Hash of all strategy parameters |
_deployer | address | Deployer address |
_bytecode | bytes | Deployment bytecode (including constructor args) |
Returns
| Name | Type | Description |
|---|---|---|
<none> | address | Predicted contract address |
_deployStrategy
Internal function to deploy strategy using CREATE2
function _deployStrategy(bytes memory _bytecode, bytes32 _parameterHash)
internal
returns (address strategyAddress);
Parameters
| Name | Type | Description |
|---|---|---|
_bytecode | bytes | Deployment bytecode including constructor args |
_parameterHash | bytes32 | Hash of all strategy parameters for deterministic deployment |
Returns
| Name | Type | Description |
|---|---|---|
strategyAddress | address | Deployed strategy address |
_recordStrategy
Internal function to record strategy deployment
function _recordStrategy(string memory _name, address _donationAddress, address _strategyAddress) internal;
Parameters
| Name | Type | Description |
|---|---|---|
_name | string | Strategy name |
_donationAddress | address | Donation address |
_strategyAddress | address | Deployed strategy address |
getStrategiesByDeployer
Returns all strategies deployed by a specific address
Get all strategies deployed by a specific address
function getStrategiesByDeployer(address deployer) external view returns (StrategyInfo[] memory);
Parameters
| Name | Type | Description |
|---|---|---|
deployer | address | Deployer address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | StrategyInfo[] | Array of StrategyInfo for all strategies deployed by the address |
Errors
StrategyAlreadyExists
error StrategyAlreadyExists(address existingStrategy);
InvalidVault
error InvalidVault(address provided, address expected);
InvalidAsset
error InvalidAsset(address provided, address expected);
Structs
StrategyInfo
Struct to store information about a strategy
struct StrategyInfo {
address deployerAddress;
uint256 timestamp;
string vaultTokenName;
address donationAddress;
}
Properties
| Name | Type | Description |
|---|---|---|
deployerAddress | address | Deployer who created the strategy |
timestamp | uint256 | Timestamp when the strategy was created (seconds) |
vaultTokenName | string | Name of the vault token associated with the strategy |
donationAddress | address | Address where donations from the strategy will be sent |