Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorized deployer contract PRO-80 #39

Merged
merged 119 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
9cb56e6
forge update
duncancmt Oct 4, 2023
9fbfa52
Add first version of deployer contract
duncancmt Oct 4, 2023
b461cbd
Move deployer into its own directory
duncancmt Oct 4, 2023
f5c6f2c
Add function for setting fee collector
duncancmt Oct 4, 2023
445e9ce
Add function to mark deployments as buggy; add convenience function f…
duncancmt Oct 4, 2023
f438299
Small optimization since we know nonce zero is illegal
duncancmt Oct 4, 2023
1e266f2
Compilation error
duncancmt Oct 4, 2023
28d5b97
Add multicall
duncancmt Oct 4, 2023
f97b13a
Utility constants
duncancmt Oct 4, 2023
86f5cc6
Storage alignment
duncancmt Oct 4, 2023
829e895
Comment
duncancmt Oct 4, 2023
c71f02a
Error checking on deployment
duncancmt Oct 4, 2023
d625f79
Add WIP unit tests
duncancmt Oct 4, 2023
e5b5fc4
More test
duncancmt Oct 4, 2023
df62e61
Use new foundry tools in test
duncancmt Oct 4, 2023
192e151
More tests
duncancmt Oct 4, 2023
78b1e21
Golf
duncancmt Oct 4, 2023
3c6e9e3
Use setNonceUnsafe for better test coverage
duncancmt Oct 4, 2023
d7f6955
Golf
duncancmt Oct 5, 2023
744091a
Golf
duncancmt Oct 5, 2023
fc9428b
Un-golf (introduced a bug)
duncancmt Oct 5, 2023
cfd0bad
Golf
duncancmt Oct 5, 2023
bc81186
Use EXTCODEHASH instead of EXTCODESIZE
duncancmt Oct 5, 2023
c9842ab
Golf
duncancmt Oct 5, 2023
e8c8bcf
Clear dirty bits
duncancmt Oct 5, 2023
d77a3e7
Delete branch specifier from forge-std submodule
duncancmt Oct 5, 2023
3006a78
Fix CI issue by reinstalling forge-std
duncancmt Oct 5, 2023
aa6c4c6
forge install: forge-std
duncancmt Oct 5, 2023
a4648db
Remove forge-std from remappings
duncancmt Oct 5, 2023
501cf61
Revert "Remove forge-std from remappings"
duncancmt Oct 5, 2023
21764b7
Use submodules to manage dependencies, not `forge`
duncancmt Oct 5, 2023
67069d8
Golf
duncancmt Oct 7, 2023
f7c3592
Golf
duncancmt Oct 7, 2023
69d31e5
Use library for address computation
duncancmt Oct 9, 2023
09e8efd
Golf
duncancmt Oct 9, 2023
0d2e498
Configure fuzz runs correctly
duncancmt Oct 17, 2023
a43ae82
Golf
duncancmt Oct 17, 2023
fdbf29e
Comment
duncancmt Oct 17, 2023
af29105
Make Deployer keep a doubly-linked list of deployments so that we can…
duncancmt Oct 31, 2023
7ffb8ed
Never store to `_deploymentLists[address(0)]`
duncancmt Oct 31, 2023
b18119c
Make authorizations expire
duncancmt Oct 31, 2023
67b622e
Disallow `feature == 0`
duncancmt Oct 31, 2023
3dda906
Fix tests
duncancmt Oct 31, 2023
85219b6
Don't use `EXTCODEHASH` because it isn't supported across EVM flavors
duncancmt Nov 8, 2023
6030621
Golf
duncancmt Nov 8, 2023
3af968f
Set EVM version to Shanghai
duncancmt Nov 8, 2023
bbf1332
Golf
duncancmt Nov 8, 2023
4c70c1e
Reorder
duncancmt Nov 9, 2023
2f7e517
Merge branch 'master' into deployer
duncancmt Jan 8, 2024
c1052f7
WIP: make Deployer an ERC721 for increased inspectability
duncancmt Jan 8, 2024
28bae3f
Add check for bad curve points
duncancmt Jan 8, 2024
7ace79c
WIP: tokenURI in IPFS
duncancmt Jan 8, 2024
6c876d4
Create directory vendor/
duncancmt Jan 8, 2024
6c9beea
Move verifyIPFS.sol into vendor/
duncancmt Jan 8, 2024
b6a4b88
Finished: make Deployer an ERC721
duncancmt Jan 8, 2024
fa2c761
Resolve TODO; fix bug
duncancmt Jan 8, 2024
70e654d
Golf
duncancmt Jan 8, 2024
e4a01e8
Fix tests
duncancmt Jan 8, 2024
d4b5402
Reorganize for clarity
duncancmt Jan 8, 2024
9c84ac5
Bug! spurious Transfer events
duncancmt Jan 8, 2024
15b1ac8
Resolve TODO
duncancmt Jan 8, 2024
e528667
Golf
duncancmt Jan 8, 2024
c19cd2c
Golf
duncancmt Jan 8, 2024
c9c73ad
Golf
duncancmt Jan 8, 2024
879a407
Golf
duncancmt Jan 8, 2024
1fa5027
Add newline to end of description
duncancmt Jan 8, 2024
dd7f7c6
Golf
duncancmt Jan 8, 2024
9ae12a7
toBase58 => base58sha256multihash
duncancmt Jan 8, 2024
067dea6
Single-chunk IPFS files can't be that long
duncancmt Jan 8, 2024
34e0a13
Fix in CIDv0 hashing; protobuf uses 7-bit bytes for varints
duncancmt Jan 9, 2024
419f8e2
Bounds checking
duncancmt Jan 9, 2024
d2e0a4a
Add TODOs
duncancmt Jan 9, 2024
d350a65
Move IPFS out of vendor/
duncancmt Jan 9, 2024
7ae3e1d
unchecked
duncancmt Jan 9, 2024
77be36f
Golf
duncancmt Jan 9, 2024
f15eea0
DRY
duncancmt Jan 9, 2024
e2a0fe0
Avoid evaluating block.timestamp if authorization is unlimited
duncancmt Jan 9, 2024
6a3a958
Golf
duncancmt Jan 9, 2024
829a6ed
Add failing unit test for empty file IPFS
duncancmt Jan 9, 2024
86a983e
Correctly, but inelegantly, handle the empty file
duncancmt Jan 9, 2024
1e9caca
Golf
duncancmt Jan 9, 2024
c2295af
Rename library and functions
duncancmt Jan 9, 2024
5515391
natspec
duncancmt Jan 9, 2024
c12c59a
Cleanup
duncancmt Jan 9, 2024
78f6209
Make base58Sha256Multihash return string
duncancmt Jan 9, 2024
79d704d
natspec
duncancmt Jan 9, 2024
7cd8395
Resolve TODO
duncancmt Jan 9, 2024
5e8ca5c
More tests for IPFS
duncancmt Jan 9, 2024
f5426bb
Bug! ERC721.ownerOf is supposed to revert for tokens that do not exist
duncancmt Jan 9, 2024
2f354ec
Add comment about gas golfing after Pralectra
duncancmt Jan 9, 2024
070bab3
Bug! ERC721.balanceOf is supposed to revert for address(0)
duncancmt Jan 9, 2024
353d74b
Comment
duncancmt Jan 9, 2024
4524952
Put nonce *and* address in events
duncancmt Jan 10, 2024
ee5cc9e
Add ItoA
duncancmt Jan 10, 2024
99530b3
Move ItoA into utils/
duncancmt Jan 10, 2024
b35f5c9
Resolve TODO by putting feature number in the name of each token
duncancmt Jan 10, 2024
ea67148
Golf
duncancmt Jan 10, 2024
f17bad6
Add bounds checks to point coordinates in AddressDerivation.deriveEOA
duncancmt Jan 10, 2024
114e690
Golf
duncancmt Jan 10, 2024
458971e
Bug! put fee collector address as last constructor argument
duncancmt Jan 11, 2024
c4d3562
Add deploy-time check that newly-deployed instances have taken up the…
duncancmt Jan 11, 2024
5766f7e
Separate FeatureInitialized from FeatureNotInitialized
duncancmt Jan 11, 2024
80a271b
Return the content, not the URI from `setDescription`
duncancmt Jan 11, 2024
285eab4
Better test for correct `feeCollector()`
duncancmt Jan 11, 2024
8720315
Single authorized address per feature
duncancmt Jan 11, 2024
f4a244b
Comments
duncancmt Jan 11, 2024
9695016
Use library; less assembly
duncancmt Jan 11, 2024
116b3a1
Prohibit questionable authorized/expiry combinations
duncancmt Jan 12, 2024
7c30b42
Add two bare-minimum test cases
duncancmt Jan 12, 2024
2ac07cd
Rename functions
duncancmt Jan 15, 2024
44b7953
Add O(1) function to mark entire feature as unsafe
duncancmt Jan 15, 2024
6313d7e
Add test case
duncancmt Jan 15, 2024
2ea6410
Bug! Fix indexed event argument checking
duncancmt Jan 15, 2024
7a921e4
Add nonce to revert reason
duncancmt Jan 15, 2024
ee5356f
Slightly smarter sanity check in `authorize`
duncancmt Jan 15, 2024
52b25ad
Storage layout
duncancmt Jan 16, 2024
7a83596
Better revert reason
duncancmt Jan 18, 2024
1209be1
Make `expiry` => `deadline` work like it does in most other protocols
duncancmt Jan 19, 2024
f3f3967
Golf
duncancmt Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ optimizer = true
via_ir = true
optimizer_runs = 1000000
no_match_path = "*/integration/*"
fuzz_runs = 10000
# needed for marktoda/forge-gas-snapshot
ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}]
Expand All @@ -15,3 +14,6 @@ evm_version = "shanghai"
no_match_path = ""
match_path = "*/integration/*"
evm_version = "shanghai"

[fuzz]
runs = 100_000
2 changes: 1 addition & 1 deletion lib/forge-gas-snapshot
2 changes: 1 addition & 1 deletion src/AllowanceHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.21;
import {IAllowanceHolder} from "./IAllowanceHolder.sol";
import {IERC20} from "./IERC20.sol";
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
import {SafeTransferLib} from "./utils/SafeTransferLib.sol";
import {SafeTransferLib} from "./vendor/SafeTransferLib.sol";
import {UnsafeMath} from "./utils/UnsafeMath.sol";
import {CheckCall} from "./utils/CheckCall.sol";
import {FreeMemory} from "./utils/FreeMemory.sol";
Expand Down
8 changes: 4 additions & 4 deletions src/Settler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {UniswapV3} from "./core/UniswapV3.sol";
import {UniswapV2} from "./core/UniswapV2.sol";
import {IPSM, MakerPSM} from "./core/MakerPSM.sol";

import {SafeTransferLib} from "./utils/SafeTransferLib.sol";
import {SafeTransferLib} from "./vendor/SafeTransferLib.sol";
import {UnsafeMath} from "./utils/UnsafeMath.sol";
import {FullMath} from "./utils/FullMath.sol";
import {FreeMemory} from "./utils/FreeMemory.sol";
Expand Down Expand Up @@ -87,10 +87,10 @@ contract Settler is Permit2Payment, Basic, OtcOrderSettlement, UniswapV3, Uniswa
address uniFactory,
bytes32 poolInitCodeHash,
address dai,
address feeRecipient,
address trustedForwarder
address trustedForwarder,
address feeCollector
)
Permit2Payment(permit2, feeRecipient, trustedForwarder)
Permit2Payment(permit2, trustedForwarder, feeCollector)
Basic()
OtcOrderSettlement()
UniswapV3(uniFactory, poolInitCodeHash)
Expand Down
2 changes: 1 addition & 1 deletion src/core/Basic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Permit2PaymentAbstract} from "./Permit2Payment.sol";
import {InvalidOffset, ConfusedDeputy, InvalidTarget} from "./SettlerErrors.sol";

import {IERC20} from "../IERC20.sol";
import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
import {SafeTransferLib} from "../vendor/SafeTransferLib.sol";
import {FullMath} from "../utils/FullMath.sol";
import {Panic} from "../utils/Panic.sol";
import {Revert} from "../utils/Revert.sol";
Expand Down
6 changes: 6 additions & 0 deletions src/core/IFeeCollector.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

interface IFeeCollector {
function feeCollector() external view returns (address);
}
2 changes: 1 addition & 1 deletion src/core/MakerPSM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.21;

import {IERC20, IERC20Meta} from "../IERC20.sol";

import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
import {SafeTransferLib} from "../vendor/SafeTransferLib.sol";
import {UnsafeMath} from "../utils/UnsafeMath.sol";

interface IPSM {
Expand Down
2 changes: 1 addition & 1 deletion src/core/OtcOrderSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IERC20} from "../IERC20.sol";
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
import {SettlerAbstract} from "../SettlerAbstract.sol";

import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
import {SafeTransferLib} from "../vendor/SafeTransferLib.sol";
import {FullMath} from "../utils/FullMath.sol";

abstract contract OtcOrderSettlement is SettlerAbstract {
Expand Down
11 changes: 6 additions & 5 deletions src/core/Permit2Payment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ForwarderNotAllowed, InvalidSignatureLen} from "./SettlerErrors.sol";
import {ContextAbstract} from "../Context.sol";
import {AllowanceHolderContext} from "../AllowanceHolderContext.sol";
import {IAllowanceHolder} from "../IAllowanceHolder.sol";
import {IFeeCollector} from "./IFeeCollector.sol";

