Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
0x60806040 | 10342570 | 1522 days ago | IN | 0 ETH | 0.03175713 |
Latest 25 internal transactions (View All)
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
ValidatorShareFactory
Compiler Version
v0.5.17+commit.d19bba13
Contract Source Code (Solidity)
/** *Submitted for verification at Etherscan.io on 2020-10-01 */ // File: openzeppelin-solidity/contracts/ownership/Ownable.sol pragma solidity ^0.5.2; /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner()); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. * @notice 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 Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: contracts/common/misc/ProxyStorage.sol pragma solidity ^0.5.2; contract ProxyStorage is Ownable { address internal proxyTo; } // File: contracts/common/misc/ERCProxy.sol /* * SPDX-License-Identitifer: MIT */ pragma solidity ^0.5.2; // See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-897.md interface ERCProxy { function proxyType() external pure returns (uint256 proxyTypeId); function implementation() external view returns (address codeAddr); } // File: contracts/common/misc/DelegateProxy.sol pragma solidity ^0.5.2; contract DelegateProxy is ERCProxy { function proxyType() external pure returns (uint256 proxyTypeId) { // Upgradeable proxy proxyTypeId = 2; } function implementation() external view returns (address); function delegatedFwd(address _dst, bytes memory _calldata) internal { // solium-disable-next-line security/no-inline-assembly assembly { let result := delegatecall( sub(gas, 10000), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0 ) let size := returndatasize let ptr := mload(0x40) returndatacopy(ptr, 0, size) // revert instead of invalid() bc if the underlying call failed with invalid() it already wasted gas. // if the call returned error data, forward it switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } } } // File: contracts/common/misc/UpgradableProxy.sol pragma solidity ^0.5.2; contract UpgradableProxy is DelegateProxy { event ProxyUpdated(address indexed _new, address indexed _old); event OwnerUpdate(address _new, address _old); bytes32 constant IMPLEMENTATION_SLOT = keccak256("matic.network.proxy.implementation"); bytes32 constant OWNER_SLOT = keccak256("matic.network.proxy.owner"); constructor(address _proxyTo) public { setOwner(msg.sender); setImplementation(_proxyTo); } function() external payable { // require(currentContract != 0, "If app code has not been set yet, do not call"); // Todo: filter out some calls or handle in the end fallback delegatedFwd(loadImplementation(), msg.data); } modifier onlyProxyOwner() { require(loadOwner() == msg.sender, "NOT_OWNER"); _; } function owner() external view returns(address) { return loadOwner(); } function loadOwner() internal view returns(address) { address _owner; bytes32 position = OWNER_SLOT; assembly { _owner := sload(position) } return _owner; } function implementation() external view returns (address) { return loadImplementation(); } function loadImplementation() internal view returns(address) { address _impl; bytes32 position = IMPLEMENTATION_SLOT; assembly { _impl := sload(position) } return _impl; } function transferOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0), "ZERO_ADDRESS"); emit OwnerUpdate(newOwner, loadOwner()); setOwner(newOwner); } function setOwner(address newOwner) private { bytes32 position = OWNER_SLOT; assembly { sstore(position, newOwner) } } function updateImplementation(address _newProxyTo) public onlyProxyOwner { require(_newProxyTo != address(0x0), "INVALID_PROXY_ADDRESS"); require(isContract(_newProxyTo), "DESTINATION_ADDRESS_IS_NOT_A_CONTRACT"); emit ProxyUpdated(_newProxyTo, loadImplementation()); setImplementation(_newProxyTo); } function updateAndCall(address _newProxyTo, bytes memory data) payable public onlyProxyOwner { updateImplementation(_newProxyTo); (bool success, bytes memory returnData) = address(this).call.value(msg.value)(data); require(success, string(returnData)); } function setImplementation(address _newProxyTo) private { bytes32 position = IMPLEMENTATION_SLOT; assembly { sstore(position, _newProxyTo) } } function isContract(address _target) internal view returns (bool) { if (_target == address(0)) { return false; } uint256 size; assembly { size := extcodesize(_target) } return size > 0; } } // File: contracts/common/governance/IGovernance.sol pragma solidity ^0.5.2; interface IGovernance { function update(address target, bytes calldata data) external; } // File: contracts/common/governance/Governable.sol pragma solidity ^0.5.2; contract Governable { IGovernance public governance; constructor(address _governance) public { governance = IGovernance(_governance); } modifier onlyGovernance() { require( msg.sender == address(governance), "Only governance contract is authorized" ); _; } } // File: contracts/root/withdrawManager/IWithdrawManager.sol pragma solidity ^0.5.2; contract IWithdrawManager { function createExitQueue(address token) external; function verifyInclusion( bytes calldata data, uint8 offset, bool verifyTxInclusion ) external view returns (uint256 age); function addExitToQueue( address exitor, address childToken, address rootToken, uint256 exitAmountOrTokenId, bytes32 txHash, bool isRegularExit, uint256 priority ) external; function addInput( uint256 exitId, uint256 age, address utxoOwner, address token ) external; function challengeExit( uint256 exitId, uint256 inputId, bytes calldata challengeData, address adjudicatorPredicate ) external; } // File: contracts/common/Registry.sol pragma solidity ^0.5.2; contract Registry is Governable { // @todo hardcode constants bytes32 private constant WETH_TOKEN = keccak256("wethToken"); bytes32 private constant DEPOSIT_MANAGER = keccak256("depositManager"); bytes32 private constant STAKE_MANAGER = keccak256("stakeManager"); bytes32 private constant VALIDATOR_SHARE = keccak256("validatorShare"); bytes32 private constant WITHDRAW_MANAGER = keccak256("withdrawManager"); bytes32 private constant CHILD_CHAIN = keccak256("childChain"); bytes32 private constant STATE_SENDER = keccak256("stateSender"); bytes32 private constant SLASHING_MANAGER = keccak256("slashingManager"); address public erc20Predicate; address public erc721Predicate; mapping(bytes32 => address) public contractMap; mapping(address => address) public rootToChildToken; mapping(address => address) public childToRootToken; mapping(address => bool) public proofValidatorContracts; mapping(address => bool) public isERC721; enum Type {Invalid, ERC20, ERC721, Custom} struct Predicate { Type _type; } mapping(address => Predicate) public predicates; event TokenMapped(address indexed rootToken, address indexed childToken); event ProofValidatorAdded(address indexed validator, address indexed from); event ProofValidatorRemoved(address indexed validator, address indexed from); event PredicateAdded(address indexed predicate, address indexed from); event PredicateRemoved(address indexed predicate, address indexed from); event ContractMapUpdated(bytes32 indexed key, address indexed previousContract, address indexed newContract); constructor(address _governance) public Governable(_governance) {} function updateContractMap(bytes32 _key, address _address) external onlyGovernance { emit ContractMapUpdated(_key, contractMap[_key], _address); contractMap[_key] = _address; } /** * @dev Map root token to child token * @param _rootToken Token address on the root chain * @param _childToken Token address on the child chain * @param _isERC721 Is the token being mapped ERC721 */ function mapToken( address _rootToken, address _childToken, bool _isERC721 ) external onlyGovernance { require(_rootToken != address(0x0) && _childToken != address(0x0), "INVALID_TOKEN_ADDRESS"); rootToChildToken[_rootToken] = _childToken; childToRootToken[_childToken] = _rootToken; isERC721[_rootToken] = _isERC721; IWithdrawManager(contractMap[WITHDRAW_MANAGER]).createExitQueue(_rootToken); emit TokenMapped(_rootToken, _childToken); } function addErc20Predicate(address predicate) public onlyGovernance { require(predicate != address(0x0), "Can not add null address as predicate"); erc20Predicate = predicate; addPredicate(predicate, Type.ERC20); } function addErc721Predicate(address predicate) public onlyGovernance { erc721Predicate = predicate; addPredicate(predicate, Type.ERC721); } function addPredicate(address predicate, Type _type) public onlyGovernance { require(predicates[predicate]._type == Type.Invalid, "Predicate already added"); predicates[predicate]._type = _type; emit PredicateAdded(predicate, msg.sender); } function removePredicate(address predicate) public onlyGovernance { require(predicates[predicate]._type != Type.Invalid, "Predicate does not exist"); delete predicates[predicate]; emit PredicateRemoved(predicate, msg.sender); } function getValidatorShareAddress() public view returns (address) { return contractMap[VALIDATOR_SHARE]; } function getWethTokenAddress() public view returns (address) { return contractMap[WETH_TOKEN]; } function getDepositManagerAddress() public view returns (address) { return contractMap[DEPOSIT_MANAGER]; } function getStakeManagerAddress() public view returns (address) { return contractMap[STAKE_MANAGER]; } function getSlashingManagerAddress() public view returns (address) { return contractMap[SLASHING_MANAGER]; } function getWithdrawManagerAddress() public view returns (address) { return contractMap[WITHDRAW_MANAGER]; } function getChildChainAndStateSender() public view returns (address, address) { return (contractMap[CHILD_CHAIN], contractMap[STATE_SENDER]); } function isTokenMapped(address _token) public view returns (bool) { return rootToChildToken[_token] != address(0x0); } function isTokenMappedAndIsErc721(address _token) public view returns (bool) { require(isTokenMapped(_token), "TOKEN_NOT_MAPPED"); return isERC721[_token]; } function isTokenMappedAndGetPredicate(address _token) public view returns (address) { if (isTokenMappedAndIsErc721(_token)) { return erc721Predicate; } return erc20Predicate; } function isChildTokenErc721(address childToken) public view returns (bool) { address rootToken = childToRootToken[childToken]; require(rootToken != address(0x0), "Child token is not mapped"); return isERC721[rootToken]; } } // File: contracts/staking/validatorShare/ValidatorShareProxy.sol pragma solidity ^0.5.2; contract ValidatorShareProxy is UpgradableProxy { constructor(address _registry) public UpgradableProxy(_registry) {} function loadImplementation() internal view returns (address) { return Registry(super.loadImplementation()).getValidatorShareAddress(); } } // File: openzeppelin-solidity/contracts/token/ERC20/IERC20.sol pragma solidity ^0.5.2; /** * @title ERC20 interface * @dev see https://eips.ethereum.org/EIPS/eip-20 */ interface IERC20 { function transfer(address to, uint256 value) external returns (bool); function approve(address spender, uint256 value) external returns (bool); function transferFrom(address from, address to, uint256 value) external returns (bool); function totalSupply() external view returns (uint256); function balanceOf(address who) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } // File: openzeppelin-solidity/contracts/math/SafeMath.sol pragma solidity ^0.5.2; /** * @title SafeMath * @dev Unsigned math operations with safety checks that revert on error */ library SafeMath { /** * @dev Multiplies two unsigned integers, reverts on 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); return c; } /** * @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a); uint256 c = a - b; return c; } /** * @dev Adds two unsigned integers, reverts on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a); return c; } /** * @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo), * reverts when dividing by zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0); return a % b; } } // File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol pragma solidity ^0.5.2; /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://eips.ethereum.org/EIPS/eip-20 * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. */ contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; uint256 private _totalSupply; /** * @dev Total number of tokens in existence */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return A uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token to a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * 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 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { _approve(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _transfer(from, to, value); _approve(from, msg.sender, _allowed[from][msg.sender].sub(value)); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when _allowed[msg.sender][spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue)); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when _allowed[msg.sender][spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue)); return true; } /** * @dev Transfer token for a specified addresses * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */ function _transfer(address from, address to, uint256 value) internal { require(to != address(0)); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); } /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */ function _mint(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Approve an address to spend another addresses' tokens. * @param owner The address that owns the tokens. * @param spender The address that will spend the tokens. * @param value The number of tokens that can be spent. */ function _approve(address owner, address spender, uint256 value) internal { require(spender != address(0)); require(owner != address(0)); _allowed[owner][spender] = value; emit Approval(owner, spender, value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _burn(account, value); _approve(account, msg.sender, _allowed[account][msg.sender].sub(value)); } } // File: contracts/common/tokens/ERC20NonTransferable.sol pragma solidity ^0.5.2; contract ERC20NonTransferable is ERC20 { function _transfer( address from, address to, uint256 value ) internal { revert("Disabled"); } } // File: contracts/common/lib/BytesLib.sol pragma solidity ^0.5.2; library BytesLib { function concat(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bytes memory) { bytes memory tempBytes; assembly { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // Store the length of the first bytes array at the beginning of // the memory for tempBytes. let length := mload(_preBytes) mstore(tempBytes, length) // Maintain a memory counter for the current write location in the // temp bytes array by adding the 32 bytes for the array length to // the starting location. let mc := add(tempBytes, 0x20) // Stop copying when the memory counter reaches the length of the // first bytes array. let end := add(mc, length) for { // Initialize a copy counter to the start of the _preBytes data, // 32 bytes into its memory. let cc := add(_preBytes, 0x20) } lt(mc, end) { // Increase both counters by 32 bytes each iteration. mc := add(mc, 0x20) cc := add(cc, 0x20) } { // Write the _preBytes data into the tempBytes memory 32 bytes // at a time. mstore(mc, mload(cc)) } // Add the length of _postBytes to the current length of tempBytes // and store it as the new length in the first 32 bytes of the // tempBytes memory. length := mload(_postBytes) mstore(tempBytes, add(length, mload(tempBytes))) // Move the memory counter back from a multiple of 0x20 to the // actual end of the _preBytes data. mc := end // Stop copying when the memory counter reaches the new combined // length of the arrays. end := add(mc, length) for { let cc := add(_postBytes, 0x20) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } // Update the free-memory pointer by padding our last write location // to 32 bytes: add 31 bytes to the end of tempBytes to move to the // next 32 byte block, then round down to the nearest multiple of // 32. If the sum of the length of the two arrays is zero then add // one before rounding down to leave a blank 32 bytes (the length block with 0). mstore( 0x40, and( add(add(end, iszero(add(length, mload(_preBytes)))), 31), not(31) // Round down to the nearest 32 bytes. ) ) } return tempBytes; } function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) { require(_bytes.length >= (_start + _length)); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add( add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)) ) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add( add( add(_bytes, lengthmod), mul(0x20, iszero(lengthmod)) ), _start ) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } // Pad a bytes array to 32 bytes function leftPad(bytes memory _bytes) internal pure returns (bytes memory) { // may underflow if bytes.length < 32. Hence using SafeMath.sub bytes memory newBytes = new bytes(SafeMath.sub(32, _bytes.length)); return concat(newBytes, _bytes); } function toBytes32(bytes memory b) internal pure returns (bytes32) { require(b.length >= 32, "Bytes array should atleast be 32 bytes"); bytes32 out; for (uint256 i = 0; i < 32; i++) { out |= bytes32(b[i] & 0xFF) >> (i * 8); } return out; } function toBytes4(bytes memory b) internal pure returns (bytes4 result) { assembly { result := mload(add(b, 32)) } } function fromBytes32(bytes32 x) internal pure returns (bytes memory) { bytes memory b = new bytes(32); for (uint256 i = 0; i < 32; i++) { b[i] = bytes1(uint8(uint256(x) / (2**(8 * (31 - i))))); } return b; } function fromUint(uint256 _num) internal pure returns (bytes memory _ret) { _ret = new bytes(32); assembly { mstore(add(_ret, 32), _num) } } function toUint(bytes memory _bytes, uint256 _start) internal pure returns (uint256) { require(_bytes.length >= (_start + 32)); uint256 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x20), _start)) } return tempUint; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= (_start + 20)); address tempAddress; assembly { tempAddress := div( mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000 ) } return tempAddress; } } // File: contracts/common/lib/ECVerify.sol pragma solidity ^0.5.2; library ECVerify { function ecrecovery(bytes32 hash, bytes memory sig) public pure returns (address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) { return address(0x0); } assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) v := and(mload(add(sig, 65)), 255) } // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) { v += 27; } if (v != 27 && v != 28) { return address(0x0); } // get address out of hash and signature address result = ecrecover(hash, v, r, s); // ecrecover returns zero on error require(result != address(0x0)); return result; } function ecrecovery(bytes32 hash, uint8 v, bytes32 r, bytes32 s) public pure returns (address) { // get address out of hash and signature address result = ecrecover(hash, v, r, s); // ecrecover returns zero on error require(result != address(0x0), "signature verification failed"); return result; } function ecverify(bytes32 hash, bytes memory sig, address signer) public pure returns (bool) { return signer == ecrecovery(hash, sig); } } // File: contracts/staking/StakingInfo.sol pragma solidity ^0.5.2; // dummy interface to avoid cyclic dependency contract IStakeManagerLocal { enum Status {Inactive, Active, Locked, Unstaked} struct Validator { uint256 amount; uint256 reward; uint256 activationEpoch; uint256 deactivationEpoch; uint256 jailTime; address signer; address contractAddress; Status status; } mapping(uint256 => Validator) public validators; bytes32 public accountStateRoot; uint256 public activeAmount; // delegation amount from validator contract uint256 public validatorRewards; function currentValidatorSetTotalStake() public view returns (uint256); // signer to Validator mapping function signerToValidator(address validatorAddress) public view returns (uint256); function isValidator(uint256 validatorId) public view returns (bool); } contract StakingInfo is Ownable { using SafeMath for uint256; mapping(uint256 => uint256) public validatorNonce; /// @dev Emitted when validator stakes in '_stakeFor()' in StakeManager. /// @param signer validator address. /// @param validatorId unique integer to identify a validator. /// @param nonce to synchronize the events in heimdal. /// @param activationEpoch validator's first epoch as proposer. /// @param amount staking amount. /// @param total total staking amount. /// @param signerPubkey public key of the validator event Staked( address indexed signer, uint256 indexed validatorId, uint256 nonce, uint256 indexed activationEpoch, uint256 amount, uint256 total, bytes signerPubkey ); /// @dev Emitted when validator unstakes in 'unstakeClaim()' /// @param user address of the validator. /// @param validatorId unique integer to identify a validator. /// @param amount staking amount. /// @param total total staking amount. event Unstaked( address indexed user, uint256 indexed validatorId, uint256 amount, uint256 total ); /// @dev Emitted when validator unstakes in '_unstake()'. /// @param user address of the validator. /// @param validatorId unique integer to identify a validator. /// @param nonce to synchronize the events in heimdal. /// @param deactivationEpoch last epoch for validator. /// @param amount staking amount. event UnstakeInit( address indexed user, uint256 indexed validatorId, uint256 nonce, uint256 deactivationEpoch, uint256 indexed amount ); /// @dev Emitted when the validator public key is updated in 'updateSigner()'. /// @param validatorId unique integer to identify a validator. /// @param nonce to synchronize the events in heimdal. /// @param oldSigner old address of the validator. /// @param newSigner new address of the validator. /// @param signerPubkey public key of the validator. event SignerChange( uint256 indexed validatorId, uint256 nonce, address indexed oldSigner, address indexed newSigner, bytes signerPubkey ); event Restaked(uint256 indexed validatorId, uint256 amount, uint256 total); event Jailed( uint256 indexed validatorId, uint256 indexed exitEpoch, address indexed signer ); event UnJailed(uint256 indexed validatorId, address indexed signer); event Slashed(uint256 indexed nonce, uint256 indexed amount); event ThresholdChange(uint256 newThreshold, uint256 oldThreshold); event DynastyValueChange(uint256 newDynasty, uint256 oldDynasty); event ProposerBonusChange( uint256 newProposerBonus, uint256 oldProposerBonus ); event RewardUpdate(uint256 newReward, uint256 oldReward); /// @dev Emitted when validator confirms the auction bid and at the time of restaking in confirmAuctionBid() and restake(). /// @param validatorId unique integer to identify a validator. /// @param nonce to synchronize the events in heimdal. /// @param newAmount the updated stake amount. event StakeUpdate( uint256 indexed validatorId, uint256 indexed nonce, uint256 indexed newAmount ); event ClaimRewards( uint256 indexed validatorId, uint256 indexed amount, uint256 indexed totalAmount ); event StartAuction( uint256 indexed validatorId, uint256 indexed amount, uint256 indexed auctionAmount ); event ConfirmAuction( uint256 indexed newValidatorId, uint256 indexed oldValidatorId, uint256 indexed amount ); event TopUpFee(address indexed user, uint256 indexed fee); event ClaimFee(address indexed user, uint256 indexed fee); // Delegator events event ShareMinted( uint256 indexed validatorId, address indexed user, uint256 indexed amount, uint256 tokens ); event ShareBurned( uint256 indexed validatorId, address indexed user, uint256 indexed amount, uint256 tokens ); event DelegatorClaimedRewards( uint256 indexed validatorId, address indexed user, uint256 indexed rewards ); event DelegatorRestaked( uint256 indexed validatorId, address indexed user, uint256 indexed totalStaked ); event DelegatorUnstaked( uint256 indexed validatorId, address indexed user, uint256 amount ); event UpdateCommissionRate( uint256 indexed validatorId, uint256 indexed newCommissionRate, uint256 indexed oldCommissionRate ); Registry public registry; modifier onlyValidatorContract(uint256 validatorId) { address _contract; (, , , , , , _contract, ) = IStakeManagerLocal( registry.getStakeManagerAddress() ) .validators(validatorId); require(_contract == msg.sender, "Invalid sender, not validator"); _; } modifier StakeManagerOrValidatorContract(uint256 validatorId) { address _contract; address _stakeManager = registry.getStakeManagerAddress(); (, , , , , , _contract, ) = IStakeManagerLocal(_stakeManager).validators( validatorId ); require(_contract == msg.sender || _stakeManager == msg.sender, "Invalid sender, not stake manager or validator contract"); _; } modifier onlyStakeManager() { require(registry.getStakeManagerAddress() == msg.sender, "Invalid sender, not stake manager"); _; } modifier onlySlashingManager() { require(registry.getSlashingManagerAddress() == msg.sender, "Invalid sender, not slashing manager"); _; } constructor(address _registry) public { registry = Registry(_registry); } function updateNonce( uint256[] calldata validatorIds, uint256[] calldata nonces ) external onlyOwner { require(validatorIds.length == nonces.length, "args length mismatch"); for (uint256 i = 0; i < validatorIds.length; ++i) { validatorNonce[validatorIds[i]] = nonces[i]; } } function logStaked( address signer, bytes memory signerPubkey, uint256 validatorId, uint256 activationEpoch, uint256 amount, uint256 total ) public onlyStakeManager { validatorNonce[validatorId] = validatorNonce[validatorId].add(1); emit Staked( signer, validatorId, validatorNonce[validatorId], activationEpoch, amount, total, signerPubkey ); } function logUnstaked( address user, uint256 validatorId, uint256 amount, uint256 total ) public onlyStakeManager { emit Unstaked(user, validatorId, amount, total); } function logUnstakeInit( address user, uint256 validatorId, uint256 deactivationEpoch, uint256 amount ) public onlyStakeManager { validatorNonce[validatorId] = validatorNonce[validatorId].add(1); emit UnstakeInit( user, validatorId, validatorNonce[validatorId], deactivationEpoch, amount ); } function logSignerChange( uint256 validatorId, address oldSigner, address newSigner, bytes memory signerPubkey ) public onlyStakeManager { validatorNonce[validatorId] = validatorNonce[validatorId].add(1); emit SignerChange( validatorId, validatorNonce[validatorId], oldSigner, newSigner, signerPubkey ); } function logRestaked(uint256 validatorId, uint256 amount, uint256 total) public onlyStakeManager { emit Restaked(validatorId, amount, total); } function logJailed(uint256 validatorId, uint256 exitEpoch, address signer) public onlyStakeManager { emit Jailed(validatorId, exitEpoch, signer); } function logUnjailed(uint256 validatorId, address signer) public onlyStakeManager { emit UnJailed(validatorId, signer); } function logSlashed(uint256 nonce, uint256 amount) public onlySlashingManager { emit Slashed(nonce, amount); } function logThresholdChange(uint256 newThreshold, uint256 oldThreshold) public onlyStakeManager { emit ThresholdChange(newThreshold, oldThreshold); } function logDynastyValueChange(uint256 newDynasty, uint256 oldDynasty) public onlyStakeManager { emit DynastyValueChange(newDynasty, oldDynasty); } function logProposerBonusChange( uint256 newProposerBonus, uint256 oldProposerBonus ) public onlyStakeManager { emit ProposerBonusChange(newProposerBonus, oldProposerBonus); } function logRewardUpdate(uint256 newReward, uint256 oldReward) public onlyStakeManager { emit RewardUpdate(newReward, oldReward); } function logStakeUpdate(uint256 validatorId) public StakeManagerOrValidatorContract(validatorId) { validatorNonce[validatorId] = validatorNonce[validatorId].add(1); emit StakeUpdate( validatorId, validatorNonce[validatorId], totalValidatorStake(validatorId) ); } function logClaimRewards( uint256 validatorId, uint256 amount, uint256 totalAmount ) public onlyStakeManager { emit ClaimRewards(validatorId, amount, totalAmount); } function logStartAuction( uint256 validatorId, uint256 amount, uint256 auctionAmount ) public onlyStakeManager { emit StartAuction(validatorId, amount, auctionAmount); } function logConfirmAuction( uint256 newValidatorId, uint256 oldValidatorId, uint256 amount ) public onlyStakeManager { emit ConfirmAuction(newValidatorId, oldValidatorId, amount); } function logTopUpFee(address user, uint256 fee) public onlyStakeManager { emit TopUpFee(user, fee); } function logClaimFee(address user, uint256 fee) public onlyStakeManager { emit ClaimFee(user, fee); } function getStakerDetails(uint256 validatorId) public view returns ( uint256 amount, uint256 reward, uint256 activationEpoch, uint256 deactivationEpoch, address signer, uint256 _status ) { IStakeManagerLocal stakeManager = IStakeManagerLocal( registry.getStakeManagerAddress() ); address _contract; IStakeManagerLocal.Status status; ( amount, reward, activationEpoch, deactivationEpoch, , signer, _contract, status ) = stakeManager.validators(validatorId); _status = uint256(status); if (_contract != address(0x0)) { reward += IStakeManagerLocal(_contract).validatorRewards(); } } function totalValidatorStake(uint256 validatorId) public view returns (uint256 validatorStake) { address contractAddress; (validatorStake, , , , , , contractAddress, ) = IStakeManagerLocal( registry.getStakeManagerAddress() ) .validators(validatorId); if (contractAddress != address(0x0)) { validatorStake += IStakeManagerLocal(contractAddress).activeAmount(); } } function getAccountStateRoot() public view returns (bytes32 accountStateRoot) { accountStateRoot = IStakeManagerLocal(registry.getStakeManagerAddress()) .accountStateRoot(); } function getValidatorContractAddress(uint256 validatorId) public view returns (address ValidatorContract) { (, , , , , , ValidatorContract, ) = IStakeManagerLocal( registry.getStakeManagerAddress() ) .validators(validatorId); } // validator Share contract logging func function logShareMinted( uint256 validatorId, address user, uint256 amount, uint256 tokens ) public onlyValidatorContract(validatorId) { emit ShareMinted(validatorId, user, amount, tokens); } function logShareBurned( uint256 validatorId, address user, uint256 amount, uint256 tokens ) public onlyValidatorContract(validatorId) { emit ShareBurned(validatorId, user, amount, tokens); } function logDelegatorClaimRewards( uint256 validatorId, address user, uint256 rewards ) public onlyValidatorContract(validatorId) { emit DelegatorClaimedRewards(validatorId, user, rewards); } function logDelegatorRestaked( uint256 validatorId, address user, uint256 totalStaked ) public onlyValidatorContract(validatorId) { emit DelegatorRestaked(validatorId, user, totalStaked); } function logDelegatorUnstaked(uint256 validatorId, address user, uint256 amount) public onlyValidatorContract(validatorId) { emit DelegatorUnstaked(validatorId, user, amount); } function logUpdateCommissionRate( uint256 validatorId, uint256 newCommissionRate, uint256 oldCommissionRate ) public onlyValidatorContract(validatorId) { emit UpdateCommissionRate( validatorId, newCommissionRate, oldCommissionRate ); } } // File: contracts/common/mixin/Lockable.sol pragma solidity ^0.5.2; contract Lockable { bool public locked; modifier onlyWhenUnlocked() { _assertUnlocked(); _; } function _assertUnlocked() private view { require(!locked, "locked"); } function lock() public { locked = true; } function unlock() public { locked = false; } } // File: contracts/common/mixin/OwnableLockable.sol pragma solidity ^0.5.2; contract OwnableLockable is Lockable, Ownable { function lock() public onlyOwner { super.lock(); } function unlock() public onlyOwner { super.unlock(); } } // File: contracts/staking/stakeManager/IStakeManager.sol pragma solidity ^0.5.2; contract IStakeManager { // validator replacement function startAuction( uint256 validatorId, uint256 amount, bool acceptDelegation, bytes calldata signerPubkey ) external; function confirmAuctionBid(uint256 validatorId, uint256 heimdallFee) external; function transferFunds( uint256 validatorId, uint256 amount, address delegator ) external returns (bool); function delegationDeposit( uint256 validatorId, uint256 amount, address delegator ) external returns (bool); function stake( uint256 amount, uint256 heimdallFee, bool acceptDelegation, bytes calldata signerPubkey ) external; function unstake(uint256 validatorId) external; function totalStakedFor(address addr) external view returns (uint256); function stakeFor( address user, uint256 amount, uint256 heimdallFee, bool acceptDelegation, bytes memory signerPubkey ) public; function checkSignatures( uint256 blockInterval, bytes32 voteHash, bytes32 stateRoot, address proposer, bytes memory sigs ) public returns (uint256); function updateValidatorState(uint256 validatorId, int256 amount) public; function ownerOf(uint256 tokenId) public view returns (address); function slash(bytes memory slashingInfoList) public returns (uint256); function validatorStake(uint256 validatorId) public view returns (uint256); function epoch() public view returns (uint256); function withdrawalDelay() public view returns (uint256); } // File: contracts/staking/validatorShare/IValidatorShare.sol pragma solidity ^0.5.2; // note this contract interface is only for stakeManager use contract IValidatorShare { function withdrawRewardsValidator() external returns (uint256); function addProposerBonus(uint256 _rewards, uint256 valStake) public; function withdrawRewards() public; function unstakeClaimTokens() public; function getLiquidRewards(address user) public view returns (uint256); function getActiveAmount() external view returns (uint256); function owner() public view returns (address); function restake() public; function updateRewards( uint256 _reward, uint256 _totalStake, uint256 validatorStake ) external returns (uint256); function unlockContract() external returns (uint256); function lockContract() external returns (uint256); function drain( address token, address payable destination, uint256 amount ) external; function slash(uint256 valPow, uint256 totalAmountToSlash) external returns (uint256); function updateDelegation(bool delegation) external; } // File: contracts/common/mixin/Initializable.sol pragma solidity ^0.5.2; contract Initializable { bool inited = false; modifier initializer() { require(!inited, "already inited"); inited = true; _; } } // File: contracts/staking/validatorShare/ValidatorShare.sol pragma solidity ^0.5.2; contract ValidatorShare is IValidatorShare, ERC20NonTransferable, OwnableLockable, Initializable { struct Delegator { uint256 shares; uint256 withdrawEpoch; } uint256 constant EXCHANGE_RATE_PRECISION = 100; uint256 constant MAX_COMMISION_RATE = 100; uint256 constant REWARD_PRECISION = 10**25; StakingInfo public stakingLogger; IStakeManager public stakeManager; uint256 public validatorId; uint256 public validatorRewards; uint256 public commissionRate; //last checkpoint where validator updated commission rate uint256 public lastCommissionUpdate; uint256 public minAmount = 10**18; uint256 public totalStake; uint256 public rewardPerShare; uint256 public activeAmount; bool public delegation = true; uint256 public withdrawPool; uint256 public withdrawShares; mapping(address => uint256) public amountStaked; mapping(address => Delegator) public delegators; mapping(address => uint256) public initalRewardPerShare; modifier onlyValidator() { require(stakeManager.ownerOf(validatorId) == msg.sender, "not validator"); _; } // onlyOwner will prevent this contract from initializing, since it's owner is going to be 0x0 address function initialize(uint256 _validatorId, address _stakingLogger, address _stakeManager) external initializer { validatorId = _validatorId; stakingLogger = StakingInfo(_stakingLogger); stakeManager = IStakeManager(_stakeManager); _transferOwnership(_stakeManager); minAmount = 10**18; delegation = true; } function updateCommissionRate(uint256 newCommissionRate) external onlyValidator { uint256 epoch = stakeManager.epoch(); uint256 _lastCommissionUpdate = lastCommissionUpdate; require( // withdrawalDelay == dynasty (_lastCommissionUpdate.add(stakeManager.withdrawalDelay()) <= epoch) || _lastCommissionUpdate == 0, // For initial setting of commission rate "Commission rate update cooldown period" ); require(newCommissionRate <= MAX_COMMISION_RATE, "Commission rate should be in range of 0-100"); stakingLogger.logUpdateCommissionRate(validatorId, newCommissionRate, commissionRate); commissionRate = newCommissionRate; lastCommissionUpdate = epoch; } function updateRewards(uint256 reward, uint256 checkpointStakePower, uint256 validatorStake) external onlyOwner returns (uint256) { /** restaking is simply buying more shares of pool but those needs to be nonswapable/transferrable(to prevent https://en.wikipedia.org/wiki/Tragedy_of_the_commons) - calculate rewards for validator stake + delgation - keep the validator rewards aside - take the commission out - add rewards to pool rewards - returns total active stake for validator */ uint256 combinedStakePower = validatorStake.add(activeAmount); // validator + delegation stake power uint256 rewards = combinedStakePower.mul(reward).div(checkpointStakePower); _updateRewards(rewards, validatorStake, combinedStakePower); return combinedStakePower; } function addProposerBonus(uint256 rewards, uint256 validatorStake) public onlyOwner { uint256 combinedStakePower = validatorStake.add(activeAmount); _updateRewards(rewards, validatorStake, combinedStakePower); } function _updateRewards(uint256 rewards, uint256 validatorStake, uint256 combinedStakePower) internal { uint256 _validatorRewards = validatorStake.mul(rewards).div(combinedStakePower); // add validator commission from delegation rewards if (commissionRate > 0) { _validatorRewards = _validatorRewards.add( rewards.sub(_validatorRewards).mul(commissionRate).div(MAX_COMMISION_RATE) ); } validatorRewards = validatorRewards.add(_validatorRewards); uint256 delegatorsRewards = rewards.sub(_validatorRewards); uint256 totalShares = totalSupply(); if (totalShares > 0) { rewardPerShare = rewardPerShare.add( delegatorsRewards.mul(REWARD_PRECISION).div(totalShares) ); } } function withdrawRewardsValidator() external onlyOwner returns (uint256) { uint256 _validatorRewards = validatorRewards; validatorRewards = 0; return _validatorRewards; } function exchangeRate() public view returns (uint256) { uint256 totalShares = totalSupply(); return totalShares == 0 ? EXCHANGE_RATE_PRECISION : activeAmount.mul(EXCHANGE_RATE_PRECISION).div(totalShares); } function withdrawExchangeRate() public view returns (uint256) { uint256 _withdrawShares = withdrawShares; return _withdrawShares == 0 ? EXCHANGE_RATE_PRECISION : withdrawPool.mul(EXCHANGE_RATE_PRECISION).div(_withdrawShares); } function buyVoucher(uint256 _amount, uint256 _minSharesToMint) public { _withdrawAndTransferReward(); uint256 amountToDeposit = _buyShares(_amount, _minSharesToMint); require(stakeManager.delegationDeposit(validatorId, amountToDeposit, msg.sender), "deposit failed"); } function restake() public { uint256 liquidReward = _withdrawReward(msg.sender); require(liquidReward >= minAmount, "Too small rewards to restake"); _buyShares(liquidReward, 0); stakingLogger.logDelegatorRestaked(validatorId, msg.sender, amountStaked[msg.sender]); } function _buyShares(uint256 _amount, uint256 _minSharesToMint) private onlyWhenUnlocked returns(uint256) { require(delegation, "Delegation is disabled"); uint256 rate = exchangeRate(); uint256 shares = _amount.mul(EXCHANGE_RATE_PRECISION).div(rate); require(shares >= _minSharesToMint, "Too much slippage"); require(delegators[msg.sender].shares == 0, "Ongoing exit"); _mint(msg.sender, shares); _amount = _amount.sub(_amount % rate.mul(shares).div(EXCHANGE_RATE_PRECISION)); totalStake = totalStake.add(_amount); amountStaked[msg.sender] = amountStaked[msg.sender].add(_amount); activeAmount = activeAmount.add(_amount); stakeManager.updateValidatorState(validatorId, int256(_amount)); StakingInfo logger = stakingLogger; logger.logShareMinted(validatorId, msg.sender, _amount, shares); logger.logStakeUpdate(validatorId); return _amount; } function sellVoucher(uint256 _minClaimAmount) public { uint256 shares = balanceOf(msg.sender); require(shares > 0, "Zero balance"); uint256 rate = exchangeRate(); uint256 _amount = rate.mul(shares).div(EXCHANGE_RATE_PRECISION); require(_amount >= _minClaimAmount, "Too much slippage"); _withdrawAndTransferReward(); _burn(msg.sender, shares); stakeManager.updateValidatorState(validatorId, -int256(_amount)); activeAmount = activeAmount.sub(_amount); uint256 _withdrawPoolShare = _amount.mul(EXCHANGE_RATE_PRECISION).div(withdrawExchangeRate()); withdrawPool = withdrawPool.add(_amount); withdrawShares = withdrawShares.add(_withdrawPoolShare); delegators[msg.sender] = Delegator({shares: _withdrawPoolShare, withdrawEpoch: stakeManager.epoch()}); amountStaked[msg.sender] = 0; StakingInfo logger = stakingLogger; logger.logShareBurned(validatorId, msg.sender, _amount, shares); logger.logStakeUpdate(validatorId); } function _withdrawReward(address user) private returns(uint256) { uint256 liquidRewards = getLiquidRewards(user); initalRewardPerShare[user] = rewardPerShare; return liquidRewards; } function _withdrawAndTransferReward() private returns(uint256) { uint256 liquidRewards = _withdrawReward(msg.sender); if (liquidRewards > 0) { require(stakeManager.transferFunds(validatorId, liquidRewards, msg.sender), "Insufficent rewards"); stakingLogger.logDelegatorClaimRewards(validatorId, msg.sender, liquidRewards); } return liquidRewards; } function withdrawRewards() public { uint256 rewards = _withdrawAndTransferReward(); require(rewards >= minAmount, "Too small rewards amount"); } function getLiquidRewards(address user) public view returns (uint256) { uint256 shares = balanceOf(user); if (shares == 0) { return 0; } return rewardPerShare.sub(initalRewardPerShare[user]).mul(shares).div(REWARD_PRECISION); } function unstakeClaimTokens() public { Delegator storage delegator = delegators[msg.sender]; uint256 shares = delegator.shares; require( delegator.withdrawEpoch.add(stakeManager.withdrawalDelay()) <= stakeManager.epoch() && shares > 0, "Incomplete withdrawal period" ); uint256 _amount = withdrawExchangeRate().mul(shares).div(EXCHANGE_RATE_PRECISION); withdrawShares = withdrawShares.sub(shares); withdrawPool = withdrawPool.sub(_amount); totalStake = totalStake.sub(_amount); require(stakeManager.transferFunds(validatorId, _amount, msg.sender), "Insufficent rewards"); stakingLogger.logDelegatorUnstaked(validatorId, msg.sender, _amount); delete delegators[msg.sender]; } function slash(uint256 valPow, uint256 totalAmountToSlash) external onlyOwner returns (uint256) { uint256 _withdrawPool = withdrawPool; uint256 delegationAmount = activeAmount.add(_withdrawPool); if (delegationAmount == 0) { return 0; } // total amount to be slashed from delegation pool (active + inactive) uint256 _amountToSlash = delegationAmount.mul(totalAmountToSlash).div(valPow.add(delegationAmount)); uint256 _amountToSlashWithdrawalPool = _withdrawPool.mul(_amountToSlash).div(delegationAmount); // slash inactive pool withdrawPool = _withdrawPool.sub(_amountToSlashWithdrawalPool); activeAmount = activeAmount.sub(_amountToSlash.sub(_amountToSlashWithdrawalPool)); return _amountToSlash; } function updateDelegation(bool _delegation) external onlyOwner { delegation = _delegation; } function drain( address token, address payable destination, uint256 amount ) external onlyOwner { if (token == address(0x0)) { destination.transfer(amount); } else { require(ERC20(token).transfer(destination, amount), "Drain failed"); } } function getActiveAmount() external view returns(uint256) { return activeAmount; } function unlockContract() external onlyOwner returns (uint256) { unlock(); return activeAmount; } function lockContract() external onlyOwner returns (uint256) { lock(); return activeAmount; } } // File: contracts/staking/validatorShare/ValidatorShareFactory.sol pragma solidity ^0.5.2; contract ValidatorShareFactory { /** - factory to create new validatorShare contracts */ function create(uint256 validatorId, address loggerAddress, address registry) public returns (address) { ValidatorShareProxy proxy = new ValidatorShareProxy(registry); proxy.transferOwnership(msg.sender); address proxyAddr = address(proxy); (bool success, bytes memory data) = proxyAddr.call.gas(gasleft())( abi.encodeWithSelector( ValidatorShare(proxyAddr).initialize.selector, validatorId, loggerAddress, msg.sender ) ); require(success, string(data)); return proxyAddr; } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"loggerAddress","type":"address"},{"internalType":"address","name":"registry","type":"address"}],"name":"create","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50610bcf806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d4ad267314610030575b600080fd5b6100646004803603606081101561004657600080fd5b508035906001600160a01b0360208201358116916040013516610080565b604080516001600160a01b039092168252519081900360200190f35b60008082604051610090906102b7565b6001600160a01b03909116815260405190819003602001906000f0801580156100bd573d6000803e3d6000fd5b506040805163f2fde38b60e01b815233600482015290519192506001600160a01b0383169163f2fde38b9160248082019260009290919082900301818387803b15801561010957600080fd5b505af115801561011d573d6000803e3d6000fd5b50505050600081905060006060826001600160a01b03165a60408051602481018c90526001600160a01b038b1660448201523360648083019190915282518083039091018152608490910182526020810180516001600160e01b0316630b4988fd60e41b17815291518151919290918291908083835b602083106101b25780518252601f199092019160209182019101610193565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038160008787f1925050503d8060008114610215576040519150601f19603f3d011682016040523d82523d6000602084013e61021a565b606091505b50915091508181906102aa5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561026f578181015183820152602001610257565b50505050905090810190601f16801561029c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5091979650505050505050565b6108d6806102c58339019056fe608060405234801561001057600080fd5b506040516108d63803806108d68339818101604052602081101561003357600080fd5b505180610048336001600160e01b0361006116565b61005a816001600160e01b0361009616565b50506100b8565b604080517f6d617469632e6e6574776f726b2e70726f78792e6f776e6572000000000000008152905190819003601901902055565b600060405180806108b460229139604051908190036022019020929092555050565b6107ed806100c76000396000f3fe6080604052600436106100555760003560e01c8063025b22bc1461009f5780634555d5c9146100d25780635c60da1b146100f95780638da5cb5b1461012a578063d88ca2c81461013f578063f2fde38b146101f5575b61009d610060610228565b6000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061029b92505050565b005b3480156100ab57600080fd5b5061009d600480360360208110156100c257600080fd5b50356001600160a01b03166102c3565b3480156100de57600080fd5b506100e76103fd565b60408051918252519081900360200190f35b34801561010557600080fd5b5061010e610402565b604080516001600160a01b039092168252519081900360200190f35b34801561013657600080fd5b5061010e610411565b61009d6004803603604081101561015557600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561018057600080fd5b82018360208201111561019257600080fd5b803590602001918460018302840111640100000000831117156101b457600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061041b945050505050565b34801561020157600080fd5b5061009d6004803603602081101561021857600080fd5b50356001600160a01b03166105b1565b60006102326106a3565b6001600160a01b0316631c9486ef6040518163ffffffff1660e01b815260040160206040518083038186803b15801561026a57600080fd5b505afa15801561027e573d6000803e3d6000fd5b505050506040513d602081101561029457600080fd5b5051905090565b600080825160208401856127105a03f43d604051816000823e8280156102bf578282f35b8282fd5b336102cc6106c9565b6001600160a01b031614610313576040805162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b604482015290519081900360640190fd5b6001600160a01b038116610366576040805162461bcd60e51b8152602060048201526015602482015274494e56414c49445f50524f58595f4144445245535360581b604482015290519081900360640190fd5b61036f816106fb565b6103aa5760405162461bcd60e51b81526004018080602001828103825260258152602001806107726025913960400191505060405180910390fd5b6103b2610228565b6001600160a01b0316816001600160a01b03167fd32d24edea94f55e932d9a008afc425a8561462d1b1f57bc6e508e9a6b9509e160405160405180910390a36103fa8161071e565b50565b600290565b600061040c610228565b905090565b600061040c6106c9565b336104246106c9565b6001600160a01b03161461046b576040805162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b604482015290519081900360640190fd5b610474826102c3565b60006060306001600160a01b031634846040518082805190602001908083835b602083106104b35780518252601f199092019160209182019101610494565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114610515576040519150601f19603f3d011682016040523d82523d6000602084013e61051a565b606091505b50915091508181906105aa5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561056f578181015183820152602001610557565b50505050905090810190601f16801561059c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5050505050565b336105ba6106c9565b6001600160a01b031614610601576040805162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b604482015290519081900360640190fd5b6001600160a01b03811661064b576040805162461bcd60e51b815260206004820152600c60248201526b5a45524f5f4144445245535360a01b604482015290519081900360640190fd5b7f343765429aea5a34b3ff6a3785a98a5abb2597aca87bfbb58632c173d585373a816106756106c9565b604080516001600160a01b03938416815291909216602082015281519081900390910190a16103fa81610740565b600080600060405180806107976022913960405190819003602201902054935050505090565b604080517836b0ba34b1973732ba3bb7b93597383937bc3c9737bbb732b960391b815290519081900360190190205490565b60006001600160a01b03821661071357506000610719565b50803b15155b919050565b6000604051808061079760229139604051908190036022019020929092555050565b604080517836b0ba34b1973732ba3bb7b93597383937bc3c9737bbb732b960391b815290519081900360190190205556fe44455354494e4154494f4e5f414444524553535f49535f4e4f545f415f434f4e54524143546d617469632e6e6574776f726b2e70726f78792e696d706c656d656e746174696f6ea265627a7a723158204e58170e48279b1cb90d113d92d52be59f280dddbca7b51d796c43ef066a09b064736f6c634300051100326d617469632e6e6574776f726b2e70726f78792e696d706c656d656e746174696f6ea265627a7a723158200bfaa3cbd55896115b097dcb624663a0433d5ee69487e6ea3020a610a3cb8b1064736f6c63430005110032
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d4ad267314610030575b600080fd5b6100646004803603606081101561004657600080fd5b508035906001600160a01b0360208201358116916040013516610080565b604080516001600160a01b039092168252519081900360200190f35b60008082604051610090906102b7565b6001600160a01b03909116815260405190819003602001906000f0801580156100bd573d6000803e3d6000fd5b506040805163f2fde38b60e01b815233600482015290519192506001600160a01b0383169163f2fde38b9160248082019260009290919082900301818387803b15801561010957600080fd5b505af115801561011d573d6000803e3d6000fd5b50505050600081905060006060826001600160a01b03165a60408051602481018c90526001600160a01b038b1660448201523360648083019190915282518083039091018152608490910182526020810180516001600160e01b0316630b4988fd60e41b17815291518151919290918291908083835b602083106101b25780518252601f199092019160209182019101610193565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038160008787f1925050503d8060008114610215576040519150601f19603f3d011682016040523d82523d6000602084013e61021a565b606091505b50915091508181906102aa5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561026f578181015183820152602001610257565b50505050905090810190601f16801561029c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5091979650505050505050565b6108d6806102c58339019056fe608060405234801561001057600080fd5b506040516108d63803806108d68339818101604052602081101561003357600080fd5b505180610048336001600160e01b0361006116565b61005a816001600160e01b0361009616565b50506100b8565b604080517f6d617469632e6e6574776f726b2e70726f78792e6f776e6572000000000000008152905190819003601901902055565b600060405180806108b460229139604051908190036022019020929092555050565b6107ed806100c76000396000f3fe6080604052600436106100555760003560e01c8063025b22bc1461009f5780634555d5c9146100d25780635c60da1b146100f95780638da5cb5b1461012a578063d88ca2c81461013f578063f2fde38b146101f5575b61009d610060610228565b6000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061029b92505050565b005b3480156100ab57600080fd5b5061009d600480360360208110156100c257600080fd5b50356001600160a01b03166102c3565b3480156100de57600080fd5b506100e76103fd565b60408051918252519081900360200190f35b34801561010557600080fd5b5061010e610402565b604080516001600160a01b039092168252519081900360200190f35b34801561013657600080fd5b5061010e610411565b61009d6004803603604081101561015557600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561018057600080fd5b82018360208201111561019257600080fd5b803590602001918460018302840111640100000000831117156101b457600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061041b945050505050565b34801561020157600080fd5b5061009d6004803603602081101561021857600080fd5b50356001600160a01b03166105b1565b60006102326106a3565b6001600160a01b0316631c9486ef6040518163ffffffff1660e01b815260040160206040518083038186803b15801561026a57600080fd5b505afa15801561027e573d6000803e3d6000fd5b505050506040513d602081101561029457600080fd5b5051905090565b600080825160208401856127105a03f43d604051816000823e8280156102bf578282f35b8282fd5b336102cc6106c9565b6001600160a01b031614610313576040805162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b604482015290519081900360640190fd5b6001600160a01b038116610366576040805162461bcd60e51b8152602060048201526015602482015274494e56414c49445f50524f58595f4144445245535360581b604482015290519081900360640190fd5b61036f816106fb565b6103aa5760405162461bcd60e51b81526004018080602001828103825260258152602001806107726025913960400191505060405180910390fd5b6103b2610228565b6001600160a01b0316816001600160a01b03167fd32d24edea94f55e932d9a008afc425a8561462d1b1f57bc6e508e9a6b9509e160405160405180910390a36103fa8161071e565b50565b600290565b600061040c610228565b905090565b600061040c6106c9565b336104246106c9565b6001600160a01b03161461046b576040805162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b604482015290519081900360640190fd5b610474826102c3565b60006060306001600160a01b031634846040518082805190602001908083835b602083106104b35780518252601f199092019160209182019101610494565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114610515576040519150601f19603f3d011682016040523d82523d6000602084013e61051a565b606091505b50915091508181906105aa5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561056f578181015183820152602001610557565b50505050905090810190601f16801561059c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5050505050565b336105ba6106c9565b6001600160a01b031614610601576040805162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b604482015290519081900360640190fd5b6001600160a01b03811661064b576040805162461bcd60e51b815260206004820152600c60248201526b5a45524f5f4144445245535360a01b604482015290519081900360640190fd5b7f343765429aea5a34b3ff6a3785a98a5abb2597aca87bfbb58632c173d585373a816106756106c9565b604080516001600160a01b03938416815291909216602082015281519081900390910190a16103fa81610740565b600080600060405180806107976022913960405190819003602201902054935050505090565b604080517836b0ba34b1973732ba3bb7b93597383937bc3c9737bbb732b960391b815290519081900360190190205490565b60006001600160a01b03821661071357506000610719565b50803b15155b919050565b6000604051808061079760229139604051908190036022019020929092555050565b604080517836b0ba34b1973732ba3bb7b93597383937bc3c9737bbb732b960391b815290519081900360190190205556fe44455354494e4154494f4e5f414444524553535f49535f4e4f545f415f434f4e54524143546d617469632e6e6574776f726b2e70726f78792e696d706c656d656e746174696f6ea265627a7a723158204e58170e48279b1cb90d113d92d52be59f280dddbca7b51d796c43ef066a09b064736f6c634300051100326d617469632e6e6574776f726b2e70726f78792e696d706c656d656e746174696f6ea265627a7a723158200bfaa3cbd55896115b097dcb624663a0433d5ee69487e6ea3020a610a3cb8b1064736f6c63430005110032
Deployed Bytecode Sourcemap
66650:756:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;66650:756:0;;;;;;;;;;;;;;;;;;;66758:645;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;66758:645:0;;;-1:-1:-1;;;;;66758:645:0;;;;;;;;;;;;:::i;:::-;;;;-1:-1:-1;;;;;66758:645:0;;;;;;;;;;;;;;;66852:7;66872:25;66924:8;66900:33;;;;;:::i;:::-;-1:-1:-1;;;;;66900:33:0;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;66946:35:0;;;-1:-1:-1;;;66946:35:0;;66970:10;66946:35;;;;;;66872:61;;-1:-1:-1;;;;;;66946:23:0;;;;;:35;;;;;-1:-1:-1;;66946:35:0;;;;;;;;-1:-1:-1;66946:23:0;:35;;;5:2:-1;;;;30:1;27;20:12;5:2;66946:35:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;66946:35:0;;;;66994:17;67022:5;66994:34;;67040:12;67054:17;67075:9;-1:-1:-1;;;;;67075:14:0;67094:9;67119:195;;;;;;;;;-1:-1:-1;;;;;67119:195:0;;;;;;67289:10;67119:195;;;;;;;;;;26:21:-1;;;22:32;;;6:49;;67119:195:0;;;;;;;25:18:-1;;61:17;;-1:-1;;;;;182:15;-1:-1;;;179:29;160:49;;67075:250:0;;;;67119:195;;67075:250;;;;25:18:-1;67075:250:0;;25:18:-1;36:153;66:2;61:3;58:11;36:153;;176:10;;164:23;;-1:-1;;139:12;;;;98:2;89:12;;;;114;36:153;;;274:1;267:3;263:2;259:12;254:3;250:22;246:30;315:4;311:9;305:3;299:10;295:26;356:4;350:3;344:10;340:21;389:7;380;377:20;372:3;365:33;3:399;;;67075:250:0;;;;;;;;;;;;;;;;;;;;;;;;;14:1:-1;21;16:31;;;;75:4;69:11;64:16;;144:4;140:9;133:4;115:16;111:27;107:43;104:1;100:51;94:4;87:65;169:16;166:1;159:27;225:16;222:1;215:4;212:1;208:12;193:49;7:242;;16:31;36:4;31:9;;7:242;;67039:286:0;;;;67344:7;67360:4;67336:30;;;;;-1:-1:-1;;;67336:30:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;23:1:-1;8:100;33:3;30:1;27:10;8:100;;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;;12:14;67336:30:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;67386:9:0;;66758:645;-1:-1:-1;;;;;;;66758:645:0:o;66650:756::-;;;;;;;;:::o
Swarm Source
bzzr://0bfaa3cbd55896115b097dcb624663a0433d5ee69487e6ea3020a610a3cb8b10
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.