Skip to content

Commit

Permalink
Support for allowlist proof
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJem committed Jan 17, 2024
1 parent a681c44 commit 0f5cade
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/AuctionHouse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,6 +53,7 @@ abstract contract Router is FeeManager {
uint256 approvalNonce;
bytes auctionData;
bytes approvalSignature;
bytes allowlistProof;
}

// ========== STATE VARIABLES ========== //
Expand Down Expand Up @@ -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();
}
}
Expand Down
14 changes: 10 additions & 4 deletions test/AuctionHouse/purchase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -142,7 +143,8 @@ contract PurchaseTest is Test, Permit2User {
minAmountOut: AMOUNT_OUT,
approvalNonce: approvalNonce,
auctionData: bytes(""),
approvalSignature: approvalSignature
approvalSignature: approvalSignature,
allowlistProof: allowlistProof
});
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
_;
}

Expand Down
17 changes: 10 additions & 7 deletions test/modules/Auction/MockAllowlist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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_;
}
}

0 comments on commit 0f5cade

Please sign in to comment.