Skip to main content

ILock

Git Source

Title: ILock

Single-asset vault with a time-locked withdrawal mechanism. Users lock tokens, initiate an unlock, and withdraw after the waiting period. State machine per user: lock(amount) unlock() withdraw() Idle ─────────────► Locked ─────────────► Unlocking ──────────► Idle │ │ lock(amount) adds to balance, relock() stays Locked returns to Locked

Functions

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) external 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;

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;

Events

Locked

event Locked(address indexed user, uint256 deposited, uint256 newBalance);

Parameters

NameTypeDescription
useraddressThe user that locked tokens.
depositeduint256The amount of tokens deposited in this call.
newBalanceuint256The cumulative locked balance after this call.

UnlockInitiated

event UnlockInitiated(address indexed user, uint256 balance, uint256 availableAt);

Parameters

NameTypeDescription
useraddressThe user that initiated unlock.
balanceuint256The full balance queued for withdrawal.
availableAtuint256Timestamp when withdraw() becomes callable.

Relocked

event Relocked(address indexed user, uint256 balance);

Parameters

NameTypeDescription
useraddressThe user that cancelled an unlock and relocked.
balanceuint256The balance that was relocked.

Withdrawn

event Withdrawn(address indexed user, uint256 balance);

Parameters

NameTypeDescription
useraddressThe user that withdrew.
balanceuint256The amount withdrawn.

Errors

InvalidAddress

The address supplied is the zero address.

error InvalidAddress();

InvalidAmount

Amount must be greater than zero.

error InvalidAmount();

InvalidPeriod

Unlock period must be greater than zero.

error InvalidPeriod();

NotLocked

Caller has no locked balance.

error NotLocked();

NotUnlocking

unlock() was not called before withdraw(), or waiting period has not elapsed.

error NotUnlocking();

AlreadyUnlocking

Caller is already in the Unlocking state.

error AlreadyUnlocking();

UnlockPeriodNotElapsed

Waiting period has not elapsed yet.

error UnlockPeriodNotElapsed(uint256 availableAt);

Parameters

NameTypeDescription
availableAtuint256Timestamp when withdraw() becomes callable.

Enums

LockState

enum LockState {
Idle,
Locked,
Unlocking
}