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
|
|||||
---|---|---|---|---|---|---|---|---|---|
Initialize | 17768385 | 542 days ago | IN | 0 ETH | 0.00678112 |
View more zero value Internal Transactions in Advanced View mode
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:
StakeManager
Compiler Version
v0.5.17+commit.d19bba13
Contract Source Code (Solidity Standard Json-Input format)
pragma solidity 0.5.17; import {IERC20} from "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; import {Math} from "openzeppelin-solidity/contracts/math/Math.sol"; import {SafeMath} from "openzeppelin-solidity/contracts/math/SafeMath.sol"; import {RLPReader} from "solidity-rlp/contracts/RLPReader.sol"; import {BytesLib} from "../../common/lib/BytesLib.sol"; import {ECVerify} from "../../common/lib/ECVerify.sol"; import {Merkle} from "../../common/lib/Merkle.sol"; import {GovernanceLockable} from "../../common/mixin/GovernanceLockable.sol"; import {DelegateProxyForwarder} from "../../common/misc/DelegateProxyForwarder.sol"; import {Registry} from "../../common/Registry.sol"; import {IStakeManager} from "./IStakeManager.sol"; import {IValidatorShare} from "../validatorShare/IValidatorShare.sol"; import {ValidatorShare} from "../validatorShare/ValidatorShare.sol"; import {StakingInfo} from "../StakingInfo.sol"; import {StakingNFT} from "./StakingNFT.sol"; import {ValidatorShareFactory} from "../validatorShare/ValidatorShareFactory.sol"; import {StakeManagerStorage} from "./StakeManagerStorage.sol"; import {StakeManagerStorageExtension} from "./StakeManagerStorageExtension.sol"; import {IGovernance} from "../../common/governance/IGovernance.sol"; import {Initializable} from "../../common/mixin/Initializable.sol"; import {StakeManagerExtension} from "./StakeManagerExtension.sol"; contract StakeManager is StakeManagerStorage, Initializable, IStakeManager, DelegateProxyForwarder, StakeManagerStorageExtension { using SafeMath for uint256; using Merkle for bytes32; using RLPReader for bytes; using RLPReader for RLPReader.RLPItem; struct UnsignedValidatorsContext { uint256 unsignedValidatorIndex; uint256 validatorIndex; uint256[] unsignedValidators; address[] validators; uint256 totalValidators; } struct UnstakedValidatorsContext { uint256 deactivationEpoch; uint256[] deactivatedValidators; uint256 validatorIndex; } modifier onlyStaker(uint256 validatorId) { _assertStaker(validatorId); _; } function _assertStaker(uint256 validatorId) private view { require(NFTContract.ownerOf(validatorId) == msg.sender); } modifier onlyDelegation(uint256 validatorId) { _assertDelegation(validatorId); _; } function _assertDelegation(uint256 validatorId) private view { require(validators[validatorId].contractAddress == msg.sender, "Invalid contract address"); } constructor() public GovernanceLockable(address(0x0)) {} function initialize( address _registry, address _rootchain, address _token, address _NFTContract, address _stakingLogger, address _validatorShareFactory, address _governance, address _owner, address _extensionCode ) external initializer { require(isContract(_extensionCode), "auction impl incorrect"); extensionCode = _extensionCode; governance = IGovernance(_governance); registry = _registry; rootChain = _rootchain; token = IERC20(_token); NFTContract = StakingNFT(_NFTContract); logger = StakingInfo(_stakingLogger); validatorShareFactory = ValidatorShareFactory(_validatorShareFactory); _transferOwnership(_owner); WITHDRAWAL_DELAY = 80; // unit: epoch currentEpoch = 1; dynasty = 80; // unit: epoch 50 days CHECKPOINT_REWARD = 20188 * (10**18); // update via governance minDeposit = (10**18); // in ERC20 token minHeimdallFee = (10**18); // in ERC20 token checkPointBlockInterval = 5120; signerUpdateLimit = 100; validatorThreshold = 7; //128 NFTCounter = 1; auctionPeriod = (2**13) / 4; // 1 week in epochs proposerBonus = 10; // 10 % of total rewards delegationEnabled = true; } function isOwner() public view returns (bool) { address _owner; bytes32 position = keccak256("matic.network.proxy.owner"); assembly { _owner := sload(position) } return msg.sender == _owner; } /** Public View Methods */ function getRegistry() public view returns (address) { return registry; } /** @dev Owner of validator slot NFT */ function ownerOf(uint256 tokenId) public view returns (address) { return NFTContract.ownerOf(tokenId); } function epoch() public view returns (uint256) { return currentEpoch; } function withdrawalDelay() public view returns (uint256) { return WITHDRAWAL_DELAY; } function validatorStake(uint256 validatorId) public view returns (uint256) { return validators[validatorId].amount; } function getValidatorId(address user) public view returns (uint256) { return NFTContract.tokenOfOwnerByIndex(user, 0); } function delegatedAmount(uint256 validatorId) public view returns (uint256) { return validators[validatorId].delegatedAmount; } function delegatorsReward(uint256 validatorId) public view returns (uint256) { (, uint256 _delegatorsReward) = _evaluateValidatorAndDelegationReward(validatorId); return validators[validatorId].delegatorsReward.add(_delegatorsReward).sub(INITIALIZED_AMOUNT); } function validatorReward(uint256 validatorId) public view returns (uint256) { uint256 _validatorReward; if (validators[validatorId].deactivationEpoch == 0) { (_validatorReward, ) = _evaluateValidatorAndDelegationReward(validatorId); } return validators[validatorId].reward.add(_validatorReward).sub(INITIALIZED_AMOUNT); } function currentValidatorSetSize() public view returns (uint256) { return validatorState.stakerCount; } function currentValidatorSetTotalStake() public view returns (uint256) { return validatorState.amount; } function getValidatorContract(uint256 validatorId) public view returns (address) { return validators[validatorId].contractAddress; } function isValidator(uint256 validatorId) public view returns (bool) { return _isValidator( validators[validatorId].status, validators[validatorId].amount, validators[validatorId].deactivationEpoch, currentEpoch ); } function validatorNonce(uint256 validatorId) public view returns (uint256) { return logger.validatorNonce(validatorId); } /** Governance Methods */ // function setDelegationEnabled(bool enabled) public onlyGovernance { // delegationEnabled = enabled; // } // Housekeeping function. @todo remove later // function forceUnstake(uint256 validatorId) external onlyGovernance { // _unstake(validatorId, currentEpoch); // } function setCurrentEpoch(uint256 _currentEpoch) external onlyGovernance { currentEpoch = _currentEpoch; } function setStakingToken(address _token) public onlyGovernance { require(_token != address(0x0)); token = IERC20(_token); } /** @dev Change the number of validators required to allow a passed header root */ function updateValidatorThreshold(uint256 newThreshold) public onlyGovernance { require(newThreshold != 0); logger.logThresholdChange(newThreshold, validatorThreshold); validatorThreshold = newThreshold; } function updateCheckPointBlockInterval(uint256 _blocks) public onlyGovernance { require(_blocks != 0); checkPointBlockInterval = _blocks; } function updateCheckpointReward(uint256 newReward) public onlyGovernance { require(newReward != 0); logger.logRewardUpdate(newReward, CHECKPOINT_REWARD); CHECKPOINT_REWARD = newReward; } function updateCheckpointRewardParams( uint256 _rewardDecreasePerCheckpoint, uint256 _maxRewardedCheckpoints, uint256 _checkpointRewardDelta ) public onlyGovernance { delegatedFwd( extensionCode, abi.encodeWithSelector( StakeManagerExtension(extensionCode).updateCheckpointRewardParams.selector, _rewardDecreasePerCheckpoint, _maxRewardedCheckpoints, _checkpointRewardDelta ) ); } // New implementation upgrade function migrateValidatorsData(uint256 validatorIdFrom, uint256 validatorIdTo) public onlyOwner { delegatedFwd( extensionCode, abi.encodeWithSelector( StakeManagerExtension(extensionCode).migrateValidatorsData.selector, validatorIdFrom, validatorIdTo ) ); } function insertSigners(address[] memory _signers) public onlyOwner { signers = _signers; } /** @dev Users must exit before this update or all funds may get lost */ function updateValidatorContractAddress(uint256 validatorId, address newContractAddress) public onlyGovernance { require(IValidatorShare(newContractAddress).owner() == address(this)); validators[validatorId].contractAddress = newContractAddress; } function updateDynastyValue(uint256 newDynasty) public onlyGovernance { require(newDynasty > 0); logger.logDynastyValueChange(newDynasty, dynasty); dynasty = newDynasty; WITHDRAWAL_DELAY = newDynasty; auctionPeriod = newDynasty.div(4); replacementCoolDown = currentEpoch.add(auctionPeriod); } // Housekeeping function. @todo remove later function stopAuctions(uint256 forNCheckpoints) public onlyGovernance { replacementCoolDown = currentEpoch.add(forNCheckpoints); } function updateProposerBonus(uint256 newProposerBonus) public onlyGovernance { logger.logProposerBonusChange(newProposerBonus, proposerBonus); require(newProposerBonus <= MAX_PROPOSER_BONUS, "too big"); proposerBonus = newProposerBonus; } function updateSignerUpdateLimit(uint256 _limit) public onlyGovernance { signerUpdateLimit = _limit; } function updateMinAmounts(uint256 _minDeposit, uint256 _minHeimdallFee) public onlyGovernance { minDeposit = _minDeposit; minHeimdallFee = _minHeimdallFee; } function drainValidatorShares( uint256 validatorId, address tokenAddr, address payable destination, uint256 amount ) external onlyGovernance { address contractAddr = validators[validatorId].contractAddress; require(contractAddr != address(0x0)); IValidatorShare(contractAddr).drain(tokenAddr, destination, amount); } function drain(address destination, uint256 amount) external onlyGovernance { _transferToken(destination, amount); } function reinitialize( address _NFTContract, address _stakingLogger, address _validatorShareFactory, address _extensionCode ) external onlyGovernance { require(isContract(_extensionCode)); eventsHub = address(0x0); extensionCode = _extensionCode; NFTContract = StakingNFT(_NFTContract); logger = StakingInfo(_stakingLogger); validatorShareFactory = ValidatorShareFactory(_validatorShareFactory); } function setValidator( uint256 validatorId, address signer, uint256 amount, uint256 activationEpoch, uint256 delegatedAmount ) public onlyGovernance { _setValidator(validatorId, signer, amount, activationEpoch, delegatedAmount); } function forceDelValidator(uint256 validatorId) public onlyGovernance { validators[validatorId].deactivationEpoch = currentEpoch; validators[validatorId].status = Status.Unstaked; uint256 amount = validators[validatorId].amount; int256 delegationAmount = int256(validators[validatorId].delegatedAmount); updateTimeline(-(int256(amount) + delegationAmount), -1, 0); uint256 newTotalStaked = totalStaked.sub(amount + validators[validatorId].delegatedAmount); totalStaked = newTotalStaked; _removeSigner(validators[validatorId].signer); } /** Public Methods */ function topUpForFee(address user, uint256 heimdallFee) public onlyWhenUnlocked { // _transferAndTopUp(user, msg.sender, heimdallFee, 0); } function claimFee( uint256 accumFeeAmount, uint256 index, bytes memory proof ) public { //Ignoring other params because rewards' distribution is on chain // require( // keccak256(abi.encode(msg.sender, accumFeeAmount)).checkMembership(index, accountStateRoot, proof), // "Wrong acc proof" // ); // uint256 withdrawAmount = accumFeeAmount.sub(userFeeExit[msg.sender]); // _claimFee(msg.sender, withdrawAmount); // userFeeExit[msg.sender] = accumFeeAmount; // _transferToken(msg.sender, withdrawAmount); } function totalStakedFor(address user) external view returns (uint256) { if (user == address(0x0) || NFTContract.balanceOf(user) == 0) { return 0; } return validators[NFTContract.tokenOfOwnerByIndex(user, 0)].amount; } function startAuction( uint256 validatorId, uint256 amount, bool _acceptDelegation, bytes calldata _signerPubkey ) external onlyWhenUnlocked { // delegatedFwd( // extensionCode, // abi.encodeWithSelector( // StakeManagerExtension(extensionCode).startAuction.selector, // validatorId, // amount, // _acceptDelegation, // _signerPubkey // ) // ); } function confirmAuctionBid( uint256 validatorId, uint256 heimdallFee /** for new validator */ ) external onlyWhenUnlocked { // delegatedFwd( // extensionCode, // abi.encodeWithSelector( // StakeManagerExtension(extensionCode).confirmAuctionBid.selector, // validatorId, // heimdallFee, // address(this) // ) // ); } function dethroneAndStake( address auctionUser, uint256 heimdallFee, uint256 validatorId, uint256 auctionAmount, bool acceptDelegation, bytes calldata signerPubkey ) external { // require(msg.sender == address(this), "not allowed"); // // dethrone // _transferAndTopUp(auctionUser, auctionUser, heimdallFee, 0); // _unstake(validatorId, currentEpoch); // // uint256 newValidatorId = _stakeFor(auctionUser, auctionAmount, acceptDelegation, signerPubkey); // logger.logConfirmAuction(newValidatorId, validatorId, auctionAmount); } function unstake(uint256 validatorId) external onlyStaker(validatorId) { // require(validatorAuction[validatorId].amount == 0); // // Status status = validators[validatorId].status; // require( // validators[validatorId].activationEpoch > 0 && // validators[validatorId].deactivationEpoch == 0 && // (status == Status.Active || status == Status.Locked) // ); // // uint256 exitEpoch = currentEpoch.add(1); // notice period // _unstake(validatorId, exitEpoch); } function transferFunds( uint256 validatorId, uint256 amount, address delegator ) external returns (bool) { require( validators[validatorId].contractAddress == msg.sender || Registry(registry).getSlashingManagerAddress() == msg.sender, "not allowed" ); return token.transfer(delegator, amount); } function delegationDeposit( uint256 validatorId, uint256 amount, address delegator ) external onlyDelegation(validatorId) returns (bool) { return token.transferFrom(delegator, address(this), amount); } function stakeFor( address user, uint256 amount, uint256 heimdallFee, bool acceptDelegation, bytes memory signerPubkey ) public onlyWhenUnlocked { // require(currentValidatorSetSize() < validatorThreshold, "no more slots"); // require(amount >= minDeposit, "not enough deposit"); // _transferAndTopUp(user, msg.sender, heimdallFee, amount); // _stakeFor(user, amount, acceptDelegation, signerPubkey); } function unstakeClaim(uint256 validatorId) public onlyStaker(validatorId) { // uint256 deactivationEpoch = validators[validatorId].deactivationEpoch; // // can only claim stake back after WITHDRAWAL_DELAY // require( // deactivationEpoch > 0 && // deactivationEpoch.add(WITHDRAWAL_DELAY) <= currentEpoch && // validators[validatorId].status != Status.Unstaked // ); // // uint256 amount = validators[validatorId].amount; // uint256 newTotalStaked = totalStaked.sub(amount); // totalStaked = newTotalStaked; // // // claim last checkpoint reward if it was signed by validator // _liquidateRewards(validatorId, msg.sender); // // NFTContract.burn(validatorId); // // validators[validatorId].amount = 0; // validators[validatorId].jailTime = 0; // validators[validatorId].signer = address(0); // // signerToValidator[validators[validatorId].signer] = INCORRECT_VALIDATOR_ID; // validators[validatorId].status = Status.Unstaked; // // _transferToken(msg.sender, amount); // logger.logUnstaked(msg.sender, validatorId, amount, newTotalStaked); } function restake( uint256 validatorId, uint256 amount, bool stakeRewards ) public onlyWhenUnlocked onlyStaker(validatorId) { // require(validators[validatorId].deactivationEpoch == 0, "No restaking"); // // if (amount > 0) { // _transferTokenFrom(msg.sender, address(this), amount); // } // // _updateRewards(validatorId); // // if (stakeRewards) { // amount = amount.add(validators[validatorId].reward).sub(INITIALIZED_AMOUNT); // validators[validatorId].reward = INITIALIZED_AMOUNT; // } // // uint256 newTotalStaked = totalStaked.add(amount); // totalStaked = newTotalStaked; // validators[validatorId].amount = validators[validatorId].amount.add(amount); // // updateTimeline(int256(amount), 0, 0); // // logger.logStakeUpdate(validatorId); // logger.logRestaked(validatorId, validators[validatorId].amount, newTotalStaked); } function withdrawRewards(uint256 validatorId) public onlyStaker(validatorId) { // _updateRewards(validatorId); // _liquidateRewards(validatorId, msg.sender); } function migrateDelegation( uint256 fromValidatorId, uint256 toValidatorId, uint256 amount ) public { // allow to move to any non-foundation node // require(toValidatorId > 7, "Invalid migration"); // IValidatorShare(validators[fromValidatorId].contractAddress).migrateOut(msg.sender, amount); // IValidatorShare(validators[toValidatorId].contractAddress).migrateIn(msg.sender, amount); } function updateValidatorState(uint256 validatorId, int256 amount) public onlyDelegation(validatorId) { if (amount > 0) { // deposit during shares purchase require(delegationEnabled, "Delegation is disabled"); } updateTimeline(amount, 0, 0); if (amount >= 0) { increaseValidatorDelegatedAmount(validatorId, uint256(amount)); } else { decreaseValidatorDelegatedAmount(validatorId, uint256(amount * -1)); } } function increaseValidatorDelegatedAmount(uint256 validatorId, uint256 amount) private { validators[validatorId].delegatedAmount = validators[validatorId].delegatedAmount.add(amount); } function decreaseValidatorDelegatedAmount(uint256 validatorId, uint256 amount) public onlyDelegation(validatorId) { validators[validatorId].delegatedAmount = validators[validatorId].delegatedAmount.sub(amount); } function updateSigner(uint256 validatorId, bytes memory signerPubkey) public onlyStaker(validatorId) { // address signer = _getAndAssertSigner(signerPubkey); // uint256 _currentEpoch = currentEpoch; // require(_currentEpoch >= latestSignerUpdateEpoch[validatorId].add(signerUpdateLimit), "Not allowed"); // // address currentSigner = validators[validatorId].signer; // // update signer event // logger.logSignerChange(validatorId, currentSigner, signer, signerPubkey); // // signerToValidator[currentSigner] = INCORRECT_VALIDATOR_ID; // signerToValidator[signer] = validatorId; // validators[validatorId].signer = signer; // _updateSigner(currentSigner, signer); // // // reset update time to current time // latestSignerUpdateEpoch[validatorId] = _currentEpoch; } function checkSignatures( uint256 blockInterval, uint256 epoch, bytes32 voteHash, bytes32 stateRoot, address proposer, uint256[3][] calldata sigs ) external onlyRootChain returns (uint256) { currentEpoch = epoch; uint256 _currentEpoch = currentEpoch; uint256 signedStakePower; address lastAdd; uint256 totalStakers = validatorState.stakerCount; UnsignedValidatorsContext memory unsignedCtx; unsignedCtx.unsignedValidators = new uint256[](signers.length + totalStakers); unsignedCtx.validators = signers; unsignedCtx.validatorIndex = 0; unsignedCtx.totalValidators = signers.length; UnstakedValidatorsContext memory unstakeCtx; unstakeCtx.deactivatedValidators = new uint256[](signers.length + totalStakers); for (uint256 i = 0; i < sigs.length; ++i) { address signer = ECVerify.ecrecovery(voteHash, sigs[i]); if (signer == lastAdd) { // if signer signs twice, just skip this signature continue; } if (signer < lastAdd) { // if signatures are out of order - break out, it is not possible to keep track of unsigned validators break; } uint256 validatorId = signerToValidator[signer]; uint256 amount = validators[validatorId].amount; Status status = validators[validatorId].status; unstakeCtx.deactivationEpoch = validators[validatorId].deactivationEpoch; if (_isValidator(status, amount, unstakeCtx.deactivationEpoch, _currentEpoch)) { lastAdd = signer; signedStakePower = signedStakePower.add(validators[validatorId].delegatedAmount).add(amount); if (unstakeCtx.deactivationEpoch != 0) { // this validator not a part of signers list anymore unstakeCtx.deactivatedValidators[unstakeCtx.validatorIndex] = validatorId; unstakeCtx.validatorIndex++; } else { unsignedCtx = _fillUnsignedValidators(unsignedCtx, signer); } } else if (status == Status.Locked) { // TODO fix double unsignedValidators appearance // make sure that jailed validator doesn't get his rewards too unsignedCtx.unsignedValidators[unsignedCtx.unsignedValidatorIndex] = validatorId; unsignedCtx.unsignedValidatorIndex++; unsignedCtx.validatorIndex++; } } // find the rest of validators without signature unsignedCtx = _fillUnsignedValidators(unsignedCtx, address(0)); return _increaseRewardAndAssertConsensus( blockInterval, proposer, signedStakePower, stateRoot, unsignedCtx.unsignedValidators, unsignedCtx.unsignedValidatorIndex, unstakeCtx.deactivatedValidators, unstakeCtx.validatorIndex ); } function updateCommissionRate(uint256 validatorId, uint256 newCommissionRate) external onlyStaker(validatorId) { // _updateRewards(validatorId); // // delegatedFwd( // extensionCode, // abi.encodeWithSelector( // StakeManagerExtension(extensionCode).updateCommissionRate.selector, // validatorId, // newCommissionRate // ) // ); } function withdrawDelegatorsReward(uint256 validatorId) public onlyDelegation(validatorId) returns (uint256) { // _updateRewards(validatorId); uint256 totalReward = 0; //validators[validatorId].delegatorsReward.sub(INITIALIZED_AMOUNT); // validators[validatorId].delegatorsReward = INITIALIZED_AMOUNT; return totalReward; } function slash(bytes calldata _slashingInfoList) external returns (uint256) { // require(Registry(registry).getSlashingManagerAddress() == msg.sender, "Not slash manager"); // // RLPReader.RLPItem[] memory slashingInfoList = _slashingInfoList.toRlpItem().toList(); // int256 valJailed; // uint256 jailedAmount; uint256 totalAmount; // uint256 i; // // for (; i < slashingInfoList.length; i++) { // RLPReader.RLPItem[] memory slashData = slashingInfoList[i].toList(); // // uint256 validatorId = slashData[0].toUint(); // _updateRewards(validatorId); // // uint256 _amount = slashData[1].toUint(); // totalAmount = totalAmount.add(_amount); // // address delegationContract = validators[validatorId].contractAddress; // if (delegationContract != address(0x0)) { // uint256 delSlashedAmount = // IValidatorShare(delegationContract).slash( // validators[validatorId].amount, // validators[validatorId].delegatedAmount, // _amount // ); // _amount = _amount.sub(delSlashedAmount); // } // // uint256 validatorStakeSlashed = validators[validatorId].amount.sub(_amount); // validators[validatorId].amount = validatorStakeSlashed; // // if (validatorStakeSlashed == 0) { // _unstake(validatorId, currentEpoch); // } else if (slashData[2].toBoolean()) { // jailedAmount = jailedAmount.add(_jail(validatorId, 1)); // valJailed++; // } // } // // //update timeline // updateTimeline(-int256(totalAmount.add(jailedAmount)), -valJailed, 0); return totalAmount; } function unjail(uint256 validatorId) public onlyStaker(validatorId) { // require(validators[validatorId].status == Status.Locked, "Not jailed"); // require(validators[validatorId].deactivationEpoch == 0, "Already unstaking"); // // uint256 _currentEpoch = currentEpoch; // require(validators[validatorId].jailTime <= _currentEpoch, "Incomplete jail period"); // // uint256 amount = validators[validatorId].amount; // require(amount >= minDeposit); // // address delegationContract = validators[validatorId].contractAddress; // if (delegationContract != address(0x0)) { // IValidatorShare(delegationContract).unlock(); // } // // // undo timeline so that validator is normal validator // updateTimeline(int256(amount.add(validators[validatorId].delegatedAmount)), 1, 0); // // validators[validatorId].status = Status.Active; // // address signer = validators[validatorId].signer; // logger.logUnjailed(validatorId, signer); } function updateTimeline( int256 amount, int256 stakerCount, uint256 targetEpoch ) internal { if (targetEpoch == 0) { // update total stake and validator count if (amount > 0) { validatorState.amount = validatorState.amount.add(uint256(amount)); } else if (amount < 0) { validatorState.amount = validatorState.amount.sub(uint256(amount * -1)); } if (stakerCount > 0) { validatorState.stakerCount = validatorState.stakerCount.add(uint256(stakerCount)); } else if (stakerCount < 0) { validatorState.stakerCount = validatorState.stakerCount.sub(uint256(stakerCount * -1)); } } else { validatorStateChanges[targetEpoch].amount += amount; validatorStateChanges[targetEpoch].stakerCount += stakerCount; } } function updateValidatorDelegation(bool delegation) external { uint256 validatorId = signerToValidator[msg.sender]; require( _isValidator( validators[validatorId].status, validators[validatorId].amount, validators[validatorId].deactivationEpoch, currentEpoch ), "not validator" ); address contractAddr = validators[validatorId].contractAddress; require(contractAddr != address(0x0), "Delegation is disabled"); IValidatorShare(contractAddr).updateDelegation(delegation); } function validatorJoin( bytes calldata data, uint[3][] calldata sigs ) external { (uint256 validatorId, uint256 nonce, uint256 amount, uint256 activationEpoch, uint256 delegatedAmount, address signer) = abi .decode(data, (uint256, uint256, uint256, uint256, uint256, address)); uint256 stakeNonce = logger.getValidatorNonce(validatorId).add(1); require(stakeNonce == nonce, "Invalid staking nonce"); uint[3][] memory siglist = sigs; require(_verifyConsensus(keccak256(abi.encodePacked(bytes(hex"01"), data)), siglist), "2/3+1 Power required"); _setValidator(validatorId, signer, amount, activationEpoch, delegatedAmount); logger.logStakeAck(validatorId); } function validatorExit( bytes calldata data, uint[3][] calldata sigs ) external { (uint256 validatorId, uint256 nonce, uint256 deactivationEpoch) = abi .decode(data, (uint256, uint256, uint256)); uint256 stakeNonce = logger.getValidatorNonce(validatorId).add(1); require(stakeNonce == nonce, "Invalid staking nonce"); uint[3][] memory siglist = sigs; require(_verifyConsensus(keccak256(abi.encodePacked(bytes(hex"01"), data)), siglist), "2/3+1 Power required"); validators[validatorId].deactivationEpoch = deactivationEpoch; uint256 amount = validators[validatorId].amount; // unbond all delegators in future int256 delegationAmount = int256(validators[validatorId].delegatedAmount); _removeSigner(validators[validatorId].signer); updateTimeline(-(int256(amount) + delegationAmount), -1, 0); uint256 newTotalStaked = totalStaked.sub(amount + validators[validatorId].delegatedAmount); totalStaked = newTotalStaked; logger.logStakeAck(validatorId); } function signerUpdate( bytes calldata data, uint[3][] calldata sigs ) external { (uint256 validatorId, uint256 nonce, address signer) = abi .decode(data, (uint256, uint256, address)); uint256 stakeNonce = logger.getValidatorNonce(validatorId).add(1); require(stakeNonce == nonce, "Invalid staking nonce"); uint[3][] memory siglist = sigs; require(_verifyConsensus(keccak256(abi.encodePacked(bytes(hex"01"), data)), siglist), "2/3+1 Power required"); address currentSigner = validators[validatorId].signer; // update signer event // bytes memory signerPubkey; // logger.logSignerChange(validatorId, currentSigner, signer, signerPubkey); signerToValidator[currentSigner] = INCORRECT_VALIDATOR_ID; signerToValidator[signer] = validatorId; validators[validatorId].signer = signer; _updateSigner(currentSigner, signer); logger.logStakeAck(validatorId); } function stakeUpdate( bytes calldata data, uint[3][] calldata sigs ) external { (uint256 validatorId, uint256 nonce, uint256 newAmount) = abi .decode(data, (uint256, uint256, uint256)); uint256 stakeNonce = logger.getValidatorNonce(validatorId).add(1); require(stakeNonce == nonce, "Invalid staking nonce"); uint[3][] memory siglist = sigs; require(_verifyConsensus(keccak256(abi.encodePacked(bytes(hex"01"), data)), siglist), "2/3+1 Power required"); int256 updateAmount = int256(newAmount) - int256(validators[validatorId].amount); validators[validatorId].amount = newAmount; updateTimeline(updateAmount, 0, 0); if (updateAmount > 0) { uint256 newTotalStaked = totalStaked.add(uint256(updateAmount)); totalStaked = newTotalStaked; } else if (updateAmount < 0) { uint256 newTotalStaked = totalStaked.add(uint256(updateAmount * -1)); totalStaked = newTotalStaked; } logger.logStakeAck(validatorId); } /** Private Methods */ function _getAndAssertSigner(bytes memory pub) private view returns (address) { require(pub.length == 64, "not pub"); address signer = address(uint160(uint256(keccak256(pub)))); require(signer != address(0) && signerToValidator[signer] == 0, "Invalid signer"); return signer; } function _isValidator( Status status, uint256 amount, uint256 deactivationEpoch, uint256 _currentEpoch ) private pure returns (bool) { return (amount > 0 && (deactivationEpoch == 0 || deactivationEpoch > _currentEpoch) && status == Status.Active); } function _fillUnsignedValidators(UnsignedValidatorsContext memory context, address signer) private view returns(UnsignedValidatorsContext memory) { while (context.validatorIndex < context.totalValidators && context.validators[context.validatorIndex] != signer) { context.unsignedValidators[context.unsignedValidatorIndex] = signerToValidator[context.validators[context.validatorIndex]]; context.unsignedValidatorIndex++; context.validatorIndex++; } context.validatorIndex++; return context; } function _calculateCheckpointReward( uint256 blockInterval, uint256 signedStakePower, uint256 currentTotalStake ) internal returns (uint256) { // checkpoint rewards are based on BlockInterval multiplied on `CHECKPOINT_REWARD` // for bigger checkpoints reward is reduced by rewardDecreasePerCheckpoint for each subsequent interval // for smaller checkpoints // if interval is 50% of checkPointBlockInterval then reward R is half of `CHECKPOINT_REWARD` // and then stakePower is 90% of currentValidatorSetTotalStake then final reward is 90% of R uint256 targetBlockInterval = checkPointBlockInterval; uint256 ckpReward = CHECKPOINT_REWARD; uint256 fullIntervals = Math.min(blockInterval / targetBlockInterval, maxRewardedCheckpoints); // only apply to full checkpoints if (fullIntervals > 0 && fullIntervals != prevBlockInterval) { if (prevBlockInterval != 0) { // give more reward for faster and less for slower checkpoint uint256 delta = (ckpReward * checkpointRewardDelta / CHK_REWARD_PRECISION); if (prevBlockInterval > fullIntervals) { // checkpoint is faster ckpReward += delta; } else { ckpReward -= delta; } } prevBlockInterval = fullIntervals; } uint256 reward; if (blockInterval > targetBlockInterval) { // count how many full intervals uint256 _rewardDecreasePerCheckpoint = rewardDecreasePerCheckpoint; // calculate reward for full intervals reward = ckpReward.mul(fullIntervals).sub(ckpReward.mul(((fullIntervals - 1) * fullIntervals / 2).mul(_rewardDecreasePerCheckpoint)).div(CHK_REWARD_PRECISION)); // adjust block interval, in case last interval is not full blockInterval = blockInterval.sub(fullIntervals.mul(targetBlockInterval)); // adjust checkpoint reward by the amount it suppose to decrease ckpReward = ckpReward.sub(ckpReward.mul(fullIntervals).mul(_rewardDecreasePerCheckpoint).div(CHK_REWARD_PRECISION)); } // give proportionally less for the rest reward = reward.add(blockInterval.mul(ckpReward).div(targetBlockInterval)); reward = reward.mul(signedStakePower).div(currentTotalStake); return reward; } function _increaseRewardAndAssertConsensus( uint256 blockInterval, address proposer, uint256 signedStakePower, bytes32 stateRoot, uint256[] memory unsignedValidators, uint256 totalUnsignedValidators, uint256[] memory deactivatedValidators, uint256 totalDeactivatedValidators ) private returns (uint256) { uint256 currentTotalStake = validatorState.amount; require(signedStakePower >= currentTotalStake.mul(2).div(3).add(1), "2/3+1 non-majority!"); uint256 reward = _calculateCheckpointReward(blockInterval, signedStakePower, currentTotalStake); uint256 _proposerBonus = reward.mul(proposerBonus).div(MAX_PROPOSER_BONUS); uint256 proposerId = signerToValidator[proposer]; Validator storage _proposer = validators[proposerId]; _proposer.reward = _proposer.reward.add(_proposerBonus); // update stateMerkleTree root for accounts balance on heimdall chain accountStateRoot = stateRoot; uint256 newRewardPerStake = rewardPerStake.add(reward.sub(_proposerBonus).mul(REWARD_PRECISION).div(signedStakePower)); // evaluate rewards for validator who did't sign and set latest reward per stake to new value to avoid them from getting new rewards. _updateValidatorsRewards(unsignedValidators, totalUnsignedValidators, newRewardPerStake); // distribute rewards between signed validators rewardPerStake = newRewardPerStake; // evaluate rewards for unstaked validators to avoid getting new rewards until they claim their stake _updateValidatorsRewards(deactivatedValidators, totalDeactivatedValidators, newRewardPerStake); _finalizeCommit(); return reward; } function _updateValidatorsRewards( uint256[] memory unsignedValidators, uint256 totalUnsignedValidators, uint256 newRewardPerStake ) private { uint256 currentRewardPerStake = rewardPerStake; for (uint256 i = 0; i < totalUnsignedValidators; ++i) { _updateRewardsAndCommit(unsignedValidators[i], currentRewardPerStake, newRewardPerStake); } } function _updateRewardsAndCommit( uint256 validatorId, uint256 currentRewardPerStake, uint256 newRewardPerStake ) private { uint256 initialRewardPerStake = validators[validatorId].initialRewardPerStake; // attempt to save gas in case if rewards were updated previosuly if (initialRewardPerStake < currentRewardPerStake) { uint256 validatorsStake = validators[validatorId].amount; uint256 delegatedAmount = validators[validatorId].delegatedAmount; if (delegatedAmount > 0) { uint256 combinedStakePower = validatorsStake.add(delegatedAmount); _increaseValidatorRewardWithDelegation( validatorId, validatorsStake, delegatedAmount, _getEligibleValidatorReward( validatorId, combinedStakePower, currentRewardPerStake, initialRewardPerStake ) ); } else { _increaseValidatorReward( validatorId, _getEligibleValidatorReward( validatorId, validatorsStake, currentRewardPerStake, initialRewardPerStake ) ); } } if (newRewardPerStake > initialRewardPerStake) { validators[validatorId].initialRewardPerStake = newRewardPerStake; } } function _updateRewards(uint256 validatorId) private { _updateRewardsAndCommit(validatorId, rewardPerStake, rewardPerStake); } function _getEligibleValidatorReward( uint256 validatorId, uint256 validatorStakePower, uint256 currentRewardPerStake, uint256 initialRewardPerStake ) private pure returns (uint256) { uint256 eligibleReward = currentRewardPerStake - initialRewardPerStake; return eligibleReward.mul(validatorStakePower).div(REWARD_PRECISION); } function _increaseValidatorReward(uint256 validatorId, uint256 reward) private { if (reward > 0) { validators[validatorId].reward = validators[validatorId].reward.add(reward); } } function _increaseValidatorRewardWithDelegation( uint256 validatorId, uint256 validatorsStake, uint256 delegatedAmount, uint256 reward ) private { uint256 combinedStakePower = delegatedAmount.add(validatorsStake); (uint256 validatorReward, uint256 delegatorsReward) = _getValidatorAndDelegationReward(validatorId, validatorsStake, reward, combinedStakePower); if (delegatorsReward > 0) { validators[validatorId].delegatorsReward = validators[validatorId].delegatorsReward.add(delegatorsReward); } if (validatorReward > 0) { validators[validatorId].reward = validators[validatorId].reward.add(validatorReward); } } function _getValidatorAndDelegationReward( uint256 validatorId, uint256 validatorsStake, uint256 reward, uint256 combinedStakePower ) internal view returns (uint256, uint256) { if (combinedStakePower == 0) { return (0, 0); } uint256 validatorReward = validatorsStake.mul(reward).div(combinedStakePower); // add validator commission from delegation reward uint256 commissionRate = validators[validatorId].commissionRate; if (commissionRate > 0) { validatorReward = validatorReward.add( reward.sub(validatorReward).mul(commissionRate).div(MAX_COMMISION_RATE) ); } uint256 delegatorsReward = reward.sub(validatorReward); return (validatorReward, delegatorsReward); } function _evaluateValidatorAndDelegationReward(uint256 validatorId) private view returns (uint256 validatorReward, uint256 delegatorsReward) { uint256 validatorsStake = validators[validatorId].amount; uint256 combinedStakePower = validatorsStake.add(validators[validatorId].delegatedAmount); uint256 eligibleReward = rewardPerStake - validators[validatorId].initialRewardPerStake; return _getValidatorAndDelegationReward( validatorId, validatorsStake, eligibleReward.mul(combinedStakePower).div(REWARD_PRECISION), combinedStakePower ); } function _jail(uint256 validatorId, uint256 jailCheckpoints) internal returns (uint256) { address delegationContract = validators[validatorId].contractAddress; if (delegationContract != address(0x0)) { IValidatorShare(delegationContract).lock(); } uint256 _currentEpoch = currentEpoch; validators[validatorId].jailTime = _currentEpoch.add(jailCheckpoints); validators[validatorId].status = Status.Locked; logger.logJailed(validatorId, _currentEpoch, validators[validatorId].signer); return validators[validatorId].amount.add(validators[validatorId].delegatedAmount); } function _stakeFor( address user, uint256 amount, bool acceptDelegation, bytes memory signerPubkey ) internal returns (uint256) { address signer = _getAndAssertSigner(signerPubkey); uint256 _currentEpoch = currentEpoch; uint256 validatorId = NFTCounter; StakingInfo _logger = logger; uint256 newTotalStaked = totalStaked.add(amount); totalStaked = newTotalStaked; validators[validatorId] = Validator({ reward: INITIALIZED_AMOUNT, amount: amount, activationEpoch: _currentEpoch, deactivationEpoch: 0, jailTime: 0, signer: signer, contractAddress: acceptDelegation ? validatorShareFactory.create(validatorId, address(_logger), registry) : address(0x0), status: Status.Active, commissionRate: 0, lastCommissionUpdate: 0, delegatorsReward: INITIALIZED_AMOUNT, delegatedAmount: 0, initialRewardPerStake: rewardPerStake }); latestSignerUpdateEpoch[validatorId] = _currentEpoch; NFTContract.mint(user, validatorId); signerToValidator[signer] = validatorId; updateTimeline(int256(amount), 1, 0); // no Auctions for 1 dynasty validatorAuction[validatorId].startEpoch = _currentEpoch; _logger.logStaked(signer, signerPubkey, validatorId, _currentEpoch, amount, newTotalStaked); NFTCounter = validatorId.add(1); _insertSigner(signer); return validatorId; } function _unstake(uint256 validatorId, uint256 exitEpoch) internal { // TODO: if validators unstake and slashed to 0, he will be forced to unstake again // must think how to handle it correctly _updateRewards(validatorId); uint256 amount = validators[validatorId].amount; address validator = ownerOf(validatorId); validators[validatorId].deactivationEpoch = exitEpoch; // unbond all delegators in future int256 delegationAmount = int256(validators[validatorId].delegatedAmount); address delegationContract = validators[validatorId].contractAddress; if (delegationContract != address(0)) { IValidatorShare(delegationContract).lock(); } _removeSigner(validators[validatorId].signer); _liquidateRewards(validatorId, validator); uint256 targetEpoch = exitEpoch <= currentEpoch ? 0 : exitEpoch; updateTimeline(-(int256(amount) + delegationAmount), -1, targetEpoch); logger.logUnstakeInit(validator, validatorId, exitEpoch, amount); } function _finalizeCommit() internal { uint256 _currentEpoch = currentEpoch; uint256 nextEpoch = _currentEpoch.add(1); StateChange memory changes = validatorStateChanges[nextEpoch]; updateTimeline(changes.amount, changes.stakerCount, 0); delete validatorStateChanges[_currentEpoch]; currentEpoch = nextEpoch; } function _liquidateRewards(uint256 validatorId, address validatorUser) private { uint256 reward = validators[validatorId].reward.sub(INITIALIZED_AMOUNT); totalRewardsLiquidated = totalRewardsLiquidated.add(reward); validators[validatorId].reward = INITIALIZED_AMOUNT; validators[validatorId].initialRewardPerStake = rewardPerStake; _transferToken(validatorUser, reward); logger.logClaimRewards(validatorId, reward, totalRewardsLiquidated); } function _transferToken(address destination, uint256 amount) private { require(token.transfer(destination, amount), "transfer failed"); } function _transferTokenFrom( address from, address destination, uint256 amount ) private { require(token.transferFrom(from, destination, amount), "transfer from failed"); } function _transferAndTopUp( address user, address from, uint256 fee, uint256 additionalAmount ) private { require(fee >= minHeimdallFee, "fee too small"); _transferTokenFrom(from, address(this), fee.add(additionalAmount)); totalHeimdallFee = totalHeimdallFee.add(fee); logger.logTopUpFee(user, fee); } function _claimFee(address user, uint256 amount) private { totalHeimdallFee = totalHeimdallFee.sub(amount); logger.logClaimFee(user, amount); } function _insertSigner(address newSigner) internal { signers.push(newSigner); uint lastIndex = signers.length - 1; uint i = lastIndex; for (; i > 0; --i) { address signer = signers[i - 1]; if (signer < newSigner) { break; } signers[i] = signer; } if (i != lastIndex) { signers[i] = newSigner; } } function _updateSigner(address prevSigner, address newSigner) internal { _removeSigner(prevSigner); _insertSigner(newSigner); } function _removeSigner(address signerToDelete) internal { uint256 totalSigners = signers.length; address swapSigner = signers[totalSigners - 1]; delete signers[totalSigners - 1]; // bubble last element to the beginning until target signer is met for (uint256 i = totalSigners - 1; i > 0; --i) { if (swapSigner == signerToDelete) { break; } (swapSigner, signers[i - 1]) = (signers[i - 1], swapSigner); } signers.length = totalSigners - 1; } function _setValidator( uint256 validatorId, address signer, uint256 amount, uint256 activationEpoch, uint256 delegatedAmount ) internal { uint256 newTotalStaked = totalStaked.add(amount); totalStaked = newTotalStaked; validators[validatorId] = Validator({ reward: INITIALIZED_AMOUNT, amount: amount, activationEpoch: activationEpoch, deactivationEpoch: 0, jailTime: 0, signer: signer, contractAddress: address(0x0), status: Status.Active, commissionRate: 0, lastCommissionUpdate: 0, delegatorsReward: INITIALIZED_AMOUNT, delegatedAmount: delegatedAmount, initialRewardPerStake: rewardPerStake }); latestSignerUpdateEpoch[validatorId] = activationEpoch; signerToValidator[signer] = validatorId; updateTimeline(int256(amount + delegatedAmount), 1, 0); // no Auctions for 1 dynasty validatorAuction[validatorId].startEpoch = activationEpoch; // bytes memory signerPubkey; // logger.logStaked(signer, signerPubkey, validatorId, _currentEpoch, amount, newTotalStaked); _insertSigner(signer); } function _verifyConsensus( bytes32 voteHash, uint[3][] memory sigs ) internal returns (bool) { // total voting power uint256 _stakePower; address lastAdd; // cannot have address(0x0) as an owner uint256 targetStake = currentValidatorSetTotalStake().mul(2).div(3).add(1); for (uint64 i = 0; i < sigs.length; ++i) { address signer = ECVerify.ecrecovery(voteHash, sigs[i]); uint256 validatorId = signerToValidator[signer]; // check if signer is staker and not proposer if (signer < lastAdd) { break; } else if (isValidator(validatorId) && signer > lastAdd) { lastAdd = signer; uint256 amount; uint256 delegatedAmount; amount = validators[validatorId].amount; delegatedAmount = validators[validatorId].delegatedAmount; // add delegation power amount = amount.add(delegatedAmount); _stakePower = _stakePower.add(amount); } if (_stakePower >= targetStake) { return true; } } return _stakePower >= targetStake; } }
pragma solidity ^0.5.2; import "../math/SafeMath.sol"; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids * * Include with `using Counters for Counters.Counter;` * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the SafeMath * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never * directly accessed. */ library Counters { using SafeMath for uint256; struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { counter._value += 1; } function decrement(Counter storage counter) internal { counter._value = counter._value.sub(1); } }
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; } }
pragma solidity ^0.5.2; import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol"; import {Ownable} from "openzeppelin-solidity/contracts/ownership/Ownable.sol"; contract StakingNFT is ERC721Full, Ownable { constructor(string memory name, string memory symbol) public ERC721Full(name, symbol) { // solhint-disable-previous-line no-empty-blocks } function mint(address to, uint256 tokenId) public onlyOwner { require( balanceOf(to) == 0, "Validators MUST NOT own multiple stake position" ); _mint(to, tokenId); } function burn(uint256 tokenId) public onlyOwner { _burn(tokenId); } function _transferFrom(address from, address to, uint256 tokenId) internal { require( balanceOf(to) == 0, "Validators MUST NOT own multiple stake position" ); super._transferFrom(from, to, tokenId); } }
pragma solidity ^0.5.2; import {Governable} from "./governance/Governable.sol"; import {IWithdrawManager} from "../root/withdrawManager/IWithdrawManager.sol"; 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]; } }
pragma solidity ^0.5.2; import { Lockable } from "./Lockable.sol"; import { Ownable } from "openzeppelin-solidity/contracts/ownership/Ownable.sol"; contract OwnableLockable is Lockable, Ownable { function lock() public onlyOwner { super.lock(); } function unlock() public onlyOwner { super.unlock(); } }
/* * 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); }
pragma solidity ^0.5.2; contract Initializable { bool inited = false; modifier initializer() { require(!inited, "already inited"); inited = true; _; } }
pragma solidity 0.5.17; import {Registry} from "../../common/Registry.sol"; import {ERC20NonTradable} from "../../common/tokens/ERC20NonTradable.sol"; import {ERC20} from "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import {StakingInfo} from "./../StakingInfo.sol"; import {EventsHub} from "./../EventsHub.sol"; import {OwnableLockable} from "../../common/mixin/OwnableLockable.sol"; import {IStakeManager} from "../stakeManager/IStakeManager.sol"; import {IValidatorShare} from "./IValidatorShare.sol"; import {Initializable} from "../../common/mixin/Initializable.sol"; contract ValidatorShare is IValidatorShare, ERC20NonTradable, OwnableLockable, Initializable { struct DelegatorUnbond { uint256 shares; uint256 withdrawEpoch; } uint256 constant EXCHANGE_RATE_PRECISION = 100; // maximum matic possible, even if rate will be 1 and all matic will be staken in one go, it will result in 10 ^ 58 shares uint256 constant EXCHANGE_RATE_HIGH_PRECISION = 10**29; uint256 constant MAX_COMMISION_RATE = 100; uint256 constant REWARD_PRECISION = 10**25; StakingInfo public stakingLogger; IStakeManager public stakeManager; uint256 public validatorId; uint256 public validatorRewards_deprecated; uint256 public commissionRate_deprecated; uint256 public lastCommissionUpdate_deprecated; uint256 public minAmount; uint256 public totalStake_deprecated; uint256 public rewardPerShare; uint256 public activeAmount; bool public delegation; uint256 public withdrawPool; uint256 public withdrawShares; mapping(address => uint256) amountStaked_deprecated; // deprecated, keep for foundation delegators mapping(address => DelegatorUnbond) public unbonds; mapping(address => uint256) public initalRewardPerShare; mapping(address => uint256) public unbondNonces; mapping(address => mapping(uint256 => DelegatorUnbond)) public unbonds_new; EventsHub public eventsHub; // 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); _getOrCacheEventsHub(); minAmount = 10**18; delegation = true; } /** Public View Methods */ function exchangeRate() public view returns (uint256) { uint256 totalShares = totalSupply(); uint256 precision = _getRatePrecision(); return totalShares == 0 ? precision : stakeManager.delegatedAmount(validatorId).mul(precision).div(totalShares); } function getTotalStake(address user) public view returns (uint256, uint256) { uint256 shares = balanceOf(user); uint256 rate = exchangeRate(); if (shares == 0) { return (0, rate); } return (rate.mul(shares).div(_getRatePrecision()), rate); } function withdrawExchangeRate() public view returns (uint256) { uint256 precision = _getRatePrecision(); if (validatorId < 8) { // fix of potentially broken withdrawals for future unbonding // foundation validators have no slashing enabled and thus we can return default exchange rate // because without slashing rate will stay constant return precision; } uint256 _withdrawShares = withdrawShares; return _withdrawShares == 0 ? precision : withdrawPool.mul(precision).div(_withdrawShares); } function getLiquidRewards(address user) public view returns (uint256) { return _calculateReward(user, getRewardPerShare()); } function getRewardPerShare() public view returns (uint256) { return _calculateRewardPerShareWithRewards(stakeManager.delegatorsReward(validatorId)); } /** Public Methods */ function buyVoucher(uint256 _amount, uint256 _minSharesToMint) public returns(uint256 amountToDeposit) { _withdrawAndTransferReward(msg.sender); amountToDeposit = _buyShares(_amount, _minSharesToMint, msg.sender); require(stakeManager.delegationDeposit(validatorId, amountToDeposit, msg.sender), "deposit failed"); return amountToDeposit; } function restake() public returns(uint256, uint256) { address user = msg.sender; uint256 liquidReward = _withdrawReward(user); uint256 amountRestaked; require(liquidReward >= minAmount, "Too small rewards to restake"); if (liquidReward != 0) { amountRestaked = _buyShares(liquidReward, 0, user); if (liquidReward > amountRestaked) { // return change to the user require( stakeManager.transferFunds(validatorId, liquidReward - amountRestaked, user), "Insufficent rewards" ); stakingLogger.logDelegatorClaimRewards(validatorId, user, liquidReward - amountRestaked); } (uint256 totalStaked, ) = getTotalStake(user); stakingLogger.logDelegatorRestaked(validatorId, user, totalStaked); } return (amountRestaked, liquidReward); } function sellVoucher(uint256 claimAmount, uint256 maximumSharesToBurn) public { (uint256 shares, uint256 _withdrawPoolShare) = _sellVoucher(claimAmount, maximumSharesToBurn); DelegatorUnbond memory unbond = unbonds[msg.sender]; unbond.shares = unbond.shares.add(_withdrawPoolShare); // refresh undond period unbond.withdrawEpoch = stakeManager.epoch(); unbonds[msg.sender] = unbond; StakingInfo logger = stakingLogger; logger.logShareBurned(validatorId, msg.sender, claimAmount, shares); logger.logStakeUpdate(validatorId); } function withdrawRewards() public { uint256 rewards = _withdrawAndTransferReward(msg.sender); require(rewards >= minAmount, "Too small rewards amount"); } function migrateOut(address user, uint256 amount) external onlyOwner { _withdrawAndTransferReward(user); (uint256 totalStaked, uint256 rate) = getTotalStake(user); require(totalStaked >= amount, "Migrating too much"); uint256 precision = _getRatePrecision(); uint256 shares = amount.mul(precision).div(rate); _burn(user, shares); stakeManager.updateValidatorState(validatorId, -int256(amount)); activeAmount = activeAmount.sub(amount); stakingLogger.logShareBurned(validatorId, user, amount, shares); stakingLogger.logStakeUpdate(validatorId); stakingLogger.logDelegatorUnstaked(validatorId, user, amount); } function migrateIn(address user, uint256 amount) external onlyOwner { _withdrawAndTransferReward(user); _buyShares(amount, 0, user); } function unstakeClaimTokens() public { DelegatorUnbond memory unbond = unbonds[msg.sender]; uint256 amount = _unstakeClaimTokens(unbond); delete unbonds[msg.sender]; stakingLogger.logDelegatorUnstaked(validatorId, msg.sender, amount); } function slash( uint256 validatorStake, uint256 delegatedAmount, uint256 totalAmountToSlash ) external onlyOwner returns (uint256) { uint256 _withdrawPool = withdrawPool; uint256 delegationAmount = delegatedAmount.add(_withdrawPool); if (delegationAmount == 0) { return 0; } // total amount to be slashed from delegation pool (active + inactive) uint256 _amountToSlash = delegationAmount.mul(totalAmountToSlash).div(validatorStake.add(delegationAmount)); uint256 _amountToSlashWithdrawalPool = _withdrawPool.mul(_amountToSlash).div(delegationAmount); // slash inactive pool uint256 stakeSlashed = _amountToSlash.sub(_amountToSlashWithdrawalPool); stakeManager.decreaseValidatorDelegatedAmount(validatorId, stakeSlashed); activeAmount = activeAmount.sub(stakeSlashed); withdrawPool = withdrawPool.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"); } } /** New shares exit API */ function sellVoucher_new(uint256 claimAmount, uint256 maximumSharesToBurn) public { (uint256 shares, uint256 _withdrawPoolShare) = _sellVoucher(claimAmount, maximumSharesToBurn); uint256 unbondNonce = unbondNonces[msg.sender].add(1); DelegatorUnbond memory unbond = DelegatorUnbond({ shares: _withdrawPoolShare, withdrawEpoch: stakeManager.epoch() }); unbonds_new[msg.sender][unbondNonce] = unbond; unbondNonces[msg.sender] = unbondNonce; _getOrCacheEventsHub().logShareBurnedWithId(validatorId, msg.sender, claimAmount, shares, unbondNonce); stakingLogger.logStakeUpdate(validatorId); } function unstakeClaimTokens_new(uint256 unbondNonce) public { DelegatorUnbond memory unbond = unbonds_new[msg.sender][unbondNonce]; uint256 amount = _unstakeClaimTokens(unbond); delete unbonds_new[msg.sender][unbondNonce]; _getOrCacheEventsHub().logDelegatorUnstakedWithId(validatorId, msg.sender, amount, unbondNonce); } /** Private Methods */ function _getOrCacheEventsHub() private returns(EventsHub) { EventsHub _eventsHub = eventsHub; if (_eventsHub == EventsHub(0x0)) { _eventsHub = EventsHub(Registry(stakeManager.getRegistry()).contractMap(keccak256("eventsHub"))); eventsHub = _eventsHub; } return _eventsHub; } function _sellVoucher(uint256 claimAmount, uint256 maximumSharesToBurn) private returns(uint256, uint256) { // first get how much staked in total and compare to target unstake amount (uint256 totalStaked, uint256 rate) = getTotalStake(msg.sender); require(totalStaked != 0 && totalStaked >= claimAmount, "Too much requested"); // convert requested amount back to shares uint256 precision = _getRatePrecision(); uint256 shares = claimAmount.mul(precision).div(rate); require(shares <= maximumSharesToBurn, "too much slippage"); _withdrawAndTransferReward(msg.sender); _burn(msg.sender, shares); stakeManager.updateValidatorState(validatorId, -int256(claimAmount)); activeAmount = activeAmount.sub(claimAmount); uint256 _withdrawPoolShare = claimAmount.mul(precision).div(withdrawExchangeRate()); withdrawPool = withdrawPool.add(claimAmount); withdrawShares = withdrawShares.add(_withdrawPoolShare); return (shares, _withdrawPoolShare); } function _unstakeClaimTokens(DelegatorUnbond memory unbond) private returns(uint256) { uint256 shares = unbond.shares; require( unbond.withdrawEpoch.add(stakeManager.withdrawalDelay()) <= stakeManager.epoch() && shares > 0, "Incomplete withdrawal period" ); uint256 _amount = withdrawExchangeRate().mul(shares).div(_getRatePrecision()); withdrawShares = withdrawShares.sub(shares); withdrawPool = withdrawPool.sub(_amount); require(stakeManager.transferFunds(validatorId, _amount, msg.sender), "Insufficent rewards"); return _amount; } function _getRatePrecision() private view returns (uint256) { // if foundation validator, use old precision if (validatorId < 8) { return EXCHANGE_RATE_PRECISION; } return EXCHANGE_RATE_HIGH_PRECISION; } function _calculateRewardPerShareWithRewards(uint256 accumulatedReward) private view returns (uint256) { uint256 _rewardPerShare = rewardPerShare; if (accumulatedReward != 0) { uint256 totalShares = totalSupply(); if (totalShares != 0) { _rewardPerShare = _rewardPerShare.add(accumulatedReward.mul(REWARD_PRECISION).div(totalShares)); } } return _rewardPerShare; } function _calculateReward(address user, uint256 _rewardPerShare) private view returns (uint256) { uint256 shares = balanceOf(user); if (shares == 0) { return 0; } uint256 _initialRewardPerShare = initalRewardPerShare[user]; if (_initialRewardPerShare == _rewardPerShare) { return 0; } return _rewardPerShare.sub(_initialRewardPerShare).mul(shares).div(REWARD_PRECISION); } function _withdrawReward(address user) private returns (uint256) { uint256 _rewardPerShare = _calculateRewardPerShareWithRewards( stakeManager.withdrawDelegatorsReward(validatorId) ); uint256 liquidRewards = _calculateReward(user, _rewardPerShare); rewardPerShare = _rewardPerShare; initalRewardPerShare[user] = _rewardPerShare; return liquidRewards; } function _withdrawAndTransferReward(address user) private returns (uint256) { uint256 liquidRewards = _withdrawReward(user); if (liquidRewards != 0) { require(stakeManager.transferFunds(validatorId, liquidRewards, user), "Insufficent rewards"); stakingLogger.logDelegatorClaimRewards(validatorId, user, liquidRewards); } return liquidRewards; } function _buyShares( uint256 _amount, uint256 _minSharesToMint, address user ) private onlyWhenUnlocked returns (uint256) { require(delegation, "Delegation is disabled"); uint256 rate = exchangeRate(); uint256 precision = _getRatePrecision(); uint256 shares = _amount.mul(precision).div(rate); require(shares >= _minSharesToMint, "Too much slippage"); require(unbonds[user].shares == 0, "Ongoing exit"); _mint(user, shares); // clamp amount of tokens in case resulted shares requires less tokens than anticipated _amount = rate.mul(shares).div(precision); stakeManager.updateValidatorState(validatorId, int256(_amount)); activeAmount = activeAmount.add(_amount); StakingInfo logger = stakingLogger; logger.logShareMinted(validatorId, user, _amount, shares); logger.logStakeUpdate(validatorId); return _amount; } function _transfer( address from, address to, uint256 value ) internal { // get rewards for recipient _withdrawAndTransferReward(to); // convert rewards to shares _withdrawAndTransferReward(from); // move shares to recipient super._transfer(from, to, value); } }
pragma solidity ^0.5.2; import {DelegateProxy} from "./DelegateProxy.sol"; 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) } } }
pragma solidity ^0.5.2; library Merkle { function checkMembership( bytes32 leaf, uint256 index, bytes32 rootHash, bytes memory proof ) public pure returns (bool) { require(proof.length % 32 == 0, "Invalid proof length"); uint256 proofHeight = proof.length / 32; // Proof of size n means, height of the tree is n+1. // In a tree of height n+1, max #leafs possible is 2 ^ n require(index < 2 ** proofHeight, "Leaf index is too big"); bytes32 proofElement; bytes32 computedHash = leaf; for (uint256 i = 32; i <= proof.length; i += 32) { assembly { proofElement := mload(add(proof, i)) } if (index % 2 == 0) { computedHash = keccak256( abi.encodePacked(computedHash, proofElement) ); } else { computedHash = keccak256( abi.encodePacked(proofElement, computedHash) ); } index = index / 2; } return computedHash == rootHash; } }
pragma solidity ^0.5.2; import {ERC20} from "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; contract ERC20NonTradable is ERC20 { function _approve( address owner, address spender, uint256 value ) internal { revert("disabled"); } }
pragma solidity ^0.5.2; import {Ownable} from "openzeppelin-solidity/contracts/ownership/Ownable.sol"; /** * @title RootChainable */ contract RootChainable is Ownable { address public rootChain; // Rootchain changed event RootChainChanged( address indexed previousRootChain, address indexed newRootChain ); // only root chain modifier onlyRootChain() { require(msg.sender == rootChain); _; } /** * @dev Allows the current owner to change root chain address. * @param newRootChain The address to new rootchain. */ function changeRootChain(address newRootChain) public onlyOwner { require(newRootChain != address(0)); emit RootChainChanged(rootChain, newRootChain); rootChain = newRootChain; } }
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; } }
// SPDX-License-Identifier: Apache-2.0 /* * @author Hamdi Allam [email protected] * Please reach out with any questions or concerns */ pragma solidity >=0.5.0 <0.7.0; library RLPReader { uint8 constant STRING_SHORT_START = 0x80; uint8 constant STRING_LONG_START = 0xb8; uint8 constant LIST_SHORT_START = 0xc0; uint8 constant LIST_LONG_START = 0xf8; uint8 constant WORD_SIZE = 32; struct RLPItem { uint len; uint memPtr; } struct Iterator { RLPItem item; // Item that's being iterated over. uint nextPtr; // Position of the next item in the list. } /* * @dev Returns the next element in the iteration. Reverts if it has not next element. * @param self The iterator. * @return The next element in the iteration. */ function next(Iterator memory self) internal pure returns (RLPItem memory) { require(hasNext(self)); uint ptr = self.nextPtr; uint itemLength = _itemLength(ptr); self.nextPtr = ptr + itemLength; return RLPItem(itemLength, ptr); } /* * @dev Returns true if the iteration has more elements. * @param self The iterator. * @return true if the iteration has more elements. */ function hasNext(Iterator memory self) internal pure returns (bool) { RLPItem memory item = self.item; return self.nextPtr < item.memPtr + item.len; } /* * @param item RLP encoded bytes */ function toRlpItem(bytes memory item) internal pure returns (RLPItem memory) { uint memPtr; assembly { memPtr := add(item, 0x20) } return RLPItem(item.length, memPtr); } /* * @dev Create an iterator. Reverts if item is not a list. * @param self The RLP item. * @return An 'Iterator' over the item. */ function iterator(RLPItem memory self) internal pure returns (Iterator memory) { require(isList(self)); uint ptr = self.memPtr + _payloadOffset(self.memPtr); return Iterator(self, ptr); } /* * @param the RLP item. */ function rlpLen(RLPItem memory item) internal pure returns (uint) { return item.len; } /* * @param the RLP item. * @return (memPtr, len) pair: location of the item's payload in memory. */ function payloadLocation(RLPItem memory item) internal pure returns (uint, uint) { uint offset = _payloadOffset(item.memPtr); uint memPtr = item.memPtr + offset; uint len = item.len - offset; // data length return (memPtr, len); } /* * @param the RLP item. */ function payloadLen(RLPItem memory item) internal pure returns (uint) { (, uint len) = payloadLocation(item); return len; } /* * @param the RLP item containing the encoded list. */ function toList(RLPItem memory item) internal pure returns (RLPItem[] memory) { require(isList(item)); uint items = numItems(item); RLPItem[] memory result = new RLPItem[](items); uint memPtr = item.memPtr + _payloadOffset(item.memPtr); uint dataLen; for (uint i = 0; i < items; i++) { dataLen = _itemLength(memPtr); result[i] = RLPItem(dataLen, memPtr); memPtr = memPtr + dataLen; } return result; } // @return indicator whether encoded payload is a list. negate this function call for isData. function isList(RLPItem memory item) internal pure returns (bool) { if (item.len == 0) return false; uint8 byte0; uint memPtr = item.memPtr; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < LIST_SHORT_START) return false; return true; } /* * @dev A cheaper version of keccak256(toRlpBytes(item)) that avoids copying memory. * @return keccak256 hash of RLP encoded bytes. */ function rlpBytesKeccak256(RLPItem memory item) internal pure returns (bytes32) { uint256 ptr = item.memPtr; uint256 len = item.len; bytes32 result; assembly { result := keccak256(ptr, len) } return result; } /* * @dev A cheaper version of keccak256(toBytes(item)) that avoids copying memory. * @return keccak256 hash of the item payload. */ function payloadKeccak256(RLPItem memory item) internal pure returns (bytes32) { (uint memPtr, uint len) = payloadLocation(item); bytes32 result; assembly { result := keccak256(memPtr, len) } return result; } /** RLPItem conversions into data types **/ // @returns raw rlp encoding in bytes function toRlpBytes(RLPItem memory item) internal pure returns (bytes memory) { bytes memory result = new bytes(item.len); if (result.length == 0) return result; uint ptr; assembly { ptr := add(0x20, result) } copy(item.memPtr, ptr, item.len); return result; } // any non-zero byte except "0x80" is considered true function toBoolean(RLPItem memory item) internal pure returns (bool) { require(item.len == 1); uint result; uint memPtr = item.memPtr; assembly { result := byte(0, mload(memPtr)) } // SEE Github Issue #5. // Summary: Most commonly used RLP libraries (i.e Geth) will encode // "0" as "0x80" instead of as "0". We handle this edge case explicitly // here. if (result == 0 || result == STRING_SHORT_START) { return false; } else { return true; } } function toAddress(RLPItem memory item) internal pure returns (address) { // 1 byte for the length prefix require(item.len == 21); return address(toUint(item)); } function toUint(RLPItem memory item) internal pure returns (uint) { require(item.len > 0 && item.len <= 33); (uint memPtr, uint len) = payloadLocation(item); uint result; assembly { result := mload(memPtr) // shfit to the correct location if neccesary if lt(len, 32) { result := div(result, exp(256, sub(32, len))) } } return result; } // enforces 32 byte length function toUintStrict(RLPItem memory item) internal pure returns (uint) { // one byte prefix require(item.len == 33); uint result; uint memPtr = item.memPtr + 1; assembly { result := mload(memPtr) } return result; } function toBytes(RLPItem memory item) internal pure returns (bytes memory) { require(item.len > 0); (uint memPtr, uint len) = payloadLocation(item); bytes memory result = new bytes(len); uint destPtr; assembly { destPtr := add(0x20, result) } copy(memPtr, destPtr, len); return result; } /* * Private Helpers */ // @return number of payload items inside an encoded list. function numItems(RLPItem memory item) private pure returns (uint) { if (item.len == 0) return 0; uint count = 0; uint currPtr = item.memPtr + _payloadOffset(item.memPtr); uint endPtr = item.memPtr + item.len; while (currPtr < endPtr) { currPtr = currPtr + _itemLength(currPtr); // skip over an item count++; } return count; } // @return entire rlp item byte length function _itemLength(uint memPtr) private pure returns (uint) { uint itemLen; uint byte0; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < STRING_SHORT_START) itemLen = 1; else if (byte0 < STRING_LONG_START) itemLen = byte0 - STRING_SHORT_START + 1; else if (byte0 < LIST_SHORT_START) { assembly { let byteLen := sub(byte0, 0xb7) // # of bytes the actual length is memPtr := add(memPtr, 1) // skip over the first byte /* 32 byte word size */ let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to get the len itemLen := add(dataLen, add(byteLen, 1)) } } else if (byte0 < LIST_LONG_START) { itemLen = byte0 - LIST_SHORT_START + 1; } else { assembly { let byteLen := sub(byte0, 0xf7) memPtr := add(memPtr, 1) let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to the correct length itemLen := add(dataLen, add(byteLen, 1)) } } return itemLen; } // @return number of bytes until the data function _payloadOffset(uint memPtr) private pure returns (uint) { uint byte0; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < STRING_SHORT_START) return 0; else if (byte0 < STRING_LONG_START || (byte0 >= LIST_SHORT_START && byte0 < LIST_LONG_START)) return 1; else if (byte0 < LIST_SHORT_START) // being explicit return byte0 - (STRING_LONG_START - 1) + 1; else return byte0 - (LIST_LONG_START - 1) + 1; } /* * @param src Pointer to source * @param dest Pointer to destination * @param len Amount of memory to copy from the source */ function copy(uint src, uint dest, uint len) private pure { if (len == 0) return; // copy as many word sizes as possible for (; len >= WORD_SIZE; len -= WORD_SIZE) { assembly { mstore(dest, mload(src)) } src += WORD_SIZE; dest += WORD_SIZE; } if (len > 0) { // left over bytes. Mask is used to remove unwanted bytes from the word uint mask = 256 ** (WORD_SIZE - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) // zero out src let destpart := and(mload(dest), mask) // retrieve the bytes mstore(dest, or(destpart, srcpart)) } } } }
pragma solidity ^0.5.2; import {Governable} from "../governance/Governable.sol"; import {Lockable} from "./Lockable.sol"; contract GovernanceLockable is Lockable, Governable { constructor(address governance) public Governable(governance) {} function lock() public onlyGovernance { super.lock(); } function unlock() public onlyGovernance { super.unlock(); } }
pragma solidity ^0.5.2; import "../../introspection/IERC165.sol"; /** * @title ERC721 Non-Fungible Token Standard basic interface * @dev see https://eips.ethereum.org/EIPS/eip-721 */ contract IERC721 is IERC165 { event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); event ApprovalForAll(address indexed owner, address indexed operator, bool approved); function balanceOf(address owner) public view returns (uint256 balance); function ownerOf(uint256 tokenId) public view returns (address owner); function approve(address to, uint256 tokenId) public; function getApproved(uint256 tokenId) public view returns (address operator); function setApprovalForAll(address operator, bool _approved) public; function isApprovedForAll(address owner, address operator) public view returns (bool); function transferFrom(address from, address to, uint256 tokenId) public; function safeTransferFrom(address from, address to, uint256 tokenId) public; function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public; }
pragma solidity ^0.5.2; import "./IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ contract IERC721Enumerable is IERC721 { function totalSupply() public view returns (uint256); function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256 tokenId); function tokenByIndex(uint256 index) public view returns (uint256); }
pragma solidity ^0.5.2; import {Registry} from "../common/Registry.sol"; import {Initializable} from "../common/mixin/Initializable.sol"; contract IStakeManagerEventsHub { struct Validator { uint256 amount; uint256 reward; uint256 activationEpoch; uint256 deactivationEpoch; uint256 jailTime; address signer; address contractAddress; } mapping(uint256 => Validator) public validators; } contract EventsHub is Initializable { Registry public registry; modifier onlyValidatorContract(uint256 validatorId) { address _contract; (, , , , , , _contract) = IStakeManagerEventsHub(registry.getStakeManagerAddress()).validators(validatorId); require(_contract == msg.sender, "not validator"); _; } modifier onlyStakeManager() { require(registry.getStakeManagerAddress() == msg.sender, "Invalid sender, not stake manager"); _; } function initialize(Registry _registry) external initializer { registry = _registry; } event ShareBurnedWithId( uint256 indexed validatorId, address indexed user, uint256 indexed amount, uint256 tokens, uint256 nonce ); function logShareBurnedWithId( uint256 validatorId, address user, uint256 amount, uint256 tokens, uint256 nonce ) public onlyValidatorContract(validatorId) { emit ShareBurnedWithId(validatorId, user, amount, tokens, nonce); } event DelegatorUnstakeWithId( uint256 indexed validatorId, address indexed user, uint256 amount, uint256 nonce ); function logDelegatorUnstakedWithId( uint256 validatorId, address user, uint256 amount, uint256 nonce ) public onlyValidatorContract(validatorId) { emit DelegatorUnstakeWithId(validatorId, user, amount, nonce); } event RewardParams( uint256 rewardDecreasePerCheckpoint, uint256 maxRewardedCheckpoints, uint256 checkpointRewardDelta ); function logRewardParams( uint256 rewardDecreasePerCheckpoint, uint256 maxRewardedCheckpoints, uint256 checkpointRewardDelta ) public onlyStakeManager { emit RewardParams(rewardDecreasePerCheckpoint, maxRewardedCheckpoints, checkpointRewardDelta); } event UpdateCommissionRate( uint256 indexed validatorId, uint256 indexed newCommissionRate, uint256 indexed oldCommissionRate ); function logUpdateCommissionRate( uint256 validatorId, uint256 newCommissionRate, uint256 oldCommissionRate ) public onlyStakeManager { emit UpdateCommissionRate( validatorId, newCommissionRate, oldCommissionRate ); } }
pragma solidity ^0.5.2; import "./ERC721.sol"; import "./ERC721Enumerable.sol"; import "./ERC721Metadata.sol"; /** * @title Full ERC721 Token * This implementation includes all the required and some optional functionality of the ERC721 standard * Moreover, it includes approve all functionality using operator terminology * @dev see https://eips.ethereum.org/EIPS/eip-721 */ contract ERC721Full is ERC721, ERC721Enumerable, ERC721Metadata { constructor (string memory name, string memory symbol) public ERC721Metadata(name, symbol) { // solhint-disable-previous-line no-empty-blocks } }
pragma solidity ^0.5.2; library ECVerify { function ecrecovery(bytes32 hash, uint[3] memory sig) internal pure returns (address) { bytes32 r; bytes32 s; uint8 v; assembly { r := mload(sig) s := mload(add(sig, 32)) v := byte(31, mload(add(sig, 64))) } if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return address(0x0); } // 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, bytes memory sig) internal 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) internal 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) internal pure returns (bool) { return signer == ecrecovery(hash, sig); } }
pragma solidity ^0.5.2; import {ValidatorShareProxy} from "./ValidatorShareProxy.sol"; import {ValidatorShare} from "./ValidatorShare.sol"; 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; } }
pragma solidity ^0.5.2; import "./IERC20.sol"; import "../../math/SafeMath.sol"; /** * @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)); } }
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; } }
pragma solidity ^0.5.2; /** * @title Math * @dev Assorted math operations */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Calculates the average of two numbers. Since these are integers, * averages of an even and odd number cannot be represented, and will be * rounded down. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } }
pragma solidity ^0.5.2; import {IGovernance} from "./IGovernance.sol"; contract Governable { IGovernance public governance; constructor(address _governance) public { governance = IGovernance(_governance); } modifier onlyGovernance() { _assertGovernance(); _; } function _assertGovernance() private view { require( msg.sender == address(governance), "Only governance contract is authorized" ); } }
pragma solidity ^0.5.2; import "./ERC721.sol"; import "./IERC721Metadata.sol"; import "../../introspection/ERC165.sol"; contract ERC721Metadata is ERC165, ERC721, IERC721Metadata { // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping(uint256 => string) private _tokenURIs; bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * 0x5b5e139f === * bytes4(keccak256('name()')) ^ * bytes4(keccak256('symbol()')) ^ * bytes4(keccak256('tokenURI(uint256)')) */ /** * @dev Constructor function */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721_METADATA); } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns (string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns (string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI(uint256 tokenId) external view returns (string memory) { require(_exists(tokenId)); return _tokenURIs[tokenId]; } /** * @dev Internal function to set the token URI for a given token * Reverts if the token ID does not exist * @param tokenId uint256 ID of the token to set its URI * @param uri string URI to assign */ function _setTokenURI(uint256 tokenId, string memory uri) internal { require(_exists(tokenId)); _tokenURIs[tokenId] = uri; } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned by the msg.sender */ function _burn(address owner, uint256 tokenId) internal { super._burn(owner, tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } } }
pragma solidity ^0.5.2; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ contract IERC721Receiver { /** * @notice Handle the receipt of an NFT * @dev The ERC721 smart contract calls this function on the recipient * after a `safeTransfer`. This function MUST return the function selector, * otherwise the caller will revert the transaction. The selector to be * returned can be obtained as `this.onERC721Received.selector`. This * function MAY throw to revert and reject the transfer. * Note: the ERC721 contract address is always the message sender. * @param operator The address which called `safeTransferFrom` function * @param from The address which previously owned the token * @param tokenId The NFT identifier which is being transferred * @param data Additional data with no specified format * @return bytes4 `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` */ function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data) public returns (bytes4); }
pragma solidity ^0.5.2; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; 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; } }
pragma solidity 0.5.17; 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 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, uint256 epoch, bytes32 voteHash, bytes32 stateRoot, address proposer, uint[3][] calldata sigs ) external returns (uint256); function updateValidatorState(uint256 validatorId, int256 amount) public; function ownerOf(uint256 tokenId) public view returns (address); function slash(bytes calldata slashingInfoList) external returns (uint256); function validatorStake(uint256 validatorId) public view returns (uint256); function epoch() public view returns (uint256); function getRegistry() public view returns (address); function withdrawalDelay() public view returns (uint256); function delegatedAmount(uint256 validatorId) public view returns(uint256); function decreaseValidatorDelegatedAmount(uint256 validatorId, uint256 amount) public; function withdrawDelegatorsReward(uint256 validatorId) public returns(uint256); function delegatorsReward(uint256 validatorId) public view returns(uint256); function dethroneAndStake( address auctionUser, uint256 heimdallFee, uint256 validatorId, uint256 auctionAmount, bool acceptDelegation, bytes calldata signerPubkey ) external; }
pragma solidity ^0.5.2; import "./IERC165.sol"; /** * @title ERC165 * @author Matt Condon (@shrugs) * @dev Implements ERC165 using a lookup table. */ contract ERC165 is IERC165 { bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /* * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @dev a mapping of interface id to whether or not it's supported */ mapping(bytes4 => bool) private _supportedInterfaces; /** * @dev A contract implementing SupportsInterfaceWithLookup * implement ERC165 itself */ constructor () internal { _registerInterface(_INTERFACE_ID_ERC165); } /** * @dev implement supportsInterface(bytes4) using a lookup table */ function supportsInterface(bytes4 interfaceId) external view returns (bool) { return _supportedInterfaces[interfaceId]; } /** * @dev internal method for registering an interface */ function _registerInterface(bytes4 interfaceId) internal { require(interfaceId != 0xffffffff); _supportedInterfaces[interfaceId] = true; } }
pragma solidity ^0.5.2; import "./IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ contract IERC721Metadata is IERC721 { function name() external view returns (string memory); function symbol() external view returns (string memory); function tokenURI(uint256 tokenId) external view returns (string memory); }
pragma solidity ^0.5.2; import "./IERC721Enumerable.sol"; import "./ERC721.sol"; import "../../introspection/ERC165.sol"; /** * @title ERC-721 Non-Fungible Token with optional enumeration extension logic * @dev See https://eips.ethereum.org/EIPS/eip-721 */ contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable { // Mapping from owner to list of owned token IDs mapping(address => uint256[]) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /* * 0x780e9d63 === * bytes4(keccak256('totalSupply()')) ^ * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ * bytes4(keccak256('tokenByIndex(uint256)')) */ /** * @dev Constructor function */ constructor () public { // register the supported interface to conform to ERC721Enumerable via ERC165 _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev Gets the token ID at a given index of the tokens list of the requested owner * @param owner address owning the tokens list to be accessed * @param index uint256 representing the index to be accessed of the requested tokens list * @return uint256 token ID at the given index of the tokens list owned by the requested address */ function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) { require(index < balanceOf(owner)); return _ownedTokens[owner][index]; } /** * @dev Gets the total amount of tokens stored by the contract * @return uint256 representing the total amount of tokens */ function totalSupply() public view returns (uint256) { return _allTokens.length; } /** * @dev Gets the token ID at a given index of all the tokens in this contract * Reverts if the index is greater or equal to the total number of tokens * @param index uint256 representing the index to be accessed of the tokens list * @return uint256 token ID at the given index of the tokens list */ function tokenByIndex(uint256 index) public view returns (uint256) { require(index < totalSupply()); return _allTokens[index]; } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom(address from, address to, uint256 tokenId) internal { super._transferFrom(from, to, tokenId); _removeTokenFromOwnerEnumeration(from, tokenId); _addTokenToOwnerEnumeration(to, tokenId); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to address the beneficiary that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint(address to, uint256 tokenId) internal { super._mint(to, tokenId); _addTokenToOwnerEnumeration(to, tokenId); _addTokenToAllTokensEnumeration(tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { super._burn(owner, tokenId); _removeTokenFromOwnerEnumeration(owner, tokenId); // Since tokenId will be deleted, we can clear its slot in _ownedTokensIndex to trigger a gas refund _ownedTokensIndex[tokenId] = 0; _removeTokenFromAllTokensEnumeration(tokenId); } /** * @dev Gets the list of token IDs of the requested owner * @param owner address owning the tokens * @return uint256[] List of token IDs owned by the requested address */ function _tokensOfOwner(address owner) internal view returns (uint256[] storage) { return _ownedTokens[owner]; } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { _ownedTokensIndex[tokenId] = _ownedTokens[to].length; _ownedTokens[to].push(tokenId); } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the _ownedTokensIndex mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _ownedTokens[from].length.sub(1); uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array _ownedTokens[from].length--; // Note that _ownedTokensIndex[tokenId] hasn't been cleared: it still points to the old slot (now occupied by // lastTokenId, or just over the end of the array if the token was the last one). } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length.sub(1); uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array _allTokens.length--; _allTokensIndex[tokenId] = 0; } }
pragma solidity 0.5.17; contract StakeManagerStorageExtension { address public eventsHub; uint256 public rewardPerStake; address public extensionCode; address[] public signers; uint256 constant CHK_REWARD_PRECISION = 100; uint256 public prevBlockInterval; // how much less reward per skipped checkpoint, 0 - 100% uint256 public rewardDecreasePerCheckpoint; // how many checkpoints to reward uint256 public maxRewardedCheckpoints; // increase / decrease value for faster or slower checkpoints, 0 - 100% uint256 public checkpointRewardDelta; }
pragma solidity ^0.5.2; /** * Utility library of inline functions on addresses */ library Address { /** * Returns whether the target address is a contract * @dev This function will return false if invoked during the constructor of a contract, * as the code is not actually created until after the constructor finishes. * @param account address of the account to check * @return whether the target address is a contract */ function isContract(address account) internal view returns (bool) { uint256 size; // XXX Currently there is no better way to check if there is a contract in an address // than to check the size of the code at that address. // See https://ethereum.stackexchange.com/a/14016/36603 // for more details about how this works. // TODO Check this again before the Serenity release, because all addresses will be // contracts then. // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } }
pragma solidity ^0.5.2; import {Registry} from "../common/Registry.sol"; import {SafeMath} from "openzeppelin-solidity/contracts/math/SafeMath.sol"; import {Ownable} from "openzeppelin-solidity/contracts/ownership/Ownable.sol"; // 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 ); event StakeAck( uint256 indexed validatorId, uint256 indexed nonce ); 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 getValidatorNonce( uint256 validatorId ) public onlyStakeManager returns (uint256) { return validatorNonce[validatorId]; } 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); } // deprecated function logUpdateCommissionRate( uint256 validatorId, uint256 newCommissionRate, uint256 oldCommissionRate ) public onlyValidatorContract(validatorId) { emit UpdateCommissionRate( validatorId, newCommissionRate, oldCommissionRate ); } function logStakeAck(uint256 validatorId) public onlyStakeManager { validatorNonce[validatorId] = validatorNonce[validatorId].add(1); emit StakeAck( validatorId, validatorNonce[validatorId] ); } }
pragma solidity ^0.5.2; interface IGovernance { function update(address target, bytes calldata data) external; }
pragma solidity ^0.5.2; contract DelegateProxyForwarder { 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) } } } function isContract(address _target) internal view returns (bool) { if (_target == address(0)) { return false; } uint256 size; assembly { size := extcodesize(_target) } return size > 0; } }
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); }
pragma solidity ^0.5.2; /** * @title IERC165 * @dev https://eips.ethereum.org/EIPS/eip-165 */ interface IERC165 { /** * @notice Query if a contract implements an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @dev Interface identification is specified in ERC-165. This function * uses less than 30,000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
pragma solidity ^0.5.2; import {ERCProxy} from "./ERCProxy.sol"; import {DelegateProxyForwarder} from "./DelegateProxyForwarder.sol"; contract DelegateProxy is ERCProxy, DelegateProxyForwarder { function proxyType() external pure returns (uint256 proxyTypeId) { // Upgradeable proxy proxyTypeId = 2; } function implementation() external view returns (address); }
pragma solidity ^0.5.2; import "./IERC721.sol"; import "./IERC721Receiver.sol"; import "../../math/SafeMath.sol"; import "../../utils/Address.sol"; import "../../drafts/Counters.sol"; import "../../introspection/ERC165.sol"; /** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */ contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; using Counters for Counters.Counter; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned token mapping (address => Counters.Counter) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf(address owner) public view returns (uint256) { require(owner != address(0)); return _ownedTokensCount[owner].current(); } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @return address currently marked as the owner of the given token ID */ function ownerOf(uint256 tokenId) public view returns (address) { address owner = _tokenOwner[tokenId]; require(owner != address(0)); return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve(address to, uint256 tokenId) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved(uint256 tokenId) public view returns (address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll(address to, bool approved) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll(address owner, address operator) public view returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg.sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom(address from, address to, uint256 tokenId) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg.sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom(address from, address to, uint256 tokenId) public { safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg.sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public { transferFrom(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return bool whether the token exists */ function _exists(uint256 tokenId) internal view returns (bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) { address owner = ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint(address to, uint256 tokenId) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to].increment(); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner].decrement(); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom(address from, address to, uint256 tokenId) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from].decrement(); _ownedTokensCount[to].increment(); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) internal returns (bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, _data); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval(uint256 tokenId) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
pragma solidity 0.5.17; import {IERC20} from "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; import {SafeMath} from "openzeppelin-solidity/contracts/math/SafeMath.sol"; import {Registry} from "../../common/Registry.sol"; import {GovernanceLockable} from "../../common/mixin/GovernanceLockable.sol"; import {IStakeManager} from "./IStakeManager.sol"; import {StakeManagerStorage} from "./StakeManagerStorage.sol"; import {StakeManagerStorageExtension} from "./StakeManagerStorageExtension.sol"; import {Math} from "openzeppelin-solidity/contracts/math/Math.sol"; import {Initializable} from "../../common/mixin/Initializable.sol"; import {EventsHub} from "../EventsHub.sol"; import {ValidatorShare} from "../validatorShare/ValidatorShare.sol"; contract StakeManagerExtension is StakeManagerStorage, Initializable, StakeManagerStorageExtension { using SafeMath for uint256; constructor() public GovernanceLockable(address(0x0)) {} function startAuction( uint256 validatorId, uint256 amount, bool _acceptDelegation, bytes calldata _signerPubkey ) external { uint256 currentValidatorAmount = validators[validatorId].amount; require( validators[validatorId].deactivationEpoch == 0 && currentValidatorAmount != 0, "Invalid validator for an auction" ); uint256 senderValidatorId = signerToValidator[msg.sender]; // make sure that signer wasn't used already require( NFTContract.balanceOf(msg.sender) == 0 && // existing validators can't bid senderValidatorId != INCORRECT_VALIDATOR_ID, "Already used address" ); uint256 _currentEpoch = currentEpoch; uint256 _replacementCoolDown = replacementCoolDown; // when dynasty period is updated validators are in cooldown period require(_replacementCoolDown == 0 || _replacementCoolDown <= _currentEpoch, "Cooldown period"); // (auctionPeriod--dynasty)--(auctionPeriod--dynasty)--(auctionPeriod--dynasty) // if it's auctionPeriod then will get residue smaller then auctionPeriod // from (CurrentPeriod of validator )%(auctionPeriod--dynasty) // make sure that its `auctionPeriod` window // dynasty = 30, auctionPeriod = 7, activationEpoch = 1, currentEpoch = 39 // residue 1 = (39-1)% (7+30), if residue <= auctionPeriod it's `auctionPeriod` require( (_currentEpoch.sub(validators[validatorId].activationEpoch) % dynasty.add(auctionPeriod)) < auctionPeriod, "Invalid auction period" ); uint256 perceivedStake = currentValidatorAmount; perceivedStake = perceivedStake.add(validators[validatorId].delegatedAmount); Auction storage auction = validatorAuction[validatorId]; uint256 currentAuctionAmount = auction.amount; perceivedStake = Math.max(perceivedStake, currentAuctionAmount); require(perceivedStake < amount, "Must bid higher"); require(token.transferFrom(msg.sender, address(this), amount), "Transfer failed"); //replace prev auction if (currentAuctionAmount != 0) { require(token.transfer(auction.user, currentAuctionAmount), "Bid return failed"); } // create new auction auction.amount = amount; auction.user = msg.sender; auction.acceptDelegation = _acceptDelegation; auction.signerPubkey = _signerPubkey; logger.logStartAuction(validatorId, currentValidatorAmount, amount); } function confirmAuctionBid( uint256 validatorId, uint256 heimdallFee, /** for new validator */ IStakeManager stakeManager ) external { Auction storage auction = validatorAuction[validatorId]; address auctionUser = auction.user; require( msg.sender == auctionUser || NFTContract.tokenOfOwnerByIndex(msg.sender, 0) == validatorId, "Only bidder can confirm" ); uint256 _currentEpoch = currentEpoch; require( _currentEpoch.sub(auction.startEpoch) % auctionPeriod.add(dynasty) >= auctionPeriod, "Not allowed before auctionPeriod" ); require(auction.user != address(0x0), "Invalid auction"); uint256 validatorAmount = validators[validatorId].amount; uint256 perceivedStake = validatorAmount; uint256 auctionAmount = auction.amount; perceivedStake = perceivedStake.add(validators[validatorId].delegatedAmount); // validator is last auctioner if (perceivedStake >= auctionAmount && validators[validatorId].deactivationEpoch == 0) { require(token.transfer(auctionUser, auctionAmount), "Bid return failed"); //cleanup auction data auction.startEpoch = _currentEpoch; logger.logConfirmAuction(validatorId, validatorId, validatorAmount); } else { stakeManager.dethroneAndStake( auctionUser, heimdallFee, validatorId, auctionAmount, auction.acceptDelegation, auction.signerPubkey ); } uint256 startEpoch = auction.startEpoch; delete validatorAuction[validatorId]; validatorAuction[validatorId].startEpoch = startEpoch; } function migrateValidatorsData(uint256 validatorIdFrom, uint256 validatorIdTo) external { for (uint256 i = validatorIdFrom; i < validatorIdTo; ++i) { ValidatorShare contractAddress = ValidatorShare(validators[i].contractAddress); if (contractAddress != ValidatorShare(0)) { // move validator rewards out from ValidatorShare contract validators[i].reward = contractAddress.validatorRewards_deprecated().add(INITIALIZED_AMOUNT); validators[i].delegatedAmount = contractAddress.activeAmount(); validators[i].commissionRate = contractAddress.commissionRate_deprecated(); } else { validators[i].reward = validators[i].reward.add(INITIALIZED_AMOUNT); } validators[i].delegatorsReward = INITIALIZED_AMOUNT; } } function updateCheckpointRewardParams( uint256 _rewardDecreasePerCheckpoint, uint256 _maxRewardedCheckpoints, uint256 _checkpointRewardDelta ) external { require(_maxRewardedCheckpoints.mul(_rewardDecreasePerCheckpoint) <= CHK_REWARD_PRECISION); require(_checkpointRewardDelta <= CHK_REWARD_PRECISION); rewardDecreasePerCheckpoint = _rewardDecreasePerCheckpoint; maxRewardedCheckpoints = _maxRewardedCheckpoints; checkpointRewardDelta = _checkpointRewardDelta; _getOrCacheEventsHub().logRewardParams(_rewardDecreasePerCheckpoint, _maxRewardedCheckpoints, _checkpointRewardDelta); } function updateCommissionRate(uint256 validatorId, uint256 newCommissionRate) external { uint256 _epoch = currentEpoch; uint256 _lastCommissionUpdate = validators[validatorId].lastCommissionUpdate; require( // withdrawalDelay == dynasty (_lastCommissionUpdate.add(WITHDRAWAL_DELAY) <= _epoch) || _lastCommissionUpdate == 0, // For initial setting of commission rate "Cooldown" ); require(newCommissionRate <= MAX_COMMISION_RATE, "Incorrect value"); _getOrCacheEventsHub().logUpdateCommissionRate(validatorId, newCommissionRate, validators[validatorId].commissionRate); validators[validatorId].commissionRate = newCommissionRate; validators[validatorId].lastCommissionUpdate = _epoch; } function _getOrCacheEventsHub() private returns(EventsHub) { EventsHub _eventsHub = EventsHub(eventsHub); if (_eventsHub == EventsHub(0x0)) { _eventsHub = EventsHub(Registry(registry).contractMap(keccak256("eventsHub"))); eventsHub = address(_eventsHub); } return _eventsHub; } }
pragma solidity 0.5.17; // note this contract interface is only for stakeManager use contract IValidatorShare { function withdrawRewards() public; function unstakeClaimTokens() public; function getLiquidRewards(address user) public view returns (uint256); function owner() public view returns (address); function restake() public returns(uint256, uint256); function unlock() external; function lock() external; function drain( address token, address payable destination, uint256 amount ) external; function slash(uint256 valPow, uint256 delegatedAmount, uint256 totalAmountToSlash) external returns (uint256); function updateDelegation(bool delegation) external; function migrateOut(address user, uint256 amount) external; function migrateIn(address user, uint256 amount) external; }
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; }
pragma solidity 0.5.17; import {IERC20} from "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; import {Registry} from "../../common/Registry.sol"; import {GovernanceLockable} from "../../common/mixin/GovernanceLockable.sol"; import {RootChainable} from "../../common/mixin/RootChainable.sol"; import {StakingInfo} from "../StakingInfo.sol"; import {StakingNFT} from "./StakingNFT.sol"; import {ValidatorShareFactory} from "../validatorShare/ValidatorShareFactory.sol"; contract StakeManagerStorage is GovernanceLockable, RootChainable { enum Status {Inactive, Active, Locked, Unstaked} struct Auction { uint256 amount; uint256 startEpoch; address user; bool acceptDelegation; bytes signerPubkey; } struct State { uint256 amount; uint256 stakerCount; } struct StateChange { int256 amount; int256 stakerCount; } struct Validator { uint256 amount; uint256 reward; uint256 activationEpoch; uint256 deactivationEpoch; uint256 jailTime; address signer; address contractAddress; Status status; uint256 commissionRate; uint256 lastCommissionUpdate; uint256 delegatorsReward; uint256 delegatedAmount; uint256 initialRewardPerStake; } uint256 constant MAX_COMMISION_RATE = 100; uint256 constant MAX_PROPOSER_BONUS = 100; uint256 constant REWARD_PRECISION = 10**25; uint256 internal constant INCORRECT_VALIDATOR_ID = 2**256 - 1; uint256 internal constant INITIALIZED_AMOUNT = 1; IERC20 public token; address public registry; StakingInfo public logger; StakingNFT public NFTContract; ValidatorShareFactory public validatorShareFactory; uint256 public WITHDRAWAL_DELAY; // unit: epoch uint256 public currentEpoch; // genesis/governance variables uint256 public dynasty; // unit: epoch 50 days uint256 public CHECKPOINT_REWARD; // update via governance uint256 public minDeposit; // in ERC20 token uint256 public minHeimdallFee; // in ERC20 token uint256 public checkPointBlockInterval; uint256 public signerUpdateLimit; uint256 public validatorThreshold; //128 uint256 public totalStaked; uint256 public NFTCounter; uint256 public totalRewards; uint256 public totalRewardsLiquidated; uint256 public auctionPeriod; // 1 week in epochs uint256 public proposerBonus; // 10 % of total rewards bytes32 public accountStateRoot; // Stop validator auction for some time when updating dynasty value uint256 public replacementCoolDown; bool public delegationEnabled; mapping(uint256 => Validator) public validators; mapping(address => uint256) public signerToValidator; // current epoch stake power and stakers count State public validatorState; mapping(uint256 => StateChange) public validatorStateChanges; mapping(address => uint256) public userFeeExit; //Ongoing auctions for validatorId mapping(uint256 => Auction) public validatorAuction; // validatorId to last signer update epoch mapping(uint256 => uint256) public latestSignerUpdateEpoch; uint256 public totalHeimdallFee; }
pragma solidity ^0.5.2; import {UpgradableProxy} from "../../common/misc/UpgradableProxy.sol"; import {Registry} from "../../common/Registry.sol"; contract ValidatorShareProxy is UpgradableProxy { constructor(address _registry) public UpgradableProxy(_registry) {} function loadImplementation() internal view returns (address) { return Registry(super.loadImplementation()).getValidatorShareAddress(); } }
{ "optimizer": { "runs": 200, "enabled": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousRootChain","type":"address"},{"indexed":true,"internalType":"address","name":"newRootChain","type":"address"}],"name":"RootChainChanged","type":"event"},{"constant":true,"inputs":[],"name":"CHECKPOINT_REWARD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"NFTContract","outputs":[{"internalType":"contract StakingNFT","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"NFTCounter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"WITHDRAWAL_DELAY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"accountStateRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"auctionPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newRootChain","type":"address"}],"name":"changeRootChain","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"checkPointBlockInterval","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"blockInterval","type":"uint256"},{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"bytes32","name":"voteHash","type":"bytes32"},{"internalType":"bytes32","name":"stateRoot","type":"bytes32"},{"internalType":"address","name":"proposer","type":"address"},{"internalType":"uint256[3][]","name":"sigs","type":"uint256[3][]"}],"name":"checkSignatures","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"checkpointRewardDelta","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"accumFeeAmount","type":"uint256"},{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"bytes","name":"proof","type":"bytes"}],"name":"claimFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"heimdallFee","type":"uint256"}],"name":"confirmAuctionBid","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"currentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"currentValidatorSetSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"currentValidatorSetTotalStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"decreaseValidatorDelegatedAmount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"delegatedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"delegator","type":"address"}],"name":"delegationDeposit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"delegationEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"delegatorsReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"auctionUser","type":"address"},{"internalType":"uint256","name":"heimdallFee","type":"uint256"},{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"auctionAmount","type":"uint256"},{"internalType":"bool","name":"acceptDelegation","type":"bool"},{"internalType":"bytes","name":"signerPubkey","type":"bytes"}],"name":"dethroneAndStake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"drain","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"tokenAddr","type":"address"},{"internalType":"address payable","name":"destination","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"drainValidatorShares","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"dynasty","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"epoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"eventsHub","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"extensionCode","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"forceDelValidator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"getValidatorContract","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getValidatorId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"governance","outputs":[{"internalType":"contract IGovernance","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_registry","type":"address"},{"internalType":"address","name":"_rootchain","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_NFTContract","type":"address"},{"internalType":"address","name":"_stakingLogger","type":"address"},{"internalType":"address","name":"_validatorShareFactory","type":"address"},{"internalType":"address","name":"_governance","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_extensionCode","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address[]","name":"_signers","type":"address[]"}],"name":"insertSigners","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"isValidator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"latestSignerUpdateEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"lock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"locked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"logger","outputs":[{"internalType":"contract StakingInfo","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxRewardedCheckpoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"fromValidatorId","type":"uint256"},{"internalType":"uint256","name":"toValidatorId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"migrateDelegation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorIdFrom","type":"uint256"},{"internalType":"uint256","name":"validatorIdTo","type":"uint256"}],"name":"migrateValidatorsData","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"minDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"minHeimdallFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"prevBlockInterval","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposerBonus","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_NFTContract","type":"address"},{"internalType":"address","name":"_stakingLogger","type":"address"},{"internalType":"address","name":"_validatorShareFactory","type":"address"},{"internalType":"address","name":"_extensionCode","type":"address"}],"name":"reinitialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"replacementCoolDown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"stakeRewards","type":"bool"}],"name":"restake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"rewardDecreasePerCheckpoint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rewardPerStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rootChain","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_currentEpoch","type":"uint256"}],"name":"setCurrentEpoch","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"setStakingToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"activationEpoch","type":"uint256"},{"internalType":"uint256","name":"delegatedAmount","type":"uint256"}],"name":"setValidator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"signerToValidator","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256[3][]","name":"sigs","type":"uint256[3][]"}],"name":"signerUpdate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"signerUpdateLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"signers","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"_slashingInfoList","type":"bytes"}],"name":"slash","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"heimdallFee","type":"uint256"},{"internalType":"bool","name":"acceptDelegation","type":"bool"},{"internalType":"bytes","name":"signerPubkey","type":"bytes"}],"name":"stakeFor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256[3][]","name":"sigs","type":"uint256[3][]"}],"name":"stakeUpdate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"_acceptDelegation","type":"bool"},{"internalType":"bytes","name":"_signerPubkey","type":"bytes"}],"name":"startAuction","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"forNCheckpoints","type":"uint256"}],"name":"stopAuctions","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"heimdallFee","type":"uint256"}],"name":"topUpForFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalHeimdallFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalRewardsLiquidated","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalStakedFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"delegator","type":"address"}],"name":"transferFunds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"unjail","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"unlock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"unstake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"unstakeClaim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_blocks","type":"uint256"}],"name":"updateCheckPointBlockInterval","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"newReward","type":"uint256"}],"name":"updateCheckpointReward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_rewardDecreasePerCheckpoint","type":"uint256"},{"internalType":"uint256","name":"_maxRewardedCheckpoints","type":"uint256"},{"internalType":"uint256","name":"_checkpointRewardDelta","type":"uint256"}],"name":"updateCheckpointRewardParams","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"newCommissionRate","type":"uint256"}],"name":"updateCommissionRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"newDynasty","type":"uint256"}],"name":"updateDynastyValue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_minDeposit","type":"uint256"},{"internalType":"uint256","name":"_minHeimdallFee","type":"uint256"}],"name":"updateMinAmounts","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"newProposerBonus","type":"uint256"}],"name":"updateProposerBonus","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"bytes","name":"signerPubkey","type":"bytes"}],"name":"updateSigner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_limit","type":"uint256"}],"name":"updateSignerUpdateLimit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"newContractAddress","type":"address"}],"name":"updateValidatorContractAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"delegation","type":"bool"}],"name":"updateValidatorDelegation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"int256","name":"amount","type":"int256"}],"name":"updateValidatorState","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"newThreshold","type":"uint256"}],"name":"updateValidatorThreshold","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userFeeExit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"validatorAuction","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"startEpoch","type":"uint256"},{"internalType":"address","name":"user","type":"address"},{"internalType":"bool","name":"acceptDelegation","type":"bool"},{"internalType":"bytes","name":"signerPubkey","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256[3][]","name":"sigs","type":"uint256[3][]"}],"name":"validatorExit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256[3][]","name":"sigs","type":"uint256[3][]"}],"name":"validatorJoin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"validatorNonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"validatorReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"validatorShareFactory","outputs":[{"internalType":"contract ValidatorShareFactory","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"validatorStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"validatorState","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"stakerCount","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"validatorStateChanges","outputs":[{"internalType":"int256","name":"amount","type":"int256"},{"internalType":"int256","name":"stakerCount","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"validatorThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"validators","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"activationEpoch","type":"uint256"},{"internalType":"uint256","name":"deactivationEpoch","type":"uint256"},{"internalType":"uint256","name":"jailTime","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"enum StakeManagerStorage.Status","name":"status","type":"uint8"},{"internalType":"uint256","name":"commissionRate","type":"uint256"},{"internalType":"uint256","name":"lastCommissionUpdate","type":"uint256"},{"internalType":"uint256","name":"delegatorsReward","type":"uint256"},{"internalType":"uint256","name":"delegatedAmount","type":"uint256"},{"internalType":"uint256","name":"initialRewardPerStake","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"withdrawDelegatorsReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"withdrawRewards","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"withdrawalDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040526023805460ff1916905534801561001a57600080fd5b5060008054610100600160a81b0319168155600180546001600160a01b0319163317908190556040516001600160a01b039190911691907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3614e9b806100856000396000f3fe608060405234801561001057600080fd5b50600436106106aa5760003560e01c80637f4b43231161036c578063b65de35e116101de578063e8afa8e81161010f578063f5e95acb116100ad578063f8a3176c11610087578063f8a3176c1461188d578063fb1ef52c14611895578063fba58f34146118be578063fc0c546a146118c6576106aa565b8063f5e95acb146117fe578063f771fc8714611868578063f83d08ba14611885576106aa565b8063f24ccbfe116100e9578063f24ccbfe146116e7578063f2fde38b146116ef578063f30b431d14611715578063f41a964214611753576106aa565b8063e8afa8e814611687578063ebde9f93146116ad578063eceec1d3146116ca576106aa565b8063d6de07d01161017c578063dcd962b211610156578063dcd962b214611637578063e568959a1461165a578063e59ee0c614611662578063e6692f491461166a576106aa565b8063d6de07d0146115fb578063d7f5549d1461161a578063d86d53e71461080f576106aa565b8063cbf383d5116101b8578063cbf383d514611510578063cd6b83881461152d578063cf30901214611535578063d1fb3d901461153d576106aa565b8063b65de35e14611495578063bc8756a9146114b2578063c710e922146114e4576106aa565b80639b33f434116102b8578063a69df4b511610256578063aa6cdb9411610230578063aa6cdb94146112ca578063b184be8114611388578063b1d23f02146113b4578063b3f958b9146113d7576106aa565b8063a69df4b5146112b2578063a7ab6961146112ba578063a8dc889b146112c2576106aa565b8063a317555711610292578063a31755571461114c578063a440ab1e1461120a578063a476907114611227578063a68548771461122f576106aa565b80639b33f434146110e95780639ddbbf85146111065780639ff1150014611129576106aa565b80638f32d59b116103255780639342c8f4116102ff5780639342c8f41461080f578063987ab9db146110b657806399d18f6f146110be5780639a8a6243146110e1576106aa565b80638f32d59b1461109e578063900cf0cf146110a657806391f1a3a5146110ae576106aa565b80637f4b43231461103e5780637f952d951461105b578063817b1cd214611063578063858a7c031461106b578063883b455f1461108e5780638da5cb5b14611096576106aa565b806348ab8b2a116105205780636352211e1161045157806376671808116103ef5780637b103999116103c95780637b103999146110095780637c7eaf1a146110115780637d669752146110195780637ed4b27c14611021576106aa565b80637667180814610fd357806377939d1014610fdb57806378f84a4414610fe3576106aa565b80636901b2531161042b5780636901b25314610f745780637060054d14610fa6578063715018a614610fae57806371d56ddb14610fb6576106aa565b80636352211e14610e7b5780636365679814610e9857806368cb812a14610ec4576106aa565b806354b8c601116104be5780635aa6e675116104985780635aa6e67514610dd45780635ab1bd5314610ddc5780635e47655f14610de457806360c8d12214610e52576106aa565b806354b8c60114610da75780635508d8e114610daf57806356342d8c14610db7576106aa565b80634fd101d7116104fa5780634fd101d714610b795780634fdd20f114610b8157806352b8115d14610c485780635325e14414610ce0576106aa565b806348ab8b2a14610b0f5780634b341aed14610b4b5780634e3c83f114610b71576106aa565b80632079fb9a116105fa57806331c2273b116105985780633862da0b116105725780633862da0b14610abc57806339610f7814610ae257806341b3d18514610aff578063451b598514610b07576106aa565b806331c2273b146109f357806334274586146109fb57806335aa2e4414610a03576106aa565b80632649263a116105d45780632649263a146108f657806328cc4e41146109275780632cf44a43146109525780632e17de781461080f576106aa565b80632079fb9a1461089b57806325316411146108b857806325726df2146108c0576106aa565b806316827b1b1161066757806317c2b9101161064157806317c2b9101461082c5780631ae4818f146108345780631dd6b9b1146108585780631e9b12ef14610875576106aa565b806316827b1b146107cc578063174e6832146107e9578063178c2c831461080f576106aa565b806306cfb104146106af578063078a13b1146106ce5780630cccfc581461070c5780630e15561a146107265780630ebb172a1461072e5780630f9fdb3714610736575b600080fd5b6106cc600480360360208110156106c557600080fd5b50356118ce565b005b6106cc600480360360808110156106e457600080fd5b506001600160a01b0381358116916020810135821691604082013581169160600135166118db565b610714611953565b60408051918252519081900360200190f35b610714611959565b61071461195f565b610714600480360360c081101561074c57600080fd5b8135916020810135916040820135916060810135916001600160a01b03608083013516919081019060c0810160a0820135600160201b81111561078e57600080fd5b8201836020820111156107a057600080fd5b803590602001918460608302840111600160201b831117156107c157600080fd5b509092509050611965565b6106cc600480360360208110156107e257600080fd5b5035611c7b565b610714600480360360208110156107ff57600080fd5b50356001600160a01b0316611d04565b6106cc6004803603602081101561082557600080fd5b5035611d8e565b610714611d9c565b61083c611da2565b604080516001600160a01b039092168252519081900360200190f35b6106cc6004803603602081101561086e57600080fd5b5035611db1565b6106cc6004803603602081101561088b57600080fd5b50356001600160a01b0316611dbe565b61083c600480360360208110156108b157600080fd5b5035611dfb565b610714611e22565b6108dd600480360360208110156108d657600080fd5b5035611e28565b6040805192835260208301919091528051918290030190f35b6109136004803603602081101561090c57600080fd5b5035611e41565b604080519115158252519081900360200190f35b6106cc6004803603606081101561093d57600080fd5b50803590602081013590604001351515611e7c565b6106cc6004803603602081101561096857600080fd5b810190602081018135600160201b81111561098257600080fd5b82018360208201111561099457600080fd5b803590602001918460208302840111600160201b831117156109b557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550611e94945050505050565b61083c611eb8565b610714611ec7565b610a2060048036036020811015610a1957600080fd5b5035611ecd565b604051808e81526020018d81526020018c81526020018b81526020018a8152602001896001600160a01b03166001600160a01b03168152602001886001600160a01b03166001600160a01b03168152602001876003811115610a7e57fe5b60ff1681526020018681526020018581526020018481526020018381526020018281526020019d505050505050505050505050505060405180910390f35b61071460048036036020811015610ad257600080fd5b50356001600160a01b0316611f3e565b61071460048036036020811015610af857600080fd5b5035611f50565b610714611f9c565b610714611fa2565b6106cc60048036036080811015610b2557600080fd5b508035906001600160a01b03602082013581169160408101359091169060600135611fa8565b61071460048036036020811015610b6157600080fd5b50356001600160a01b031661204e565b610714612185565b61071461218b565b6106cc600480360360a0811015610b9757600080fd5b6001600160a01b0382351691602081013591604082013591606081013515159181019060a081016080820135600160201b811115610bd457600080fd5b820183602082011115610be657600080fd5b803590602001918460018302840111600160201b83111715610c0757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550612191945050505050565b6106cc600480360360c0811015610c5e57600080fd5b6001600160a01b038235169160208101359160408201359160608101359160808201351515919081019060c0810160a0820135600160201b811115610ca257600080fd5b820183602082011115610cb457600080fd5b803590602001918460018302840111600160201b83111715610cd557600080fd5b5090925090506121a0565b610cfd60048036036020811015610cf657600080fd5b50356121a9565b60405180868152602001858152602001846001600160a01b03166001600160a01b031681526020018315151515815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610d68578181015183820152602001610d50565b50505050905090810190601f168015610d955780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390f35b61091361226f565b610714612278565b61083c60048036036020811015610dcd57600080fd5b503561227e565b61083c61229c565b61083c6122b0565b61071460048036036020811015610dfa57600080fd5b810190602081018135600160201b811115610e1457600080fd5b820183602082011115610e2657600080fd5b803590602001918460018302840111600160201b83111715610e4757600080fd5b5090925090506122c0565b6106cc60048036036060811015610e6857600080fd5b50803590602081013590604001356122c8565b61083c60048036036020811015610e9157600080fd5b5035612331565b6106cc60048036036040811015610eae57600080fd5b506001600160a01b03813516906020013561237d565b6106cc60048036036060811015610eda57600080fd5b813591602081013591810190606081016040820135600160201b811115610f0057600080fd5b820183602082011115610f1257600080fd5b803590602001918460018302840111600160201b83111715610f3357600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061232c945050505050565b61091360048036036060811015610f8a57600080fd5b50803590602081013590604001356001600160a01b0316612385565b610714612422565b6106cc612428565b6106cc60048036036020811015610fcc57600080fd5b5035612483565b610714612527565b61071461252d565b61071460048036036020811015610ff957600080fd5b50356001600160a01b0316612533565b61083c612545565b610714612554565b61071461255a565b6107146004803603602081101561103757600080fd5b5035612560565b6107146004803603602081101561105457600080fd5b5035612575565b61071461258a565b610714612590565b6106cc6004803603604081101561108157600080fd5b5080359060200135612596565b61083c6125dc565b61083c6125f0565b6109136125ff565b610714612642565b610714612648565b61083c61264e565b6106cc600480360360408110156110d457600080fd5b508035906020013561237d565b61071461265d565b6106cc600480360360208110156110ff57600080fd5b5035612663565b6106cc6004803603604081101561111c57600080fd5b508035906020013561271f565b6106cc6004803603604081101561113f57600080fd5b5080359060200135612785565b6106cc6004803603604081101561116257600080fd5b810190602081018135600160201b81111561117c57600080fd5b82018360208201111561118e57600080fd5b803590602001918460018302840111600160201b831117156111af57600080fd5b919390929091602081019035600160201b8111156111cc57600080fd5b8201836020820111156111de57600080fd5b803590602001918460608302840111600160201b831117156111ff57600080fd5b509092509050612819565b6106cc6004803603602081101561122057600080fd5b5035612b52565b610714612b69565b6106cc6004803603608081101561124557600080fd5b813591602081013591604082013515159190810190608081016060820135600160201b81111561127457600080fd5b82018360208201111561128657600080fd5b803590602001918460018302840111600160201b831117156112a757600080fd5b509092509050612191565b6106cc612b6f565b610714612b81565b610714612b87565b6106cc600480360360408110156112e057600080fd5b810190602081018135600160201b8111156112fa57600080fd5b82018360208201111561130c57600080fd5b803590602001918460018302840111600160201b8311171561132d57600080fd5b919390929091602081019035600160201b81111561134a57600080fd5b82018360208201111561135c57600080fd5b803590602001918460608302840111600160201b8311171561137d57600080fd5b509092509050612b8d565b6106cc6004803603604081101561139e57600080fd5b506001600160a01b038135169060200135612e46565b6106cc600480360360408110156113ca57600080fd5b5080359060200135612e58565b6106cc600480360360408110156113ed57600080fd5b810190602081018135600160201b81111561140757600080fd5b82018360208201111561141957600080fd5b803590602001918460018302840111600160201b8311171561143a57600080fd5b919390929091602081019035600160201b81111561145757600080fd5b82018360208201111561146957600080fd5b803590602001918460608302840111600160201b8311171561148a57600080fd5b509092509050612e6b565b610714600480360360208110156114ab57600080fd5b5035613096565b610913600480360360608110156114c857600080fd5b50803590602081013590604001356001600160a01b03166130e4565b6106cc600480360360408110156114fa57600080fd5b50803590602001356001600160a01b031661324c565b6106cc6004803603602081101561152657600080fd5b5035613307565b610714613390565b610913613396565b6106cc6004803603604081101561155357600080fd5b810190602081018135600160201b81111561156d57600080fd5b82018360208201111561157f57600080fd5b803590602001918460018302840111600160201b831117156115a057600080fd5b919390929091602081019035600160201b8111156115bd57600080fd5b8201836020820111156115cf57600080fd5b803590602001918460608302840111600160201b831117156115f057600080fd5b50909250905061339f565b6106cc6004803603602081101561161157600080fd5b503515156135e1565b6107146004803603602081101561163057600080fd5b503561372a565b6106cc6004803603604081101561164d57600080fd5b508035906020013561373c565b610714613746565b6108dd61374c565b6106cc6004803603602081101561168057600080fd5b5035613755565b6106cc6004803603602081101561169d57600080fd5b50356001600160a01b0316613811565b610714600480360360208110156116c357600080fd5b5035613891565b610714600480360360208110156116e057600080fd5b50356138dd565b61083c6138ef565b6106cc6004803603602081101561170557600080fd5b50356001600160a01b03166138fe565b6106cc600480360360a081101561172b57600080fd5b508035906001600160a01b03602082013516906040810135906060810135906080013561391b565b6106cc6004803603604081101561176957600080fd5b81359190810190604081016020820135600160201b81111561178a57600080fd5b82018360208201111561179c57600080fd5b803590602001918460018302840111600160201b831117156117bd57600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061373c945050505050565b6106cc600480360361012081101561181557600080fd5b506001600160a01b038135811691602081013582169160408201358116916060810135821691608082013581169160a081013582169160c082013581169160e08101358216916101009091013516613930565b6106cc6004803603602081101561187e57600080fd5b5035613ad4565b6106cc613aef565b61083c613aff565b6106cc600480360360608110156118ab57600080fd5b508035906020810135906040013561232c565b610714613b0e565b61083c613b14565b6118d6613b23565b600f55565b6118e3613b23565b6118ec81613b71565b6118f557600080fd5b60238054610100600160a81b0319169055602580546001600160a01b03199081166001600160a01b03938416179091556006805482169583169590951790945560058054851693821693909317909255600780549093169116179055565b60155481565b60135481565b60085481565b6002546000906001600160a01b0316331461197f57600080fd5b6009879055601d5487906000908190611996614d0f565b60265460408051918401808352602080820284010190915280156119c4578160200160208202803883390190505b5060408083019190915260268054825160208083028201810190945281815292830182828015611a1d57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116119ff575b50505050506060820152600060208201526026546080820152611a3e614d3e565b6026546040805191850180835260208082028401019091528015611a6c578160200160208202803883390190505b50602082015260005b88811015611c3b576000611ac38e8c8c85818110611a8f57fe5b9050606002016003806020026040519081016040528092919082600360200280828437600092019190915250613b90915050565b9050856001600160a01b0316816001600160a01b03161415611ae55750611c33565b856001600160a01b0316816001600160a01b03161015611b055750611c3b565b6001600160a01b0381166000908152601b6020908152604080832054808452601a909252909120805460068201546003909201548087529091600160a01b900460ff1690611b5790829084908e613c93565b15611be2576000838152601a60205260409020600a01549398508893611b96908390611b8a908d9063ffffffff613ccb16565b9063ffffffff613ccb16565b8651909a5015611bd057828660200151876040015181518110611bb557fe5b60209081029190910101526040860180516001019052611bdd565b611bda8785613cdd565b96505b611c2e565b6002816003811115611bf057fe5b1415611c2e57828760400151886000015181518110611c0b57fe5b602090810291909101810191909152875160019081018952908801805190910190525b505050505b600101611a75565b50611c47826000613cdd565b9150611c698e8b878e8660400151876000015187602001518860400151613dba565b9e9d5050505050505050505050505050565b611c83613b23565b80611c8d57600080fd5b60055460105460408051630f1980a560e41b8152600481018590526024810192909252516001600160a01b039092169163f1980a509160448082019260009290919082900301818387803b158015611ce457600080fd5b505af1158015611cf8573d6000803e3d6000fd5b50505060109190915550565b60065460408051632f745c5960e01b81526001600160a01b038481166004830152600060248301819052925192931691632f745c5991604480820192602092909190829003018186803b158015611d5a57600080fd5b505afa158015611d6e573d6000803e3d6000fd5b505050506040513d6020811015611d8457600080fd5b505190505b919050565b80611d9881613f22565b5050565b60175481565b6007546001600160a01b031681565b611db9613b23565b600955565b611dc6613b23565b6001600160a01b038116611dd957600080fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b60268181548110611e0857fe5b6000918252602090912001546001600160a01b0316905081565b600e5481565b601e602052600090815260409020805460019091015482565b6000818152601a6020526040812060068101548154600390920154600954611e7693600160a01b90930460ff16929190613c93565b92915050565b611e84613fac565b82611e8e81613f22565b50505050565b611e9c6125ff565b611ea557600080fd5b8051611d98906026906020840190614d5f565b6006546001600160a01b031681565b60165481565b601a60205260009081526040902080546001820154600283015460038401546004850154600586015460068701546007880154600889015460098a0154600a8b0154600b909b0154999a98999798969795966001600160a01b039586169695851695600160a01b90950460ff16948d565b601b6020526000908152604090205481565b600080611f5c83613fed565b6000858152601a6020526040902060090154909250611f959150600190611f89908463ffffffff613ccb16565b9063ffffffff61406916565b9392505050565b600c5481565b60295481565b611fb0613b23565b6000848152601a60205260409020600601546001600160a01b031680611fd557600080fd5b6040805163abf59fc960e01b81526001600160a01b03868116600483015285811660248301526044820185905291519183169163abf59fc99160648082019260009290919082900301818387803b15801561202f57600080fd5b505af1158015612043573d6000803e3d6000fd5b505050505050505050565b60006001600160a01b03821615806120dc5750600654604080516370a0823160e01b81526001600160a01b038581166004830152915191909216916370a08231916024808301926020929190829003018186803b1580156120ae57600080fd5b505afa1580156120c2573d6000803e3d6000fd5b505050506040513d60208110156120d857600080fd5b5051155b156120e957506000611d89565b60065460408051632f745c5960e01b81526001600160a01b0385811660048301526000602483018190529251601a949190911691632f745c59916044808301926020929190829003018186803b15801561214257600080fd5b505afa158015612156573d6000803e3d6000fd5b505050506040513d602081101561216c57600080fd5b5051815260208101919091526040016000205492915050565b600f5481565b60105481565b612199613fac565b5050505050565b50505050505050565b60208080526000918252604091829020805460018083015460028085015460038601805489516101009682161596909602600019011692909204601f8101889004880285018801909852878452939691956001600160a01b03851695600160a01b90950460ff16949392908301828280156122655780601f1061223a57610100808354040283529160200191612265565b820191906000526020600020905b81548152906001019060200180831161224857829003601f168201915b5050505050905085565b60195460ff1681565b60125481565b6000908152601a60205260409020600601546001600160a01b031690565b60005461010090046001600160a01b031681565b6004546001600160a01b03165b90565b600092915050565b6122d0613b23565b60255460408051602481018690526044810185905260648082018590528251808303909101815260849091019091526020810180516001600160e01b0316633064689160e11b17905261232c916001600160a01b03169061407e565b505050565b600654604080516331a9108f60e11b81526004810184905290516000926001600160a01b031691636352211e916024808301926020929190829003018186803b158015611d5a57600080fd5b611d98613fac565b600083612391816140ae565b600354604080516323b872dd60e01b81526001600160a01b03868116600483015230602483015260448201889052915191909216916323b872dd9160648083019260209291908290030181600087803b1580156123ed57600080fd5b505af1158015612401573d6000803e3d6000fd5b505050506040513d602081101561241757600080fd5b505195945050505050565b600a5481565b6124306125ff565b61243957600080fd5b6001546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600180546001600160a01b0319169055565b61248b613b23565b6009546000828152601a60205260408120600381019290925560068201805460ff60a01b1916600360a01b1790558154600a90920154906124d5908284018103906000199061411c565b6000838152601a60205260408120600a01546011546124fb91850163ffffffff61406916565b60118190556000858152601a6020526040902060050154909150611e8e906001600160a01b03166141d7565b60095481565b60185481565b601f6020526000908152604090205481565b6004546001600160a01b031681565b602a5481565b600b5481565b60008161256c816140ae565b50600092915050565b6000908152601a60205260409020600a015490565b601d5490565b60115481565b816125a0816140ae565b6000838152601a60205260409020600a01546125c2908363ffffffff61406916565b6000938452601a6020526040909320600a01929092555050565b60235461010090046001600160a01b031681565b6001546001600160a01b031690565b604080517f6d617469632e6e6574776f726b2e70726f78792e6f776e6572000000000000008152905190819003601901902054336001600160a01b039091161490565b60095490565b60275481565b6002546001600160a01b031681565b60225481565b61266b613b23565b6005546016546040805163a3b1d8cb60e01b8152600481018590526024810192909252516001600160a01b039092169163a3b1d8cb9160448082019260009290919082900301818387803b1580156126c257600080fd5b505af11580156126d6573d6000803e3d6000fd5b50505050606481111561271a576040805162461bcd60e51b8152602060048201526007602482015266746f6f2062696760c81b604482015290519081900360640190fd5b601655565b6127276125ff565b61273057600080fd5b602554604080516024810185905260448082018590528251808303909101815260649091019091526020810180516001600160e01b0316639ddbbf8560e01b179052611d98916001600160a01b03169061407e565b8161278f816140ae565b60008213156127e85760195460ff166127e8576040805162461bcd60e51b815260206004820152601660248201527511195b1959d85d1a5bdb881a5cc8191a5cd8589b195960521b604482015290519081900360640190fd5b6127f48260008061411c565b6000821261280b5761280683836142e1565b61232c565b61232c838360001902612596565b60008060008686606081101561282e57600080fd5b506005546040805163e1d5362b60e01b815283356004820181905282519097506020808601359750929094013594506000936128cd936001936001600160a01b039091169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b505af11580156128a9573d6000803e3d6000fd5b505050506040513d60208110156128bf57600080fd5b50519063ffffffff613ccb16565b905082811461291b576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608686808060200260200160405190810160405280939291908181526020016000905b82821015612980576040805160608181019092529080840287019060039083908390808284376000920191909152505050815260019091019060200161293f565b50505050509050612a28604051806040016040528060018152602001600160f81b8152508a8a6040516020018084805190602001908083835b602083106129d85780518252601f1990920191602091820191016129b9565b6001836020036101000a038019825116818451168082178552505050505050905001838380828437808301925050509350505050604051602081830303815290604052805190602001208261431c565b612a70576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6000858152601a60205260408120805490859055840390612a939082908061411c565b6000811315612abb57601154600090612ab2908363ffffffff613ccb16565b60115550612ae1565b6000811215612ae157601154600090612adc9083830363ffffffff613ccb16565b601155505b60055460408051630fe1745760e31b81526004810189905290516001600160a01b0390921691637f0ba2b89160248082019260009290919082900301818387803b158015612b2e57600080fd5b505af1158015612b42573d6000803e3d6000fd5b5050505050505050505050505050565b612b5a613b23565b80612b6457600080fd5b600e55565b601c5490565b612b77613b23565b612b7f614441565b565b60085490565b60245481565b600080600086866060811015612ba257600080fd5b506005546040805163e1d5362b60e01b81528335600482018190528251909750602080860135975092909401359450600093612c09936001936001600160a01b039091169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b9050828114612c57576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608686808060200260200160405190810160405280939291908181526020016000905b82821015612cbc5760408051606081810190925290808402870190600390839083908082843760009201919091525050508152600190910190602001612c7b565b50505050509050612d13604051806040016040528060018152602001600160f81b8152508a8a604051602001808480519060200190808383602083106129d85780518252601f1990920191602091820191016129b9565b612d5b576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6000858152601a60205260409020600381018490558054600a820154600590920154909190612d92906001600160a01b03166141d7565b612da5818301600003600019600061411c565b6000878152601a60205260408120600a0154601154612dcb91850163ffffffff61406916565b601181905560055460408051630fe1745760e31b8152600481018c905290519293506001600160a01b0390911691637f0ba2b89160248082019260009290919082900301818387803b158015612e2057600080fd5b505af1158015612e34573d6000803e3d6000fd5b50505050505050505050505050505050565b612e4e613b23565b611d98828261444d565b612e60613b23565b600c91909155600d55565b600080600086866060811015612e8057600080fd5b506005546040805163e1d5362b60e01b8152833560048201819052825190975060208086013597506001600160a01b03939095013583169550600094612ee794600194169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b9050828114612f35576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608686808060200260200160405190810160405280939291908181526020016000905b82821015612f9a5760408051606081810190925290808402870190600390839083908082843760009201919091525050508152600190910190602001612f59565b50505050509050612ff1604051806040016040528060018152602001600160f81b8152508a8a604051602001808480519060200190808383602083106129d85780518252601f1990920191602091820191016129b9565b613039576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6000858152601a6020818152604080842060050180546001600160a01b03908116808752601b855283872060001990559089168087529286208b9055948a90529290915281546001600160a01b031916179055612ae18185614512565b6000818152601a602052604081206003015481906130bb576130b783613fed565b5090505b6000838152601a60205260409020600190810154611f959190611f89908463ffffffff613ccb16565b6000838152601a60205260408120600601546001600160a01b031633148061318357506004805460408051631ab0168360e31b8152905133936001600160a01b039093169263d580b41892808201926020929091829003018186803b15801561314c57600080fd5b505afa158015613160573d6000803e3d6000fd5b505050506040513d602081101561317657600080fd5b50516001600160a01b0316145b6131c2576040805162461bcd60e51b815260206004820152600b60248201526a1b9bdd08185b1b1bddd95960aa1b604482015290519081900360640190fd5b6003546040805163a9059cbb60e01b81526001600160a01b038581166004830152602482018790529151919092169163a9059cbb9160448083019260209291908290030181600087803b15801561321857600080fd5b505af115801561322c573d6000803e3d6000fd5b505050506040513d602081101561324257600080fd5b5051949350505050565b613254613b23565b306001600160a01b0316816001600160a01b0316638da5cb5b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561329757600080fd5b505afa1580156132ab573d6000803e3d6000fd5b505050506040513d60208110156132c157600080fd5b50516001600160a01b0316146132d657600080fd5b6000918252601a602052604090912060060180546001600160a01b0319166001600160a01b03909216919091179055565b61330f613b23565b8061331957600080fd5b600554600b5460408051632dbe9d3160e21b8152600481018590526024810192909252516001600160a01b039092169163b6fa74c49160448082019260009290919082900301818387803b15801561337057600080fd5b505af1158015613384573d6000803e3d6000fd5b505050600b9190915550565b60145481565b60005460ff1681565b600080600080600080898960c08110156133b857600080fd5b506005546040805163e1d5362b60e01b81528335600482018190528251909a506020808601359a5092850135985060608501359750608085013596506001600160a01b0360a090950135851695506000946134359460019491169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b9050858114613483576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608989808060200260200160405190810160405280939291908181526020016000905b828210156134e857604080516060818101909252908084028701906003908390839080828437600092019190915250505081526001909101906020016134a7565b5050505050905061353f604051806040016040528060018152602001600160f81b8152508d8d604051602001808480519060200190808383602083106129d85780518252601f1990920191602091820191016129b9565b613587576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6135948884888888614524565b60055460408051630fe1745760e31b8152600481018b905290516001600160a01b0390921691637f0ba2b89160248082019260009290919082900301818387803b158015612e2057600080fd5b336000908152601b6020908152604080832054808452601a9092529091206006810154815460039092015460095461362693600160a01b90930460ff16929190613c93565b613667576040805162461bcd60e51b815260206004820152600d60248201526c3737ba103b30b634b230ba37b960991b604482015290519081900360640190fd5b6000818152601a60205260409020600601546001600160a01b0316806136cd576040805162461bcd60e51b815260206004820152601660248201527511195b1959d85d1a5bdb881a5cc8191a5cd8589b195960521b604482015290519081900360640190fd5b604080516303dd464160e51b8152841515600482015290516001600160a01b03831691637ba8c82091602480830192600092919082900301818387803b15801561371657600080fd5b505af11580156121a0573d6000803e3d6000fd5b60216020526000908152604090205481565b8161232c81613f22565b60285481565b601c54601d5482565b61375d613b23565b6000811161376a57600080fd5b600554600a5460408051635071805360e11b8152600481018590526024810192909252516001600160a01b039092169163a0e300a69160448082019260009290919082900301818387803b1580156137c157600080fd5b505af11580156137d5573d6000803e3d6000fd5b505050600a8290555060088190556137f481600463ffffffff6146de16565b601581905560095461380b9163ffffffff613ccb16565b60185550565b6138196125ff565b61382257600080fd5b6001600160a01b03811661383557600080fd5b6002546040516001600160a01b038084169216907f211c9015fc81c0dbd45bd99f0f29fc1c143bfd53442d5ffd722bbbef7a887fe990600090a3600280546001600160a01b0319166001600160a01b0392909216919091179055565b6005546040805163ebde9f9360e01b81526004810184905290516000926001600160a01b03169163ebde9f93916024808301926020929190829003018186803b158015611d5a57600080fd5b6000908152601a602052604090205490565b6005546001600160a01b031681565b6139066125ff565b61390f57600080fd5b61391881614700565b50565b613923613b23565b6121998585858585614524565b60235460ff1615613979576040805162461bcd60e51b815260206004820152600e60248201526d185b1c9958591e481a5b9a5d195960921b604482015290519081900360640190fd5b6023805460ff1916600117905561398f81613b71565b6139d9576040805162461bcd60e51b8152602060048201526016602482015275185d58dd1a5bdb881a5b5c1b081a5b98dbdc9c9958dd60521b604482015290519081900360640190fd5b602580546001600160a01b03199081166001600160a01b038481169190911790925560008054610100600160a81b031916610100878516021790556004805482168c84161790556002805482168b84161790556003805482168a841617905560068054821689841617905560058054821688841617905560078054909116918616919091179055613a6982614700565b50506050600881905560016009819055600a91825569044664c7bf6451f00000600b55670de0b6b3a7640000600c819055600d55611400600e556064600f55600760105560128190556108006015556016919091556019805460ff1916909117905550505050505050565b613adc613b23565b60095461380b908263ffffffff613ccb16565b613af7613b23565b612b7f61476f565b6025546001600160a01b031681565b600d5481565b6003546001600160a01b031681565b60005461010090046001600160a01b03163314612b7f5760405162461bcd60e51b8152600401808060200182810382526026815260200180614e416026913960400191505060405180910390fd5b60006001600160a01b038216613b8957506000611d89565b503b151590565b805160208201516040830151600092919060ff167f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115613bd85760009350505050611e76565b601b8160ff161015613be857601b015b8060ff16601b14158015613c0057508060ff16601c14155b15613c115760009350505050611e76565b60408051600080825260208083018085528a905260ff85168385015260608301879052608083018690529251909260019260a080820193601f1981019281900390910190855afa158015613c69573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116613c8957600080fd5b9695505050505050565b60008084118015613cab5750821580613cab57508183115b8015613cc257506001856003811115613cc057fe5b145b95945050505050565b600082820183811015611f9557600080fd5b613ce5614d0f565b82608001518360200151108015613d295750816001600160a01b03168360600151846020015181518110613d1557fe5b60200260200101516001600160a01b031614155b15613daa57601b60008460600151856020015181518110613d4657fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020548360400151846000015181518110613d8357fe5b60209081029190910181019190915283516001908101855290840180519091019052613ce5565b5050602081018051600101905290565b601c54600090613de76001611b8a6003613ddb85600263ffffffff61477e16565b9063ffffffff6146de16565b881015613e31576040805162461bcd60e51b8152602060048201526013602482015272322f332b31206e6f6e2d6d616a6f726974792160681b604482015290519081900360640190fd5b6000613e3e8b8a846147a5565b90506000613e5c6064613ddb6016548561477e90919063ffffffff16565b6001600160a01b038c166000908152601b6020908152604080832054808452601a90925290912060018101549293509091613e9d908463ffffffff613ccb16565b600182015560178b90556000613eea613edb8e613ddb6a084595161401484a000000613ecf8a8a63ffffffff61406916565b9063ffffffff61477e16565b6024549063ffffffff613ccb16565b9050613ef78b8b836148f9565b6024819055613f078989836148f9565b613f0f61492d565b50929d9c50505050505050505050505050565b600654604080516331a9108f60e11b815260048101849052905133926001600160a01b031691636352211e916024808301926020929190829003018186803b158015613f6d57600080fd5b505afa158015613f81573d6000803e3d6000fd5b505050506040513d6020811015613f9757600080fd5b50516001600160a01b03161461391857600080fd5b60005460ff1615612b7f576040805162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b604482015290519081900360640190fd5b6000818152601a602052604081208054600a90910154829190829061401990839063ffffffff613ccb16565b6000868152601a60205260409020600b0154602454919250900361405d86846140576a084595161401484a000000613ddb868863ffffffff61477e16565b856149a2565b94509450505050915091565b60008282111561407857600080fd5b50900390565b600080825160208401856127105a03f43d604051816000823e8280156140a2578282f35b8282fd5b505050505050565b6000818152601a60205260409020600601546001600160a01b03163314613918576040805162461bcd60e51b815260206004820152601860248201527f496e76616c696420636f6e747261637420616464726573730000000000000000604482015290519081900360640190fd5b806141b557600083131561414557601c5461413d908463ffffffff613ccb16565b601c55614169565b600083121561416957601c5461416590600085900363ffffffff61406916565b601c555b600082131561418d57601d54614185908363ffffffff613ccb16565b601d55612806565b600082121561280657601d546141ad90600084900363ffffffff61406916565b601d5561232c565b6000818152601e60205260409020805484018155600101805483019055505050565b602680549060009060001983018381106141ed57fe5b600091825260209091200154602680546001600160a01b03909216925090600019840190811061421957fe5b600091825260209091200180546001600160a01b031916905560001982015b80156142d057836001600160a01b0316826001600160a01b0316141561425d576142d0565b6026600182038154811061426d57fe5b9060005260206000200160009054906101000a90046001600160a01b0316826026600184038154811061429c57fe5b600091825260209091200180546001600160a01b0319166001600160a01b0392909216919091179055915060001901614238565b506000198201611e8e602682614dc4565b6000828152601a60205260409020600a0154614303908263ffffffff613ccb16565b6000928352601a6020526040909220600a019190915550565b6000806000806143396001611b8a6003613ddb6002613ecf612b69565b905060005b85518167ffffffffffffffff16101561443457600061437a88888467ffffffffffffffff168151811061436d57fe5b6020026020010151613b90565b6001600160a01b038082166000818152601b602052604090205492935090861611156143a7575050614434565b6143b081611e41565b80156143cd5750846001600160a01b0316826001600160a01b0316115b15614414576000818152601a602052604090208054600a9091015492955085926143fd828263ffffffff613ccb16565b915061440f888363ffffffff613ccb16565b975050505b83861061442a5760019650505050505050611e76565b505060010161433e565b5090911015949350505050565b6000805460ff19169055565b6003546040805163a9059cbb60e01b81526001600160a01b038581166004830152602482018590529151919092169163a9059cbb9160448083019260209291908290030181600087803b1580156144a357600080fd5b505af11580156144b7573d6000803e3d6000fd5b505050506040513d60208110156144cd57600080fd5b5051611d98576040805162461bcd60e51b815260206004820152600f60248201526e1d1c985b9cd9995c8819985a5b1959608a1b604482015290519081900360640190fd5b61451b826141d7565b611d9881614a36565b60115460009061453a908563ffffffff613ccb16565b6011819055604080516101a081018252868152600160208201819052918101869052600060608201819052608082018190526001600160a01b03891660a083015260c082015291925060e082019081526000602080830182905260408084018390526001606080860182905260808087018a905260245460a0978801528d8652601a855294839020875181559387015191840191909155908501516002830155840151600380830191909155918401516004820155918301516005830180546001600160a01b039283166001600160a01b03199182161790915560c08501516006850180549190931691161780825560e08501519260ff60a01b1990911690600160a01b90849081111561464a57fe5b0217905550610100820151600782015561012082015160088201556101408201516009820155610160820151600a82015561018090910151600b9091015560008681526021602090815260408083208690556001600160a01b0388168352601b90915281208790556146c2908584019060019061411c565b600086815260208052604090206001018390556140a685614a36565b60008082116146ec57600080fd5b60008284816146f757fe5b04949350505050565b6001600160a01b03811661471357600080fd5b6001546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000805460ff19166001179055565b60008261478d57506000611e76565b8282028284828161479a57fe5b0414611f9557600080fd5b600e54600b5460009190826147c58388816147bc57fe5b04602954614b50565b90506000811180156147d957506027548114155b1561481a57602754156148145760006064602a548402816147f657fe5b04905081602754111561480c5791820191614812565b80830392505b505b60278190555b6000838811156148b3576028546148626148526064613ddb614845600260001989018902048661477e565b889063ffffffff61477e16565b611f89868663ffffffff61477e16565b9150614884614877848763ffffffff61477e16565b8a9063ffffffff61406916565b98506148af6148a26064613ddb84613ecf898963ffffffff61477e16565b859063ffffffff61406916565b9350505b6148d76148ca85613ddb8b8763ffffffff61477e16565b829063ffffffff613ccb16565b90506148ed86613ddb838a63ffffffff61477e16565b98975050505050505050565b60245460005b838110156121995761492585828151811061491657fe5b60200260200101518385614b66565b6001016148ff565b600954600061494382600163ffffffff613ccb16565b905061494d614de8565b506000818152601e60209081526040808320815180830190925280548083526001909101549282018390529092614984929061411c565b506000918252601e6020526040822082815560010191909155600955565b600080826149b557506000905080614a2d565b60006149cb84613ddb888863ffffffff61477e16565b6000888152601a60205260409020600701549091508015614a1257614a0f614a026064613ddb84613ecf8b8863ffffffff61406916565b839063ffffffff613ccb16565b91505b6000614a24878463ffffffff61406916565b92945091925050505b94509492505050565b6026805460018101825560008290527f744a2cf8fd7008e3d53b67916e73460df9fa5214e3ef23dd4259ca09493a35940180546001600160a01b0319166001600160a01b0384161790555460001901805b8015614b0857600060266001830381548110614a9f57fe5b6000918252602090912001546001600160a01b0390811691508416811015614ac75750614b08565b8060268381548110614ad557fe5b600091825260209091200180546001600160a01b0319166001600160a01b03929092169190911790555060001901614a87565b81811461232c578260268281548110614b1d57fe5b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550505050565b6000818310614b5f5781611f95565b5090919050565b6000838152601a60205260409020600b015482811015614be5576000848152601a602052604090208054600a909101548015614bcd576000614bae838363ffffffff613ccb16565b9050614bc7878484614bc28b868c8b614c07565b614c2b565b50614be2565b614be286614bdd88858988614c07565b614cd1565b50505b80821115611e8e576000848152601a60205260409020600b0182905550505050565b6000818303613c896a084595161401484a000000613ddb838863ffffffff61477e16565b6000614c3d838563ffffffff613ccb16565b9050600080614c4e878786866149a2565b90925090508015614c8e576000878152601a6020526040902060090154614c7b908263ffffffff613ccb16565b6000888152601a60205260409020600901555b81156121a0576000878152601a6020526040902060010154614cb6908363ffffffff613ccb16565b6000888152601a602052604090206001015550505050505050565b8015611d98576000828152601a6020526040902060010154614cf9908263ffffffff613ccb16565b6000838152601a60205260409020600101555050565b6040518060a0016040528060008152602001600081526020016060815260200160608152602001600081525090565b60405180606001604052806000815260200160608152602001600081525090565b828054828255906000526020600020908101928215614db4579160200282015b82811115614db457825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190614d7f565b50614dc0929150614e02565b5090565b81548183558181111561232c5760008381526020902061232c918101908301614e26565b604051806040016040528060008152602001600081525090565b6122bd91905b80821115614dc05780546001600160a01b0319168155600101614e08565b6122bd91905b80821115614dc05760008155600101614e2c56fe4f6e6c7920676f7665726e616e636520636f6e747261637420697320617574686f72697a6564a265627a7a7231582023d76d2f4b31a8301ab8d82424ac6db9c3dfd4d6b8f199bcdd0011603654804264736f6c63430005110032
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106106aa5760003560e01c80637f4b43231161036c578063b65de35e116101de578063e8afa8e81161010f578063f5e95acb116100ad578063f8a3176c11610087578063f8a3176c1461188d578063fb1ef52c14611895578063fba58f34146118be578063fc0c546a146118c6576106aa565b8063f5e95acb146117fe578063f771fc8714611868578063f83d08ba14611885576106aa565b8063f24ccbfe116100e9578063f24ccbfe146116e7578063f2fde38b146116ef578063f30b431d14611715578063f41a964214611753576106aa565b8063e8afa8e814611687578063ebde9f93146116ad578063eceec1d3146116ca576106aa565b8063d6de07d01161017c578063dcd962b211610156578063dcd962b214611637578063e568959a1461165a578063e59ee0c614611662578063e6692f491461166a576106aa565b8063d6de07d0146115fb578063d7f5549d1461161a578063d86d53e71461080f576106aa565b8063cbf383d5116101b8578063cbf383d514611510578063cd6b83881461152d578063cf30901214611535578063d1fb3d901461153d576106aa565b8063b65de35e14611495578063bc8756a9146114b2578063c710e922146114e4576106aa565b80639b33f434116102b8578063a69df4b511610256578063aa6cdb9411610230578063aa6cdb94146112ca578063b184be8114611388578063b1d23f02146113b4578063b3f958b9146113d7576106aa565b8063a69df4b5146112b2578063a7ab6961146112ba578063a8dc889b146112c2576106aa565b8063a317555711610292578063a31755571461114c578063a440ab1e1461120a578063a476907114611227578063a68548771461122f576106aa565b80639b33f434146110e95780639ddbbf85146111065780639ff1150014611129576106aa565b80638f32d59b116103255780639342c8f4116102ff5780639342c8f41461080f578063987ab9db146110b657806399d18f6f146110be5780639a8a6243146110e1576106aa565b80638f32d59b1461109e578063900cf0cf146110a657806391f1a3a5146110ae576106aa565b80637f4b43231461103e5780637f952d951461105b578063817b1cd214611063578063858a7c031461106b578063883b455f1461108e5780638da5cb5b14611096576106aa565b806348ab8b2a116105205780636352211e1161045157806376671808116103ef5780637b103999116103c95780637b103999146110095780637c7eaf1a146110115780637d669752146110195780637ed4b27c14611021576106aa565b80637667180814610fd357806377939d1014610fdb57806378f84a4414610fe3576106aa565b80636901b2531161042b5780636901b25314610f745780637060054d14610fa6578063715018a614610fae57806371d56ddb14610fb6576106aa565b80636352211e14610e7b5780636365679814610e9857806368cb812a14610ec4576106aa565b806354b8c601116104be5780635aa6e675116104985780635aa6e67514610dd45780635ab1bd5314610ddc5780635e47655f14610de457806360c8d12214610e52576106aa565b806354b8c60114610da75780635508d8e114610daf57806356342d8c14610db7576106aa565b80634fd101d7116104fa5780634fd101d714610b795780634fdd20f114610b8157806352b8115d14610c485780635325e14414610ce0576106aa565b806348ab8b2a14610b0f5780634b341aed14610b4b5780634e3c83f114610b71576106aa565b80632079fb9a116105fa57806331c2273b116105985780633862da0b116105725780633862da0b14610abc57806339610f7814610ae257806341b3d18514610aff578063451b598514610b07576106aa565b806331c2273b146109f357806334274586146109fb57806335aa2e4414610a03576106aa565b80632649263a116105d45780632649263a146108f657806328cc4e41146109275780632cf44a43146109525780632e17de781461080f576106aa565b80632079fb9a1461089b57806325316411146108b857806325726df2146108c0576106aa565b806316827b1b1161066757806317c2b9101161064157806317c2b9101461082c5780631ae4818f146108345780631dd6b9b1146108585780631e9b12ef14610875576106aa565b806316827b1b146107cc578063174e6832146107e9578063178c2c831461080f576106aa565b806306cfb104146106af578063078a13b1146106ce5780630cccfc581461070c5780630e15561a146107265780630ebb172a1461072e5780630f9fdb3714610736575b600080fd5b6106cc600480360360208110156106c557600080fd5b50356118ce565b005b6106cc600480360360808110156106e457600080fd5b506001600160a01b0381358116916020810135821691604082013581169160600135166118db565b610714611953565b60408051918252519081900360200190f35b610714611959565b61071461195f565b610714600480360360c081101561074c57600080fd5b8135916020810135916040820135916060810135916001600160a01b03608083013516919081019060c0810160a0820135600160201b81111561078e57600080fd5b8201836020820111156107a057600080fd5b803590602001918460608302840111600160201b831117156107c157600080fd5b509092509050611965565b6106cc600480360360208110156107e257600080fd5b5035611c7b565b610714600480360360208110156107ff57600080fd5b50356001600160a01b0316611d04565b6106cc6004803603602081101561082557600080fd5b5035611d8e565b610714611d9c565b61083c611da2565b604080516001600160a01b039092168252519081900360200190f35b6106cc6004803603602081101561086e57600080fd5b5035611db1565b6106cc6004803603602081101561088b57600080fd5b50356001600160a01b0316611dbe565b61083c600480360360208110156108b157600080fd5b5035611dfb565b610714611e22565b6108dd600480360360208110156108d657600080fd5b5035611e28565b6040805192835260208301919091528051918290030190f35b6109136004803603602081101561090c57600080fd5b5035611e41565b604080519115158252519081900360200190f35b6106cc6004803603606081101561093d57600080fd5b50803590602081013590604001351515611e7c565b6106cc6004803603602081101561096857600080fd5b810190602081018135600160201b81111561098257600080fd5b82018360208201111561099457600080fd5b803590602001918460208302840111600160201b831117156109b557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550611e94945050505050565b61083c611eb8565b610714611ec7565b610a2060048036036020811015610a1957600080fd5b5035611ecd565b604051808e81526020018d81526020018c81526020018b81526020018a8152602001896001600160a01b03166001600160a01b03168152602001886001600160a01b03166001600160a01b03168152602001876003811115610a7e57fe5b60ff1681526020018681526020018581526020018481526020018381526020018281526020019d505050505050505050505050505060405180910390f35b61071460048036036020811015610ad257600080fd5b50356001600160a01b0316611f3e565b61071460048036036020811015610af857600080fd5b5035611f50565b610714611f9c565b610714611fa2565b6106cc60048036036080811015610b2557600080fd5b508035906001600160a01b03602082013581169160408101359091169060600135611fa8565b61071460048036036020811015610b6157600080fd5b50356001600160a01b031661204e565b610714612185565b61071461218b565b6106cc600480360360a0811015610b9757600080fd5b6001600160a01b0382351691602081013591604082013591606081013515159181019060a081016080820135600160201b811115610bd457600080fd5b820183602082011115610be657600080fd5b803590602001918460018302840111600160201b83111715610c0757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550612191945050505050565b6106cc600480360360c0811015610c5e57600080fd5b6001600160a01b038235169160208101359160408201359160608101359160808201351515919081019060c0810160a0820135600160201b811115610ca257600080fd5b820183602082011115610cb457600080fd5b803590602001918460018302840111600160201b83111715610cd557600080fd5b5090925090506121a0565b610cfd60048036036020811015610cf657600080fd5b50356121a9565b60405180868152602001858152602001846001600160a01b03166001600160a01b031681526020018315151515815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610d68578181015183820152602001610d50565b50505050905090810190601f168015610d955780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390f35b61091361226f565b610714612278565b61083c60048036036020811015610dcd57600080fd5b503561227e565b61083c61229c565b61083c6122b0565b61071460048036036020811015610dfa57600080fd5b810190602081018135600160201b811115610e1457600080fd5b820183602082011115610e2657600080fd5b803590602001918460018302840111600160201b83111715610e4757600080fd5b5090925090506122c0565b6106cc60048036036060811015610e6857600080fd5b50803590602081013590604001356122c8565b61083c60048036036020811015610e9157600080fd5b5035612331565b6106cc60048036036040811015610eae57600080fd5b506001600160a01b03813516906020013561237d565b6106cc60048036036060811015610eda57600080fd5b813591602081013591810190606081016040820135600160201b811115610f0057600080fd5b820183602082011115610f1257600080fd5b803590602001918460018302840111600160201b83111715610f3357600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061232c945050505050565b61091360048036036060811015610f8a57600080fd5b50803590602081013590604001356001600160a01b0316612385565b610714612422565b6106cc612428565b6106cc60048036036020811015610fcc57600080fd5b5035612483565b610714612527565b61071461252d565b61071460048036036020811015610ff957600080fd5b50356001600160a01b0316612533565b61083c612545565b610714612554565b61071461255a565b6107146004803603602081101561103757600080fd5b5035612560565b6107146004803603602081101561105457600080fd5b5035612575565b61071461258a565b610714612590565b6106cc6004803603604081101561108157600080fd5b5080359060200135612596565b61083c6125dc565b61083c6125f0565b6109136125ff565b610714612642565b610714612648565b61083c61264e565b6106cc600480360360408110156110d457600080fd5b508035906020013561237d565b61071461265d565b6106cc600480360360208110156110ff57600080fd5b5035612663565b6106cc6004803603604081101561111c57600080fd5b508035906020013561271f565b6106cc6004803603604081101561113f57600080fd5b5080359060200135612785565b6106cc6004803603604081101561116257600080fd5b810190602081018135600160201b81111561117c57600080fd5b82018360208201111561118e57600080fd5b803590602001918460018302840111600160201b831117156111af57600080fd5b919390929091602081019035600160201b8111156111cc57600080fd5b8201836020820111156111de57600080fd5b803590602001918460608302840111600160201b831117156111ff57600080fd5b509092509050612819565b6106cc6004803603602081101561122057600080fd5b5035612b52565b610714612b69565b6106cc6004803603608081101561124557600080fd5b813591602081013591604082013515159190810190608081016060820135600160201b81111561127457600080fd5b82018360208201111561128657600080fd5b803590602001918460018302840111600160201b831117156112a757600080fd5b509092509050612191565b6106cc612b6f565b610714612b81565b610714612b87565b6106cc600480360360408110156112e057600080fd5b810190602081018135600160201b8111156112fa57600080fd5b82018360208201111561130c57600080fd5b803590602001918460018302840111600160201b8311171561132d57600080fd5b919390929091602081019035600160201b81111561134a57600080fd5b82018360208201111561135c57600080fd5b803590602001918460608302840111600160201b8311171561137d57600080fd5b509092509050612b8d565b6106cc6004803603604081101561139e57600080fd5b506001600160a01b038135169060200135612e46565b6106cc600480360360408110156113ca57600080fd5b5080359060200135612e58565b6106cc600480360360408110156113ed57600080fd5b810190602081018135600160201b81111561140757600080fd5b82018360208201111561141957600080fd5b803590602001918460018302840111600160201b8311171561143a57600080fd5b919390929091602081019035600160201b81111561145757600080fd5b82018360208201111561146957600080fd5b803590602001918460608302840111600160201b8311171561148a57600080fd5b509092509050612e6b565b610714600480360360208110156114ab57600080fd5b5035613096565b610913600480360360608110156114c857600080fd5b50803590602081013590604001356001600160a01b03166130e4565b6106cc600480360360408110156114fa57600080fd5b50803590602001356001600160a01b031661324c565b6106cc6004803603602081101561152657600080fd5b5035613307565b610714613390565b610913613396565b6106cc6004803603604081101561155357600080fd5b810190602081018135600160201b81111561156d57600080fd5b82018360208201111561157f57600080fd5b803590602001918460018302840111600160201b831117156115a057600080fd5b919390929091602081019035600160201b8111156115bd57600080fd5b8201836020820111156115cf57600080fd5b803590602001918460608302840111600160201b831117156115f057600080fd5b50909250905061339f565b6106cc6004803603602081101561161157600080fd5b503515156135e1565b6107146004803603602081101561163057600080fd5b503561372a565b6106cc6004803603604081101561164d57600080fd5b508035906020013561373c565b610714613746565b6108dd61374c565b6106cc6004803603602081101561168057600080fd5b5035613755565b6106cc6004803603602081101561169d57600080fd5b50356001600160a01b0316613811565b610714600480360360208110156116c357600080fd5b5035613891565b610714600480360360208110156116e057600080fd5b50356138dd565b61083c6138ef565b6106cc6004803603602081101561170557600080fd5b50356001600160a01b03166138fe565b6106cc600480360360a081101561172b57600080fd5b508035906001600160a01b03602082013516906040810135906060810135906080013561391b565b6106cc6004803603604081101561176957600080fd5b81359190810190604081016020820135600160201b81111561178a57600080fd5b82018360208201111561179c57600080fd5b803590602001918460018302840111600160201b831117156117bd57600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061373c945050505050565b6106cc600480360361012081101561181557600080fd5b506001600160a01b038135811691602081013582169160408201358116916060810135821691608082013581169160a081013582169160c082013581169160e08101358216916101009091013516613930565b6106cc6004803603602081101561187e57600080fd5b5035613ad4565b6106cc613aef565b61083c613aff565b6106cc600480360360608110156118ab57600080fd5b508035906020810135906040013561232c565b610714613b0e565b61083c613b14565b6118d6613b23565b600f55565b6118e3613b23565b6118ec81613b71565b6118f557600080fd5b60238054610100600160a81b0319169055602580546001600160a01b03199081166001600160a01b03938416179091556006805482169583169590951790945560058054851693821693909317909255600780549093169116179055565b60155481565b60135481565b60085481565b6002546000906001600160a01b0316331461197f57600080fd5b6009879055601d5487906000908190611996614d0f565b60265460408051918401808352602080820284010190915280156119c4578160200160208202803883390190505b5060408083019190915260268054825160208083028201810190945281815292830182828015611a1d57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116119ff575b50505050506060820152600060208201526026546080820152611a3e614d3e565b6026546040805191850180835260208082028401019091528015611a6c578160200160208202803883390190505b50602082015260005b88811015611c3b576000611ac38e8c8c85818110611a8f57fe5b9050606002016003806020026040519081016040528092919082600360200280828437600092019190915250613b90915050565b9050856001600160a01b0316816001600160a01b03161415611ae55750611c33565b856001600160a01b0316816001600160a01b03161015611b055750611c3b565b6001600160a01b0381166000908152601b6020908152604080832054808452601a909252909120805460068201546003909201548087529091600160a01b900460ff1690611b5790829084908e613c93565b15611be2576000838152601a60205260409020600a01549398508893611b96908390611b8a908d9063ffffffff613ccb16565b9063ffffffff613ccb16565b8651909a5015611bd057828660200151876040015181518110611bb557fe5b60209081029190910101526040860180516001019052611bdd565b611bda8785613cdd565b96505b611c2e565b6002816003811115611bf057fe5b1415611c2e57828760400151886000015181518110611c0b57fe5b602090810291909101810191909152875160019081018952908801805190910190525b505050505b600101611a75565b50611c47826000613cdd565b9150611c698e8b878e8660400151876000015187602001518860400151613dba565b9e9d5050505050505050505050505050565b611c83613b23565b80611c8d57600080fd5b60055460105460408051630f1980a560e41b8152600481018590526024810192909252516001600160a01b039092169163f1980a509160448082019260009290919082900301818387803b158015611ce457600080fd5b505af1158015611cf8573d6000803e3d6000fd5b50505060109190915550565b60065460408051632f745c5960e01b81526001600160a01b038481166004830152600060248301819052925192931691632f745c5991604480820192602092909190829003018186803b158015611d5a57600080fd5b505afa158015611d6e573d6000803e3d6000fd5b505050506040513d6020811015611d8457600080fd5b505190505b919050565b80611d9881613f22565b5050565b60175481565b6007546001600160a01b031681565b611db9613b23565b600955565b611dc6613b23565b6001600160a01b038116611dd957600080fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b60268181548110611e0857fe5b6000918252602090912001546001600160a01b0316905081565b600e5481565b601e602052600090815260409020805460019091015482565b6000818152601a6020526040812060068101548154600390920154600954611e7693600160a01b90930460ff16929190613c93565b92915050565b611e84613fac565b82611e8e81613f22565b50505050565b611e9c6125ff565b611ea557600080fd5b8051611d98906026906020840190614d5f565b6006546001600160a01b031681565b60165481565b601a60205260009081526040902080546001820154600283015460038401546004850154600586015460068701546007880154600889015460098a0154600a8b0154600b909b0154999a98999798969795966001600160a01b039586169695851695600160a01b90950460ff16948d565b601b6020526000908152604090205481565b600080611f5c83613fed565b6000858152601a6020526040902060090154909250611f959150600190611f89908463ffffffff613ccb16565b9063ffffffff61406916565b9392505050565b600c5481565b60295481565b611fb0613b23565b6000848152601a60205260409020600601546001600160a01b031680611fd557600080fd5b6040805163abf59fc960e01b81526001600160a01b03868116600483015285811660248301526044820185905291519183169163abf59fc99160648082019260009290919082900301818387803b15801561202f57600080fd5b505af1158015612043573d6000803e3d6000fd5b505050505050505050565b60006001600160a01b03821615806120dc5750600654604080516370a0823160e01b81526001600160a01b038581166004830152915191909216916370a08231916024808301926020929190829003018186803b1580156120ae57600080fd5b505afa1580156120c2573d6000803e3d6000fd5b505050506040513d60208110156120d857600080fd5b5051155b156120e957506000611d89565b60065460408051632f745c5960e01b81526001600160a01b0385811660048301526000602483018190529251601a949190911691632f745c59916044808301926020929190829003018186803b15801561214257600080fd5b505afa158015612156573d6000803e3d6000fd5b505050506040513d602081101561216c57600080fd5b5051815260208101919091526040016000205492915050565b600f5481565b60105481565b612199613fac565b5050505050565b50505050505050565b60208080526000918252604091829020805460018083015460028085015460038601805489516101009682161596909602600019011692909204601f8101889004880285018801909852878452939691956001600160a01b03851695600160a01b90950460ff16949392908301828280156122655780601f1061223a57610100808354040283529160200191612265565b820191906000526020600020905b81548152906001019060200180831161224857829003601f168201915b5050505050905085565b60195460ff1681565b60125481565b6000908152601a60205260409020600601546001600160a01b031690565b60005461010090046001600160a01b031681565b6004546001600160a01b03165b90565b600092915050565b6122d0613b23565b60255460408051602481018690526044810185905260648082018590528251808303909101815260849091019091526020810180516001600160e01b0316633064689160e11b17905261232c916001600160a01b03169061407e565b505050565b600654604080516331a9108f60e11b81526004810184905290516000926001600160a01b031691636352211e916024808301926020929190829003018186803b158015611d5a57600080fd5b611d98613fac565b600083612391816140ae565b600354604080516323b872dd60e01b81526001600160a01b03868116600483015230602483015260448201889052915191909216916323b872dd9160648083019260209291908290030181600087803b1580156123ed57600080fd5b505af1158015612401573d6000803e3d6000fd5b505050506040513d602081101561241757600080fd5b505195945050505050565b600a5481565b6124306125ff565b61243957600080fd5b6001546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600180546001600160a01b0319169055565b61248b613b23565b6009546000828152601a60205260408120600381019290925560068201805460ff60a01b1916600360a01b1790558154600a90920154906124d5908284018103906000199061411c565b6000838152601a60205260408120600a01546011546124fb91850163ffffffff61406916565b60118190556000858152601a6020526040902060050154909150611e8e906001600160a01b03166141d7565b60095481565b60185481565b601f6020526000908152604090205481565b6004546001600160a01b031681565b602a5481565b600b5481565b60008161256c816140ae565b50600092915050565b6000908152601a60205260409020600a015490565b601d5490565b60115481565b816125a0816140ae565b6000838152601a60205260409020600a01546125c2908363ffffffff61406916565b6000938452601a6020526040909320600a01929092555050565b60235461010090046001600160a01b031681565b6001546001600160a01b031690565b604080517f6d617469632e6e6574776f726b2e70726f78792e6f776e6572000000000000008152905190819003601901902054336001600160a01b039091161490565b60095490565b60275481565b6002546001600160a01b031681565b60225481565b61266b613b23565b6005546016546040805163a3b1d8cb60e01b8152600481018590526024810192909252516001600160a01b039092169163a3b1d8cb9160448082019260009290919082900301818387803b1580156126c257600080fd5b505af11580156126d6573d6000803e3d6000fd5b50505050606481111561271a576040805162461bcd60e51b8152602060048201526007602482015266746f6f2062696760c81b604482015290519081900360640190fd5b601655565b6127276125ff565b61273057600080fd5b602554604080516024810185905260448082018590528251808303909101815260649091019091526020810180516001600160e01b0316639ddbbf8560e01b179052611d98916001600160a01b03169061407e565b8161278f816140ae565b60008213156127e85760195460ff166127e8576040805162461bcd60e51b815260206004820152601660248201527511195b1959d85d1a5bdb881a5cc8191a5cd8589b195960521b604482015290519081900360640190fd5b6127f48260008061411c565b6000821261280b5761280683836142e1565b61232c565b61232c838360001902612596565b60008060008686606081101561282e57600080fd5b506005546040805163e1d5362b60e01b815283356004820181905282519097506020808601359750929094013594506000936128cd936001936001600160a01b039091169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b505af11580156128a9573d6000803e3d6000fd5b505050506040513d60208110156128bf57600080fd5b50519063ffffffff613ccb16565b905082811461291b576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608686808060200260200160405190810160405280939291908181526020016000905b82821015612980576040805160608181019092529080840287019060039083908390808284376000920191909152505050815260019091019060200161293f565b50505050509050612a28604051806040016040528060018152602001600160f81b8152508a8a6040516020018084805190602001908083835b602083106129d85780518252601f1990920191602091820191016129b9565b6001836020036101000a038019825116818451168082178552505050505050905001838380828437808301925050509350505050604051602081830303815290604052805190602001208261431c565b612a70576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6000858152601a60205260408120805490859055840390612a939082908061411c565b6000811315612abb57601154600090612ab2908363ffffffff613ccb16565b60115550612ae1565b6000811215612ae157601154600090612adc9083830363ffffffff613ccb16565b601155505b60055460408051630fe1745760e31b81526004810189905290516001600160a01b0390921691637f0ba2b89160248082019260009290919082900301818387803b158015612b2e57600080fd5b505af1158015612b42573d6000803e3d6000fd5b5050505050505050505050505050565b612b5a613b23565b80612b6457600080fd5b600e55565b601c5490565b612b77613b23565b612b7f614441565b565b60085490565b60245481565b600080600086866060811015612ba257600080fd5b506005546040805163e1d5362b60e01b81528335600482018190528251909750602080860135975092909401359450600093612c09936001936001600160a01b039091169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b9050828114612c57576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608686808060200260200160405190810160405280939291908181526020016000905b82821015612cbc5760408051606081810190925290808402870190600390839083908082843760009201919091525050508152600190910190602001612c7b565b50505050509050612d13604051806040016040528060018152602001600160f81b8152508a8a604051602001808480519060200190808383602083106129d85780518252601f1990920191602091820191016129b9565b612d5b576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6000858152601a60205260409020600381018490558054600a820154600590920154909190612d92906001600160a01b03166141d7565b612da5818301600003600019600061411c565b6000878152601a60205260408120600a0154601154612dcb91850163ffffffff61406916565b601181905560055460408051630fe1745760e31b8152600481018c905290519293506001600160a01b0390911691637f0ba2b89160248082019260009290919082900301818387803b158015612e2057600080fd5b505af1158015612e34573d6000803e3d6000fd5b50505050505050505050505050505050565b612e4e613b23565b611d98828261444d565b612e60613b23565b600c91909155600d55565b600080600086866060811015612e8057600080fd5b506005546040805163e1d5362b60e01b8152833560048201819052825190975060208086013597506001600160a01b03939095013583169550600094612ee794600194169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b9050828114612f35576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608686808060200260200160405190810160405280939291908181526020016000905b82821015612f9a5760408051606081810190925290808402870190600390839083908082843760009201919091525050508152600190910190602001612f59565b50505050509050612ff1604051806040016040528060018152602001600160f81b8152508a8a604051602001808480519060200190808383602083106129d85780518252601f1990920191602091820191016129b9565b613039576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6000858152601a6020818152604080842060050180546001600160a01b03908116808752601b855283872060001990559089168087529286208b9055948a90529290915281546001600160a01b031916179055612ae18185614512565b6000818152601a602052604081206003015481906130bb576130b783613fed565b5090505b6000838152601a60205260409020600190810154611f959190611f89908463ffffffff613ccb16565b6000838152601a60205260408120600601546001600160a01b031633148061318357506004805460408051631ab0168360e31b8152905133936001600160a01b039093169263d580b41892808201926020929091829003018186803b15801561314c57600080fd5b505afa158015613160573d6000803e3d6000fd5b505050506040513d602081101561317657600080fd5b50516001600160a01b0316145b6131c2576040805162461bcd60e51b815260206004820152600b60248201526a1b9bdd08185b1b1bddd95960aa1b604482015290519081900360640190fd5b6003546040805163a9059cbb60e01b81526001600160a01b038581166004830152602482018790529151919092169163a9059cbb9160448083019260209291908290030181600087803b15801561321857600080fd5b505af115801561322c573d6000803e3d6000fd5b505050506040513d602081101561324257600080fd5b5051949350505050565b613254613b23565b306001600160a01b0316816001600160a01b0316638da5cb5b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561329757600080fd5b505afa1580156132ab573d6000803e3d6000fd5b505050506040513d60208110156132c157600080fd5b50516001600160a01b0316146132d657600080fd5b6000918252601a602052604090912060060180546001600160a01b0319166001600160a01b03909216919091179055565b61330f613b23565b8061331957600080fd5b600554600b5460408051632dbe9d3160e21b8152600481018590526024810192909252516001600160a01b039092169163b6fa74c49160448082019260009290919082900301818387803b15801561337057600080fd5b505af1158015613384573d6000803e3d6000fd5b505050600b9190915550565b60145481565b60005460ff1681565b600080600080600080898960c08110156133b857600080fd5b506005546040805163e1d5362b60e01b81528335600482018190528251909a506020808601359a5092850135985060608501359750608085013596506001600160a01b0360a090950135851695506000946134359460019491169263e1d5362b926024808301939282900301818987803b15801561289557600080fd5b9050858114613483576040805162461bcd60e51b8152602060048201526015602482015274496e76616c6964207374616b696e67206e6f6e636560581b604482015290519081900360640190fd5b60608989808060200260200160405190810160405280939291908181526020016000905b828210156134e857604080516060818101909252908084028701906003908390839080828437600092019190915250505081526001909101906020016134a7565b5050505050905061353f604051806040016040528060018152602001600160f81b8152508d8d604051602001808480519060200190808383602083106129d85780518252601f1990920191602091820191016129b9565b613587576040805162461bcd60e51b81526020600482015260146024820152730c8bcccacc48141bddd95c881c995c5d5a5c995960621b604482015290519081900360640190fd5b6135948884888888614524565b60055460408051630fe1745760e31b8152600481018b905290516001600160a01b0390921691637f0ba2b89160248082019260009290919082900301818387803b158015612e2057600080fd5b336000908152601b6020908152604080832054808452601a9092529091206006810154815460039092015460095461362693600160a01b90930460ff16929190613c93565b613667576040805162461bcd60e51b815260206004820152600d60248201526c3737ba103b30b634b230ba37b960991b604482015290519081900360640190fd5b6000818152601a60205260409020600601546001600160a01b0316806136cd576040805162461bcd60e51b815260206004820152601660248201527511195b1959d85d1a5bdb881a5cc8191a5cd8589b195960521b604482015290519081900360640190fd5b604080516303dd464160e51b8152841515600482015290516001600160a01b03831691637ba8c82091602480830192600092919082900301818387803b15801561371657600080fd5b505af11580156121a0573d6000803e3d6000fd5b60216020526000908152604090205481565b8161232c81613f22565b60285481565b601c54601d5482565b61375d613b23565b6000811161376a57600080fd5b600554600a5460408051635071805360e11b8152600481018590526024810192909252516001600160a01b039092169163a0e300a69160448082019260009290919082900301818387803b1580156137c157600080fd5b505af11580156137d5573d6000803e3d6000fd5b505050600a8290555060088190556137f481600463ffffffff6146de16565b601581905560095461380b9163ffffffff613ccb16565b60185550565b6138196125ff565b61382257600080fd5b6001600160a01b03811661383557600080fd5b6002546040516001600160a01b038084169216907f211c9015fc81c0dbd45bd99f0f29fc1c143bfd53442d5ffd722bbbef7a887fe990600090a3600280546001600160a01b0319166001600160a01b0392909216919091179055565b6005546040805163ebde9f9360e01b81526004810184905290516000926001600160a01b03169163ebde9f93916024808301926020929190829003018186803b158015611d5a57600080fd5b6000908152601a602052604090205490565b6005546001600160a01b031681565b6139066125ff565b61390f57600080fd5b61391881614700565b50565b613923613b23565b6121998585858585614524565b60235460ff1615613979576040805162461bcd60e51b815260206004820152600e60248201526d185b1c9958591e481a5b9a5d195960921b604482015290519081900360640190fd5b6023805460ff1916600117905561398f81613b71565b6139d9576040805162461bcd60e51b8152602060048201526016602482015275185d58dd1a5bdb881a5b5c1b081a5b98dbdc9c9958dd60521b604482015290519081900360640190fd5b602580546001600160a01b03199081166001600160a01b038481169190911790925560008054610100600160a81b031916610100878516021790556004805482168c84161790556002805482168b84161790556003805482168a841617905560068054821689841617905560058054821688841617905560078054909116918616919091179055613a6982614700565b50506050600881905560016009819055600a91825569044664c7bf6451f00000600b55670de0b6b3a7640000600c819055600d55611400600e556064600f55600760105560128190556108006015556016919091556019805460ff1916909117905550505050505050565b613adc613b23565b60095461380b908263ffffffff613ccb16565b613af7613b23565b612b7f61476f565b6025546001600160a01b031681565b600d5481565b6003546001600160a01b031681565b60005461010090046001600160a01b03163314612b7f5760405162461bcd60e51b8152600401808060200182810382526026815260200180614e416026913960400191505060405180910390fd5b60006001600160a01b038216613b8957506000611d89565b503b151590565b805160208201516040830151600092919060ff167f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115613bd85760009350505050611e76565b601b8160ff161015613be857601b015b8060ff16601b14158015613c0057508060ff16601c14155b15613c115760009350505050611e76565b60408051600080825260208083018085528a905260ff85168385015260608301879052608083018690529251909260019260a080820193601f1981019281900390910190855afa158015613c69573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116613c8957600080fd5b9695505050505050565b60008084118015613cab5750821580613cab57508183115b8015613cc257506001856003811115613cc057fe5b145b95945050505050565b600082820183811015611f9557600080fd5b613ce5614d0f565b82608001518360200151108015613d295750816001600160a01b03168360600151846020015181518110613d1557fe5b60200260200101516001600160a01b031614155b15613daa57601b60008460600151856020015181518110613d4657fe5b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020548360400151846000015181518110613d8357fe5b60209081029190910181019190915283516001908101855290840180519091019052613ce5565b5050602081018051600101905290565b601c54600090613de76001611b8a6003613ddb85600263ffffffff61477e16565b9063ffffffff6146de16565b881015613e31576040805162461bcd60e51b8152602060048201526013602482015272322f332b31206e6f6e2d6d616a6f726974792160681b604482015290519081900360640190fd5b6000613e3e8b8a846147a5565b90506000613e5c6064613ddb6016548561477e90919063ffffffff16565b6001600160a01b038c166000908152601b6020908152604080832054808452601a90925290912060018101549293509091613e9d908463ffffffff613ccb16565b600182015560178b90556000613eea613edb8e613ddb6a084595161401484a000000613ecf8a8a63ffffffff61406916565b9063ffffffff61477e16565b6024549063ffffffff613ccb16565b9050613ef78b8b836148f9565b6024819055613f078989836148f9565b613f0f61492d565b50929d9c50505050505050505050505050565b600654604080516331a9108f60e11b815260048101849052905133926001600160a01b031691636352211e916024808301926020929190829003018186803b158015613f6d57600080fd5b505afa158015613f81573d6000803e3d6000fd5b505050506040513d6020811015613f9757600080fd5b50516001600160a01b03161461391857600080fd5b60005460ff1615612b7f576040805162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b604482015290519081900360640190fd5b6000818152601a602052604081208054600a90910154829190829061401990839063ffffffff613ccb16565b6000868152601a60205260409020600b0154602454919250900361405d86846140576a084595161401484a000000613ddb868863ffffffff61477e16565b856149a2565b94509450505050915091565b60008282111561407857600080fd5b50900390565b600080825160208401856127105a03f43d604051816000823e8280156140a2578282f35b8282fd5b505050505050565b6000818152601a60205260409020600601546001600160a01b03163314613918576040805162461bcd60e51b815260206004820152601860248201527f496e76616c696420636f6e747261637420616464726573730000000000000000604482015290519081900360640190fd5b806141b557600083131561414557601c5461413d908463ffffffff613ccb16565b601c55614169565b600083121561416957601c5461416590600085900363ffffffff61406916565b601c555b600082131561418d57601d54614185908363ffffffff613ccb16565b601d55612806565b600082121561280657601d546141ad90600084900363ffffffff61406916565b601d5561232c565b6000818152601e60205260409020805484018155600101805483019055505050565b602680549060009060001983018381106141ed57fe5b600091825260209091200154602680546001600160a01b03909216925090600019840190811061421957fe5b600091825260209091200180546001600160a01b031916905560001982015b80156142d057836001600160a01b0316826001600160a01b0316141561425d576142d0565b6026600182038154811061426d57fe5b9060005260206000200160009054906101000a90046001600160a01b0316826026600184038154811061429c57fe5b600091825260209091200180546001600160a01b0319166001600160a01b0392909216919091179055915060001901614238565b506000198201611e8e602682614dc4565b6000828152601a60205260409020600a0154614303908263ffffffff613ccb16565b6000928352601a6020526040909220600a019190915550565b6000806000806143396001611b8a6003613ddb6002613ecf612b69565b905060005b85518167ffffffffffffffff16101561443457600061437a88888467ffffffffffffffff168151811061436d57fe5b6020026020010151613b90565b6001600160a01b038082166000818152601b602052604090205492935090861611156143a7575050614434565b6143b081611e41565b80156143cd5750846001600160a01b0316826001600160a01b0316115b15614414576000818152601a602052604090208054600a9091015492955085926143fd828263ffffffff613ccb16565b915061440f888363ffffffff613ccb16565b975050505b83861061442a5760019650505050505050611e76565b505060010161433e565b5090911015949350505050565b6000805460ff19169055565b6003546040805163a9059cbb60e01b81526001600160a01b038581166004830152602482018590529151919092169163a9059cbb9160448083019260209291908290030181600087803b1580156144a357600080fd5b505af11580156144b7573d6000803e3d6000fd5b505050506040513d60208110156144cd57600080fd5b5051611d98576040805162461bcd60e51b815260206004820152600f60248201526e1d1c985b9cd9995c8819985a5b1959608a1b604482015290519081900360640190fd5b61451b826141d7565b611d9881614a36565b60115460009061453a908563ffffffff613ccb16565b6011819055604080516101a081018252868152600160208201819052918101869052600060608201819052608082018190526001600160a01b03891660a083015260c082015291925060e082019081526000602080830182905260408084018390526001606080860182905260808087018a905260245460a0978801528d8652601a855294839020875181559387015191840191909155908501516002830155840151600380830191909155918401516004820155918301516005830180546001600160a01b039283166001600160a01b03199182161790915560c08501516006850180549190931691161780825560e08501519260ff60a01b1990911690600160a01b90849081111561464a57fe5b0217905550610100820151600782015561012082015160088201556101408201516009820155610160820151600a82015561018090910151600b9091015560008681526021602090815260408083208690556001600160a01b0388168352601b90915281208790556146c2908584019060019061411c565b600086815260208052604090206001018390556140a685614a36565b60008082116146ec57600080fd5b60008284816146f757fe5b04949350505050565b6001600160a01b03811661471357600080fd5b6001546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000805460ff19166001179055565b60008261478d57506000611e76565b8282028284828161479a57fe5b0414611f9557600080fd5b600e54600b5460009190826147c58388816147bc57fe5b04602954614b50565b90506000811180156147d957506027548114155b1561481a57602754156148145760006064602a548402816147f657fe5b04905081602754111561480c5791820191614812565b80830392505b505b60278190555b6000838811156148b3576028546148626148526064613ddb614845600260001989018902048661477e565b889063ffffffff61477e16565b611f89868663ffffffff61477e16565b9150614884614877848763ffffffff61477e16565b8a9063ffffffff61406916565b98506148af6148a26064613ddb84613ecf898963ffffffff61477e16565b859063ffffffff61406916565b9350505b6148d76148ca85613ddb8b8763ffffffff61477e16565b829063ffffffff613ccb16565b90506148ed86613ddb838a63ffffffff61477e16565b98975050505050505050565b60245460005b838110156121995761492585828151811061491657fe5b60200260200101518385614b66565b6001016148ff565b600954600061494382600163ffffffff613ccb16565b905061494d614de8565b506000818152601e60209081526040808320815180830190925280548083526001909101549282018390529092614984929061411c565b506000918252601e6020526040822082815560010191909155600955565b600080826149b557506000905080614a2d565b60006149cb84613ddb888863ffffffff61477e16565b6000888152601a60205260409020600701549091508015614a1257614a0f614a026064613ddb84613ecf8b8863ffffffff61406916565b839063ffffffff613ccb16565b91505b6000614a24878463ffffffff61406916565b92945091925050505b94509492505050565b6026805460018101825560008290527f744a2cf8fd7008e3d53b67916e73460df9fa5214e3ef23dd4259ca09493a35940180546001600160a01b0319166001600160a01b0384161790555460001901805b8015614b0857600060266001830381548110614a9f57fe5b6000918252602090912001546001600160a01b0390811691508416811015614ac75750614b08565b8060268381548110614ad557fe5b600091825260209091200180546001600160a01b0319166001600160a01b03929092169190911790555060001901614a87565b81811461232c578260268281548110614b1d57fe5b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550505050565b6000818310614b5f5781611f95565b5090919050565b6000838152601a60205260409020600b015482811015614be5576000848152601a602052604090208054600a909101548015614bcd576000614bae838363ffffffff613ccb16565b9050614bc7878484614bc28b868c8b614c07565b614c2b565b50614be2565b614be286614bdd88858988614c07565b614cd1565b50505b80821115611e8e576000848152601a60205260409020600b0182905550505050565b6000818303613c896a084595161401484a000000613ddb838863ffffffff61477e16565b6000614c3d838563ffffffff613ccb16565b9050600080614c4e878786866149a2565b90925090508015614c8e576000878152601a6020526040902060090154614c7b908263ffffffff613ccb16565b6000888152601a60205260409020600901555b81156121a0576000878152601a6020526040902060010154614cb6908363ffffffff613ccb16565b6000888152601a602052604090206001015550505050505050565b8015611d98576000828152601a6020526040902060010154614cf9908263ffffffff613ccb16565b6000838152601a60205260409020600101555050565b6040518060a0016040528060008152602001600081526020016060815260200160608152602001600081525090565b60405180606001604052806000815260200160608152602001600081525090565b828054828255906000526020600020908101928215614db4579160200282015b82811115614db457825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190614d7f565b50614dc0929150614e02565b5090565b81548183558181111561232c5760008381526020902061232c918101908301614e26565b604051806040016040528060008152602001600081525090565b6122bd91905b80821115614dc05780546001600160a01b0319168155600101614e08565b6122bd91905b80821115614dc05760008155600101614e2c56fe4f6e6c7920676f7665726e616e636520636f6e747261637420697320617574686f72697a6564a265627a7a7231582023d76d2f4b31a8301ab8d82424ac6db9c3dfd4d6b8f199bcdd0011603654804264736f6c63430005110032
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ 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.