• Stars
    star
    669
  • Rank 64,972 (Top 2 %)
  • Language
    Solidity
  • License
    MIT License
  • Created over 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”‘๐Ÿ”‘๐Ÿ”‘ next generation token approvals mechanism

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

  • Signature Based Approvals: Any ERC20 token, even those that do not support EIP-2612, can now use permit style approvals. This allows applications to have a single transaction flow by sending a permit signature along with the transaction data when using Permit2 integrated contracts.
  • Batched Token Approvals: Set permissions on different tokens to different spenders with one signature.
  • Signature Based Token Transfers: Owners can sign messages to transfer tokens directly to signed spenders, bypassing setting any allowance. This means that approvals aren't necessary for applications to receive tokens and that there will never be hanging approvals when using this method. The signature is valid only for the duration of the transaction in which it is spent.
  • Batched Token Transfers: Transfer different tokens to different recipients with one signature.
  • Safe Arbitrary Data Verification: Verify any extra data by passing through a witness hash and witness type. The type string must follow the EIP-712 standard.
  • Signature Verification for Contracts: All signature verification supports EIP-1271 so contracts can approve tokens and transfer tokens through signatures.
  • Non-monotonic Replay Protection: Signature based transfers use unordered, non-monotonic nonces so that signed permits do not need to be transacted in any particular order.
  • Expiring Approvals: Approvals can be time-bound, removing security concerns around hanging approvals on a walletโ€™s entire token balance. This also means that revoking approvals do not necessarily have to be a new transaction since an approval that expiries will no longer be valid.
  • Batch Revoke Allowances: Remove allowances on any number of tokens and spenders in one transaction.

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.

More Repositories

1

web3-react

A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps
TypeScript
5,373
star
2

interface

๐Ÿฆ„ Open source interfaces for the Uniswap protocol
TypeScript
4,689
star
3

v3-core

๐Ÿฆ„ ๐Ÿฆ„ ๐Ÿฆ„ Core smart contracts of Uniswap v3
TypeScript
4,154
star
4

v2-core

๐Ÿฆ„ ๐Ÿฆ„ Core smart contracts of Uniswap V2
TypeScript
2,813
star
5

v4-core

๐Ÿฆ„ ๐Ÿฆ„ ๐Ÿฆ„ ๐Ÿฆ„ Core smart contracts of Uniswap v4
Solidity
1,760
star
6

v3-periphery

๐Ÿฆ„ ๐Ÿฆ„ ๐Ÿฆ„ Peripheral smart contracts for interacting with Uniswap v3
TypeScript
1,114
star
7

token-lists

๐Ÿ“š The Token Lists specification
TypeScript
926
star
8

v2-periphery

๐ŸŽš Peripheral smart contracts for interacting with Uniswap V2
Solidity
916
star
9

v4-periphery

๐Ÿฆ„ ๐Ÿฆ„ ๐Ÿฆ„ ๐Ÿฆ„ Peripheral smart contracts for interacting with Uniswap v4
Solidity
628
star
10

wallet

Uniswap Wallet is the simplest, safest, and most powerful self-custodial crypto wallet. It is developed by the Uniswap Labs team, inventors of the Uniswap Protocol.
TypeScript
530
star
11

merkle-distributor

๐Ÿ“ฆ A smart contract that distributes a balance of tokens according to a merkle root
TypeScript
497
star
12

v3-sdk

๐Ÿ›  An SDK for building applications on top of Uniswap V3
TypeScript
453
star
13

v1-contracts

๐ŸUniswap V1 smart contracts
Python
438
star
14

v2-sdk

๐Ÿ›  An SDK for building applications on top of Uniswap V2
TypeScript
421
star
15

v2-subgraph

Uniswap V2 subgraph ๐Ÿ“Š
TypeScript
392
star
16

v3-info

Interface for Uniswap V3 analytics. ๐Ÿ“Š
TypeScript
378
star
17

smart-order-router

TypeScript
369
star
18

universal-router

Uniswap's Universal Router for NFT and ERC20 swapping
TypeScript
363
star
19

UniswapX

๐Ÿฆ„ Gasless ERC20 swap settlement protocol ๐Ÿฆ„
Solidity
352
star
20

v3-staker

Canonical liquidity mining contract for Uniswap V3
TypeScript
330
star
21

v3-subgraph

Subgraph for Uniswap V3
TypeScript
312
star
22

default-token-list

โ—ฆ The Uniswap default token list
JavaScript
298
star
23

docs

๐Ÿ““ Uniswap V3 docs website
TypeScript
289
star
24

info

โ„น๏ธ Uniswap v1+v2 analytics
JavaScript
283
star
25

tokenlists-org

A site for browsing featured token lists
JavaScript
175
star
26

sybil-list

List of verified mappings from Ethereum addresses to social profiles
162
star
27

org-v1

๐ŸŒ Uniswap protocol homepage
JavaScript
144
star
28

routing-api

TypeScript
131
star
29

solidity-lib

๐Ÿ“– Solidity libraries that are shared across Uniswap contracts
TypeScript
131
star
30

governance-seatbelt

Make governance safer
TypeScript
116
star
31

token-list-bridge-utils

TypeScript
116
star
32

widgets

TypeScript
112
star
33

retroactive-query

๐Ÿ‘€โฌ…๏ธ Queries for surfacing information about past users of Uniswap
109
star
34

v3-market-depth-study

Market depth calculation for Uniswap v3
Python
107
star
35

examples

TypeScript
102
star
36

swap-router-contracts

Smart contracts for swapping on Uniswap V2 and V3. Superseded by https://github.com/Uniswap/universal-router
TypeScript
102
star
37

unisocks

๐Ÿงฆ
JavaScript
101
star
38

redux-multicall

A React + Redux library for fetching, batching, and caching chain state via the MultiCall contract.
TypeScript
93
star
39

api-deprecated

๐Ÿ”ฎ Uniswap market data
TypeScript
86
star
40

governance

๐Ÿ› Governance contracts for the Uniswap protocol
Solidity
78
star
41

sdk-core

โš™๏ธ Code shared across TypeScript Uniswap SDK versions
TypeScript
77
star
42

hardhat-v3-deploy

Hardhat plugin for Uniswap V3 deployment
TypeScript
75
star
43

v3-polars

Jupyter Notebook
75
star
44

universal-router-sdk

TypeScript
72
star
45

sybil-interface

Interface that incorporates Sybil, a governance tool for discovering delegates.
TypeScript
69
star
46

deploy-v3

CLI to deploy Uniswap V3 to any Ethereum compatible network
TypeScript
62
star
47

liquidity-staker

Initial UNI liquidity staking contracts
TypeScript
60
star
48

unisocks-erc721

๐Ÿงฆ
Python
52
star
49

v1-docs

42
star
50

widgets-demo

@uniswap/widgets demo
40
star
51

uniswapx-sdk

SDK bindings for the UniswapX protocol
TypeScript
39
star
52

unipig

๐Ÿฆ„๐Ÿท
JavaScript
38
star
53

marketdepth-v3

Uniswap v3 onchain market depth calculator
Solidity
32
star
54

uniswapx-service

UniswapX Order Service
TypeScript
30
star
55

v3-new-chain-deployments

Instructions for deploying the Uniswap V3 protocol to new chains after receiving approval from governance.
29
star
56

permit2-sdk

TypeScript
29
star
57

old-solidity-contracts

โš ๏ธ DEPRECATED
Python
29
star
58

uniswapx-parameterization-api

TypeScript
28
star
59

unified-routing-api

TypeScript
26
star
60

unisocks-erc20

๐Ÿงฆ
Python
26
star
61

v3-core-optimism

Optimism fork of the V3 core contracts
TypeScript
25
star
62

lp-action-contracts

Solidity
25
star
63

sybil-verifier-worker

Cloudlfare worker to verify mappings for Sybil, a governance tool for delegates.
JavaScript
25
star
64

router-sdk

TypeScript
21
star
65

advanced-weth

A smart contract that wraps WETH that adds functionality for transparently dealing in WETH
JavaScript
20
star
66

uniswap-first-contract-example

Example code for the smart contract getting started example.
JavaScript
19
star
67

v3-periphery-optimism

Optimism fork of the V3 periphery contracts
TypeScript
17
star
68

ds-tools

Python
15
star
69

jest-environment-hardhat

TypeScript
15
star
70

ethers-rs-mobile

Rust
15
star
71

conedison

Utilities for Uniswap repositories
TypeScript
13
star
72

extended-token-list

JavaScript
12
star
73

v1-interface

๐Ÿ’€ Legacy interface for the Uniswap V1 protocol
JavaScript
12
star
74

returns-comparison-study

Python
11
star
75

mask-app

TypeScript
10
star
76

convert-cidv0-cidv1

GitHub action that converts CIDv0 for IPFS to CIDv1
JavaScript
9
star
77

polygon-bridge

Bridge contract for Polygon
TypeScript
9
star
78

mrkl-drop-data-chunks

The Merkle drop data broken up into chunks of 101 addresses and including a mapping file
TypeScript
8
star
79

fx-comparison-study

R
7
star
80

snapshot-gas-cost

Tiny utility package for snapshotting gas costs
TypeScript
7
star
81

eslint-config

Uniswap ESLint config
JavaScript
7
star
82

analytics

Uniswap analytics
TypeScript
7
star
83

interface-redirects

โ†ช๏ธ Redirects for alternative app.uniswap.org domains
6
star
84

analytics-events

Uniswap analytics events
TypeScript
6
star
85

permit2-dashboard

a dashboard for managing permit2 permissions
TypeScript
6
star
86

replace-vercel-dns-records

GitHub action for replacing Vercel DNS records, particularly useful for IPFS DNSLink TXT records
JavaScript
5
star
87

view-quoter-v3

Solidity
5
star
88

ticketblaster

a whimsical ticketing thing
TypeScript
4
star
89

relayer

Contracts supporting relayed UniversalRouter swaps
Solidity
4
star
90

v1-sdk

๐Ÿ›  An SDK for building applications on top of Uniswap V1
TypeScript
3
star
91

signer

TypeScript
3
star
92

info-redirects

โ†ช๏ธ Redirects for the uniswap.info domain
1
star