Address Contract Partially Verified
Address
0xA919D7a5fb7ad4ab6F2aae82b6F39d181A027d35
Balance
0 ETH
Nonce
1
Code Size
6811 bytes
Creator
0x2b1634bc...69Df at tx 0x35bec35f...917a46
Indexed Transactions
0
Contract Bytecode
6811 bytes
0x608060405234801561001057600080fd5b506004361061020a5760003560e01c806379ba50971161012a578063a694fc3a116100bd578063d1af0c7d1161008c578063df136d6511610071578063df136d651461050a578063e9fad8ee14610512578063ebe2b12b1461051a5761020a565b8063d1af0c7d146104fa578063dbbc4a57146105025761020a565b8063a694fc3a146104b0578063c8f33c91146104cd578063cc1a378f146104d5578063cd3daf9d146104f25761020a565b80638b876347116100f95780638b876347146104655780638da5cb5b14610498578063904440bd146104a057806391b4ded9146104a85761020a565b806379ba5097146104145780637b0a47ee1461041c57806380faa57d146104245780638980f11f1461042c5761020a565b8063386a9525116101a25780635c975abb116101715780635c975abb1461038457806368d53c43146103a057806370a08231146103d957806372f702f31461040c5761020a565b8063386a95251461033b5780633d18b912146103435780633fc6df6e1461034b57806353a47bb71461037c5761020a565b806318160ddd116101de57806318160ddd146102db57806319762143146102e35780631c1f78eb146103165780632e1a7d4d1461031e5761020a565b80628cc2621461020f5780630700037d146102545780631627540c1461028757806316c38b3c146102bc575b600080fd5b6102426004803603602081101561022557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610522565b60408051918252519081900360200190f35b6102426004803603602081101561026a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166105d2565b6102ba6004803603602081101561029d57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166105e4565b005b6102ba600480360360208110156102d257600080fd5b50351515610665565b6102426106fd565b6102ba600480360360208110156102f957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610704565b610242610753565b6102ba6004803603602081101561033457600080fd5b5035610771565b610242610946565b6102ba61094c565b610353610b72565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b610353610b8e565b61038c610baa565b604080519115158252519081900360200190f35b6102ba600480360360408110156103b657600080fd5b508035906020013573ffffffffffffffffffffffffffffffffffffffff16610bb3565b610242600480360360208110156103ef57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610d71565b610353610d99565b6102ba610db5565b610242610eb0565b610242610eb6565b6102ba6004803603604081101561044257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610ec4565b6102426004803603602081101561047b57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610fa8565b610353610fba565b610242610fd6565b610242611063565b6102ba600480360360208110156104c657600080fd5b5035611069565b61024261127d565b6102ba600480360360208110156104eb57600080fd5b5035611283565b610242611306565b610353611360565b610353611381565b610242611399565b6102ba61139f565b6102426113c2565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600d6020908152604080832054600c9092528220546105cc91906105c090670de0b6b3a7640000906105b49061058290610576611306565b9063ffffffff6113c816565b73ffffffffffffffffffffffffffffffffffffffff88166000908152600f60205260409020549063ffffffff61142516565b9063ffffffff61148516565b9063ffffffff6114ef16565b92915050565b600d6020526000908152604090205481565b6105ec611549565b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce229181900360200190a150565b61066d611549565b60055460ff1615158115151415610683576106fa565b600580547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016821515179081905560ff16156106be57426004555b6005546040805160ff90921615158252517f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec59181900360200190a15b50565b600e545b90565b61070c611549565b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600061076c60095460085461142590919063ffffffff16565b905090565b600380546001019081905533610785611306565b600b55610790610eb6565b600a5573ffffffffffffffffffffffffffffffffffffffff8116156107f1576107b881610522565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600d6020908152604080832093909355600b54600c909152919020555b60008311610846576040805162461bcd60e51b815260206004820152601160248201527f43616e6e6f742077697468647261772030000000000000000000000000000000604482015290519081900360640190fd5b600e54610859908463ffffffff6113c816565b600e55336000908152600f602052604090205461087c908463ffffffff6113c816565b336000818152600f60205260409020919091556006546108b59173ffffffffffffffffffffffffffffffffffffffff909116908561159f565b60408051848152905133917f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5919081900360200190a2506003548114610942576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b5050565b60095481565b600380546001019081905533610960611306565b600b5561096b610eb6565b600a5573ffffffffffffffffffffffffffffffffffffffff8116156109cc5761099381610522565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600d6020908152604080832093909355600b54600c909152919020555b336000908152600d60205260409020548015610b1a57600554604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600092610100900473ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015610a5857600080fd5b505afa158015610a6c573d6000803e3d6000fd5b505050506040513d6020811015610a8257600080fd5b5051336000908152600d6020526040902054909150811015610aa2578091505b336000818152600d6020526040812055600554610ae29161010090910473ffffffffffffffffffffffffffffffffffffffff16908463ffffffff61159f16565b60408051838152905133917fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486919081900360200190a2505b505060035481146106fa576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60025473ffffffffffffffffffffffffffffffffffffffff1681565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60055460ff1681565b60025473ffffffffffffffffffffffffffffffffffffffff163314610c095760405162461bcd60e51b815260040180806020018281038252602a8152602001806119f2602a913960400191505060405180910390fd5b6000610c13611306565b600b55610c1e610eb6565b600a5573ffffffffffffffffffffffffffffffffffffffff811615610c7f57610c4681610522565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600d6020908152604080832093909355600b54600c909152919020555b600554610ca990610100900473ffffffffffffffffffffffffffffffffffffffff16833086611631565b6007544210610cce57600954610cc690849063ffffffff61148516565b600855610d1d565b600754600090610ce4904263ffffffff6113c816565b90506000610cfd6008548361142590919063ffffffff16565b600954909150610d17906105b4878463ffffffff6114ef16565b60085550505b42600a819055600954610d36919063ffffffff6114ef16565b6007556040805184815290517fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d9181900360200190a1505050565b73ffffffffffffffffffffffffffffffffffffffff166000908152600f602052604090205490565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60015473ffffffffffffffffffffffffffffffffffffffff163314610e0b5760405162461bcd60e51b81526004018080602001828103825260358152602001806119316035913960400191505060405180910390fd5b6000546001546040805173ffffffffffffffffffffffffffffffffffffffff938416815292909116602083015280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a160018054600080547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff841617909155169055565b60085481565b600061076c426007546116cc565b610ecc611549565b60065473ffffffffffffffffffffffffffffffffffffffff83811691161415610f265760405162461bcd60e51b8152600401808060200182810382526021815260200180611a466021913960400191505060405180910390fd5b600054610f539073ffffffffffffffffffffffffffffffffffffffff84811691168363ffffffff61159f16565b6040805173ffffffffffffffffffffffffffffffffffffffff841681526020810183905281517f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa28929181900390910190a15050565b600c6020526000908152604090205481565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b600073169e633a2d1e6c10dd91238ba11c4a708dfef37c73ffffffffffffffffffffffffffffffffffffffff166350d25bcd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561103257600080fd5b505afa158015611046573d6000803e3d6000fd5b505050506040513d602081101561105c57600080fd5b5051905090565b60045481565b600380546001019081905560055460ff16156110b65760405162461bcd60e51b815260040180806020018281038252603c8152602001806119b6603c913960400191505060405180910390fd5b336110bf611306565b600b556110ca610eb6565b600a5573ffffffffffffffffffffffffffffffffffffffff81161561112b576110f281610522565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600d6020908152604080832093909355600b54600c909152919020555b60008311611180576040805162461bcd60e51b815260206004820152600e60248201527f43616e6e6f74207374616b652030000000000000000000000000000000000000604482015290519081900360640190fd5b600e54611193908463ffffffff6114ef16565b600e55336000908152600f60205260409020546111b6908463ffffffff6114ef16565b336000818152600f60205260409020919091556006546111f09173ffffffffffffffffffffffffffffffffffffffff909116903086611631565b60408051848152905133917f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d919081900360200190a2506003548114610942576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600a5481565b61128b611549565b60075442116112cb5760405162461bcd60e51b81526004018080602001828103825260588152602001806118d96058913960600191505060405180910390fd5b60098190556040805182815290517ffb46ca5a5e06d4540d6387b930a7c978bce0db5f449ec6b3f5d07c6e1d44f2d39181900360200190a150565b6000600e546000141561131c5750600b54610701565b61076c611351600e546105b4670de0b6b3a7640000611345600854611345600a54610576610eb6565b9063ffffffff61142516565b600b549063ffffffff6114ef16565b600554610100900473ffffffffffffffffffffffffffffffffffffffff1681565b73169e633a2d1e6c10dd91238ba11c4a708dfef37c81565b600b5481565b336000908152600f60205260409020546113b890610771565b6113c061094c565b565b60075481565b60008282111561141f576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600082611434575060006105cc565b8282028284828161144157fe5b041461147e5760405162461bcd60e51b81526004018080602001828103825260218152602001806119956021913960400191505060405180910390fd5b9392505050565b60008082116114db576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b60008284816114e657fe5b04949350505050565b60008282018381101561147e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60005473ffffffffffffffffffffffffffffffffffffffff1633146113c05760405162461bcd60e51b815260040180806020018281038252602f815260200180611966602f913960400191505060405180910390fd5b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb0000000000000000000000000000000000000000000000000000000017905261162c9084906116e2565b505050565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd000000000000000000000000000000000000000000000000000000001790526116c69085906116e2565b50505050565b60008183106116db578161147e565b5090919050565b6117018273ffffffffffffffffffffffffffffffffffffffff166118d2565b611752576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b600060608373ffffffffffffffffffffffffffffffffffffffff16836040518082805190602001908083835b602083106117bb57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161177e565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461181d576040519150601f19603f3d011682016040523d82523d6000602084013e611822565b606091505b509150915081611879576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b8051156116c65780806020019051602081101561189557600080fd5b50516116c65760405162461bcd60e51b815260040180806020018281038252602a815260200180611a1c602a913960400191505060405180910390fd5b3b15159056fe50726576696f7573207265776172647320706572696f64206d75737420626520636f6d706c657465206265666f7265206368616e67696e6720746865206475726174696f6e20666f7220746865206e657720706572696f64596f75206d757374206265206e6f6d696e61746564206265666f726520796f752063616e20616363657074206f776e6572736869704f6e6c792074686520636f6e7472616374206f776e6572206d617920706572666f726d207468697320616374696f6e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775468697320616374696f6e2063616e6e6f7420626520706572666f726d6564207768696c652074686520636f6e74726163742069732070617573656443616c6c6572206973206e6f742052657761726473446973747269627574696f6e20636f6e74726163745361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656443616e6e6f7420776974686472617720746865207374616b696e6720746f6b656ea265627a7a723158207492e6cb69feea92b1673543cfee3f7d8d7b5539bc988a24095a032b2029077164736f6c63430005110032
Verified Source Code Partial Match
Compiler: v0.5.17+commit.d19bba13
EVM: istanbul
Optimization: Yes (9999 runs)
StakingRewards.sol 929 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.5.17;
/*
* Docs: https://docs.synthetix.io/
*
*
* MIT License
* ===========
*
* Copyright (c) 2020 Synthetix
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* This test is non-exhaustive, and there may be false-negatives: during the
* execution of a contract's constructor, its address will be reported as
* not containing a contract.
*
* > It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*/
function isContract(address account) internal view returns (bool) {
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly {
size := extcodesize(account)
}
return size > 0;
}
}
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transfer(address recipient, uint256 amount)
external
returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through `transferFrom`. This is
* zero by default.
*
* This value changes when `approve` or `transferFrom` are called.
*/
function allowance(address owner, address spender)
external
view
returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* > Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an `Approval` event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to `approve`. `value` is the new allowance.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
interface IStakingRewards {
// Views
function lastTimeRewardApplicable() external view returns (uint256);
function rewardPerToken() external view returns (uint256);
function earned(address account) external view returns (uint256);
function getRewardForDuration() external view returns (uint256);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
// Mutative
function stake(uint256 amount) external;
function withdraw(uint256 amount) external;
function getReward() external;
function exit() external;
}
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + (((a % 2) + (b % 2)) / 2);
}
}
contract Owned {
address public owner;
address public nominatedOwner;
constructor(address _owner) public {
require(_owner != address(0), "Owner address cannot be 0");
owner = _owner;
emit OwnerChanged(address(0), _owner);
}
function nominateNewOwner(address _owner) external onlyOwner {
nominatedOwner = _owner;
emit OwnerNominated(_owner);
}
function acceptOwnership() external {
require(
msg.sender == nominatedOwner,
"You must be nominated before you can accept ownership"
);
emit OwnerChanged(owner, nominatedOwner);
owner = nominatedOwner;
nominatedOwner = address(0);
}
modifier onlyOwner {
_onlyOwner();
_;
}
function _onlyOwner() private view {
require(
msg.sender == owner,
"Only the contract owner may perform this action"
);
}
event OwnerNominated(address newOwner);
event OwnerChanged(address oldOwner, address newOwner);
}
contract Pausable is Owned {
uint256 public lastPauseTime;
bool public paused;
constructor() internal {
// This contract is abstract, and thus cannot be instantiated directly
require(owner != address(0), "Owner must be set");
// Paused will be false, and lastPauseTime will be 0 upon initialisation
}
/**
* @notice Change the paused state of the contract
* @dev Only the contract owner may call this.
*/
function setPaused(bool _paused) external onlyOwner {
// Ensure we're actually changing the state before we do anything
if (_paused == paused) {
return;
}
// Set our paused state.
paused = _paused;
// If applicable, set the last pause time.
if (paused) {
lastPauseTime = now;
}
// Let everyone know that our pause state has changed.
emit PauseChanged(paused);
}
event PauseChanged(bool isPaused);
modifier notPaused {
require(
!paused,
"This action cannot be performed while the contract is paused"
);
_;
}
}
contract ReentrancyGuard {
/// @dev counter to allow mutex lock with only one SSTORE operation
uint256 private _guardCounter;
constructor() internal {
// The counter starts at one to prevent changing it from zero to a non-zero
// value, which is a more expensive operation.
_guardCounter = 1;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_guardCounter += 1;
uint256 localCounter = _guardCounter;
_;
require(
localCounter == _guardCounter,
"ReentrancyGuard: reentrant call"
);
}
}
contract RewardsDistributionRecipient is Owned {
address public rewardsDistribution;
function notifyRewardAmount(uint256 reward, address rewardHolder) external;
modifier onlyRewardsDistribution() {
require(
msg.sender == rewardsDistribution,
"Caller is not RewardsDistribution contract"
);
_;
}
function setRewardsDistribution(address _rewardsDistribution)
external
onlyOwner
{
rewardsDistribution = _rewardsDistribution;
}
}
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
callOptionalReturn(
token,
abi.encodeWithSelector(token.transfer.selector, to, value)
);
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
callOptionalReturn(
token,
abi.encodeWithSelector(token.transferFrom.selector, from, to, value)
);
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(
token,
abi.encodeWithSelector(token.approve.selector, spender, value)
);
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance =
token.allowance(address(this), spender).add(value);
callOptionalReturn(
token,
abi.encodeWithSelector(
token.approve.selector,
spender,
newAllowance
)
);
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance =
token.allowance(address(this), spender).sub(value);
callOptionalReturn(
token,
abi.encodeWithSelector(
token.approve.selector,
spender,
newAllowance
)
);
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
// solhint-disable-next-line max-line-length
require(
abi.decode(returndata, (bool)),
"SafeERC20: ERC20 operation did not succeed"
);
}
}
}
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
}
interface IChainLinkFeed {
function latestAnswer() external view returns (int256);
}
contract StakingRewards is
IStakingRewards,
RewardsDistributionRecipient,
ReentrancyGuard,
Pausable
{
using SafeMath for uint256;
using SafeERC20 for IERC20;
/* ========== STATE VARIABLES ========== */
IChainLinkFeed public constant FASTGAS =
IChainLinkFeed(0x169E633A2D1E6c10dD91238Ba11c4A708dfEF37C);
IERC20 public rewardsToken;
IERC20 public stakingToken;
uint256 public periodFinish = 0;
uint256 public rewardRate = 0;
uint256 public rewardsDuration;
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
uint256 private _totalSupply;
mapping(address => uint256) private _balances;
/* ========== CONSTRUCTOR ========== */
constructor(
address _owner,
address _rewardsDistribution,
address _rewardsToken,
address _stakingToken,
uint256 _rewardsDuration
) public Owned(_owner) {
rewardsToken = IERC20(_rewardsToken);
stakingToken = IERC20(_stakingToken);
rewardsDistribution = _rewardsDistribution;
rewardsDuration = _rewardsDuration;
}
/* ========== VIEWS ========== */
function totalSupply() external view returns (uint256) {
return _totalSupply;
}
function getFastGas() external view returns (uint256) {
return uint256(FASTGAS.latestAnswer());
}
function balanceOf(address account) external view returns (uint256) {
return _balances[account];
}
function lastTimeRewardApplicable() public view returns (uint256) {
return Math.min(block.timestamp, periodFinish);
}
function rewardPerToken() public view returns (uint256) {
if (_totalSupply == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored.add(
lastTimeRewardApplicable()
.sub(lastUpdateTime)
.mul(rewardRate)
.mul(1e18)
.div(_totalSupply)
);
}
function earned(address account) public view returns (uint256) {
return
_balances[account]
.mul(rewardPerToken().sub(userRewardPerTokenPaid[account]))
.div(1e18)
.add(rewards[account]);
}
function getRewardForDuration() external view returns (uint256) {
return rewardRate.mul(rewardsDuration);
}
/* ========== MUTATIVE FUNCTIONS ========== */
function stake(uint256 amount)
external
nonReentrant
notPaused
updateReward(msg.sender)
{
require(amount > 0, "Cannot stake 0");
_totalSupply = _totalSupply.add(amount);
_balances[msg.sender] = _balances[msg.sender].add(amount);
stakingToken.safeTransferFrom(msg.sender, address(this), amount);
emit Staked(msg.sender, amount);
}
function withdraw(uint256 amount)
public
nonReentrant
updateReward(msg.sender)
{
require(amount > 0, "Cannot withdraw 0");
_totalSupply = _totalSupply.sub(amount);
_balances[msg.sender] = _balances[msg.sender].sub(amount);
stakingToken.safeTransfer(msg.sender, amount);
emit Withdrawn(msg.sender, amount);
}
function getReward() public nonReentrant updateReward(msg.sender) {
uint256 reward = rewards[msg.sender];
if (reward > 0) {
// Safe gaurd against error if reward is greater than balance in contract
uint256 balance = rewardsToken.balanceOf(address(this));
if (rewards[msg.sender] > balance) {
reward = balance;
}
rewards[msg.sender] = 0;
rewardsToken.safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
}
function exit() external {
withdraw(_balances[msg.sender]);
getReward();
}
/* ========== RESTRICTED FUNCTIONS ========== */
function notifyRewardAmount(uint256 reward, address rewardHolder)
external
onlyRewardsDistribution
updateReward(address(0))
{
// handle the transfer of reward tokens via `transferFrom` to reduce the number
// of transactions required and ensure correctness of the reward amount
rewardsToken.safeTransferFrom(rewardHolder, address(this), reward);
if (block.timestamp >= periodFinish) {
rewardRate = reward.div(rewardsDuration);
} else {
uint256 remaining = periodFinish.sub(block.timestamp);
uint256 leftover = remaining.mul(rewardRate);
rewardRate = reward.add(leftover).div(rewardsDuration);
}
lastUpdateTime = block.timestamp;
periodFinish = block.timestamp.add(rewardsDuration);
emit RewardAdded(reward);
}
// Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders
function recoverERC20(address tokenAddress, uint256 tokenAmount)
external
onlyOwner
{
require(
tokenAddress != address(stakingToken),
"Cannot withdraw the staking token"
);
IERC20(tokenAddress).safeTransfer(owner, tokenAmount);
emit Recovered(tokenAddress, tokenAmount);
}
function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner {
require(
block.timestamp > periodFinish,
"Previous rewards period must be complete before changing the duration for the new period"
);
rewardsDuration = _rewardsDuration;
emit RewardsDurationUpdated(rewardsDuration);
}
/* ========== MODIFIERS ========== */
modifier updateReward(address account) {
rewardPerTokenStored = rewardPerToken();
lastUpdateTime = lastTimeRewardApplicable();
if (account != address(0)) {
rewards[account] = earned(account);
userRewardPerTokenPaid[account] = rewardPerTokenStored;
}
_;
}
/* ========== EVENTS ========== */
event RewardAdded(uint256 reward);
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(address indexed user, uint256 reward);
event RewardsDurationUpdated(uint256 newDuration);
event Recovered(address token, uint256 amount);
}
/**
* @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.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be aplied to your functions to restrict their use to
* the owner.
*/
contract Ownable {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* > Note: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = 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 onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
contract StakingRewardsFactory is Ownable {
// immutables
address public rewardsToken;
uint256 public stakingRewardsGenesis;
// the staking tokens for which the rewards contract has been deployed
address[] public stakingTokens;
// info about rewards for a particular staking token
struct StakingRewardsInfo {
address stakingRewards;
uint256 rewardAmount;
}
// rewards info by staking token
mapping(address => StakingRewardsInfo)
public stakingRewardsInfoByStakingToken;
constructor(address _rewardsToken, uint256 _stakingRewardsGenesis)
public
Ownable()
{
require(
_stakingRewardsGenesis >= block.timestamp,
"StakingRewardsFactory::constructor: genesis too soon"
);
rewardsToken = _rewardsToken;
stakingRewardsGenesis = _stakingRewardsGenesis;
}
///// permissioned functions
// deploy a staking reward contract for the staking token, and store the reward amount
// the reward will be distributed to the staking reward contract no sooner than the genesis
function deploy(
address stakingToken,
uint256 rewardAmount,
uint256 rewardsDuration
) public onlyOwner {
StakingRewardsInfo storage info =
stakingRewardsInfoByStakingToken[stakingToken];
require(
info.stakingRewards == address(0),
"StakingRewardsFactory::deploy: already deployed"
);
// Args on the StakingRewards
// address _owner,
// address _rewardsDistribution,
// address _rewardsToken,
// address _stakingToken,
// uint256 _rewardsDuration
info.stakingRewards = address(
new StakingRewards(
/*_rewardsDistribution=*/
owner(),
address(this),
rewardsToken,
stakingToken,
rewardsDuration
)
);
info.rewardAmount = rewardAmount;
stakingTokens.push(stakingToken);
}
// Fallback function to return money to reward distributer via pool deployer
// In case of issues or incorrect calls or errors
function refund(uint256 amount, address refundAddress) public onlyOwner {
require(
IERC20(rewardsToken).transfer(refundAddress, amount),
"StakingRewardsFactory::notifyRewardAmount: transfer failed"
);
}
///// permissionless functions
// call notifyRewardAmount for all staking tokens.
function notifyRewardAmounts() public {
require(
stakingTokens.length > 0,
"StakingRewardsFactory::notifyRewardAmounts: called before any deploys"
);
for (uint256 i = 0; i < stakingTokens.length; i++) {
notifyRewardAmount(stakingTokens[i]);
}
}
// notify reward amount for an individual staking token.
// this is a fallback in case the notifyRewardAmounts costs too much gas to call for all contracts
function notifyRewardAmount(address stakingToken) public {
require(
block.timestamp >= stakingRewardsGenesis,
"StakingRewardsFactory::notifyRewardAmount: not ready"
);
StakingRewardsInfo storage info =
stakingRewardsInfoByStakingToken[stakingToken];
require(
info.stakingRewards != address(0),
"StakingRewardsFactory::notifyRewardAmount: not deployed"
);
if (info.rewardAmount > 0) {
uint256 rewardAmount = info.rewardAmount;
info.rewardAmount = 0;
IERC20(rewardsToken).approve(info.stakingRewards, rewardAmount);
StakingRewards(info.stakingRewards).notifyRewardAmount(
rewardAmount,
address(this)
);
}
}
}
Read Contract
FASTGAS 0xdbbc4a57 → address
balanceOf 0x70a08231 → uint256
earned 0x008cc262 → uint256
getFastGas 0x904440bd → uint256
getRewardForDuration 0x1c1f78eb → uint256
lastPauseTime 0x91b4ded9 → uint256
lastTimeRewardApplicable 0x80faa57d → uint256
lastUpdateTime 0xc8f33c91 → uint256
nominatedOwner 0x53a47bb7 → address
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
periodFinish 0xebe2b12b → uint256
rewardPerToken 0xcd3daf9d → uint256
rewardPerTokenStored 0xdf136d65 → uint256
rewardRate 0x7b0a47ee → uint256
rewards 0x0700037d → uint256
rewardsDistribution 0x3fc6df6e → address
rewardsDuration 0x386a9525 → uint256
rewardsToken 0xd1af0c7d → address
stakingToken 0x72f702f3 → address
totalSupply 0x18160ddd → uint256
userRewardPerTokenPaid 0x8b876347 → uint256
Write Contract 11 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
exit 0xe9fad8ee
No parameters
getReward 0x3d18b912
No parameters
nominateNewOwner 0x1627540c
address _owner
notifyRewardAmount 0x68d53c43
uint256 reward
address rewardHolder
recoverERC20 0x8980f11f
address tokenAddress
uint256 tokenAmount
setPaused 0x16c38b3c
bool _paused
setRewardsDistribution 0x19762143
address _rewardsDistribution
setRewardsDuration 0xcc1a378f
uint256 _rewardsDuration
stake 0xa694fc3a
uint256 amount
withdraw 0x2e1a7d4d
uint256 amount
Recent Transactions
No transactions found for this address