From 0f5cadeee943a9e435d19f11ba3c3a2834463f49 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Wed, 17 Jan 2024 15:16:28 +0400 Subject: [PATCH] Support for allowlist proof --- src/AuctionHouse.sol | 4 +++- test/AuctionHouse/purchase.t.sol | 14 ++++++++++---- test/modules/Auction/MockAllowlist.sol | 17 ++++++++++------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/AuctionHouse.sol b/src/AuctionHouse.sol index cbe84e5c..eb432a08 100644 --- a/src/AuctionHouse.sol +++ b/src/AuctionHouse.sol @@ -42,6 +42,7 @@ abstract contract Router is FeeManager { /// @param approvalNonce Nonce for permit approval signature /// @param auctionData Custom data used by the auction module /// @param approvalSignature Permit approval signature for the quoteToken + /// @param allowlistProof Proof of allowlist inclusion struct PurchaseParams { address recipient; address referrer; @@ -52,6 +53,7 @@ abstract contract Router is FeeManager { uint256 approvalNonce; bytes auctionData; bytes approvalSignature; + bytes allowlistProof; } // ========== STATE VARIABLES ========== // @@ -235,7 +237,7 @@ contract AuctionHouse is Derivatizer, Auctioneer, Router { // Check if the purchaser is on the allowlist if (address(routing.allowlist) != address(0)) { - if (!routing.allowlist.isAllowed(params_.lotId, msg.sender, bytes(""))) { + if (!routing.allowlist.isAllowed(params_.lotId, msg.sender, params_.allowlistProof)) { revert NotAuthorized(); } } diff --git a/test/AuctionHouse/purchase.t.sol b/test/AuctionHouse/purchase.t.sol index 1c6b7c78..17a908bc 100644 --- a/test/AuctionHouse/purchase.t.sol +++ b/test/AuctionHouse/purchase.t.sol @@ -73,6 +73,7 @@ contract PurchaseTest is Test, Permit2User { bytes internal approvalSignature; uint48 internal approvalDeadline; uint256 internal derivativeTokenId; + bytes internal allowlistProof; function setUp() external { aliceKey = _getRandomUint256(); @@ -142,7 +143,8 @@ contract PurchaseTest is Test, Permit2User { minAmountOut: AMOUNT_OUT, approvalNonce: approvalNonce, auctionData: bytes(""), - approvalSignature: approvalSignature + approvalSignature: approvalSignature, + allowlistProof: allowlistProof }); } @@ -327,8 +329,6 @@ contract PurchaseTest is Test, Permit2User { // [X] when the caller is on the allowlist // [X] it succeeds - // TODO add support for allowlist proof - modifier givenAuctionHasAllowlist() { // Register a new auction with an allowlist routingParams.allowlist = mockAllowlist; @@ -345,8 +345,14 @@ contract PurchaseTest is Test, Permit2User { // Assumes the allowlist is set require(address(routingParams.allowlist) != address(0), "allowlist not set"); + // Set the allowlist proof + allowlistProof = abi.encode("i am allowed"); + // Set the caller to be on the allowlist - mockAllowlist.setAllowed(alice, true); + mockAllowlist.setAllowedWithProof(alice, allowlistProof, true); + + // Update the purchase params + purchaseParams.allowlistProof = allowlistProof; _; } diff --git a/test/modules/Auction/MockAllowlist.sol b/test/modules/Auction/MockAllowlist.sol index 431a2d7a..0a88e614 100644 --- a/test/modules/Auction/MockAllowlist.sol +++ b/test/modules/Auction/MockAllowlist.sol @@ -8,18 +8,21 @@ contract MockAllowlist is IAllowlist { uint256[] public registeredIds; - mapping(address => bool) public allowed; + mapping(address => mapping(bytes => bool)) public allowedWithProof; - function isAllowed(address address_, bytes calldata) external view override returns (bool) { - return allowed[address_]; + function isAllowed( + address address_, + bytes calldata proof_ + ) external view override returns (bool) { + return allowedWithProof[address_][proof_]; } function isAllowed( uint256, address address_, - bytes calldata + bytes calldata proof_ ) external view override returns (bool) { - return allowed[address_]; + return allowedWithProof[address_][proof_]; } function register(bytes calldata) external override {} @@ -40,7 +43,7 @@ contract MockAllowlist is IAllowlist { return registeredIds; } - function setAllowed(address account, bool allowed_) external { - allowed[account] = allowed_; + function setAllowedWithProof(address account, bytes calldata proof, bool allowed_) external { + allowedWithProof[account][proof] = allowed_; } }