Activate / Deactivate Farming Setups
Activate Setup
Created setups are inactive by default, and must be manually activated through the public activateSetup
function. This can be called by a host or any other user:
If the setup has startBlock
equal to 0 (initially passed in the FarmingSetupInfo
), the activateSetup
function can be called at any time. If the setup has a defined startBlock
, the activateSetup
function can only be called if the startBlock
has been reached (look at the Add New Farming Setups section to understand how to set the startBlock
in the FarmingSetupInfo
).
Setting a delayed startBlock
is useful because it allows the host to have enough time to send to the extension the amount of reward tokens needed to activate setups (e.g. do a reward token transfer or make the required proposal in case of a DFO).
The activateSetup
function calls, internally, the _toggleSetup
function, which is responsible for both the activation and deactivation of setups.
A setup's treasury must also contain the amount of reward tokens required to reward all potential farmers at a minimum, before it can be activated. This minimum amount of reward tokens is calculated for each setup as RewardPerBlock*Duration
(the duration is calculated as Endblock-StartBlock
), and must be manually sent by the host to the treasury address. Only then, at the exact time of activation (when the activateSetup
function is called), will the treasury transfer the exact amount to the farming contract.
This means that the farming contract always only has the exact amount of tokens required to reward all potential farmers who could create positions throughout the duration of a setup. If the extension is not able to send this amount (e.g. because the host did not send them to it), the setup cannot be activated.
For example:
If a host wants to create and activate a setup, each with RewardPerBlock
=0.1 and Duration
= 1week (750 blocks), the extension at the time of activation must have at least 75 reward tokens to be sent to the contract. If the host wants to simultaneously create and activate another setup with RewardPerBlock
=0.1 and Duration
=1 month (3000 blocks), he must send at least 75 + 300 = 375 reward tokens.
If the _toggleSetup
function does not return a positive result, because the extension does not have the necessary amount of tokens to activate the setup, that specific setup remains inactive.
Deactivate Setup
An active setup can become inactive in 3 possible ways:
The host intentionally deactivates the setup
The setup reaches its end block and is not set to renew
The setup reaches its end block and is set to renew 1 or more times, but when it tries to, it fails
Regarding 1., the host (and only the host) can deactivate an active setup before its end block by using the setFarmingSetups
function passing the FarmingSetupConfiguration
struct:
add
->false
disable
->true
index
-> index of the setup to deactiveFarmingSetupInfo
-> this parameter is empty in case of setup deactivation
A deactivated setup can never be reactivated.
Regarding 2., a setup that reaches its end block and is not set to renew (so at that point RenewTimes
=0) is automatically deactivated when the first user withdraws their liquidity or redeems their rewards.
Regarding 3., a setup that reaches its end block and is set to renew (RenewTimes
> 0) will automatically attempt to reactivate when the first user withdraws their liquidity or redeems their rewards.
When a setup is deactivated, the unissued rewards that were yet to be distributed from the current block (i.e the new end block) until the original end block are added to the unissued token amounts that the host can then retrieve. Look at Unissued tokens section for more details.
For example:
Setup A
RewardPerBlock: 0.5 BUIDL
StartBlock: 1000
EndBlock: 2000
Duration (calculated as EndBlock-StartBlock): 1000
Total rewards held by the extension: 1000*0.5= 500 Buidl
Deactivation block: 1500
The amount of reward tokens that the contract sends back to the extension upon deactivation is calculated as
(EndBlock-deactivation block)*RewardPerBlock
, which in this case is (2000-1500)*0.5 = 250 BUIDL.
At the moment a setup is deactivated, the following functions can no longer be called by farmers:
openPosition
addLiquidity
(in the case of free setups)
This means that the contract will still have within it the necessary amount of tokens to reward farmers who entered prior to deactivation of the setup—however, no one can open new positions in that setup.
Last updated