β°Alarm Clock
Trust-less Time Delays
Design Ethos
One of the first use cases that comes with storing assets on-chain is locking them up for a specific amount of time. Combined with events, this enables a lot of use cases that can move funds without the immediate interaction of the trust owner.
This implementation of a Dispatcher models an Alarm Clock that can be preemptively "snoozed." The root key registers an event, that is eligible to fire by anyone at a specified time. Optionally, it can be configured to be repeatedly "snoozed" and extending the event eligibility.
This enables a few immediate use cases:
Proof-of-life inheritance, proof-of-presence recovery
Coming of age inheritance
One-time Vesting schedules
Storage
ILocksmith public locksmith;
ITrustEventLog public trustEventLog;
struct Alarm {
bytes32 eventHash; // the event to fire upon challenge
uint256 alarmTime; // when the event can be fired
uint256 snoozeInterval; // alarm time extension, or '0' if disabled
uint256 snoozeKeyId; // the key that can extend the alarm time, if interval isn't zero
}
// eventHash => Alarm
mapping(bytes32 => Alarm) public alarms;locksmith
The reference the contract uses to verify key possession.
trustEventLog
The reference the contract use to register and fire events.
struct Alarm
This structure models the alarm that is created by the key holder.
eventHash
The unique identifier for the event.
alarmTime
The epoch timestamp that signifies when the alarm is elligible to be challenged and fired. This can be changed if the alarm is snooze-able.
snoozeInterval
If non-zero, specifies how much time will be added to the alarm's deadline when successfully snoozed.
snoozeKeyId
The key Id that is enabled to snooze the alarm. Must belong to the trust model of the root key holder establishing the alarm.
alarms
A registery of alarms attached to their specified event hash.
Operations
createAlarm
A root key holder can call this method to create an alarm clock event.
This method will revert if the root key isn't held by the caller, the snooze key ID is not within the trust's key ring, or if there happens to be a duplicate event for some reason.
If the snooze interval is zero, then the snoozeKeyId is considered invalid and ignored. The deadline will be considered immutable.
If the snooze internval is non-zero, then only a message sender that holds snoozeKeyId is able to extend the deadline by snoozeInterval amount.
snoozeAlarm
If the snooze internval is non-zero, the snoozeKeyId holder can call this method to extend the alarm clock's deadline, but only if the deadline is within the snooze interval itself.
challengeAlarm
If an alarm's deadline has passed, any caller can challenge the alarm and formally trigger the event.
Last updated