Locker
Inherits: ILock, ReentrancyGuard
Title: Locker
Abstract single-asset vault with a time-locked withdrawal mechanism. Subcontracts define the unlock period and may add parameter administration or slashing logic.
ASSET is immutably set to YellowToken, a standard ERC-20 with a fixed supply and no mint, burn, fee-on-transfer, or rebasing mechanics. Workflow:
- lock(amount) — deposit tokens; can top-up while in Locked state.
- unlock() — start the countdown.
- withdraw() — after the period elapses, receive the full balance.
State Variables
ASSET
address public immutable ASSET
UNLOCK_PERIOD
uint256 public immutable UNLOCK_PERIOD
_balances
mapping(address user => uint256 balance) internal _balances
_unlockTimestamps
mapping(address user => uint256 unlockTimestamp) internal _unlockTimestamps
Functions
constructor
constructor(address asset_, uint256 unlockPeriod_) ;
asset
The address of the single ERC-20 token this vault accepts.
function asset() external view returns (address);
lockStateOf
Returns the current lock state for a user.
function lockStateOf(address user) public view returns (LockState);
balanceOf
Returns the locked balance for a user.
function balanceOf(address user) external view returns (uint256);
unlockTimestampOf
Returns the timestamp when withdraw() becomes callable (0 if not unlocking).
function unlockTimestampOf(address user) external view returns (uint256);
lock
Transfers amount tokens from the caller into the vault, crediting target.
Can be called multiple times to add to an existing Locked balance.
Reverts with AlreadyUnlocking if target is in the Unlocking state.
function lock(address target, uint256 amount) external nonReentrant;
unlock
Starts the waiting period for the caller's full balance. Reverts with NotLocked if the caller has no balance. Reverts with AlreadyUnlocking if unlock() was already called.
function unlock() external;
relock
Cancels an in-progress unlock and returns to Locked state. Restores collateral weight. Reverts with NotUnlocking if not unlocking.
function relock() external;
withdraw
Transfers the caller's full balance to destination.
Reverts with NotUnlocking if unlock() was not called.
Reverts with UnlockPeriodNotElapsed if the waiting period has not elapsed.
function withdraw(address destination) external nonReentrant;
_afterLock
Hook called after tokens are locked. Override to add custom logic (e.g. collateral weight).
function _afterLock(address target, uint256 amount) internal virtual;
_afterUnlock
Hook called after unlock is initiated. Override to add custom logic.
function _afterUnlock(address account, uint256 balance) internal virtual;
_afterRelock
Hook called after relock. Override to add custom logic.
function _afterRelock(address account, uint256 balance) internal virtual;