Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generic Token Staking Contract
contract TokenStake {
using SafeMath for uint256;
StandardToken token;
mapping (address => uint256) staked;
event Staked(address _staker, uint256 _value);
event Released(address _staker, uint256 _value);
modifier onlyToken {
require (msg.sender == token.address);
}
function TokenStake (ERC23Token _token) {
token = _token;
}
function tokenFallback(address _sender, uint _value, bytes _data) onlyToken {
stake(_sender, _value, _data)
}
// could be overridden in case you need to do something with _data
function stake(address _sender, uint256 _value, bytes _data) internal {
staked[_sender] = staked[_sender].add(_value);
Staked(_staker, _value);
}
// this function should be overridden with custom logic
function release(address _staker, uint _value) {
if (staked[_staker] > _value) {
staked[_staker].sub(_value);
token.transfer(_staker, _value);
Released(_staker, _value);
}
}
function stakedOf(address _staker) constant returns (uint256) {
return staked[_staker];
}
}
contract TokenTimelock is TokenStake {
uint256 releaseTime;
function TokenTimelock(uint256 _releaseTime, ERC23Token _token) TokenStake(_token) {
releaseTime = _releaseTime;
}
function release(address _staker, uint256 _value, bytes _data) {
if (now >= releaseTime) super.release(_staker, _value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.