contract MasterChef is Ownable {
using SafeMath for uint256;
using SafeBEP20 for IBEP20;

// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 rewardDebt; // Reward debt. See explanation below.
//
// We do some fancy math here. Basically, any point in time, the amount of sages
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSagePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's accSagePerShare (and lastRewardBlock) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's amount gets updated.
// 4. User's rewardDebt gets updated. Try Again
}

// Info of each pool.
struct PoolInfo {
IBEP20 lpToken; // Address of LP token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. sages to distribute per block.
uint256 lastRewardBlock; // Last block number that sages distribution occurs.
uint256 accSagePerShare; // Accumulated SAGEs per share, times 1e12. See below.
uint16 depositFeeBP; // Deposit fee in basis points
}

// The SAGE TOKEN!!
SageToken public sage;
// Dev address.
address public devaddr;
// SAGE tokens created per block.
uint256 public sagePerBlock;
// Bonus muliplier for early sage makers.
uint256 public constant BONUS_MULTIPLIER = 1;
// Deposit Fee address.
address public feeAddress;
// Owner address.
address public owner;

// Initial emission rate: 1 SAIL per block.
uint256 public constant INITIAL_EMISSION_RATE = 1 ether;
// Minimum emission rate: 0.1 SAIL per block.
uint256 public constant MINIMUM_EMISSION_RATE = 100 finney;
// Reduce emission every 7,200 blocks ~ 6 hours.
uint256 public constant EMISSION_REDUCTION_PERIOD_BLOCKS = 7200;
// Emission reduction rate per period in basis points: 3%.
uint256 public constant EMISSION_REDUCTION_RATE_PER_PERIOD = 300;
// Last reduction period index
uint256 public lastReductionPeriodIndex = 0;

// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens.
mapping (uint256 => mapping (address => UserInfo)) public userInfo;
// Total allocation points. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAGE mining starts.
uint256 public startBlock;

mapping(address => address) public referrers; // account_address -> referrer_address
mapping(address => uint256) public referredCount; // referrer_address -> num_of_referred

event Referral(address indexed referrer, address indexed farmer);
event ReferralPaid(address indexed user,address indexed userTo, uint256 reward);

event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
event EmissionRateUpdated(address indexed caller, uint256 previousAmount, uint256 newAmount);

constructor(
SageToken _sage,
address _feeAddress,
address _owner,
uint256 _startBlock
) public {
sage = _sage;
devaddr = msg.sender;
owner = _owner;
feeAddress = _feeAddress;
sagePerBlock = INITIAL_EMISSION_RATE;
startBlock = _startBlock;
}

function poolLength() external view returns (uint256) {
return poolInfo.length;
}

Mar 21, 2021, 12:53 PM

© 2024 Draquery.com All rights reserved.