import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
import {Panic} from "../utils/Panic.sol";
Expand Down Expand Up @@ -42,7 +43,7 @@ library UnsafeArray {
}
}

abstract contract Permit2PaymentAbstract is ContextAbstract {
abstract contract Permit2PaymentAbstract is ContextAbstract, IFeeCollector {
string internal constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount)";

function isRestrictedTarget(address) internal view virtual returns (bool);
Expand Down Expand Up @@ -136,17 +137,17 @@ abstract contract Permit2Payment is Permit2PaymentAbstract, AllowanceHolderConte

/// @dev Permit2 address
ISignatureTransfer private immutable _PERMIT2;
address private immutable _FEE_RECIPIENT;
address public immutable override feeCollector;

function isRestrictedTarget(address target) internal view override returns (bool) {
return target == address(_PERMIT2) || target == address(allowanceHolder);
}

constructor(address permit2, address feeRecipient, address allowanceHolder)
constructor(address permit2, address allowanceHolder, address feeCollector)
AllowanceHolderContext(allowanceHolder)
{
_PERMIT2 = ISignatureTransfer(permit2);
_FEE_RECIPIENT = feeRecipient;
feeCollector = feeCollector;
}

error FeeTokenMismatch(address paymentToken, address feeToken);
Expand Down Expand Up @@ -175,7 +176,7 @@ abstract contract Permit2Payment is Permit2PaymentAbstract, AllowanceHolderConte
revert FeeTokenMismatch(token, permitted.token);
}
ISignatureTransfer.SignatureTransferDetails memory transferDetail = transferDetails.unsafeGet(1);
transferDetail.to = _FEE_RECIPIENT;
transferDetail.to = feeCollector;
transferDetail.requestedAmount = permitted.amount;
}
}
Expand Down
34 changes: 16 additions & 18 deletions src/core/UniswapV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {IERC20} from "../IERC20.sol";
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
import {UnsafeMath} from "../utils/UnsafeMath.sol";
import {Panic} from "../utils/Panic.sol";
import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
import {SafeTransferLib} from "../vendor/SafeTransferLib.sol";
import {AddressDerivation} from "../utils/AddressDerivation.sol";
import {VIPBase} from "./VIPBase.sol";
import {SettlerAbstract} from "../SettlerAbstract.sol";

