From 9560d0377e07b81367fa7d33b3e56095bcb2e032 Mon Sep 17 00:00:00 2001 From: Ron Turetzky Date: Sat, 28 Sep 2024 07:21:25 +0300 Subject: [PATCH] chore: init of Imultiplier @secbajor --- src/interfaces/IMultiplier.sol | 82 ---------------------- src/interfaces/multipliers/IMultiplier.sol | 10 +++ 2 files changed, 10 insertions(+), 82 deletions(-) delete mode 100644 src/interfaces/IMultiplier.sol create mode 100644 src/interfaces/multipliers/IMultiplier.sol diff --git a/src/interfaces/IMultiplier.sol b/src/interfaces/IMultiplier.sol deleted file mode 100644 index f99d452..0000000 --- a/src/interfaces/IMultiplier.sol +++ /dev/null @@ -1,82 +0,0 @@ -// IMultiplier.sol -pragma solidity ^0.8.22; - -interface IMultiplier { - function getMultiplyingFactor(address user) external view returns (uint256); - function validUntil(address user) external view returns (uint256); -} - -// INFTMultiplier.sol -pragma solidity ^0.8.22; - -import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; -import "./IMultiplier.sol"; - -interface INFTMultiplier is IMultiplier { - function NFTAddress() external view returns (IERC721); - function hasNFT(address user) external view returns (bool); -} - -// PermanentNFTMultiplier.sol -pragma solidity ^0.8.22; - -import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; -import "./INFTMultiplier.sol"; - -contract PermanentNFTMultiplier is INFTMultiplier { - IERC721 public immutable NFTAddress; - uint256 public immutable multiplyingFactor; - uint256 public constant validity = type(uint256).max; - - constructor(IERC721 _nftAddress, uint256 _multiplyingFactor) { - NFTAddress = _nftAddress; - multiplyingFactor = _multiplyingFactor; - } - - function getMultiplyingFactor(address user) external view override returns (uint256) { - return hasNFT(user) ? multiplyingFactor : 0; - } - - function validUntil(address) external pure override returns (uint256) { - return validity; - } - - function hasNFT(address user) public view override returns (bool) { - return NFTAddress.balanceOf(user) > 0; - } -} - -// DynamicNFTMultiplier.sol -pragma solidity ^0.8.22; - -import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; -import "./INFTMultiplier.sol"; - -contract DynamicNFTMultiplier is INFTMultiplier { - IERC721 public immutable NFTAddress; - mapping(address => uint256) public userToFactor; - mapping(address => uint256) public userToValidity; - - constructor(IERC721 _nftAddress) { - NFTAddress = _nftAddress; - } - - function getMultiplyingFactor(address user) external view override returns (uint256) { - return hasNFT(user) ? userToFactor[user] : 0; - } - - function validUntil(address user) external view override returns (uint256) { - return userToValidity[user]; - } - - function hasNFT(address user) public view override returns (bool) { - return NFTAddress.balanceOf(user) > 0; - } - - function setUserFactor(address user, uint256 factor, uint256 validity) external { - // Add appropriate access control - require(hasNFT(user), "User does not have the required NFT"); - userToFactor[user] = factor; - userToValidity[user] = validity; - } -} \ No newline at end of file diff --git a/src/interfaces/multipliers/IMultiplier.sol b/src/interfaces/multipliers/IMultiplier.sol new file mode 100644 index 0000000..117f10b --- /dev/null +++ b/src/interfaces/multipliers/IMultiplier.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +interface IMultiplier { + /// @notice Returns the voting multiplier for `user`. + function getMultiplyingFactor(address user) external view returns (uint256); + + /// @notice Returns the validity period of the multiplier for `user`. + function validUntil(address user) external view returns (uint256); +}