Skip to main content

BaseStrategyFactory

Git Source

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

NameTypeDescription
_vaultaddressVault address (e.g., Yearn vault, or factory constant for hardcoded vaults)
_assetaddressUnderlying asset address (or factory constant for hardcoded assets)
_namestringStrategy share token name
_symbolstringStrategy share token symbol
_managementaddressManagement address
_keeperaddressKeeper address
_emergencyAdminaddressEmergency admin address
_donationAddressaddressDonation address
_enableBurningboolEnable burning flag
_tokenizedStrategyAddressaddressTokenizedStrategy implementation
_deployeraddressAddress that will deploy the strategy

Returns

NameTypeDescription
<none>addressPredicted 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

NameTypeDescription
_parameterHashbytes32Hash of all strategy parameters
_deployeraddressDeployer address
_bytecodebytesDeployment bytecode (including constructor args)

Returns

NameTypeDescription
<none>addressPredicted contract address

_deployStrategy

Internal function to deploy strategy using CREATE2

function _deployStrategy(bytes memory _bytecode, bytes32 _parameterHash)
internal
returns (address strategyAddress);

Parameters

NameTypeDescription
_bytecodebytesDeployment bytecode including constructor args
_parameterHashbytes32Hash of all strategy parameters for deterministic deployment

Returns

NameTypeDescription
strategyAddressaddressDeployed strategy address

_recordStrategy

Internal function to record strategy deployment

function _recordStrategy(string memory _name, address _donationAddress, address _strategyAddress) internal;

Parameters

NameTypeDescription
_namestringStrategy name
_donationAddressaddressDonation address
_strategyAddressaddressDeployed 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

NameTypeDescription
deployeraddressDeployer address

Returns

NameTypeDescription
<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

NameTypeDescription
deployerAddressaddressDeployer who created the strategy
timestampuint256Timestamp when the strategy was created (seconds)
vaultTokenNamestringName of the vault token associated with the strategy
donationAddressaddressAddress where donations from the strategy will be sent