FarmingPluginFactory
Inherits: AccessControlEnumerable
Deploys new FarmingPlugin
s and acts as a registry.
Roles
- DEFAULT_ADMIN_ROLE — can grant/revoke all roles and set default plugin owner
- MANAGER_ROLE — allowed to deploy new farming plugins
This factory uses CREATE2 to deploy the farming plugin, therefore there cannot be two plugins with the same staking token and rewards token.
State Variables
MANAGER_ROLE
Role for managing the factory.
bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
defaultPluginOwner
Default plugin owner.
address public defaultPluginOwner;
_CREATE3_FACTORY
CREATE3Factory address
CREATE3Factory private constant _CREATE3_FACTORY = CREATE3Factory(0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1);
_plugins
staking token => list of all farming plugins created for that token
mapping(address => address[]) private _plugins;
_allPlugins
flat list of every plugin ever deployed (useful for iteration off-chain)
address[] private _allPlugins;
Functions
constructor
Constructor.
constructor(address admin, address manager, address _defaultPluginOwner) payable;
Parameters
Name | Type | Description |
---|---|---|
admin | address | Address that receives DEFAULT_ADMIN_ROLE. |
manager | address | Address that receives MANAGER_ROLE. |
_defaultPluginOwner | address | Address that will be the default plugin owner. |
allPlugins
All plugins ever created.
function allPlugins() external view returns (address[] memory);
Returns
Name | Type | Description |
---|---|---|
<none> | address[] | allPlugins Array of all farming plugins. |
plugins
Plugins for a given staking token.
function plugins(address stakingToken) external view returns (address[] memory);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | Address of the staking token. |
Returns
Name | Type | Description |
---|---|---|
<none> | address[] | plugins Array of farming plugins for the given staking token. |
computePluginAddress
Compute the address of a plugin for a given staking token and rewards token.
The corresponding contract may not have been deployed yet, so the address may be empty. For existence, either check for the code size or compare against the allPlugins array.
function computePluginAddress(IERC20Plugins stakingToken, IERC20 rewardsToken) external view returns (address);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | IERC20Plugins | Address of the staking token. |
rewardsToken | IERC20 | Address of the rewards token. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | plugin Address of the plugin. |
setDefaultPluginOwner
Set the default plugin owner.
function setDefaultPluginOwner(address pluginOwner) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
pluginOwner | address | Address that will own the plugin (controls start/stop farming & rescue). |
deployFarmingPluginWithDefaultOwner
Deploy a new farming plugin with the default plugin owner.
Access: only accounts with MANAGER_ROLE. Default plugin owner must be set.
function deployFarmingPluginWithDefaultOwner(
IERC20Plugins stakingToken,
IERC20 rewardsToken
)
external
onlyRole(MANAGER_ROLE)
returns (address plugin);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | IERC20Plugins | ERC-20 token users deposit (must support plugins). |
rewardsToken | IERC20 | ERC-20 token distributed as rewards. |
deployFarmingPlugin
Deploy a new farming plugin.
Access: only accounts with MANAGER_ROLE.
function deployFarmingPlugin(
IERC20Plugins stakingToken,
IERC20 rewardsToken,
address pluginOwner
)
external
onlyRole(MANAGER_ROLE)
returns (address plugin);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | IERC20Plugins | ERC-20 token users deposit (must support plugins). |
rewardsToken | IERC20 | ERC-20 token distributed as rewards. |
pluginOwner | address | Address that will own the plugin (controls start/stop farming & rescue). |
_setDefaultPluginOwner
Set the default plugin owner.
function _setDefaultPluginOwner(address pluginOwner) internal;
Parameters
Name | Type | Description |
---|---|---|
pluginOwner | address | Address that will own the plugin (controls start/stop farming & rescue). |
_deployFarmingPlugin
Deploy a new farming plugin with a unique salt to avoid collisions.
function _deployFarmingPlugin(
IERC20Plugins stakingToken,
IERC20 rewardsToken,
address pluginOwner
)
internal
returns (address plugin);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | IERC20Plugins | ERC-20 token users deposit (must support plugins). |
rewardsToken | IERC20 | ERC-20 token distributed as rewards. |
pluginOwner | address | Address that will own the plugin (controls start/stop farming & rescue). |
Events
FarmingPluginCreated
Emitted when a new farming plugin is created.
event FarmingPluginCreated(
address indexed stakingToken, address indexed rewardsToken, address indexed plugin, address pluginOwner
);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | ERC-20 token users deposit (must support plugins). |
rewardsToken | address | ERC-20 token distributed as rewards. |
plugin | address | Address of the new farming plugin. |
pluginOwner | address | Address that will own the plugin (controls start/stop farming & rescue). |
DefaultPluginOwnerSet
Emitted when the default plugin owner is set.
event DefaultPluginOwnerSet(address indexed previousOwner, address indexed newOwner);
Parameters
Name | Type | Description |
---|---|---|
previousOwner | address | Address that was the previous default plugin owner. |
newOwner | address | Address that will be the new default plugin owner. |
Errors
ZeroAddress
Emitted when a zero address is used.
error ZeroAddress();