Expand Down Expand Up @@ -38,8 +39,8 @@ abstract contract UniswapV3 is SettlerAbstract, VIPBase {
using UnsafeMath for uint256;
using SafeTransferLib for IERC20;

/// @dev UniswapV3 Factory contract address prepended with '0xff' and left-aligned.
bytes32 private immutable UNI_FF_FACTORY_ADDRESS;
/// @dev UniswapV3 Factory contract address
address private immutable UNI_FACTORY_ADDRESS;
/// @dev UniswapV3 pool init code hash.
bytes32 private immutable UNI_POOL_INIT_CODE_HASH;
/// @dev Minimum size of an encoded swap path:
Expand All @@ -64,7 +65,7 @@ abstract contract UniswapV3 is SettlerAbstract, VIPBase {
uint256 private constant UINT24_MASK = 0xffffff;

constructor(address uniFactory, bytes32 poolInitCodeHash) {
UNI_FF_FACTORY_ADDRESS = bytes32((uint256(0xff) << 248) | (uint256(uint160(uniFactory)) << 88));
UNI_FACTORY_ADDRESS = uniFactory;
UNI_POOL_INIT_CODE_HASH = poolInitCodeHash;
}

Expand Down Expand Up @@ -294,30 +295,27 @@ abstract contract UniswapV3 is SettlerAbstract, VIPBase {
}

// Compute the pool address given two tokens and a fee.
function _toPool(IERC20 inputToken, uint24 fee, IERC20 outputToken) private view returns (IUniswapV3Pool pool) {
function _toPool(IERC20 inputToken, uint24 fee, IERC20 outputToken) private view returns (IUniswapV3Pool) {
// address(keccak256(abi.encodePacked(
// hex"ff",
// UNI_FACTORY_ADDRESS,
// keccak256(abi.encode(inputToken, outputToken, fee)),
// UNI_POOL_INIT_CODE_HASH
// )))
bytes32 ffFactoryAddress = UNI_FF_FACTORY_ADDRESS;
bytes32 poolInitCodeHash = UNI_POOL_INIT_CODE_HASH;
(IERC20 token0, IERC20 token1) =
inputToken < outputToken ? (inputToken, outputToken) : (outputToken, inputToken);
bytes32 salt;
assembly ("memory-safe") {
let s := mload(0x40)
mstore(s, ffFactoryAddress)
let p := add(s, 0x15)
// Compute the inner hash in-place
mstore(p, and(ADDRESS_MASK, token0))
mstore(add(p, 0x20), and(ADDRESS_MASK, token1))
mstore(add(p, 0x40), and(UINT24_MASK, fee))
mstore(p, keccak256(p, 0x60))
// compute the address
mstore(add(p, 0x20), poolInitCodeHash)
pool := keccak256(s, 0x55) // solidity clears dirty bits for us
let ptr := mload(0x40)
mstore(0x00, and(ADDRESS_MASK, token0))
mstore(0x20, and(ADDRESS_MASK, token1))
mstore(0x40, and(UINT24_MASK, fee))
salt := keccak256(0x00, 0x60)
mstore(0x40, ptr)
}
return IUniswapV3Pool(
AddressDerivation.deriveDeterministicContract(UNI_FACTORY_ADDRESS, salt, UNI_POOL_INIT_CODE_HASH)
);
}

error ZeroSwapAmount();
Expand Down
Loading
Loading