Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x4f2bC163c8758D7F88771496F7B0Afde767045F3
Balance 0 ETH
Nonce 1
Code Size 4174 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

4174 bytes
0x6080604052600436106100c45763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630e89439b81146100c95780630ef9635614610129578063201d3be71461019f57806320bf96201461021d5780634b341aed1461032957806366e6360d146103695780637033e4a6146103975780638033f6bc146103c0578063817b1cd2146103ee578063c8fd6ed014610403578063e26ff10a14610461578063e8297da2146104af578063fc0c546a146104c4575b600080fd5b3480156100d557600080fd5b5060408051602060046024803582810135601f81018590048502860185019096528585526101279583359536956044949193909101919081908401838280828437509497506105029650505050505050565b005b34801561013557600080fd5b50604080516020600460443581810135601f810184900484028501840190955284845261012794823573ffffffffffffffffffffffffffffffffffffffff169460248035953695946064949201919081908401838280828437509497506105149650505050505050565b3480156101ab57600080fd5b506101cd73ffffffffffffffffffffffffffffffffffffffff60043516610527565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156102095781810151838201526020016101f1565b505050509050019250505060405180910390f35b34801561022957600080fd5b5061024b73ffffffffffffffffffffffffffffffffffffffff6004351661053d565b60405180806020018060200180602001848103845287818151815260200191508051906020019060200280838360005b8381101561029357818101518382015260200161027b565b50505050905001848103835286818151815260200191508051906020019060200280838360005b838110156102d25781810151838201526020016102ba565b50505050905001848103825285818151815260200191508051906020019060200280838360005b838110156103115781810151838201526020016102f9565b50505050905001965050505050505060405180910390f35b34801561033557600080fd5b5061035773ffffffffffffffffffffffffffffffffffffffff60043516610721565b60408051918252519081900360200190f35b34801561037557600080fd5b506101cd73ffffffffffffffffffffffffffffffffffffffff60043516610749565b3480156103a357600080fd5b506103ac61075e565b604080519115158252519081900360200190f35b3480156103cc57600080fd5b506101cd73ffffffffffffffffffffffffffffffffffffffff60043516610763565b3480156103fa57600080fd5b50610357610778565b34801561040f57600080fd5b5060408051602060046024803582810135601f810185900485028601850190965285855261012795833595369560449491939091019190819084018382808284375094975061081c9650505050505050565b34801561046d57600080fd5b5061048f73ffffffffffffffffffffffffffffffffffffffff60043516610826565b604080519384526020840192909252151582820152519081900360600190f35b3480156104bb57600080fd5b5061035761084a565b3480156104d057600080fd5b506104d9610850565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61051033836001548461086c565b5050565b61052283836001548461086c565b505050565b6060806105338361053d565b5090949350505050565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260026020818152604080842060018101549381015482519490038085528084028501909301909152606093849384939184918291829181908680156105a8578160200160208202803883390190505b509450856040519080825280602002602001820160405280156105d5578160200160208202803883390190505b50935085604051908082528060200260200182016040528015610602578160200160208202803883390190505b509250866001015491505b600287015482101561071157866001015482039050866002018281548110151561063357fe5b906000526020600020906003020160000154858281518110151561065357fe5b602090810290910101526002870180548390811061066d57fe5b906000526020600020906003020160010154848281518110151561068d57fe5b60209081029091010152600287018054839081106106a757fe5b6000918252602090912060026003909202010154835173ffffffffffffffffffffffffffffffffffffffff909116908490839081106106e257fe5b73ffffffffffffffffffffffffffffffffffffffff90921660209283029091019091015260019091019061060d565b5092999198509650945050505050565b73ffffffffffffffffffffffffffffffffffffffff1660009081526002602052604090205490565b6060806107558361053d565b50949350505050565b600090565b60608061076f8361053d565b95945050505050565b60008054604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a082319160248082019260209290919082900301818787803b1580156107eb57600080fd5b505af11580156107ff573d6000803e3d6000fd5b505050506040513d602081101561081557600080fd5b5051905090565b6105108282610c3c565b60026020526000908152604090208054600182015460039092015490919060ff1683565b60015481565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b60008054604080517f23b872dd00000000000000000000000000000000000000000000000000000000815233600482018190523060248301526044820188905291519193879373ffffffffffffffffffffffffffffffffffffffff16926323b872dd926064808201936020939283900390910190829087803b1580156108f157600080fd5b505af1158015610905573d6000803e3d6000fd5b505050506040513d602081101561091b57600080fd5b5051151561098a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f5374616b65207265717569726564000000000000000000000000000000000000604482015290519081900360640190fd5b60008511610a1f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f5374616b6520616d6f756e742068617320746f2062652067726561746572207460448201527f68616e2030210000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b3360009081526002602052604090206003015460ff161515610a775733600090815260026020526040902060030180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790555b73ffffffffffffffffffffffffffffffffffffffff8616600090815260026020526040902054610aad908663ffffffff610ffd16565b73ffffffffffffffffffffffffffffffffffffffff871660009081526002602081905260408083209390935533825290829020825160608101909352019080610afc428863ffffffff610ffd16565b8152602080820189905273ffffffffffffffffffffffffffffffffffffffff8a81166040938401819052855460018082018855600097885296849020865160039092020190815592850151958301959095559290910151600290910180547fffffffffffffffffffffffff000000000000000000000000000000000000000016919092161790557fc65e53b88159e7d2c0fc12a0600072e28ae53ff73b4c1715369c30f16093514286610bae89610721565b866040518084815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610bf8578181015183820152602001610be0565b50505050905090810190601f168015610c255780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a2505050505050565b33600090815260026020819052604082206001810154910180549091908110610c6157fe5b9060005260206000209060030201905042816000015411151515610d0c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f5468652063757272656e74207374616b65206861736e277420756e6c6f636b6560448201527f6420796574000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b60018101548314610da457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603360248201527f54686520756e7374616b6520616d6f756e7420646f6573206e6f74206d61746360448201527f68207468652063757272656e74207374616b6500000000000000000000000000606482015290519081900360840190fd5b60008054604080517fa9059cbb00000000000000000000000000000000000000000000000000000000815233600482015260248101879052905173ffffffffffffffffffffffffffffffffffffffff9092169263a9059cbb926044808401936020939083900390910190829087803b158015610e1f57600080fd5b505af1158015610e33573d6000803e3d6000fd5b505050506040513d6020811015610e4957600080fd5b50511515610eb857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f556e61626c6520746f207769746864726177207374616b650000000000000000604482015290519081900360640190fd5b600181015460028083015473ffffffffffffffffffffffffffffffffffffffff1660009081526020919091526040902054610ef89163ffffffff61101016565b6002828101805473ffffffffffffffffffffffffffffffffffffffff9081166000908152602093909352604080842094909455600180860184905533845293909220830180549093019092559054167faf01bfc8475df280aca00b578c4a948e6d95700f0db8c13365240f7f973c875484610f7283610721565b856040518084815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610fbc578181015183820152602001610fa4565b50505050905090810190601f168015610fe95780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a2505050565b8181018281101561100a57fe5b92915050565b60008282111561101c57fe5b509003905600a165627a7a72305820675d79e13abd325d0f89df551f7447d3bf9609228ae44650c82a6e12c00365090029

