EIPs Explained

ERC-1132 · Stagnant · ERC · 2018-06-03

ERC-1132: Extending ERC20 with token locking capability

An ERC-20 extension that lets tokens be time-locked for a named reason inside the token contract itself, so holders keep them in their own balance instead of sending them to an escrow.

What problem does it solve?

Many apps need users to lock tokens for a while: vesting schedules, governance voting, or showing "skin in the game" as a claim assessor. The usual way is to transfer tokens to a staking or escrow contract (ERC-900 style). That has costs:

  • users must trust the escrow and approve it first,
  • extra transfers cost gas,
  • tokens disappear from balanceOf, so wallets show a misleading balance,
  • users must remember to claim them back, and cannot use locked tokens elsewhere in the same app.

ERC-1132 keeps the tokens in the holder's account and records locks inside the token contract, each tagged with a bytes32 reason (for example "GOV" or "CLAIM_ASSESS").

How it works

The extension adds these functions to an ERC-20 token:

Function Purpose
lock(reason, amount, time) Lock amount of the caller's tokens for time seconds under reason
tokensLocked(of, reason) Amount currently locked for a reason
tokensLockedAtTime(of, reason, time) Amount that will still be locked at a future timestamp
totalBalanceOf(of) Locked + transferable balance
extendLock(reason, time) Push the unlock time further out
increaseLockAmount(reason, amount) Add more tokens to an existing lock
tokensUnlockable(of, reason) / getUnlockableTokens(of) Tokens whose lock has expired
unlock(of) Release all expired locks back to the transferable balance

Events Locked and Unlocked let wallets and indexers track lock status the same way Transfer tracks balances.

Because one lock can be read by many parts of an app, a user who locks tokens for n days can, for example, cast several votes during that period, which a one-shot staking transfer does not easily allow.

Sample code

Using a lockable token from another contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface ILockableToken {
    function lock(bytes32 reason, uint256 amount, uint256 time) external returns (bool);
    function tokensLocked(address of_, bytes32 reason) external view returns (uint256);
    function totalBalanceOf(address of_) external view returns (uint256);
    function unlock(address of_) external returns (uint256);
}

contract Voting {
    ILockableToken public immutable token;
    bytes32 public constant GOV = "GOV";

    constructor(ILockableToken t) { token = t; }

    // Voting weight = tokens the voter has locked for governance.
    function weight(address voter) external view returns (uint256) {
        return token.tokensLocked(voter, GOV);
    }
}

The user locks directly on the token (the lock is on msg.sender's own tokens):

await token.lock(encodeBytes32String("GOV"), parseUnits("100", 18), 7n * 24n * 3600n);

Things to know

  • Status is Stagnant. It was not finalised, so interfaces in the wild may differ from the one above.
  • The spec mixes uint256 and bytes32 for the reason in the event signatures; check the actual contract you integrate with.
  • transfer must be overridden so that only the unlocked part of the balance can move. The spec leaves this to implementations, so audit it carefully.
  • Locks are keyed by reason; to change an existing lock use increaseLockAmount or extendLock.

#token #erc20 #locking #vesting #governance

Details

Authors
nitika-goel <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2018-06-03

Machine-readable: Markdown · JSON