From 3cb35623f49c9cb891cc50d3bc56dea55910467f Mon Sep 17 00:00:00 2001 From: Ron Turetzky Date: Sat, 28 Sep 2024 07:45:33 +0300 Subject: [PATCH] chore: implementing interfaces from #71 --- .../multipliers/DynamicNFTMultiplier.sol | 46 +++++++++++++++++++ src/interfaces/multipliers/INFTMultiplier.sol | 19 ++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/interfaces/multipliers/DynamicNFTMultiplier.sol create mode 100644 src/interfaces/multipliers/INFTMultiplier.sol diff --git a/src/interfaces/multipliers/DynamicNFTMultiplier.sol b/src/interfaces/multipliers/DynamicNFTMultiplier.sol new file mode 100644 index 0000000..36c69db --- /dev/null +++ b/src/interfaces/multipliers/DynamicNFTMultiplier.sol @@ -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; + } +} diff --git a/src/interfaces/multipliers/INFTMultiplier.sol b/src/interfaces/multipliers/INFTMultiplier.sol new file mode 100644 index 0000000..1a80933 --- /dev/null +++ b/src/interfaces/multipliers/INFTMultiplier.sol @@ -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); +}