Verified Source Code Partial Match

Compiler: v0.4.25+commit.59dbf8f1 EVM: byzantium Optimization: Yes (999999 runs)
BasicStakingContract.sol 460 lines
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol

pragma solidity ^0.4.23;


/**
 * @title ERC20Basic
 * @dev Simpler version of ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/179
 */
contract ERC20Basic {
  function totalSupply() public view returns (uint256);
  function balanceOf(address who) public view returns (uint256);
  function transfer(address to, uint256 value) public returns (bool);
  event Transfer(address indexed from, address indexed to, uint256 value);
}

// File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol

pragma solidity ^0.4.23;



/**
 * @title ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/20
 */
contract ERC20 is ERC20Basic {
  function allowance(address owner, address spender)
    public view returns (uint256);

  function transferFrom(address from, address to, uint256 value)
    public returns (bool);

  function approve(address spender, uint256 value) public returns (bool);
  event Approval(
    address indexed owner,
    address indexed spender,
    uint256 value
  );
}

// File: openzeppelin-solidity/contracts/math/SafeMath.sol

pragma solidity ^0.4.23;


/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {

  /**
  * @dev Multiplies two numbers, throws on overflow.
  */
  function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
    // Gas optimization: this is cheaper than asserting '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;
    }

    c = a * b;
    assert(c / a == b);
    return c;
  }

  /**
  * @dev Integer division of two numbers, truncating the quotient.
  */
  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    // uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return a / b;
  }

  /**
  * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
  */
  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  /**
  * @dev Adds two numbers, throws on overflow.
  */
  function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
    c = a + b;
    assert(c >= a);
    return c;
  }
}

