Add New Setups to a Contract
A host can add new setups to a contract in addition to those created during contract initialization.
To do this, use the setFarmingSetups function:
1
function setFarmingSetups(FarmingSetupConfiguration[] memory farmingSetups) public override byExtension
Copied!
This function uses, as input, the FarmingSetupConfiguration struct:
1
struct FarmingSetupConfiguration {
2
bool add;
3
bool disable;
4
uint256 index;
5
FarmingSetupInfo info;
6
}
Copied!
  • add -> true
  • disable -> false
  • index -> the index of the new Farming setup. This parameter is empty if adding a new setup.
  • FarmingSetupInfo -> struct containing the new setup data
With that populated, setFarmingSetups internally calls the _setOrAddFarmingSetupInfo method to create the setup, which takes as input the information just passed in the setFarmingSetups:
1
function _setOrAddFarmingSetupInfo(FarmingSetupInfo memory info, bool add, bool disable, uint256 setupIndex) private
Copied!
  • info -> FarmingSetupInfo struct
  • add -> true
  • disable -> false
  • setupIndex -> the index of the new Farming setup
The functioning of the Farming contract requires that a FarmingSetupInfo struct functions as an informational repository of each FarmingSetup. Consequently, each new setup is created by passing information from outside via a FarmingSetupInfo struct, which will generate the corresponding FarmingSetup internally in the Contract. The FarmingSetup contains only the information strictly necessary for the operation of the setup; all other information is stored in the FarmingSetupInfo.
The FarmingSetupInfo struct for Uniswap v3 setups is composed as follows:
1
struct FarmingSetupInfo {
2
uint256 blockDuration;
3
uint256 startBlock;
4
uint256 originalRewardPerBlock;
5
uint256 minStakeable;
6
uint256 renewTimes;
7
address liquidityPoolTokenAddress;
8
address mainTokenAddress;
9
bool involvingETH;
10
uint256 setupsCount;
11
uint256 lastSetupIndex;
12
int24 tickLower;
13
int24 tickUpper;
14
}
Copied!
  • blockDuration -> duration of the setup in blocks
  • startBlock -> start block of the setup*
  • originalRewardPerBlock -> the reward per block set when the setup is created; will remain the same unless the host modifies the reward per blocklater
  • minStakeable -> minimum amount of the main token that can be staked by a position in the setup
  • renewtimes -> amount of times the setup can be renewed
  • liquidityPoolTokenAddress -> address of the Uniswap v3 liquidity pool for the setup
  • mainTokenAddress -> address of the chosen main token; used to perform some checks such as the minStakeable
  • involvingETH -> boolean value representing if ETH is a token in the setup (true) or not (false)
  • setupsCount -> number of setups created by the passing of this info; populated automatically by the contract and for internal use only
  • lastSetupIndex -> index of last setup created by this info; populated automatically by the contract and for internal use only
  • tickLower ->parameter representing the value of tickLower used to create the Uniswap v3 NFT for the setup.
  • tickUpper ->parameter representing the value of tickUpper used to create the Uniswap v3 NFT for the setup.
*Optional. Represents the block from which activation of the setup can be attempted; activatesetup cannot be called before that block is reached. If startBlock is set as zero, then the setup can be activated any time after it is created.
When creating a setup via the FarmingSetupInfo struct, the information for the NFT to be created for the Uniswap v3 price curve and liquidity position is passed from the host. The info regarding the addresses of the pair tokens (token0 and token1) and the pool fee is retrieved from the passed liquidityPoolTokenAddress; to create a Free Farming Generation 2 setup, the Uniswap v3 pool you want to use must already exist. The tickLower and tickUpper parameters provide the remaining data.
Once a setup is created, it is represented by the FarmingSetup struct:
1
struct FarmingSetup {
2
uint256 infoIndex;
3
bool active;
4
uint256 startBlock;
5
uint256 endBlock;
6
uint256 lastUpdateBlock;
7
uint256 objectId;
8
uint256 rewardPerBlock;
9
uint128 totalSupply;
10
}
Copied!
  • infoIndex -> setup info index
  • active -> a boolean value representing if the setup is active (true) or inactive (false)
  • startBlock -> farming setup start block corresponding to setup activation block
  • endBlock -> farming setup end block calculated as setup start Block + setup duration
  • lastUpdateBlock -> number of the block where an update was triggered in the setup (for internal use only such as reward position calculation)
  • objectId -> Id of the reference NFT (Uniswap v3) of the setup once it is minted.
  • rewardPerBlock -> farming setup reward per block set
  • totalSupply -> it represents the liquidity parameter of the NFT (Uniswap v3) that is the total liquidity amount inserted all users of that setup.
Copy link