Links

Creation & Initialization

Creation & Initialization
To create and initialize a contract, first use the deploy function to have the Factory clone the model farming contract.
function deploy(bytes memory data) public returns (address contractAddress, bytes memory initResultData) {
initResultData = _call(contractAddress = _clone(farmMainImplAddress), data);
emit FarmMainDeployed(contractAddress, msg.sender, initResultData);
}
By doing so, the Factory also calls the initialize function (init) for the clone contract.
The init function works as follows:
function init(address extension, bytes memory extensionInitData, address uniswapV3NonfungiblePositionManager, address rewardTokenAddress, bytes memory farmingSetupInfosBytes) public returns(bytes memory extensionReturnCall) {
  • address extension -> the address of the extension to link with the contract*
  • extensionInitData -> the extension's initialization data**
  • uniswapV3NonfungiblePositionManager -> the address of the Uniswap V3 Nonfungible Position Manager
  • rewardTokenAddress -> the address of the reward token (one per contract)
  • farmingSetupInfoBytes -> ABI-encoded data of the contract's setups, which can be created directly during this initialization phase or afterwards***
*The extension (whether default or custom) must have already been deployed if the extension has an init method (in the case of a custom extension). **Available only if the extension has not yet been initialized. If the extension has not already been initialized and has an init function, it will be called:
if(keccak256(extensionPayload) != keccak256("")) {
extensionInitResult = _call(_extension, extensionPayload);
}
***If the farmingSetupInfoBytes parameter is passed in this initialization phase, then the _setOrAddFarmingSetupInfo function is called internally to create the setups:
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);
}
If it will be passed afterwards, setups can be created directly using the setFarmingSetups function (see the Add New Setups to a Contract section for how to customize and create new setups for a contract).
After creating the setups, remember to send the correct amount of reward tokens to the extension in order to correctly activate the setup/s. For more info, see here.
Last modified 2yr ago