Skip to content

Commit

Permalink
deploy permit2 with forge (Uniswap#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz authored Nov 10, 2022
1 parent d4f55d8 commit 41e405b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/batchTransferFrom.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62253
62244
136 changes: 68 additions & 68 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
AllowanceTransferTest:testApprove() (gas: 47747)
AllowanceTransferTest:testBatchTransferFrom() (gas: 159705)
AllowanceTransferTest:testBatchTransferFromDifferentOwners() (gas: 235778)
AllowanceTransferTest:testBatchTransferFrom() (gas: 159742)
AllowanceTransferTest:testBatchTransferFromDifferentOwners() (gas: 235756)
AllowanceTransferTest:testBatchTransferFromMultiToken() (gas: 232008)
AllowanceTransferTest:testBatchTransferFromWithGasSnapshot() (gas: 160255)
AllowanceTransferTest:testExcessiveInvalidation() (gas: 64209)
AllowanceTransferTest:testBatchTransferFromWithGasSnapshot() (gas: 160270)
AllowanceTransferTest:testExcessiveInvalidation() (gas: 64187)
AllowanceTransferTest:testInvalidateMultipleNonces() (gas: 83635)
AllowanceTransferTest:testInvalidateNonces() (gas: 63173)
AllowanceTransferTest:testInvalidateNoncesInvalid() (gas: 16330)
AllowanceTransferTest:testLockdown() (gas: 146073)
AllowanceTransferTest:testInvalidateNonces() (gas: 63151)
AllowanceTransferTest:testInvalidateNoncesInvalid() (gas: 16308)
AllowanceTransferTest:testLockdown() (gas: 146051)
AllowanceTransferTest:testLockdownEvent() (gas: 117879)
AllowanceTransferTest:testMaxAllowance() (gas: 135012)
AllowanceTransferTest:testMaxAllowanceDirtyWrite() (gas: 117601)
AllowanceTransferTest:testMaxAllowance() (gas: 134990)
AllowanceTransferTest:testMaxAllowanceDirtyWrite() (gas: 117579)
AllowanceTransferTest:testPartialAllowance() (gas: 105214)
AllowanceTransferTest:testReuseOrderedNonceInvalid() (gas: 69369)
AllowanceTransferTest:testSetAllowance() (gas: 89585)
AllowanceTransferTest:testSetAllowanceBatch() (gas: 133561)
AllowanceTransferTest:testSetAllowanceBatchDifferentNonces() (gas: 118517)
AllowanceTransferTest:testSetAllowanceBatchDirtyWrite() (gas: 99076)
AllowanceTransferTest:testSetAllowanceBatchEvent() (gas: 111693)
AllowanceTransferTest:testSetAllowanceCompactSig() (gas: 89518)
AllowanceTransferTest:testReuseOrderedNonceInvalid() (gas: 69347)
AllowanceTransferTest:testSetAllowance() (gas: 89563)
AllowanceTransferTest:testSetAllowanceBatch() (gas: 133539)
AllowanceTransferTest:testSetAllowanceBatchDifferentNonces() (gas: 118489)
AllowanceTransferTest:testSetAllowanceBatchDirtyWrite() (gas: 99054)
AllowanceTransferTest:testSetAllowanceBatchEvent() (gas: 111671)
AllowanceTransferTest:testSetAllowanceCompactSig() (gas: 89496)
AllowanceTransferTest:testSetAllowanceDeadlinePassed() (gas: 56197)
AllowanceTransferTest:testSetAllowanceDirtyWrite() (gas: 72177)
AllowanceTransferTest:testSetAllowanceIncorrectSigLength() (gas: 29287)
AllowanceTransferTest:testSetAllowanceIncorrectSigLength() (gas: 29265)
AllowanceTransferTest:testSetAllowanceInvalidSignature() (gas: 64316)
AllowanceTransferTest:testSetAllowanceTransfer() (gas: 103320)
AllowanceTransferTest:testSetAllowanceTransferDirtyNonceDirtyTransfer() (gas: 97591)
AllowanceTransferTest:testTransferFromWithGasSnapshot() (gas: 133163)
CompactSignature:testCompactSignature27() (gas: 253)
AllowanceTransferTest:testSetAllowanceTransfer() (gas: 103298)
AllowanceTransferTest:testSetAllowanceTransferDirtyNonceDirtyTransfer() (gas: 97569)
AllowanceTransferTest:testTransferFromWithGasSnapshot() (gas: 133141)
CompactSignature:testCompactSignature27() (gas: 231)
CompactSignature:testCompactSignature28() (gas: 141)
EIP712Test:testDomainSeparator() (gas: 5781)
EIP712Test:testDomainSeparatorAfterFork() (gas: 10718)
NonceBitmapTest:testHighNonces() (gas: 35958)
NonceBitmapTest:testInvalidateFullWord() (gas: 62849)
EIP712Test:testDomainSeparator() (gas: 5759)
EIP712Test:testDomainSeparatorAfterFork() (gas: 10696)
NonceBitmapTest:testHighNonces() (gas: 35936)
NonceBitmapTest:testInvalidateFullWord() (gas: 62827)
NonceBitmapTest:testInvalidateNonzeroWord() (gas: 85329)
NonceBitmapTest:testLowNonces() (gas: 40671)
NonceBitmapTest:testNonceWordBoundary() (gas: 42042)
NonceBitmapTest:testUseTwoRandomNonces(uint256,uint256) (runs: 256, ΞΌ: 48832, ~: 51523)
NonceBitmapTest:testUsingNonceTwiceFails(uint256) (runs: 256, ΞΌ: 21775, ~: 21798)
Permit2LibTest:testOZSafePermit() (gas: 24443)
Permit2LibTest:testOZSafePermitPlusOZSafeTransferFrom() (gas: 129153)
Permit2LibTest:testOZSafeTransferFrom() (gas: 38875)
Permit2LibTest:testPermit2() (gas: 22737)
Permit2LibTest:testPermit2DSLessToken() (gas: 6818)
Permit2LibTest:testPermit2DSMore32Token() (gas: 6905)
Permit2LibTest:testPermit2DSMoreToken() (gas: 6808)
Permit2LibTest:testPermit2Full() (gas: 42071)
Permit2LibTest:testPermit2InvalidAmount() (gas: 20445)
Permit2LibTest:testPermit2LargerDS() (gas: 51040)
Permit2LibTest:testPermit2LargerDSRevert() (gas: 32757)
Permit2LibTest:testPermit2NonPermitToken() (gas: 31880)
Permit2LibTest:testPermit2PlusTransferFrom2() (gas: 126854)
Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermit() (gas: 147991)
NonceBitmapTest:testLowNonces() (gas: 40649)
NonceBitmapTest:testNonceWordBoundary() (gas: 42024)
NonceBitmapTest:testUseTwoRandomNonces(uint256,uint256) (runs: 256, ΞΌ: 49067, ~: 51501)
NonceBitmapTest:testUsingNonceTwiceFails(uint256) (runs: 256, ΞΌ: 21758, ~: 21780)
Permit2LibTest:testOZSafePermit() (gas: 24421)
Permit2LibTest:testOZSafePermitPlusOZSafeTransferFrom() (gas: 129137)
Permit2LibTest:testOZSafeTransferFrom() (gas: 38853)
Permit2LibTest:testPermit2() (gas: 22715)
Permit2LibTest:testPermit2DSLessToken() (gas: 6796)
Permit2LibTest:testPermit2DSMore32Token() (gas: 6883)
Permit2LibTest:testPermit2DSMoreToken() (gas: 6786)
Permit2LibTest:testPermit2Full() (gas: 42049)
Permit2LibTest:testPermit2InvalidAmount() (gas: 20423)
Permit2LibTest:testPermit2LargerDS() (gas: 51018)
Permit2LibTest:testPermit2LargerDSRevert() (gas: 32735)
Permit2LibTest:testPermit2NonPermitToken() (gas: 31858)
Permit2LibTest:testPermit2PlusTransferFrom2() (gas: 126838)
Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermit() (gas: 147975)
Permit2LibTest:testPermit2SmallerDS() (gas: 77505)
Permit2LibTest:testPermit2SmallerDSNoRevert() (gas: 59230)
Permit2LibTest:testStandardPermit() (gas: 22252)
Permit2LibTest:testStandardTransferFrom() (gas: 38077)
Permit2LibTest:testTransferFrom2() (gas: 38514)
Permit2LibTest:testTransferFrom2Full() (gas: 53371)
Permit2LibTest:testStandardPermit() (gas: 22230)
Permit2LibTest:testStandardTransferFrom() (gas: 38055)
Permit2LibTest:testTransferFrom2() (gas: 38492)
Permit2LibTest:testTransferFrom2Full() (gas: 53349)
Permit2LibTest:testTransferFrom2InvalidAmount() (gas: 12666)
Permit2LibTest:testTransferFrom2NonPermitToken() (gas: 53217)
Permit2LibTest:testTransferFrom2NonPermitToken() (gas: 53195)
SignatureTransferTest:testCorrectWitnessTypehashes() (gas: 3075)
SignatureTransferTest:testGasMultiplePermitBatchTransferFrom() (gas: 271102)
SignatureTransferTest:testGasSinglePermitBatchTransferFrom() (gas: 186335)
SignatureTransferTest:testGasSinglePermitTransferFrom() (gas: 123983)
SignatureTransferTest:testInvalidateUnorderedNonces() (gas: 41198)
SignatureTransferTest:testGasMultiplePermitBatchTransferFrom() (gas: 271080)
SignatureTransferTest:testGasSinglePermitBatchTransferFrom() (gas: 186313)
SignatureTransferTest:testGasSinglePermitTransferFrom() (gas: 123961)
SignatureTransferTest:testInvalidateUnorderedNonces() (gas: 41180)
SignatureTransferTest:testPermitBatchMultiPermitSingleTransfer() (gas: 133684)
SignatureTransferTest:testPermitBatchTransferFrom() (gas: 162111)
SignatureTransferTest:testPermitBatchTransferFromSingleRecipient() (gas: 190420)
SignatureTransferTest:testPermitBatchTransferFromTypedWitness() (gas: 240298)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidType() (gas: 84780)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidTypeHash() (gas: 86186)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidWitness() (gas: 86004)
SignatureTransferTest:testPermitBatchTransferInvalidAmountsLengthMismatch() (gas: 43834)
SignatureTransferTest:testPermitBatchTransferMultiAddr() (gas: 160507)
SignatureTransferTest:testPermitBatchTransferSingleRecipientManyTokens() (gas: 212603)
SignatureTransferTest:testPermitBatchTransferFromSingleRecipient() (gas: 190398)
SignatureTransferTest:testPermitBatchTransferFromTypedWitness() (gas: 240201)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidType() (gas: 84705)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidTypeHash() (gas: 86164)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidWitness() (gas: 85907)
SignatureTransferTest:testPermitBatchTransferInvalidAmountsLengthMismatch() (gas: 43812)
SignatureTransferTest:testPermitBatchTransferMultiAddr() (gas: 160485)
SignatureTransferTest:testPermitBatchTransferSingleRecipientManyTokens() (gas: 212581)
SignatureTransferTest:testPermitTransferFrom() (gas: 93052)
SignatureTransferTest:testPermitTransferFromCompactSig() (gas: 124032)
SignatureTransferTest:testPermitTransferFromCompactSig() (gas: 124010)
SignatureTransferTest:testPermitTransferFromIncorrectSigLength() (gas: 51305)
SignatureTransferTest:testPermitTransferFromInvalidNonce() (gas: 73297)
SignatureTransferTest:testPermitTransferFromRandomNonceAndAmount(uint256,uint128) (runs: 256, ΞΌ: 95730, ~: 96706)
SignatureTransferTest:testPermitTransferFromToSpender() (gas: 93382)
SignatureTransferTest:testPermitTransferFromTypedWitness() (gas: 125506)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidType() (gas: 56074)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidTypehash() (gas: 56983)
SignatureTransferTest:testPermitTransferSpendLessThanFull(uint256,uint128) (runs: 256, ΞΌ: 98043, ~: 99761)
SignatureTransferTest:testPermitTransferFromInvalidNonce() (gas: 73275)
SignatureTransferTest:testPermitTransferFromRandomNonceAndAmount(uint256,uint128) (runs: 256, ΞΌ: 95708, ~: 96684)
SignatureTransferTest:testPermitTransferFromToSpender() (gas: 93360)
SignatureTransferTest:testPermitTransferFromTypedWitness() (gas: 125534)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidType() (gas: 56077)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidTypehash() (gas: 56961)
SignatureTransferTest:testPermitTransferSpendLessThanFull(uint256,uint128) (runs: 256, ΞΌ: 98021, ~: 99739)
MockPermit2Lib:testPermit2Code(address):(bool) (runs: 256, ΞΌ: 2911, ~: 2911)
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ FOUNDRY_PROFILE=integration forge test
forge snapshot
```

### Deploy
Run the command below. Remove `--broadcast`, `---rpc-url`, `--private-key` and `--verify` options to test locally
```sh
forge script --broadcast --rpc-url <RPC-URL> --private-key <PRIVATE_KEY> --verify script/DeployPermit2.s.sol:DeployPermit2
```

## Acknowledgments

Inspired by [merklejerk](https://github.com/merklejerk)'s [permit-everywhere](https://github.com/merklejerk/permit-everywhere) contracts which introduce permit based approvals for all tokens regardless of EIP2612 support.
21 changes: 21 additions & 0 deletions script/DeployPermit2.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.15;

import "forge-std/console2.sol";
import "forge-std/Script.sol";
import {Permit2} from "src/Permit2.sol";

bytes32 constant SALT = bytes32(uint256(0x1234));

contract DeployPermit2 is Script {
function setUp() public {}

function run() public returns (Permit2 permit2) {
vm.startBroadcast();

permit2 = new Permit2{salt: SALT}();
console2.log("Permit2 Deployed:", address(permit2));

vm.stopBroadcast();
}
}

0 comments on commit 41e405b

Please sign in to comment.