EGG MasterChef vs SALT MasterChef

Criado O diff nunca expira
68 remoções
235 linhas
70 adições
239 linhas
//
// MasterChef is the master of Egg. He can make Egg and he is a fair guy.
// MasterChef is the master of Salt. He can make Salt and he is a fair guy.
//
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once EGG is sufficiently
// will be transferred to a governance smart contract once SALT is sufficiently
// distributed and the community can show to govern itself.
// distributed and the community can show to govern itself.
//
//
// Have fun reading it. Hopefully it's bug-free. God bless.
// Have fun reading it. Hopefully it's bug-free. God bless.
contract MasterChef is Ownable {
contract MasterChef is Ownable {
using SafeMath for uint256;
using SafeMath for uint256;
using SafeBEP20 for IBEP20;
using SafeBEP20 for IBEP20;


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


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


// The EGG TOKEN!
// The SALT TOKEN!
EggToken public egg;
SaltToken public salt;
// Dev address.
// Dev address.
address public devaddr;
address public devaddr;
// EGG tokens created per block.
// SALT tokens created per block.
uint256 public eggPerBlock;
uint256 public saltPerBlock;
// Bonus muliplier for early egg makers.
// Bonus muliplier for early salt makers.
uint256 public constant BONUS_MULTIPLIER = 1;
uint256 public constant BONUS_MULTIPLIER = 1;
// Deposit Fee address
// Deposit Fee address
address public feeAddress;
address public feeAddress;


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


event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(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 EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);


constructor(
constructor(
EggToken _egg,
SaltToken _salt,
address _devaddr,
address _devaddr,
address _feeAddress,
address _feeAddress,
uint256 _eggPerBlock,
uint256 _saltPerBlock
uint256 _startBlock
) public {
) public {
egg = _egg;
salt = _salt;
devaddr = _devaddr;
devaddr = _devaddr;
feeAddress = _feeAddress;
feeAddress = _feeAddress;
eggPerBlock = _eggPerBlock;
saltPerBlock = _saltPerBlock;
startBlock = _startBlock;
}
}


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


function setStartBlock(uint256 _startBlock) public onlyOwner {
require(_startBlock == 0, "already started");
startBlock = _startBlock;
}

// Add a new lp to the pool. Can only be called by the owner.
// Add a new lp to the pool. Can only be called by the owner.
// XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.
// XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.
function add(uint256 _allocPoint, IBEP20 _lpToken, uint16 _depositFeeBP, bool _withUpdate) public onlyOwner {
function add(uint256 _allocPoint, IBEP20 _lpToken, uint16 _depositFeeBP, bool _withUpdate) public onlyOwner {
require(_depositFeeBP <= 10000, "add: invalid deposit fee basis points");
require(_depositFeeBP <= 10000, "add: invalid deposit fee basis points");
if (_withUpdate) {
if (_withUpdate) {
massUpdatePools();
massUpdatePools();
}
}
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(PoolInfo({
poolInfo.push(PoolInfo({
lpToken: _lpToken,
lpToken: _lpToken,
allocPoint: _allocPoint,
allocPoint: _allocPoint,
lastRewardBlock: lastRewardBlock,
lastRewardBlock: lastRewardBlock,
accEggPerShare: 0,
accSaltPerShare: 0,
depositFeeBP: _depositFeeBP
depositFeeBP: _depositFeeBP