Skip to content

About

Non-custodial liquidity/token locker: multi-lock, only-lengthen extension, no admin unlock, custody-solvency invariant

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

LiquidityLocker

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.

Trust model — no admin, no backdoor

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 lifecycle

  1. lock(token, amount, unlockTime, beneficiary) → lockId — pulls amount via SafeERC20 and creates a new lock. Requires amount > 0, unlockTime > block.timestamp, beneficiary != 0.
  2. increaseLock(lockId, addAmount) — beneficiary adds more of the same token to an un-withdrawn lock.
  3. extend(lockId, newUnlockTime) — beneficiary pushes the unlock time later. Only-lengthen: newUnlockTime must be strictly greater than the current one; an earlier or equal time reverts (UnlockNotLater). A lock can never be shortened.
  4. 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.
  5. withdraw(lockId) — beneficiary withdraws the full recorded amount once block.timestamp >= unlockTime. Reentrancy-guarded, checks-effects- interactions, and withdrawn is a terminal flag (no double-withdraw).

Only-lengthen guarantee

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.

Fee-on-transfer-safe accounting

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.

Views

  • getLock(lockId) — full Lock {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.

Errors

ZeroAmount, ZeroBeneficiary, UnlockNotInFuture, UnlockNotLater, InvalidLockId, NotBeneficiary, AlreadyWithdrawn, StillLocked.

Testing

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 extend reverts; a forward extend then blocks withdraw until 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/warp across three tokens (one fee-on-transfer) and three actors: 12,800 calls, 0 reverts under fail_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 transferBeneficiary the 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 withdraw cannot 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-170

Deep dive (v2)

A 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 — withdraw is CEI (terminal withdrawn set before transfer), reentrancy-guarded, and time-gated; neither an early exit nor a second payout is reachable.
  • extend shortening — the strict newUnlockTime > unlockTime check makes a lock only ever lengthenable; equal or earlier times revert.
  • Enumeration corruption — the transferBeneficiary swap-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: withdraw reads the Lock struct directly, so even a corrupted list could not move funds.)
  • FoT over-crediting — _pull credits 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/transferBeneficiary are intentionally not reentrancy-guarded. A test proves that even a successful re-entry into transferBeneficiary mid-withdraw cannot drain or corrupt a sibling lock, while re-entry into the guarded withdraw is 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.

Deploy

forge script script/Deploy.s.sol:Deploy --rpc-url <RPC> --broadcast

The constructor takes no arguments — the locker is a shared, permissionless vault.

License

MIT.

About

Non-custodial liquidity/token locker: multi-lock, only-lengthen extension, no admin unlock, custody-solvency invariant

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages