Address Contract Partially Verified
Address
0xB99D38eB69214e493B1183FFA3d561FC9F75D519
Balance
0 ETH
Nonce
1
Code Size
5483 bytes
Creator
0xeE645cAd...4233 at tx 0xa387ac55...55cd86
Indexed Transactions
0
Contract Bytecode
5483 bytes
0x608060405234801561001057600080fd5b50600436106101365760003560e01c8063820356c5116100b2578063c96679fe11610081578063f40f0f5211610066578063f40f0f521461034b578063f69f1e4a1461037e578063f7c618c1146103b157610136565b8063c96679fe146102e5578063f2fde38b1461031857610136565b8063820356c5146102005780638da5cb5b146102a3578063a55d8257146102ab578063b6b55f25146102c857610136565b80634b6fdff1116101095780635c0f6bd1116100ee5780635c0f6bd1146101e857806361c90c06146101f0578063715018a6146101f857610136565b80634b6fdff11461018457806351ed6a30146101b757610136565b806321d570cf1461013b5780632986c0e5146101555780632e1a7d4d1461015d5780634ac8eb5f1461017c575b600080fd5b6101436103b9565b60408051918252519081900360200190f35b6101436103bf565b61017a6004803603602081101561017357600080fd5b50356103c5565b005b61014361055f565b6101436004803603602081101561019a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610565565b6101bf610577565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b610143610593565b61017a610599565b61017a6107c1565b61017a6004803603602081101561021657600080fd5b81019060208101813564010000000081111561023157600080fd5b82018360208201111561024357600080fd5b8035906020019184602083028401116401000000008311171561026557600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506108d8945050505050565b6101bf610914565b61017a600480360360208110156102c157600080fd5b5035610930565b61017a600480360360208110156102de57600080fd5b5035610a27565b610143600480360360208110156102fb57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610bc7565b61017a6004803603602081101561032e57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610bd9565b6101436004803603602081101561036157600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610d7a565b6101436004803603602081101561039457600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610f24565b6101bf610f36565b60095481565b60075481565b6103cd610f52565b6103d633610fd9565b600154604080517fa9059cbb00000000000000000000000000000000000000000000000000000000815233600482015260248101849052905173ffffffffffffffffffffffffffffffffffffffff9092169163a9059cbb916044808201926020929091908290030181600087803b15801561045057600080fd5b505af1158015610464573d6000803e3d6000fd5b505050506040513d602081101561047a57600080fd5b50516104e757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f7472616e73666572206661696c65640000000000000000000000000000000000604482015290519081900360640190fd5b3360009081526004602052604090205461050190826112ff565b3360009081526004602052604090205560055461051e90826112ff565b600555604080513381526020810183905281517f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364929181900390910190a150565b60055481565b60086020526000908152604090205481565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60035481565b6105a161137b565b73ffffffffffffffffffffffffffffffffffffffff166105bf610914565b73ffffffffffffffffffffffffffffffffffffffff161461064157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600254604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905160009273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b1580156106b257600080fd5b505afa1580156106c6573d6000803e3d6000fd5b505050506040513d60208110156106dc57600080fd5b505160015460025491925073ffffffffffffffffffffffffffffffffffffffff91821691161415610718576005546107159082906112ff565b90505b60025473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb61073e610914565b836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b15801561079257600080fd5b505af11580156107a6573d6000803e3d6000fd5b505050506040513d60208110156107bc57600080fd5b505050565b6107c961137b565b73ffffffffffffffffffffffffffffffffffffffff166107e7610914565b73ffffffffffffffffffffffffffffffffffffffff161461086957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b6108e0610f52565b60005b8151811015610910576109088282815181106108fb57fe5b6020026020010151610fd9565b6001016108e3565b5050565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b61093861137b565b73ffffffffffffffffffffffffffffffffffffffff16610956610914565b73ffffffffffffffffffffffffffffffffffffffff16146109d857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6109e0610f52565b6003805490829055604080518281526020810184905281517f2ced109ade5b38f636b63cec7b7f27685b64deac2adfdaa6d737890f268094da929181900390910190a15050565b610a2f610f52565b610a3833610fd9565b600154604080517f23b872dd00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101849052905173ffffffffffffffffffffffffffffffffffffffff909216916323b872dd916064808201926020929091908290030181600087803b158015610ab857600080fd5b505af1158015610acc573d6000803e3d6000fd5b505050506040513d6020811015610ae257600080fd5b5051610b4f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f7472616e7366657246726f6d206661696c656400000000000000000000000000604482015290519081900360640190fd5b33600090815260046020526040902054610b69908261137f565b33600090815260046020526040902055600554610b86908261137f565b600555604080513381526020810183905281517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c929181900390910190a150565b60066020526000908152604090205481565b610be161137b565b73ffffffffffffffffffffffffffffffffffffffff16610bff610914565b73ffffffffffffffffffffffffffffffffffffffff1614610c8157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116610ced576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806114ef6026913960400191505060405180910390fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600080610d92600954436112ff90919063ffffffff16565b90506000610dab600354836113fa90919063ffffffff16565b905060055460001415610de65750505073ffffffffffffffffffffffffffffffffffffffff8116600090815260086020526040902054610f1f565b600554600090610e0f90610e09846ec097ce7bc90715b34b9f10000000006113fa565b9061146d565b90506000610e288260075461137f90919063ffffffff16565b73ffffffffffffffffffffffffffffffffffffffff871660009081526006602052604081205491925090158015610e6157506000600754115b610e905773ffffffffffffffffffffffffffffffffffffffff8716600090815260066020526040902054610ea1565b6ec097ce7bc90715b34b9f10000000005b73ffffffffffffffffffffffffffffffffffffffff881660009081526004602052604081205491925082840391610eee906ec097ce7bc90715b34b9f100000000090610e099085906113fa565b73ffffffffffffffffffffffffffffffffffffffff8a16600090815260086020526040902054019750505050505050505b919050565b60046020526000908152604090205481565b60025473ffffffffffffffffffffffffffffffffffffffff1681565b6000610f69600954436112ff90919063ffffffff16565b905080610f765750610fd7565b6000610f8d600354836113fa90919063ffffffff16565b60055490915015610fd057600554600090610fbb90610e09846ec097ce7bc90715b34b9f10000000006113fa565b600754909150610fcb908261137f565b600755505b5050436009555b565b73ffffffffffffffffffffffffffffffffffffffff811660009081526006602052604090205415801561100e57506000600754115b1561104b5773ffffffffffffffffffffffffffffffffffffffff811660009081526006602052604090206ec097ce7bc90715b34b9f100000000090555b73ffffffffffffffffffffffffffffffffffffffff8116600090815260066020908152604080832080546007549182905560049093529083205491900391906110aa906ec097ce7bc90715b34b9f100000000090610e099085906113fa565b73ffffffffffffffffffffffffffffffffffffffff84166000908152600860205260409020549091506110dd908261137f565b73ffffffffffffffffffffffffffffffffffffffff80851660009081526008602090815260409182902084905560025482517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015292519316926370a08231926024808201939291829003018186803b15801561115f57600080fd5b505afa158015611173573d6000803e3d6000fd5b505050506040513d602081101561118957600080fd5b5051108015906111bd575073ffffffffffffffffffffffffffffffffffffffff831660009081526008602052604090205415155b156112a55760025473ffffffffffffffffffffffffffffffffffffffff84811660008181526008602090815260408083205481517fa9059cbb0000000000000000000000000000000000000000000000000000000081526004810195909552602485015251939094169363a9059cbb93604480850194929391928390030190829087803b15801561124d57600080fd5b505af1158015611261573d6000803e3d6000fd5b505050506040513d602081101561127757600080fd5b5051156112a55773ffffffffffffffffffffffffffffffffffffffff83166000908152600860205260408120555b600754604080518381526020810192909252805173ffffffffffffffffffffffffffffffffffffffff8616927f53118bff2fb56701752f5bf54053d24fb83cec92f9f6ce664b90c38a2991caa492908290030190a2505050565b60008282111561137057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b3390565b6000828201838110156113f357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b60008261140957506000611375565b8282028284828161141657fe5b04146113f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806115156021913960400191505060405180910390fd5b60008082116114dd57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816114e657fe5b04939250505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a26469706673582212208963485796f9c8ae68f26b6a6eb6a371d173423748dd9a0791872a52902bb22264736f6c63430007060033
Verified Source Code Partial Match
Compiler: v0.7.6+commit.7338295f
EVM: istanbul
Optimization: Yes (999999 runs)
SimpleStaking.sol 503 lines
/**
*Submitted for verification at BscScan.com on 2021-07-11
*/
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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.
*
* IMPORTANT: 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);
}
/*
* @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 GSN 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 payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @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 () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the 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 virtual 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 virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
/* users could create staking-reward model with this contract at single mode */
contract SimpleStaking is Ownable {
using SafeMath for uint;
uint constant doubleScale = 10 ** 36;
// stake token
IERC20 public stakeToken;
// reward token
IERC20 public rewardToken;
// the number of reward token distribution for each block
uint public rewardSpeed;
// user deposit
mapping(address => uint) public userCollateral;
uint public totalCollateral;
// use index to distribute reward token
// index is compound exponential
mapping(address => uint) public userIndex;
uint public index;
mapping(address => uint) public userAccrued;
// record latest block height of reward token distributed
uint public lastDistributedBlock;
/* event */
event Deposit(address user, uint amount);
event Withdraw(address user, uint amount);
event RewardSpeedUpdated(uint oldSpeed, uint newSpeed);
event RewardDistributed(address indexed user, uint delta, uint index);
constructor(IERC20 _stakeToken, IERC20 _rewardToken) Ownable(){
stakeToken = _stakeToken;
rewardToken = _rewardToken;
index = doubleScale;
}
function deposit(uint amount) public {
updateIndex();
distributeReward(msg.sender);
require(stakeToken.transferFrom(msg.sender, address(this), amount), "transferFrom failed");
userCollateral[msg.sender] = userCollateral[msg.sender].add(amount);
totalCollateral = totalCollateral.add(amount);
emit Deposit(msg.sender, amount);
}
function withdraw(uint amount) public {
updateIndex();
distributeReward(msg.sender);
require(stakeToken.transfer(msg.sender, amount), "transfer failed");
userCollateral[msg.sender] = userCollateral[msg.sender].sub(amount);
totalCollateral = totalCollateral.sub(amount);
emit Withdraw(msg.sender, amount);
}
function setRewardSpeed(uint speed) public onlyOwner {
updateIndex();
uint oldSpeed = rewardSpeed;
rewardSpeed = speed;
emit RewardSpeedUpdated(oldSpeed, speed);
}
function updateIndex() private {
uint blockDelta = block.number.sub(lastDistributedBlock);
if (blockDelta == 0) {
return;
}
uint rewardAccrued = blockDelta.mul(rewardSpeed);
if (totalCollateral > 0) {
uint indexDelta = rewardAccrued.mul(doubleScale).div(totalCollateral);
index = index.add(indexDelta);
}
lastDistributedBlock = block.number;
}
function distributeReward(address user) private {
if (userIndex[user] == 0 && index > 0) {
userIndex[user] = doubleScale;
}
uint indexDelta = index - userIndex[user];
userIndex[user] = index;
uint rewardDelta = indexDelta.mul(userCollateral[user]).div(doubleScale);
userAccrued[user] = userAccrued[user].add(rewardDelta);
if (rewardToken.balanceOf(address(this)) >= userAccrued[user] && userAccrued[user] > 0) {
if (rewardToken.transfer(user, userAccrued[user])) {
userAccrued[user] = 0;
}
}
emit RewardDistributed(user, rewardDelta, index);
}
function claimReward(address[] memory user) public {
updateIndex();
for (uint i = 0; i < user.length; i++) {
distributeReward(user[i]);
}
}
function withdrawRemainReward() public onlyOwner {
uint amount = rewardToken.balanceOf(address(this));
if (rewardToken == stakeToken) {
amount = amount.sub(totalCollateral);
}
rewardToken.transfer(owner(), amount);
}
function pendingReward(address user) public view returns (uint){
uint blockDelta = block.number.sub(lastDistributedBlock);
uint rewardAccrued = blockDelta.mul(rewardSpeed);
if (totalCollateral == 0) {
return userAccrued[user];
}
uint ratio = rewardAccrued.mul(doubleScale).div(totalCollateral);
uint currentIndex = index.add(ratio);
uint uIndex = userIndex[user] == 0 && index > 0 ? doubleScale : userIndex[user];
uint indexDelta = currentIndex - uIndex;
uint rewardDelta = indexDelta.mul(userCollateral[user]).div(doubleScale);
return rewardDelta + userAccrued[user];
}
}
Read Contract
index 0x2986c0e5 → uint256
lastDistributedBlock 0x21d570cf → uint256
owner 0x8da5cb5b → address
pendingReward 0xf40f0f52 → uint256
rewardSpeed 0x5c0f6bd1 → uint256
rewardToken 0xf7c618c1 → address
stakeToken 0x51ed6a30 → address
totalCollateral 0x4ac8eb5f → uint256
userAccrued 0x4b6fdff1 → uint256
userCollateral 0xf69f1e4a → uint256
userIndex 0xc96679fe → uint256
Write Contract 7 functions
These functions modify contract state and require a wallet transaction to execute.
claimReward 0x820356c5
address[] user
deposit 0xb6b55f25
uint256 amount
renounceOwnership 0x715018a6
No parameters
setRewardSpeed 0xa55d8257
uint256 speed
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x2e1a7d4d
uint256 amount
withdrawRemainReward 0x61c90c06
No parameters
Recent Transactions
No transactions found for this address