Home

Awesome

permit2

Permit2 introduces a low-overhead, next-generation token approval/meta-tx system to make token approvals easier, more secure, and more consistent across applications.

Features

Architecture

Permit2 is the union of two contracts: AllowanceTransfer and SignatureTransfer.

The SignatureTransfer contract handles all signature-based transfers, meaning that an allowance on the token is bypassed and permissions to the spender only last for the duration of the transaction that the one-time signature is spent.

The AllowanceTransfer contract handles setting allowances on tokens, giving permissions to spenders on a specified amount for a specified duration of time. Any transfers that then happen through the AllowanceTransfer contract will only succeed if the proper permissions have been set.

Integrating with Permit2

Before integrating, contracts can request users’ tokens through Permit2, users must approve the Permit2 contract through the specific token contract. To see a detailed technical reference, visit the Uniswap documentation site.

Note on viaIR compilation

Permit2 uses viaIR compilation, so importing and deploying it in an integration for tests will require the integrating repository to also use viaIR compilation. This is often quite slow, so can be avoided using the precompiled DeployPermit2 utility:

import {DeployPermit2} from "permit2/test/utils/DeployPermit2.sol";

contract MyTest is DeployPermit2 {
    address permit2;

    function setUp() public {
        permit2 = deployPermit2();
    }
}

Bug Bounty

This repository is subject to the Uniswap Labs Bug Bounty program, per the terms defined here.

Contributing

You will need a copy of Foundry installed before proceeding. See the installation guide for details.

Setup

git clone https://github.com/Uniswap/permit2.git
cd permit2
forge install

Lint

forge fmt [--check]

Run Tests

# unit
forge test

# integration
source .env
FOUNDRY_PROFILE=integration forge test

Update Gas Snapshots

forge snapshot

Deploy

Run the command below. Remove --broadcast, ---rpc-url, --private-key and --verify options to test locally

forge script --broadcast --rpc-url <RPC-URL> --private-key <PRIVATE_KEY> --verify script/DeployPermit2.s.sol:DeployPermit2

Acknowledgments

Inspired by merklejerk's permit-everywhere contracts which introduce permit based approvals for all tokens regardless of EIP2612 support.