diff --git a/.forge-snapshots/batchTransferFrom.snap b/.forge-snapshots/batchTransferFrom.snap index 6bb275af..b6d31f54 100644 --- a/.forge-snapshots/batchTransferFrom.snap +++ b/.forge-snapshots/batchTransferFrom.snap @@ -1 +1 @@ -62253 \ No newline at end of file +62244 \ No newline at end of file diff --git a/.gas-snapshot b/.gas-snapshot index b4994d08..05b7466c 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -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) diff --git a/README.md b/README.md index bfe59312..52429419 100644 --- a/README.md +++ b/README.md @@ -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 --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. diff --git a/lib/forge-std b/lib/forge-std index 27e14b7f..e8e3dbfb 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 27e14b7f2448e5f5ac32719f51fe652aa0b0733e +Subproject commit e8e3dbfb870c8457ca77343173509f6d899df63d diff --git a/script/DeployPermit2.s.sol b/script/DeployPermit2.s.sol new file mode 100644 index 00000000..e871d0a1 --- /dev/null +++ b/script/DeployPermit2.s.sol @@ -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(); + } +}