Skip to content

Instantly share code, notes, and snippets.

@io4
Created December 1, 2017 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save io4/1a92cd9764cc245344cb41dbe33742d0 to your computer and use it in GitHub Desktop.
Save io4/1a92cd9764cc245344cb41dbe33742d0 to your computer and use it in GitHub Desktop.
A contract to force HODL-ing cats
pragma solidity ^0.4.18;
contract ERC721 {
function totalSupply() public view returns (uint256 total);
function balanceOf(address _owner) public view returns (uint256 balance);
function ownerOf(uint256 _tokenId) external view returns (address owner);
function approve(address _to, uint256 _tokenId) external;
function transfer(address _to, uint256 _tokenId) external;
function transferFrom(address _from, address _to, uint256 _tokenId) external;
event Transfer(address from, address to, uint256 tokenId);
event Approval(address owner, address approved, uint256 tokenId);
function supportsInterface(bytes4 _interfaceID) external view returns (bool);
}
contract Owned {
address public owner;
function Owned () public {
owner = msg.sender;
}
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
function changeOwner (address newOwner) public onlyOwner {
owner = newOwner;
}
}
contract Targeted is Owned {
ERC721 public target;
function changeTarget (address newTarget) public onlyOwner {
target = ERC721(newTarget);
}
}
contract CatHODL is Targeted {
uint public releaseDate;
mapping (uint => address) public catOwners;
function CatHODL () public {
releaseDate = now + 1 years;
}
function bringCat (uint catId) public {
require(now < releaseDate ); // If you can get it anytime, its not forced HODL!
catOwners[catId] = msg.sender; // Set the user as owner.
target.transferFrom(msg.sender, this, catId); // Get the cat, throws if fails
}
function getCat (uint catId) public {
require(catOwners[catId] == msg.sender);
require(now >= releaseDate);
catOwners[catId] = 0x0;
target.transfer(msg.sender, catId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment