FarmingInstance
Link to FarmingInstance source code on Shibarium
Implementation of the logic of the UniV2 liquidity farming contract (version for ShibaSwap)
UniV2 farming implementation contract for Shibaswap with a main reward pool and several bonus (up to 9) pools. Main pool reward is esKNINE token which is minted by the farming contract.
Variables
uint8 public constant MAX_POOL_LENGTH = 10;
- maximum number of reward pools.
uint256 public constant MULTIPLIER = 10**20;
- calculations multiplier.
address public pool;
- liquidity pool address (ShibaSwap LP Token) for which the farming was created.
address public router;
- UniswapV2Router02 (ShibaSwap) contract address.
address public factory;
- FarmingFactory contract address.
LiquidityPool public liquidityPool;
- an object of LiquidityPool type.
Intermediate public intermediate;
- object of the Intermediate type (see below).
RewardPool[] public rewardPools;
- an array of reward pools like RewardPool.
struct Deposit {
- struct to describe the deposit.
uint256 liquidity;
- number of user LP tokens.
uint256[] accumulators;
- an array of batteries for each rewardPool.
uint256[] debts;
- an array of calculated 'not claimed' rewards (updated upon actions with a deposit) for each rewardPool.
}
struct Intermediate {
- struct for storing intermediary calculations.
uint256 totalLiquidity;
- the total amount of liquidity stored in farming pool at the moment.
uint256[] lastUpdate;
- an array of the latest updates timestamps for each rewardPool (will not be visible through mapping, check through the getUserDeposits method).
uint256[] accumulators;
- an array of accumulators for each rewardPool (will not be visible through mapping, check through the getUserDeposits method).
}
Events
event Deposited(address user,
- user address.
uint256 liquidity
- number of LP tokens.
);
- Upon zap
or deposit
call.
event Withdrawed(address user,
- user address.
uint256 liquidity
- number of LP tokens.
);
- Upon withdraw
or unzap
call.
event ClaimedReward(
address user,
- user address.
uint256 halfId,
- reward pool id.
bool fromZap,
- true
- reward withdrawn for deposit made via zap; otherwise - false
address rewardToken,
- reward token.
uint256 amount
- number of cliamied rewards.
);
- upon reward withdrawal (claimRewards, claimRewardsAll, withdraw, unzap).
event Zap(address inputToken,
- token submitted for input.
uint256 amount,
- the number of tokens (except for phi) submitted to the input.
uint256 fee
- how many tokens went to the factory as a fee.
);
- upon zap
call.
event Unzap(address outputToken,
- output token.
uint256 amount,
- number of tokens at the output (excluding fee).
uint256 fee
- how many tokens were received by the factory as a fee.
);
- upon unzap
call.
event BonusPoolAdded(
uint256 halfId,
- index in the rewardPools array assigned to the created pool.
address rewardToken,
- reward token of the created pool.
uint64starts,
- start time.
uint64ends,
- end time.
uint256 rps
- reward per second.
);
- upon addBonusPool
call.
event BonusPoolStopped(uint256 halfId);
- upon stopBonusPool
or when the pool stopped itself by the endTime.
event MainRewardPoolStopped();
- upon stopMainPool
or when the pool stopped itself by the endTime.
event RewardPerSecondChanged(uint256 rps);
- upon changeRPS
, returns a new RPS value for the main pool.
Factory Functions
addBonusPool
Add a bonus pool (call from farmingFactory.addBonusPool).
stopBonusPool
Stop the bonus pool (call from farmingFactory.stopBonusPool).
stopMainPool
Stop the main pool and all bonus ones (call with farmingFactory.stopFarming).
changeRPS
Change the RPS value in the main reward pool (call from farmingFactory.changeFarmingRPS
).
Initializer Functions
initialize
Initializer function, not called after initialization.
Only for the initializer role
User Functions
deposit
Depositing LP tokens.
withdraw
Withdraw all LP tokens from user's deposits made via deposit
method.
claimRewardsAll
Withdraw all rewards both from a deposit via zap
and from a regular deposit
at the same time (withdraws rewards from all pools).
claimRewards
Withdraw reward from the specified reward pool for the specified type of the deposit (made through zap == false
, otherwise == true
).
zap
An option for making a deposit without the user having LP tokens.
User deposits one of the available tokens token0
or token1
(if one of them is a wrapped native, then a zero address should be specified in inputToken
and send the native, then the contract will wrap it itself).
Then part of the deposited tokens is swapped into another and this pair is added into liquidity, which is how LP tokens are formed. These LP are used for farming and accumulate the reward.
unzap
Withdraw a deposit made through zap
.
Liquidity is removed,
LP tokens are burned,
Share of tokens (a token other than
tokenOut
) is swapped totokenOut
and transferred to the user.
View Functions
pendingReward
Method for displaying earned rewards in a specific reward pool (will return two values: first for a deposit via deposit
, second for a deposit via zap
).
pendingRewardsMultiple
Method for displaying earned rewards in all reward pools.
getActualPools
Method for displaying a list of active reward pools (the ones that are still distributing rewards).
ids
- its indexes in the array of reward pools,
pools
- its contents
getUserDeposits
Method for displaying user deposits.
Deposits marked with
index 0
are made viadeposit
Deposits marked with
index 1
are made viazap
getFarmingState
Method for displaying the intermediate variable in full.
Last updated