Verified contractPartialGPL-3.0
esLBRMiner
Address0xdaee25eeff49ed3f09028aa2e194e213e747709a
- Balance
0 ETH
- Transactions
108
- Compiler
solc 0.8.17
- Same code
Only this contract
Details
- Compiler
- solc 0.8.17+commit.8df45f5f
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- GPL-3.0
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 17,115,104
- Creation transaction
- 0xa53445e7ec…18e2b03c98
5 files
- esLBRMiner.solmain4.16 KB
- Context.sol866 B
- ILybra.sol1.25 KB
- IesLBR.sol367 B
- Ownable.sol2.69 KB
esLBRMiner.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
/**
* @title esLBRMiner is a stripped down version of Synthetix StakingRewards.sol, to reward esLBR to EUSD minters.
* Differences from the original contract,
* - Get `totalStaked` from totalSupply() in contract EUSD.
* - Get `stakedOf(user)` from getBorrowedOf(user) in contract EUSD.
* - When an address borrowed EUSD amount changes, call the refreshReward method to update rewards to be claimed.
*/
import "./ILybra.sol";
import "./Ownable.sol";
import "./IesLBR.sol";
contract esLBRMiner is Ownable {
ILybra public immutable lybra;
address public esLBR;
// Duration of rewards to be paid out (in seconds)
uint256 public duration;
// Timestamp of when the rewards finish
uint256 public finishAt;
// Minimum of last updated time and reward finish time
uint256 public updatedAt;
// Reward to be paid out per second
uint256 public rewardRate;
// Sum of (reward rate * dt * 1e18 / total supply)
uint256 public rewardPerTokenStored;
// User address => rewardPerTokenStored
mapping(address => uint256) public userRewardPerTokenPaid;
// User address => rewards to be claimed
mapping(address => uint256) public rewards;
uint256 public extraRate = 150;
constructor(
address _lybra
) {
lybra = ILybra(_lybra);
}
function setEsLBR(address _eslbr) external onlyOwner {
esLBR = _eslbr;
}
function setExtraRate(uint256 rate) external onlyOwner {
require(rate > 100);
extraRate = rate;
}
function totalStaked() internal view returns (uint256) {
return lybra.totalSupply();
}
function stakedOf(address user) public view returns (uint256) {
uint256 amount = lybra.getBorrowedOf(user);
if (lybra.isRedemptionProvider(user)) {
amount = (amount * extraRate) / 100;
}
return amount;
}
modifier updateReward(address _account) {
rewardPerTokenStored = rewardPerToken();
updatedAt = lastTimeRewardApplicable();
if (_account != address(0)) {
rewards[_account] = earned(_account);
userRewardPerTokenPaid[_account] = rewardPerTokenStored;
}
_;
}
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 refreshReward(address _account) external updateReward(_account) {}
function earned(address _account) public view returns (uint256) {
return
((stakedOf(_account) *
(rewardPerToken() - userRewardPerTokenPaid[_account])) / 1e18) +
rewards[_account];
}
function getReward() external updateReward(msg.sender) {
uint256 reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
IesLBR(esLBR).mint(msg.sender, reward);
}
}
function setRewardsDuration(uint256 _duration) external onlyOwner {
require(finishAt < block.timestamp, "reward duration not finished");
duration = _duration;
}
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;
}
}
Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}ILybra.sol
// SPDX-License-Identifier: BUSL-1.1
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);
}
IesLBR.sol
// SPDX-License-Identifier: BUSL-1.1
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);
}Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.