AshSwap Docs
Search…
⌃K

Liquidity Staking (Farming)

Contract Interface

1. Notations & Structs

EnterFarmResultType = EsdtTokenPayment
FARM token: a Meta-ESDT token representing the farming position.

1. Write functions

1.1. enterFarm

Start farming.
Attached tokens:
  • LP tokens from Ashswap’s pools
  • old FARM tokens: if you attach multiple FARM tokens, they will be automatically merged with the new FARM token (like mergeFarmTokens).
Return: EsdtTokenPayment - a new Farm token.
#[payable("*")]
#[endpoint(enterFarm)]
fn enter_farm(&self, self_boost: &bool) -> ManagedVec<EsdtTokenPayment<Self::Api>>

1.2. exitFarm

Claim reward + withdraw LP token. You can only exit one farm using one FARM token per transaction.
Attached token: FARM token received from enterFarm function.
Return: MultiValue2<EsdtTokenPayment<BigUint>, EsdtTokenPayment<BigUint>>
  • 1st EsdtTokenPayment: LP token
  • 2nd EsdtTokenPayment: Reward token
#[payable("*")]
#[endpoint(exitFarm)]
fn exit_farm(&self) -> ManagedVec<EsdtTokenPayment<Self::Api>>

1.3. claimRewards

Claim rewards (ASH token) without withdrawal. You can only claim rewards from one FARM token in one transaction.
Return: MultiValue2<EsdtTokenPayment<BigUint>, EsdtTokenPayment<BigUint>>
  • 1st EsdtTokenPayment: LP token
  • 2nd EsdtTokenPayment: Reward token
#[payable("*")]
#[endpoint(claimRewards)]
fn claim_rewards(&self, self_boost: &bool) -> ManagedVec<EsdtTokenPayment<Self::Api>>

2. Read functions

2.1. getState

Get the current state of a farm.
#[derive(TopEncode, TopDecode, PartialEq, TypeAbi, Clone, Copy)]
pub enum State { Inactive, Active }
#[view(getState)]
fn state(&self) -> State;

2.2. getRewardPerShare

Return:
  • BigUint - the number of ASH tokens received each block per FARM token.
#[view(getRewardPerShare)]
fn reward_per_share(&self) -> SingleValueMapper<BigUint>;

2.3. getFarmTokenSupply

Return:
  • BigUint - the total supply of the FARM token.
#[view(getFarmTokenSupply)]
fn farm_token_supply(&self) -> BigUint;

2.4 calculateRewardsForGivenPosition

Get your current reward from a farm.
Params:
  • amount: BigUint - your FARM token’s balance
  • attributes: FarmTokenAttributes
    Note: The struct is decoded from FARM token’s attributes.
#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi, Clone, ManagedVecItem, Debug)]
pub struct FarmTokenAttributes<M: ManagedTypeApi> {
pub reward_per_share: BigUint<M>,
pub slope_used: BigUint<M>, // slope that user used to boost in this farm token.
pub booster: ManagedAddress<M>,
pub initial_farm_amount: BigUint<M>,
pub initial_farming_amount: BigUint<M>,
pub reward_tokens: ManagedVec<M, RewardTokens<M>>,
}
#[view(calculateRewardsForGivenPosition)]
fn calculate_rewards_for_given_position(&self, amount: BigUint, attributes: FarmTokenAttributes<Self::Api>) -> BigUint