编译器
0.8.17+commit.8df45f5f
文件 1 的 5:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 5:ILybra.sol
pragma solidity 0.8.17;
interface ILybra {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function totalDepositedEther() external view returns (uint256);
function safeCollateralRate() external view returns (uint256);
function redemptionFee() external view returns (uint256);
function keeperRate() external view returns (uint256);
function depositedEther(address user) external view returns (uint256);
function getBorrowedOf(address user) external view returns (uint256);
function isRedemptionProvider(address user) external view returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
function transferShares(
address _recipient,
uint256 _sharesAmount
) external returns (uint256);
function getSharesByMintedEUSD(
uint256 _EUSDAmount
) external view returns (uint256);
function getMintedEUSDByShares(
uint256 _sharesAmount
) external view returns (uint256);
}
文件 3 的 5:IesLBR.sol
pragma solidity 0.8.17;
interface IesLBR {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function mint(address user, uint256 amount) external returns(bool);
function burn(address user, uint256 amount) external returns(bool);
}
文件 4 的 5:Ownable.sol
pragma solidity ^0.8.0;
import "./Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 5 的 5:esLBRMinterV2.sol
pragma solidity 0.8.17;
import "./ILybra.sol";
import "./Ownable.sol";
import "./IesLBR.sol";
interface Ihelper {
function getCollateralRate(address user) external view returns (uint256);
}
interface IlybraFund {
function refreshReward(address user) external;
}
interface IesLBRBoost {
function getUserBoost(
address user,
uint256 userUpdatedAt,
uint256 finishAt
) external view returns (uint256);
function getUnlockTime(address user)
external
view
returns (uint256 unlockTime);
}
contract esLBRMinerV2 is Ownable {
ILybra public immutable lybra;
Ihelper public helper;
IesLBRBoost public esLBRBoost;
IlybraFund public lybraFund;
address public esLBR;
uint256 public duration = 2_592_000;
uint256 public finishAt;
uint256 public updatedAt;
uint256 public rewardRate;
uint256 public rewardPerTokenStored;
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
mapping(address => uint256) public userUpdatedAt;
uint256 public extraRate = 50 * 1e18;
uint256 public lockdownPeriod = 12 hours;
constructor(
address _lybra,
address _helper,
address _boost,
address _fund
) {
lybra = ILybra(_lybra);
helper = Ihelper(_helper);
esLBRBoost = IesLBRBoost(_boost);
lybraFund = IlybraFund(_fund);
}
function setEsLBR(address _eslbr) external onlyOwner {
esLBR = _eslbr;
}
function setExtraRate(uint256 rate) external onlyOwner {
extraRate = rate;
}
function setLockdownPeriod(uint256 _time) external onlyOwner {
lockdownPeriod = _time;
}
function setBoost(address _boost) external onlyOwner {
esLBRBoost = IesLBRBoost(_boost);
}
function setLybraFund(address _fund) external onlyOwner {
lybraFund = IlybraFund(_fund);
}
function setRewardsDuration(uint256 _duration) external onlyOwner {
require(finishAt < block.timestamp, "reward duration not finished");
duration = _duration;
}
function totalStaked() internal view returns (uint256) {
return lybra.totalSupply();
}
function stakedOf(address user) public view returns (uint256) {
return lybra.getBorrowedOf(user);
}
modifier updateReward(address _account) {
rewardPerTokenStored = rewardPerToken();
updatedAt = lastTimeRewardApplicable();
if (_account != address(0)) {
rewards[_account] = earned(_account);
userRewardPerTokenPaid[_account] = rewardPerTokenStored;
userUpdatedAt[_account] = block.timestamp;
}
_;
}
function lastTimeRewardApplicable() public view returns (uint256) {
return _min(finishAt, block.timestamp);
}
function rewardPerToken() public view returns (uint256) {
if (totalStaked() == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored +
(rewardRate * (lastTimeRewardApplicable() - updatedAt) * 1e18) /
totalStaked();
}
function pausedByLido(address _account) public view returns(bool) {
uint256 collateralRate = helper.getCollateralRate(_account);
return (block.timestamp - lockdownPeriod) % 1 days < 1 hours &&
collateralRate >= lybra.safeCollateralRate();
}
function refreshReward(address _account) external updateReward(_account) {
if (
pausedByLido(_account)
) {
revert(
"Minting and repaying functions of eUSD are temporarily disabled during stETH rebasing periods."
);
}
}
function getBoost(address _account) public view returns (uint256) {
uint256 redemptionBoost;
if (lybra.isRedemptionProvider(_account)) {
redemptionBoost = extraRate;
}
return 100 * 1e18 + redemptionBoost + esLBRBoost.getUserBoost(
_account,
userUpdatedAt[_account],
finishAt
);
}
function earned(address _account) public view returns (uint256) {
return
((stakedOf(_account) *
getBoost(_account) *
(rewardPerToken() - userRewardPerTokenPaid[_account])) / 1e38) +
rewards[_account];
}
function getReward() external updateReward(msg.sender) {
require(
block.timestamp >= esLBRBoost.getUnlockTime(msg.sender),
"Your lock-in period has not ended. You can't claim your esLBR now."
);
uint256 reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
lybraFund.refreshReward(msg.sender);
IesLBR(esLBR).mint(msg.sender, reward);
}
}
function notifyRewardAmount(uint256 amount)
external
onlyOwner
updateReward(address(0))
{
require(amount > 0, "amount = 0");
if (block.timestamp >= finishAt) {
rewardRate = amount / duration;
} else {
uint256 remainingRewards = (finishAt - block.timestamp) *
rewardRate;
rewardRate = (amount + remainingRewards) / duration;
}
require(rewardRate > 0, "reward rate = 0");
finishAt = block.timestamp + duration;
updatedAt = block.timestamp;
}
function _min(uint256 x, uint256 y) private pure returns (uint256) {
return x <= y ? x : y;
}
}
{
"compilationTarget": {
"contracts/esLBRMinterV2.sol": "esLBRMinerV2"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_lybra","type":"address"},{"internalType":"address","name":"_helper","type":"address"},{"internalType":"address","name":"_boost","type":"address"},{"internalType":"address","name":"_fund","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"duration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"esLBR","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"esLBRBoost","outputs":[{"internalType":"contract IesLBRBoost","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"extraRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finishAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"getBoost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"helper","outputs":[{"internalType":"contract Ihelper","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockdownPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lybra","outputs":[{"internalType":"contract ILybra","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lybraFund","outputs":[{"internalType":"contract IlybraFund","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"notifyRewardAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"pausedByLido","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"refreshReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_boost","type":"address"}],"name":"setBoost","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_eslbr","type":"address"}],"name":"setEsLBR","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rate","type":"uint256"}],"name":"setExtraRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_time","type":"uint256"}],"name":"setLockdownPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_fund","type":"address"}],"name":"setLybraFund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_duration","type":"uint256"}],"name":"setRewardsDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"stakedOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updatedAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userUpdatedAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]