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

Add generic ERC1155 Discount Validator #37

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions src/L2/discounts/ERC1155DiscountValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

import {IDiscountValidator} from "src/L2/interface/IDiscountValidator.sol";

/// @title Discount Validator for: ERC1155 NFTs
///
/// @notice Implements an NFT ownership validator for a stored `tokenId` for an ERC1155 `token` contract.
///
/// @author Coinbase (https://github.com/base-org/usernames)
contract ERC1155DiscountValidator is IDiscountValidator {
/// @notice The ERC1155 token contract to validate against.
IERC1155 token;

/// @notice The ERC1155 token ID of the relevant NFT.
uint256 tokenId;

/// @notice ERC1155 Discount Validator constructor.
///
/// @param tokenAddress The address of the token contract.
/// @param tokenId_ The ID of the token `claimer` must hold.
constructor(address tokenAddress, uint256 tokenId_) {
token = IERC1155(tokenAddress);
tokenId = tokenId_;
}

/// @notice Required implementation for compatibility with IDiscountValidator.
///
/// @dev No additional data is necessary to complete this validation. This validator checks that `claimer` has a nonzero
/// `balanceOf` the stored `tokenId` for the stored `token` ERC1155 contract.
///
/// @param claimer the discount claimer's address.
///
/// @return `true` if the validation data provided is determined to be valid for the specified claimer, else `false`.
function isValidDiscountRegistration(address claimer, bytes calldata) external view returns (bool) {
return (token.balanceOf(claimer, tokenId) > 0);
}
}