Activate/Deactivate Setups
Activate Setup
Created setups are initially inactive by default, and must be manually activated through the public activateSetup
function. This can be called by the host of their parent contract, or anyone else:
The activateSetup
function internally calls the _toggleSetup
function, which is responsible for both the activation and deactivation of setups.
Start Blocks
A setup can have a defined startBlock
, which is the block at which it can be activated. The startBlock
is passed in the FarmingSetupInfo
parameter; see the Add New Farming Setups to a Contract section to learn how. If the startBlock
is equal to 0, it can be activated any time (by calling activateSetup
).
Setting a delayed startBlock
can be useful, as it allows the host enough time to send to the extension the required amount of reward tokens (e.g. via a Metamask transfer, or a proposal if the host is a DFO).
Reward Tokens
A contract's extension must contain the amount of reward tokens required to reward all potential farmers before it can be activated. This amount is calculated as RewardPerBlock*Duration
(duration
is calculated as Endblock-StartBlock
), and must be manually sent by the host to the extension address. Then, when activateSetup
is called, the extension will transfer this amount to the farming contract.
This ensures that the farming contract always at least has the amount of tokens required to reward all farmers who could potentially create positions throughout the duration of a setup. If the extension is not able to send this amount (i.e because it was not received from the host), the setup cannot be activated.
For example:
If a host creates and wants to activate a setup with RewardPerBlock
= 0.1 and Duration
= 750 blocks (~1 week), the extension at the time of activation must have at least 75 (750 / 1) reward tokens, so that they can be sent to the contract. If the host creates and wants to simultaneously activate an additional setup, one with RewardPerBlock
= 0.1 and Duration
= 3000 blocks (~1 month), then it must contain 300 additional reward tokens, i.e 375 (300 + 75) in total.
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) then the setup remains inactive and can no longer be activated.
Deactivate Setup
An active setup can become deactivated 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. See the 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
This means that the contract will still have within it the necessary amount of tokens to reward farmers who entered prior to the deactivation of the setup—but, no one can open new positions in that setup.
Last updated