FarmingPluginFactory

Git Source

Inherits: AccessControlEnumerable

Deploys new FarmingPlugins 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

NameTypeDescription
adminaddressAddress that receives DEFAULT_ADMIN_ROLE.
manageraddressAddress that receives MANAGER_ROLE.
_defaultPluginOwneraddressAddress that will be the default plugin owner.

allPlugins

All plugins ever created.

function allPlugins() external view returns (address[] memory);

Returns

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

NameTypeDescription
stakingTokenaddressAddress of the staking token.

Returns

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

NameTypeDescription
stakingTokenIERC20PluginsAddress of the staking token.
rewardsTokenIERC20Address of the rewards token.

Returns

NameTypeDescription
<none>addressplugin Address of the plugin.

setDefaultPluginOwner

Set the default plugin owner.

function setDefaultPluginOwner(address pluginOwner) external onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

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

NameTypeDescription
stakingTokenIERC20PluginsERC-20 token users deposit (must support plugins).
rewardsTokenIERC20ERC-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

NameTypeDescription
stakingTokenIERC20PluginsERC-20 token users deposit (must support plugins).
rewardsTokenIERC20ERC-20 token distributed as rewards.
pluginOwneraddressAddress that will own the plugin (controls start/stop farming & rescue).

_setDefaultPluginOwner

Set the default plugin owner.

function _setDefaultPluginOwner(address pluginOwner) internal;

Parameters

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

NameTypeDescription
stakingTokenIERC20PluginsERC-20 token users deposit (must support plugins).
rewardsTokenIERC20ERC-20 token distributed as rewards.
pluginOwneraddressAddress 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

NameTypeDescription
stakingTokenaddressERC-20 token users deposit (must support plugins).
rewardsTokenaddressERC-20 token distributed as rewards.
pluginaddressAddress of the new farming plugin.
pluginOwneraddressAddress 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

NameTypeDescription
previousOwneraddressAddress that was the previous default plugin owner.
newOwneraddressAddress that will be the new default plugin owner.

Errors

ZeroAddress

Emitted when a zero address is used.

error ZeroAddress();