Farm
Each farm
contract allows users to deposit, withdraw their LP token to earn rewards. The rewards are distributed to the users based on the amount of LP token they have deposited and the duration of the deposit.
InstantiateMsg
The InstantiateMsg for the farm
contract's instantiation is shown below.
{
"staked_token": "aura...",
"reward_token": [
{
"token": {
"contract_addr": "aura..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
],
"start_time": 1689148800,
"end_time": 1689192000,
"phases_limit_per_user": 1000000000000000000,
"farm_owner": "aura...",
"whitelist": "aura1..."
}
Where:
staked_token
: The LP token that users will deposit to the farm.reward_token
: The token that users will receive as reward. It can be a native token or a CW-20 token.start_time
: The time when the farm starts.end_time
: The time when the farm ends.phases_limit_per_user
: The maximum amount of phases that a user can deposit to the farm.farm_owner
: The owner of the farm contract.whitelist
: The address of the whitelist. Whitelist is a wallet that can add reward token balance to the farm contract.
ExecuteMsg
Below are the available ExecuteMsg (write) methods for the farm
contract.
AddRewardBalance
The add_reward_balance
method is used to add reward token balance to the farm contract. The method takes two required arguments: the phase index and the amount.
{
"add_reward_balance": {
"phase_index": 0,
"amount": 1000000000000000000
}
}
Where:
phase_index
: The index of the phase that the reward balance will be added to.amount
: The amount of reward token that will be added to the farm contract.
Deposit
The deposit
method is used to deposit LP token to the farm contract. The method takes one required argument: the amount.
{
"deposit": {
"amount": 1000000000000000000
}
}
Where:
amount
: The amount of LP token that will be deposited to the farm contract.
Withdraw
The withdraw
method is used to withdraw LP token from the farm contract. The method takes one required argument: the amount.
{
"withdraw": {
"amount": 1000000000000000000
}
}
Where:
amount
: The amount of LP token that will be withdrawn from the farm contract.
Harvest
The harvest
method is used to harvest reward token from the farm contract. The method takes no arguments.
{
"harvest": {}
}
AddPhase
The add_phase
method is used to add a new phase to the farm contract. The method takes three required arguments: the new start time, the new end time and the whitelist.
{
"add_phase": {
"new_start_time": 1689148800,
"new_end_time": 1689192000,
"whitelist": "aura1..."
}
}
Where:
new_start_time
: The start time of the new phase.new_end_time
: The end time of the new phase.whitelist
: The address of the whitelist. Whitelist is a wallet that can add reward token balance to the farm contract.
RemovePhase
The remove_phase
method is used to remove a phase from the farm contract. The method takes one required argument: the phase index. If the phase has already added reward balance, the balance will be sent to the whitelist. It can be called by the farm owner only and the phase must not have activated yet.
{
"remove_phase": {
"phase_index": 0
}
}
Where:
phase_index
: The index of the phase that will be removed. It can be called by the farm owner only and before the start time. If the phase has already added reward balance, the balance will be sent to the whitelist.
ActivatePhase
The activate_phase
method is used to activate the latest phase. The method takes no arguments. It can be called by the farm owner only, before the start time and reward balance must be added to this phase.
{
"activate_phase": {}
}
QueryMsg
Below are the available QueryMsg (read) methods for the farm
contract.
Farm
Displays the current information of the contract. This query returns a FarmInfo
response type.
{
"farm": {}
}
The FarmInfo
struct is shown below.
pub struct FarmInfo {
pub staked_token: Addr,
pub reward_token: TokenInfo,
pub current_phase_index: u64,
pub phases_info: Vec<PhaseInfo>,
pub phases_limit_per_user: Option<Uint128>,
pub staked_token_balance: Uint128, // Total staked token balance in the farm contract
}
Where:
staked_token
: The LP token that users will deposit to the farm.reward_token
: The token that users will receive as reward. It can be a native token or a CW-20 token.current_phase_index
: The index of the current phase.phases_info
: The list of phases that contains the start time, end time, whitelist, reward balance, last reward time and accrued token per share.phases_limit_per_user
: The maximum amount of phases that a user can deposit to the farm.staked_token_balance
: The total staked token balance in the farm contract.
PendingReward
Displays the pending reward of the user. This query returns a PendingRewardResponse
response type.
{
"pending_reward": {
"address": "aura1..."
}
}
Where:
address
: The address of the user.
The PendingRewardResponse
struct is shown below.
pub struct PendingRewardResponse {
pub info: TokenInfo,
pub amount: Uint128,
pub time_query: u64,
}
Where:
info
: The token info of the reward token. It can be a native token or a CW-20 token.amount
: The pending reward amount of the user.time_query
: The time when the query is executed.
TotalStaked
Displays the total staked token balance in the farm contract. This query returns a Uint128
response type.
{
"total_staked": {}
}
StakerInfo
Displays the info of the staker. This query returns a StakerInfoResponse
response type.
{
"staker_info": {
"address": "aura1..."
}
}
Where:
address
: The address of the user.
The StakerInfoResponse
struct is shown below.
pub struct StakerInfoResponse {
pub amount: Uint128, // How many staked tokens the user has provided.
pub joined_phase: u64,
}
Where:
amount
: The amount of LP token that the user has deposited to the farm contract.joined_phase
: The index of the phase that the user has joined to the farm contract.