Creation and Initialization

Create a Farming Contract

Hosts use the deploy function to have the Factory clone the model (which, as mentioned, contains the standard logic):

function deploy(bytes memory data) public returns (address contractAddress, bytes memory initResultData) {
    initResultData = _call(contractAddress = _clone(farmMainImplAddress), data);
    emit FarmMainDeployed(contractAddress, msg.sender, initResultData);

When the Factory does this, it calls the init function for the farming contract, passing the encoded data as a data parameter.

The init function works as follow:

function init(address extension, bytes memory extensionInitData, address orchestrator, address rewardTokenAddress, bytes memory farmingSetupInfosBytes) public returns(bytes memory extensionReturnCall)
  • extension -> the address of the deployed extension to be linked to the contract

  • extensionInitData -> the encoded initialize extension data (available if an init extension function is provided). The default extension's init data contains three parameters: a boolean value representing if the reward token is minted (true) or from reserve (false); the host address; and the treasury address.

  • rewardTokenAddress -> the address of the reward token of the contract. Each contract has one.

  • farmingSetupInfoBytes -> ABI-encoded data of the contract's setups, which can be created directly during the initialization phase.

The extension (whether default or custom) must be deployed before deploying the farming contract through the Factory's deploy function. This allows the deployed extension to be linked to the Farming contract through the Farming contract init function. As noted above, the deployed extension doesn't need to have been initialized before this (and thus an init function is not provided), but can be done directly through the contract's init function, passing the extensionInitData in the payload. If the extension has an init function, it will be called, otherwise not:

if(keccak256(extensionPayload) != keccak256("")) {
   extensionInitResult = _call(_extension, extensionPayload);

If the farmingSetupInfoBytes parameter was passed in init function, also the passed setups are created.

if(farmingSetupInfosBytes.length > 0) {
    FarmingSetupInfo[] memory farmingSetupInfos = abi.decode(farmingSetupInfosBytes, (FarmingSetupInfo[]));
    for(uint256 i = 0; i < farmingSetupInfos.length; i++) {
        _setOrAddFarmingSetupInfo(farmingSetupInfos[i], true, false, 0);

Otherwise, setups can be created directly using the setFarmingSetups function (look at the Add New Farming Setups to a Contract section to see how to customize setups and create new ones).

Last updated