// File: contracts/ERC900/ERC900.sol

pragma solidity ^0.4.24;


/**
 * @title ERC900 Simple Staking Interface
 * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-900.md
 */
contract ERC900 {
  event Staked(address indexed user, uint256 amount, uint256 total, bytes data);
  event Unstaked(address indexed user, uint256 amount, uint256 total, bytes data);

  function stake(uint256 amount, bytes data) public;
  function stakeFor(address user, uint256 amount, bytes data) public;
  function unstake(uint256 amount, bytes data) public;
  function totalStakedFor(address addr) public view returns (uint256);
  function totalStaked() public view returns (uint256);
  function token() public view returns (address);
  function supportsHistory() public pure returns (bool);

  // NOTE: Not implementing the optional functions
  // function lastStakedFor(address addr) public view returns (uint256);
  // function totalStakedForAt(address addr, uint256 blockNumber) public view returns (uint256);
  // function totalStakedAt(uint256 blockNumber) public view returns (uint256);
}

// File: contracts/ERC900/ERC900BasicStakeContract.sol

/* solium-disable security/no-block-members */
pragma solidity ^0.4.24;





/**
 * @title ERC900 Simple Staking Interface basic implementation
 * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-900.md
 */
contract ERC900BasicStakeContract is ERC900 {
  // @TODO: deploy this separately so we don't have to deploy it multiple times for each contract
  using SafeMath for uint256;

  // Token used for staking
  ERC20 stakingToken;

  // The default duration of stake lock-in (in seconds)
  uint256 public defaultLockInDuration;

  // To save on gas, rather than create a separate mapping for totalStakedFor & personalStakes,
  //  both data structures are stored in a single mapping for a given addresses.
  //
  // It's possible to have a non-existing personalStakes, but have tokens in totalStakedFor
  //  if other users are staking on behalf of a given address.
  mapping (address => StakeContract) public stakeHolders;

  // Struct for personal stakes (i.e., stakes made by this address)
  // unlockedTimestamp - when the stake unlocks (in seconds since Unix epoch)
  // actualAmount - the amount of tokens in the stake
  // stakedFor - the address the stake was staked for
  struct Stake {
    uint256 unlockedTimestamp;
    uint256 actualAmount;
    address stakedFor;
  }

  // Struct for all stake metadata at a particular address
  // totalStakedFor - the number of tokens staked for this address
  // personalStakeIndex - the index in the personalStakes array.
  // personalStakes - append only array of stakes made by this address
  // exists - whether or not there are stakes that involve this address
  struct StakeContract {
    uint256 totalStakedFor;

    uint256 personalStakeIndex;

    Stake[] personalStakes;

    bool exists;
  }

  /**
   * @dev Modifier that checks that this contract can transfer tokens from the
   *  balance in the stakingToken contract for the given address.
   * @dev This modifier also transfers the tokens.
   * @param _address address to transfer tokens from
   * @param _amount uint256 the number of tokens
   */
  modifier canStake(address _address, uint256 _amount) {
    require(
      stakingToken.transferFrom(_address, this, _amount),
      "Stake required");

    _;
  }

  /**
   * @dev Constructor function
   * @param _stakingToken ERC20 The address of the token contract used for staking
   */
  constructor(ERC20 _stakingToken) public {
    stakingToken = _stakingToken;
  }

  /**
   * @dev Returns the timestamps for when active personal stakes for an address will unlock
   * @dev These accessors functions are needed until https://github.com/ethereum/web3.js/issues/1241 is solved
   * @param _address address that created the stakes
   * @return uint256[] array of timestamps
   */
  function getPersonalStakeUnlockedTimestamps(address _address) external view returns (uint256[]) {
    uint256[] memory timestamps;
    (timestamps,,) = getPersonalStakes(_address);

    return timestamps;
  }

  /**
   * @dev Returns the stake actualAmount for active personal stakes for an address
   * @dev These accessors functions are needed until https://github.com/ethereum/web3.js/issues/1241 is solved
   * @param _address address that created the stakes
   * @return uint256[] array of actualAmounts
   */
  function getPersonalStakeActualAmounts(address _address) external view returns (uint256[]) {
    uint256[] memory actualAmounts;
    (,actualAmounts,) = getPersonalStakes(_address);

    return actualAmounts;
  }

  /**
   * @dev Returns the addresses that each personal stake was created for by an address
   * @dev These accessors functions are needed until https://github.com/ethereum/web3.js/issues/1241 is solved
   * @param _address address that created the stakes
   * @return address[] array of amounts
   */
  function getPersonalStakeForAddresses(address _address) external view returns (address[]) {
    address[] memory stakedFor;
    (,,stakedFor) = getPersonalStakes(_address);

    return stakedFor;
  }

  /**
   * @notice Stakes a certain amount of tokens, this MUST transfer the given amount from the user
   * @notice MUST trigger Staked event
   * @param _amount uint256 the amount of tokens to stake
   * @param _data bytes optional data to include in the Stake event
   */
  function stake(uint256 _amount, bytes _data) public {
    createStake(
      msg.sender,
      _amount,
      defaultLockInDuration,
      _data);
  }

  /**
   * @notice Stakes a certain amount of tokens, this MUST transfer the given amount from the caller
   * @notice MUST trigger Staked event
   * @param _user address the address the tokens are staked for
   * @param _amount uint256 the amount of tokens to stake
   * @param _data bytes optional data to include in the Stake event
   */
  function stakeFor(address _user, uint256 _amount, bytes _data) public {
    createStake(
      _user,
      _amount,
      defaultLockInDuration,
      _data);
  }

  /**
   * @notice Unstakes a certain amount of tokens, this SHOULD return the given amount of tokens to the user, if unstaking is currently not possible the function MUST revert
   * @notice MUST trigger Unstaked event
   * @dev Unstaking tokens is an atomic operation—either all of the tokens in a stake, or none of the tokens.
   * @dev Users can only unstake a single stake at a time, it is must be their oldest active stake. Upon releasing that stake, the tokens will be
   *  transferred back to their account, and their personalStakeIndex will increment to the next active stake.
   * @param _amount uint256 the amount of tokens to unstake
   * @param _data bytes optional data to include in the Unstake event
   */
  function unstake(uint256 _amount, bytes _data) public {
    withdrawStake(
      _amount,
      _data);
  }

  /**
   * @notice Returns the current total of tokens staked for an address
   * @param _address address The address to query
   * @return uint256 The number of tokens staked for the given address
   */
  function totalStakedFor(address _address) public view returns (uint256) {
    return stakeHolders[_address].totalStakedFor;
  }

  /**
   * @notice Returns the current total of tokens staked
   * @return uint256 The number of tokens staked in the contract
   */
  function totalStaked() public view returns (uint256) {
    return stakingToken.balanceOf(this);
  }

  /**
   * @notice Address of the token being used by the staking interface
   * @return address The address of the ERC20 token used for staking
   */
  function token() public view returns (address) {
    return stakingToken;
  }

  /**
   * @notice MUST return true if the optional history functions are implemented, otherwise false
   * @dev Since we don't implement the optional interface, this always returns false
   * @return bool Whether or not the optional history functions are implemented
   */
  function supportsHistory() public pure returns (bool) {
    return false;
  }

  /**
   * @dev Helper function to get specific properties of all of the personal stakes created by an address
   * @param _address address The address to query
   * @return (uint256[], uint256[], address[])
   *  timestamps array, actualAmounts array, stakedFor array
   */
  function getPersonalStakes(
    address _address
  )
    public
    view
    returns(uint256[], uint256[], address[])
  {
    StakeContract storage stakeContract = stakeHolders[_address];

    uint256 arraySize = stakeContract.personalStakes.length - stakeContract.personalStakeIndex;
    uint256[] memory unlockedTimestamps = new uint256[](arraySize);
    uint256[] memory actualAmounts = new uint256[](arraySize);
    address[] memory stakedFor = new address[](arraySize);

    for (uint256 i = stakeContract.personalStakeIndex; i < stakeContract.personalStakes.length; i++) {
      uint256 index = i - stakeContract.personalStakeIndex;
      unlockedTimestamps[index] = stakeContract.personalStakes[i].unlockedTimestamp;
      actualAmounts[index] = stakeContract.personalStakes[i].actualAmount;
      stakedFor[index] = stakeContract.personalStakes[i].stakedFor;
    }

    return (
      unlockedTimestamps,
      actualAmounts,
      stakedFor
    );
  }

  /**
   * @dev Helper function to create stakes for a given address
   * @param _address address The address the stake is being created for
   * @param _amount uint256 The number of tokens being staked
   * @param _lockInDuration uint256 The duration to lock the tokens for
   * @param _data bytes optional data to include in the Stake event
   */
  function createStake(
    address _address,
    uint256 _amount,
    uint256 _lockInDuration,
    bytes _data
  )
    internal
    canStake(msg.sender, _amount)
  {
    require(
      _amount > 0,
      "Stake amount has to be greater than 0!");
    if (!stakeHolders[msg.sender].exists) {
      stakeHolders[msg.sender].exists = true;
    }

    stakeHolders[_address].totalStakedFor = stakeHolders[_address].totalStakedFor.add(_amount);
    stakeHolders[msg.sender].personalStakes.push(
      Stake(
        block.timestamp.add(_lockInDuration),
        _amount,
        _address)
      );

    emit Staked(
      _address,
      _amount,
      totalStakedFor(_address),
      _data);
  }

  /**
   * @dev Helper function to withdraw stakes for the msg.sender
   * @param _amount uint256 The amount to withdraw. MUST match the stake amount for the
   *  stake at personalStakeIndex.
   * @param _data bytes optional data to include in the Unstake event
   */
  function withdrawStake(
    uint256 _amount,
    bytes _data
  )
    internal
  {
    Stake storage personalStake = stakeHolders[msg.sender].personalStakes[stakeHolders[msg.sender].personalStakeIndex];

    // Check that the current stake has unlocked & matches the unstake amount
    require(
      personalStake.unlockedTimestamp <= block.timestamp,
      "The current stake hasn't unlocked yet");

    require(
      personalStake.actualAmount == _amount,
      "The unstake amount does not match the current stake");

    // Transfer the staked tokens from this contract back to the sender
    // Notice that we are using transfer instead of transferFrom here, so
    //  no approval is needed beforehand.
    require(
      stakingToken.transfer(msg.sender, _amount),
      "Unable to withdraw stake");

    stakeHolders[personalStake.stakedFor].totalStakedFor = stakeHolders[personalStake.stakedFor]
      .totalStakedFor.sub(personalStake.actualAmount);

    personalStake.actualAmount = 0;
    stakeHolders[msg.sender].personalStakeIndex++;

    emit Unstaked(
      personalStake.stakedFor,
      _amount,
      totalStakedFor(personalStake.stakedFor),
      _data);
  }
}

