Skip to content

Instantly share code, notes, and snippets.

@pirapira
Last active October 19, 2017 15: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 pirapira/e7f5d3d44d5b6b14ca2ad1980083e233 to your computer and use it in GitHub Desktop.
Save pirapira/e7f5d3d44d5b6b14ca2ad1980083e233 to your computer and use it in GitHub Desktop.
// Based on http://www.blunderingcode.com/ether-vaults/
contract Vault(address hotwallet, address vaultKey, address recoveryKey) {
case(void unvault(uint256 amount)) {
if (sender(msg) != vaultKey) abort;
uint256 unvaultPeriod = 60 * 60 * 24 * 7 * 2; // two weeks
if (now(block) + unvaultPeriod < now(block)) abort;
return then become UnVaulting(now(block) + unvaultPeriod, amount, hotwallet, vaultKey, recoveryKey);
}
case(void recover(address _newHotWallet)) {
if (sender(msg) != recoveryKey) abort;
return then become Vault(_newHotWallet, vaultKey, recoveryKey);
}
case(void destroy()) {
if (sender(msg) != recoveryKey) abort;
return then become Destroyed();
}
}
contract UnVaulting(uint256 redeemtime, uint256 amount, address hotwallet, address vaultKey, address recoveryKey) {
case(void redeem()) {
if (amount > balance(this)) abort;
void = hotwallet.default() with amount reentrance { abort; };
return then become Vault(hotwallet, vaultKey, recoveryKey);
}
case(void recover(address _newHotWallet)) {
if (sender(msg) != recoveryKey) abort;
return then become Vault(_newHotWallet, vaultKey, recoveryKey);
}
case(void destroy()) {
if (sender(msg) != recoveryKey) abort;
return then become Destroyed();
}
}
contract Destroyed() {
// any call just throws;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment