Uniswap / permit2
- понедельник, 21 ноября 2022 г. в 00:32:57
🔑 🔑 🔑 next generation token approvals mechanism
Permit2 introduces a low-overhead, next generation token approval/meta-tx system to make token approvals easier, more secure, and more consistent across applications.
Permit2
integrated contracts.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.
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.
This repository is subject to the Uniswap Labs Bug Bounty program, per the terms defined here.
You will need a copy of Foundry installed before proceeding. See the installation guide for details.
git clone https://github.com/Uniswap/permit2.git
cd permit2
forge install
forge fmt [--check]
# unit
forge test
# integration
source .env
FOUNDRY_PROFILE=integration forge test
forge snapshot
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
Inspired by merklejerk's permit-everywhere contracts which introduce permit based approvals for all tokens regardless of EIP2612 support.