// File: contracts/ERC900/BasicStakingContract.sol

pragma solidity ^0.4.24;



/**
 * @title BasicStakingContract
 */
contract BasicStakingContract is ERC900BasicStakeContract {
  /**
   * @dev Constructor function
   * @param _stakingToken ERC20 The address of the token used for staking
   * @param _lockInDuration uint256 The duration (in seconds) that stakes are required to be locked for
   */
  constructor(
    ERC20 _stakingToken,
    uint256 _lockInDuration
  )
    public
    ERC900BasicStakeContract(_stakingToken)
  {
    defaultLockInDuration = _lockInDuration;
  }
}

Read Contract

defaultLockInDuration 0xe8297da2 → uint256
getPersonalStakeActualAmounts 0x66e6360d → uint256[]
getPersonalStakeForAddresses 0x8033f6bc → address[]
getPersonalStakeUnlockedTimestamps 0x201d3be7 → uint256[]
getPersonalStakes 0x20bf9620 → uint256[], uint256[], address[]
stakeHolders 0xe26ff10a → uint256, uint256, bool
supportsHistory 0x7033e4a6 → bool
token 0xfc0c546a → address
totalStaked 0x817b1cd2 → uint256
totalStakedFor 0x4b341aed → uint256

Write Contract 3 functions

These functions modify contract state and require a wallet transaction to execute.

stake 0x0e89439b
uint256 _amount
bytes _data
stakeFor 0x0ef96356
address _user
uint256 _amount
bytes _data
unstake 0xc8fd6ed0
uint256 _amount
bytes _data

Recent Transactions

No transactions found for this address