A production-grade, non-custodial liquidity locker: a single vault that holds many independent time-locks of ERC-20 or LP tokens. Projects lock their liquidity here until an unlock timestamp to prove they cannot rug — the tokens are provably time-locked, and only a lock's beneficiary can withdraw once the time has elapsed.
Solidity 0.8.26, via_ir, OpenZeppelin v5.0.2 (SafeERC20, ReentrancyGuard),
custom errors, and a full unit + fuzz + stateful-invariant suite.
There is intentionally no owner, admin, pauser, or emergency path that can touch locked funds. Not even the deployer can:
- pull tokens out early,
- shorten a lock,
- or reassign a beneficiary.
The only way tokens leave the contract is the current beneficiary calling
withdraw at or after unlockTime. This non-custodial guarantee is the entire
point of the contract; there is no configuration and the deploy takes no
arguments.
lock(token, amount, unlockTime, beneficiary) → lockId— pullsamountviaSafeERC20and creates a new lock. Requiresamount > 0,unlockTime > block.timestamp,beneficiary != 0.increaseLock(lockId, addAmount)— beneficiary adds more of the same token to an un-withdrawn lock.extend(lockId, newUnlockTime)— beneficiary pushes the unlock time later. Only-lengthen:newUnlockTimemust be strictly greater than the current one; an earlier or equal time reverts (UnlockNotLater). A lock can never be shortened.transferBeneficiary(lockId, newBeneficiary)— beneficiary hands over all rights. The old beneficiary loses every right immediately; the new one gains them. Per-beneficiary enumeration is kept in sync.withdraw(lockId)— beneficiary withdraws the full recorded amount onceblock.timestamp >= unlockTime. Reentrancy-guarded, checks-effects- interactions, andwithdrawnis a terminal flag (no double-withdraw).
extend accepts a new unlock time strictly in the future of the current one and
nothing else. Combined with the absence of any admin path, a published lock's
maturity can only ever move later, never earlier — buyers can rely on the
on-chain unlockTime as a floor.
Every inbound transfer (lock, increaseLock) credits the actual balance
delta received by the contract, measured as balanceAfter - balanceBefore.
A token that skims a fee on transfer records exactly what truly arrived, so the
contract never over-credits and withdraw returns precisely the recorded amount.
This underpins the custody-solvency invariant below.
getLock(lockId)— fullLock {token, amount, unlockTime, beneficiary, withdrawn}.lockCount()— total locks ever created.locksOf(beneficiary)— the lockIds currently owned by an address (enumerable).isUnlocked(lockId)— whether the unlock time has elapsed.
ZeroAmount, ZeroBeneficiary, UnlockNotInFuture, UnlockNotLater,
InvalidLockId, NotBeneficiary, AlreadyWithdrawn, StillLocked.
32 tests, all green (30 unit/fuzz + 2 stateful invariants). Highlights:
- No early withdraw — reverts before
unlockTime, succeeds exactly at it, fuzzed over the duration. - Only-lengthen — earlier/equal
extendreverts; a forward extend then blockswithdrawuntil the new time; fuzzed. - Custody solvency (invariant) — for every token, the locker's on-chain
balance always covers the sum of every un-withdrawn lock amount. Stateful over
randomized
lock/increase/extend/withdraw/transfer/warpacross three tokens (one fee-on-transfer) and three actors: 12,800 calls, 0 reverts underfail_on_revert = true(pinned inline), reading real on-chain state so it is non-hollow. - Access control — non-beneficiaries cannot withdraw/extend/increase/transfer;
after
transferBeneficiarythe old address loses all rights and the new one gains them. - No double-withdraw / withdrawn is terminal — a withdrawn lock rejects every further action.
- Fee-on-transfer — recorded amount equals what actually arrived; solvency still holds; withdraw returns exactly the recorded amount.
- Reentrancy — a malicious token re-entering
withdrawcannot double-withdraw or drain another lock. - Isolation — locks of different tokens/beneficiaries never cross-fund.
Mutation-checked: breaking the block.timestamp >= unlockTime gate or the
beneficiary check each makes tests fail.
forge test # unit + fuzz + invariants
forge test --match-path test/LiquidityLocker.invariant.t.sol # invariants only
forge build --sizes # runtime bytecode ~3.0 KB, well under EIP-170A second adversarial pass audited the custody-critical paths end to end. No bug was found; no contract code changed. The review specifically chased, and ruled out, each of these:
- Early / double withdraw —
withdrawis CEI (terminalwithdrawnset before transfer), reentrancy-guarded, and time-gated; neither an early exit nor a second payout is reachable. extendshortening — the strictnewUnlockTime > unlockTimecheck makes a lock only ever lengthenable; equal or earlier times revert.- Enumeration corruption — the
transferBeneficiaryswap-and-pop was stress-tested for the middle-of-many, round-trip (a→b→c→a), and repeated self-transfer cases: a lockId is present in exactly one owner's list at all times — never dropped, never duplicated. (It is also purely informational:withdrawreads theLockstruct directly, so even a corrupted list could not move funds.) - FoT over-crediting —
_pullcredits the exact balance delta, so a recorded amount can never exceed what actually arrived; solvency (Σ un-withdrawn ≤ balance) holds across interleaved lock/increase/withdraw. - Non-guarded-path reentrancy —
extend/transferBeneficiaryare intentionally not reentrancy-guarded. A test proves that even a successful re-entry intotransferBeneficiarymid-withdraw cannot drain or corrupt a sibling lock, while re-entry into the guardedwithdrawis rejected.
Coverage expanded from 32 to 39 tests (7 new adversarial cases + the existing invariants,
still fail_on_revert = true, 0 reverts). Mutation-checked: neutering the terminal
withdrawn flag makes the double-withdraw test fail.
forge script script/Deploy.s.sol:Deploy --rpc-url <RPC> --broadcastThe constructor takes no arguments — the locker is a shared, permissionless vault.
MIT.