Skip to content

Commit

Permalink
feat: add deploy permit2 util (Uniswap#187)
Browse files Browse the repository at this point in the history
For folks building on top of permit2 it's kinda annoying to have to use
viaIR just becuase permit2 uses viaIR. This commit adds a test utility
that they can import to deploy permit2 from precompiled bytecode to
avoid needing to recompile it on their end
  • Loading branch information
marktoda authored Mar 8, 2023
1 parent 4382d76 commit db96e06
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ AllowanceUnitTest:testUpdateAllRandomly(uint160,uint48,uint48) (runs: 256, μ: 4
AllowanceUnitTest:testUpdateAmountExpirationRandomly(uint160,uint48) (runs: 256, μ: 39224, ~: 39225)
CompactSignature:testCompactSignature27() (gas: 253)
CompactSignature:testCompactSignature28() (gas: 141)
DeployPermit2Test:testAllowanceTransferSanityCheck() (gas: 101958)
DeployPermit2Test:testDeployPermit2() (gas: 4337486)
DeployPermit2Test:testSignatureTransferSanityCheck() (gas: 92819)
EIP712Test:testDomainSeparator() (gas: 5804)
EIP712Test:testDomainSeparatorAfterFork() (gas: 10787)
MockPermit2Lib:testPermit2Code(address):(bool) (runs: 256, μ: 3016, ~: 3016)
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ The `AllowanceTransfer` contract handles setting allowances on tokens, giving pe

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](https://docs.uniswap.org/contracts/permit2/overview).

### 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](https://uniswap.org/bug-bounty).
Expand Down
Loading

0 comments on commit db96e06

Please sign in to comment.