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
function addBonusPool(RewardPool calldata rew) external
Add a bonus pool (call from farmingFactory.addBonusPool).
stopBonusPool
function stopBonusPool(uint256 halfId) external
Stop the bonus pool (call from farmingFactory.stopBonusPool).
stopMainPool
function stopMainPool() external
Stop the main pool and all bonus ones (call with farmingFactory.stopFarming).
changeRPS
function changeRPS(uint256 value) external
Change the RPS value in the main reward pool (call from farmingFactory.changeFarmingRPS
).
Initializer Functions
initialize
function initialize(
address _factory,
address _router,
address _pool,
LiquidityPool memory _liq,
RewardPool calldata _rew
) public
Initializer function, not called after initialization.
User Functions
deposit
function deposit(uint256 amount) external
Depositing LP tokens.
withdraw
function withdraw() external
Withdraw all LP tokens from user's deposits made via deposit
method.
claimRewardsAll
function claimRewardsAll() external
Withdraw all rewards both from a deposit via zap
and from a regular deposit
at the same time (withdraws rewards from all pools).
claimRewards
function claimRewards(
uint256 halfId,
bool fromStake
) external
Withdraw reward from the specified reward pool for the specified type of the deposit (made through zap == false
, otherwise == true
).
zap
function zap(
address inputToken,
uint256 amount
) external payable
An option for making a deposit without the user having LP tokens.
unzap
function unzap(address tokenOut) external
Withdraw a deposit made through zap
.
View Functions
pendingReward
function pendingReward(
address user,
uint256 halfId
) public view returns (uint256 fromStake, uint256 fromZap)
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
function pendingRewardsMultiple(
address user - user address
) external view returns (uint256[] memory fromStake, uint256[] memory fromZap)
Method for displaying earned rewards in all reward pools.
getActualPools
function getActualPools()
external
view
returns (uint256[] memory ids, RewardPool[] memory pools)
Method for displaying a list of active reward pools (the ones that are still distributing rewards).
getUserDeposits
function getUserDeposits(
address user -
) external view returns (Deposit[2] memory dept)
Method for displaying user deposits.
getFarmingState
function getFarmingState() external view returns (Intermediate memory)
Method for displaying the intermediate variable in full.
Last updated