Skip to content

Commit

Permalink
chore: implementing interfaces from #71
Browse files Browse the repository at this point in the history
  • Loading branch information
RonTuretzky committed Sep 28, 2024
1 parent 0aa29f4 commit 2534725
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/interfaces/multipliers/DynamicNFTMultiplier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "./INFTMultiplier.sol";

/// @title Dynamic NFT Multiplier
/// @notice This contract provides a dynamic multiplying factor for users based on NFT ownership
/// @dev Implements the INFTMultiplier interface
contract DynamicNFTMultiplier is INFTMultiplier {
/// @notice The address of the NFT contract
IERC721 public immutable NFTAddress;

/// @notice Mapping of user addresses to their multiplying factors
mapping(address => uint256) public userToFactor;

/// @notice Mapping of user addresses to the validity period of their multiplying factors
mapping(address => uint256) public userToValidity;

/// @notice Constructs the DynamicNFTMultiplier contract
/// @param _nftAddress The address of the NFT contract to check for ownership
constructor(IERC721 _nftAddress) {
NFTAddress = _nftAddress;
}

/// @notice Get the multiplying factor for a user
/// @param user The address of the user
/// @return The multiplying factor if the user has an NFT, 0 otherwise
function getMultiplyingFactor(address user) external view override returns (uint256) {
return hasNFT(user) ? userToFactor[user] : 0;
}

/// @notice Get the validity period for a user's factor
/// @param user The address of the user
/// @return The timestamp until which the user's factor is valid
function validUntil(address user) external view override returns (uint256) {
return userToValidity[user];
}

/// @notice Check if a user owns an NFT
/// @param user The address of the user to check
/// @return True if the user owns at least one NFT, false otherwise
function hasNFT(address user) public view override returns (bool) {
return NFTAddress.balanceOf(user) > 0;
}
}
19 changes: 19 additions & 0 deletions src/interfaces/multipliers/INFTMultiplier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IMultiplier} from "src/interfaces/multipliers/IMultiplier.sol";

/// @title NFT Multiplier Interface
/// @notice Interface for contracts that provide multiplying factors based on NFT ownership
/// @dev Extends the IMultiplier interface with NFT-specific functionality
interface INFTMultiplier is IMultiplier {
/// @notice Get the address of the NFT contract
/// @return The address of the NFT contract used for checking ownership
function NFTAddress() external view returns (IERC721);

/// @notice Check if a user owns an NFT
/// @param user The address of the user to check
/// @return True if the user owns at least one NFT, false otherwise
function hasNFT(address user) external view returns (bool);
}

0 comments on commit 2534725

Please sign in to comment.