Skip to content

Instantly share code, notes, and snippets.

@izqui
Last active September 24, 2018 19:20
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 izqui/395a216e8518686f39032a80bb87cae7 to your computer and use it in GitHub Desktop.
Save izqui/395a216e8518686f39032a80bb87cae7 to your computer and use it in GitHub Desktop.
contract LockManager {
function canUnlock(bytes32 lockId, bytes lockData) public view returns (bool);
}
// ERC900 compatibility left out of this spec
contract StakeLocking /*is ERC900*/{
struct Staker {
// would need to be checkpointed
uint256 amount;
// evaluate when it makes sense to keep an updated unlockedAmount or a list of locks that gets checked
// probably no need for checkpointing unlockedAmount
uint256 unlockedAmount;
}
mapping (address => Staker) public stakers;
struct Lock {
uint256 amount;
uint64 createdAt;
uint64 updatedAt;
uint64 unlockedAt;
address staker;
LockManager manager; // can also be an EOA
bytes data;
}
mapping (bytes32 => Lock) public locks;
// STAKER
function lock(uint256 amount, address manager, bytes data) external returns (bytes32 lockId);
// Same as lock, but staker doesnt need to directly call it. Staker can provide signed message to someone else that can then lock.
function lockFor(address staker, uint256 amount, LockManager manager, bytes data, bytes signature) external returns (bytes32 lockId);
// Directly unlock if msg.sender is the lock's manager otherwise check `manager.canUnlock(lockId, data)` and msg.sender is staker
function unlock(bytes32 lockId) external;
// Staker can transfer unlocked tokens to another account or to a lock
// If toLockId is provided, MUST not have already been unlocked
// `toLockId` staker MUST be `to`
function transfer(uint256 amount, address to, bytes32 toLockId);
// ONLY MANAGER
// Manager can transfer from a lock to another staker account, or to a lock
// `amount` MUST be decreased from `lockId`'s amount
// If toLockId is provided, MUST not have already been unlocked
// `toLockId` staker MUST be `to`
function transferFromLock(bytes32 lockId, uint256 amount, address to, bytes32 toLockId);
// Manager can only decrease lock amount
function setLockAmount(bytes32 lockId, uint256 newAmount) external;
// Manager can set another manager for the lock
function setLockManager(bytes32 lockId, LockManager newManager) external;
// Manager can change lock data
function setLockData(bytes32 lockId, bytes newData) external;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment