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

Voting Multipliers #100

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
47bdbff
chore: init
Sep 23, 2024
0aa29f4
chore: init of Imultiplier @secbajor
RonTuretzky Sep 28, 2024
2534725
chore: implementing interfaces from #71
RonTuretzky Sep 28, 2024
bc9abf8
chore: init permanftmul impl
RonTuretzky Sep 28, 2024
12fa7ea
chore: tmp commit
RonTuretzky Sep 28, 2024
faf437f
fix: reverting auto changes to yd
RonTuretzky Sep 28, 2024
8c89ed0
fix: changing to interface
RonTuretzky Sep 28, 2024
8dd45db
fix: fixing imports
RonTuretzky Sep 28, 2024
e0d2527
chore: init derived interfaces
RonTuretzky Sep 28, 2024
3906049
fix: changing variable name"
RonTuretzky Sep 28, 2024
3f06af0
fix: removing ref to external, impl in implemtations
RonTuretzky Sep 28, 2024
0cc8661
chore: first multiplier
RonTuretzky Sep 28, 2024
6f95cc5
chore: Adding voting multiplier handling and integration to yd
RonTuretzky Sep 28, 2024
1c6c8c0
fix: amending functionality to handle no multiplier for voter properly
RonTuretzky Sep 28, 2024
fffe13b
chore: adding unit and fuzzy tests
RonTuretzky Sep 28, 2024
fc1221b
chore: adding basic NFTMultiplier implementation, deploy script and c…
RonTuretzky Sep 28, 2024
daeb1ce
fix: updating wrong documentation
RonTuretzky Sep 28, 2024
cf53a4f
fix: reducing scope of pr
RonTuretzky Sep 28, 2024
dce84d8
Merge branch 'dev' into feat/voting_multiplier
RonTuretzky Oct 24, 2024
3d92685
merge: merging dev
RonTuretzky Oct 24, 2024
bf324f1
fix: order of operations clarification
RonTuretzky Oct 26, 2024
5b9b7b3
chore: adding gas benchmark tests for mutipliers
RonTuretzky Oct 29, 2024
12bfd60
rename: using PRECISION instead of hardcoded 1e18 for clarity"
RonTuretzky Dec 1, 2024
50787c1
chore: removing external calls by declaring public
RonTuretzky Dec 1, 2024
47333b3
chore: renaming outdating convention
RonTuretzky Dec 1, 2024
967d6cc
chore: including prefix for function param and fixing up previous com…
RonTuretzky Dec 1, 2024
706cd8e
chore: renaming constant to fit camel case convention
RonTuretzky Dec 1, 2024
2d04f5c
chore: refactoring constant to snake case
RonTuretzky Dec 1, 2024
6e78550
style: underscore for internal vars"
RonTuretzky Dec 1, 2024
ec07fb1
docs: updating authors
RonTuretzky Dec 1, 2024
f867e06
chore: removing voting multiplier gas snapshot testing
RonTuretzky Dec 1, 2024
80b7345
style: internal / function-scoped variables should have underscore
RonTuretzky Dec 1, 2024
de0309d
perf: optimizing init variable validation
RonTuretzky Dec 1, 2024
1c5f5cd
Revert "perf: optimizing init variable validation"
RonTuretzky Dec 1, 2024
0d4836e
chore: introducing offchain indexing of multipliers to be bundled wit…
RonTuretzky Dec 1, 2024
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
64 changes: 64 additions & 0 deletions script/deploy/DeployNFTMultiplier.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {Script} from "forge-std/Script.sol";
import {NFTMultiplier} from "src/multipliers/NFTMultiplier.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {console} from "forge-std/console.sol";

contract DeployNFTMultiplier is Script {
function run() external {
uint256 deployerPrivateKey;
address nftContractAddress;
uint256 initialMultiplyingFactor;
uint256 validUntilBlock;

string memory configPath = "deploy_config.json";
string memory jsonData;
// Try to read the JSON file, if it doesn't exist or can't be read, catch the error
try vm.readFile(configPath) returns (string memory data) {
jsonData = data;
} catch {
console.log("Config file not found or couldn't be read. Falling back to environment variables.");
jsonData = "";
}

if (bytes(jsonData).length > 0) {
// Read from JSON if file exists
deployerPrivateKey = vm.parseJsonUint(jsonData, ".deployerPrivateKey");
nftContractAddress = vm.parseJsonAddress(jsonData, ".nftContractAddress");
initialMultiplyingFactor = vm.parseJsonUint(jsonData, ".initialMultiplyingFactor");
validUntilBlock = vm.parseJsonUint(jsonData, ".validUntilBlock");
} else {
// Fall back to environment variables
deployerPrivateKey = vm.envUint("PRIVATE_KEY");
nftContractAddress = vm.envAddress("NFT_CONTRACT_ADDRESS");
initialMultiplyingFactor = vm.envUint("INITIAL_MULTIPLYING_FACTOR");
validUntilBlock = vm.envUint("VALID_UNTIL_BLOCK");
}

// Check if all required variables are set
require(deployerPrivateKey != 0, "Deployer private key not set");
require(nftContractAddress != address(0), "NFT contract address not set");
require(initialMultiplyingFactor != 0, "Initial multiplying factor not set");
require(validUntilBlock != 0, "Valid until block not set");

vm.startBroadcast(deployerPrivateKey);

NFTMultiplier implementation = new NFTMultiplier();

bytes memory initData = abi.encodeWithSelector(
NFTMultiplier.initialize.selector, IERC721(nftContractAddress), initialMultiplyingFactor, validUntilBlock
);

TransparentUpgradeableProxy proxy =
new TransparentUpgradeableProxy(address(implementation), vm.addr(deployerPrivateKey), initData);

NFTMultiplier nftMultiplier = NFTMultiplier(address(proxy));

vm.stopBroadcast();

console.log("NFTMultiplier deployed at:", address(nftMultiplier));
}
}
6 changes: 6 additions & 0 deletions script/deploy/config/deployNFTMul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"deployerPrivateKey": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"nftContractAddress": "0x1234567890123456789012345678901234567890",
"initialMultiplyingFactor": 100,
"validUntilBlock": 1000000
}
58 changes: 58 additions & 0 deletions src/VotingMultipliers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {IVotingMultipliers, IMultiplier} from "src/interfaces/IVotingMultipliers.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/// @title VotingMultipliers
/// @notice A contract for managing voting multipliers
/// @dev Implements IVotingMultipliers interface
contract VotingMultipliers is OwnableUpgradeable, IVotingMultipliers {
bagelface marked this conversation as resolved.
Show resolved Hide resolved
/// @notice Array of whitelisted multiplier contracts
IMultiplier[] public whitelistedMultipliers;

/// @notice Calculates the total multiplier for a given user
/// @param user The address of the user
/// @return The total multiplier value for the user
function getTotalMultipliers(address user) external view returns (uint256) {
uint256 totalMultiplier = 0;
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
for (uint256 i = 0; i < whitelistedMultipliers.length; i++) {
IMultiplier multiplier = whitelistedMultipliers[i];
if (block.number <= multiplier.validUntil(user)) {
totalMultiplier += multiplier.getMultiplyingFactor(user);
}
}
return totalMultiplier;
}

/// @notice Adds a multiplier to the whitelist
/// @param _multiplier The multiplier contract to be added
function addMultiplier(IMultiplier _multiplier) external onlyOwner {
// Check if the multiplier is already whitelisted
for (uint256 i = 0; i < whitelistedMultipliers.length; i++) {
if (whitelistedMultipliers[i] == _multiplier) {
revert MultiplierAlreadyWhitelisted();
}
}
whitelistedMultipliers.push(_multiplier);
emit MultiplierAdded(_multiplier);
}

/// @notice Removes a multiplier from the whitelist
/// @param _multiplier The multiplier contract to be removed
function removeMultiplier(IMultiplier _multiplier) external onlyOwner {
bool isWhitelisted = false;
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
for (uint256 i = 0; i < whitelistedMultipliers.length; i++) {
if (whitelistedMultipliers[i] == _multiplier) {
whitelistedMultipliers[i] = whitelistedMultipliers[whitelistedMultipliers.length - 1];
whitelistedMultipliers.pop();
isWhitelisted = true;
emit MultiplierRemoved(_multiplier);
break;
}
}
if (!isWhitelisted) {
revert MultiplierNotWhitelisted();
}
}
}
16 changes: 9 additions & 7 deletions src/YieldDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {ERC20VotesUpgradeable} from
import {Bread} from "bread-token/src/Bread.sol";

import {IYieldDistributor} from "src/interfaces/IYieldDistributor.sol";
import {VotingMultipliers} from "src/VotingMultipliers.sol";

/**
* @title Breadchain Yield Distributor
Expand All @@ -20,7 +21,7 @@ import {IYieldDistributor} from "src/interfaces/IYieldDistributor.sol";
* @custom:coauthor kassandra.eth
* @custom:coauthor theblockchainsocialist.eth
*/
contract YieldDistributor is IYieldDistributor, OwnableUpgradeable {
contract YieldDistributor is IYieldDistributor, OwnableUpgradeable, VotingMultipliers {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I'm a little dubious of the upgrade safety here. It would probably be best to implement VotingMultipliers to use ERC7201 storage layouts (like they do with OwnableUpgradeable) to avoid storage layout collisions. It seems complicated but it's actually a pretty trivial one time calculation and some boilerplate code for accessing storage variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we should just deploy a new proxy for this version, and use the setter on the bread contract, as this would also help us resolve #96

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a foreseeable problem deploying as a new proxy, thus changing the address? if there is not, i would prefer we deploy fresh, therefore do not need to worry about upgrade-safety, and not over-complicated things. but again, this is assuming there is no major problem with changing the address.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying a new contract is definitely the move in this instance but I mean in future instances where we maybe want to make some changes to the VotingMultipliers.sol contract. Namespacing the storage layouts ensure YieldDistributor and VotingMultipliers are using their own storage locations that won't clash, so if we want to add a variable to one or the other, we can do so safely. I can make a quick branch so show what it would look like.

Copy link
Contributor

@bagelface bagelface Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think there is a strong case to be made for VotingMultipliers to be its own contract.

/// @notice The address of the $BREAD token contract
Bread public BREAD;
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
/// @notice The precision to use for calculations
Expand Down Expand Up @@ -108,12 +109,13 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable {
* @return uint256 The voting power of the user
*/
function getCurrentVotingPower(address _account) public view returns (uint256) {
return this.getVotingPowerForPeriod(
BREAD, lastClaimedBlockNumber - cycleLength, lastClaimedBlockNumber, _account
)
+ this.getVotingPowerForPeriod(
BUTTERED_BREAD, lastClaimedBlockNumber - cycleLength, lastClaimedBlockNumber, _account
);
uint256 lastCycleStart = lastClaimedBlockNumber - cycleLength;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realizing this will be invalid if cycleLength is changed. We need a "lastCycleLength" variable. Maybe it'd be good to create a Cycle struct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should open a separate issue for this ... also mark it as bug so we don't upgrade changes without considering this...

uint256 multiplier = this.getTotalMultipliers(_account);
multiplier = multiplier == 0 ? 1e18 : multiplier;
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
uint256 breadVotingPower = this.getVotingPowerForPeriod(BREAD, lastCycleStart, lastClaimedBlockNumber, _account);
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
uint256 butteredBreadVotingPower =
this.getVotingPowerForPeriod(BUTTERED_BREAD, lastCycleStart, lastClaimedBlockNumber, _account);
return (breadVotingPower + butteredBreadVotingPower) * multiplier / PRECISION;
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see what's going on. TBH I don't think PRECISION should be shared here since it's being used in two different calculations. I think the getTotalMultipliers function should probably return a tuple like (multiplier, multiplier_precision) and that should be used here. Ignore my previous comment about using "1 instead of 1e18"

Copy link
Collaborator Author

@RonTuretzky RonTuretzky Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you're saying each multiplier should have it's own precision potentially? can't we just assume they are all 1e18?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return a single number formatted to 1e18, to avoid confusion and enforce standardization

}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/interfaces/IVotingMultipliers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.8.22;

import {IMultiplier} from "./multipliers/IMultiplier.sol";

/// @title IVotingMultipliers
/// @notice Interface for the VotingMultipliers contract
/// @dev This interface defines the structure and functions for managing voting multipliers
interface IVotingMultipliers {
/// @notice Thrown when attempting to add a multiplier that is already whitelisted
error MultiplierAlreadyWhitelisted();
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
/// @notice Thrown when attempting to remove a multiplier that is not whitelisted
error MultiplierNotWhitelisted();
/// @notice Emitted when a new multiplier is added to the whitelist
/// @param multiplier The address of the added multiplier

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line break

event MultiplierAdded(IMultiplier indexed multiplier);
/// @notice Emitted when a multiplier is removed from the whitelist
/// @param multiplier The address of the removed multiplier
event MultiplierRemoved(IMultiplier indexed multiplier);
/// @notice Returns the multiplier at the specified index in the whitelist
/// @param index The index of the multiplier in the whitelist
/// @return The multiplier contract at the specified index

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line break

function whitelistedMultipliers(uint256 index) external view returns (IMultiplier);
/// @notice Calculates the total multiplier for a given user
/// @param user The address of the user
/// @return The total multiplier value for the user
function getTotalMultipliers(address user) external view returns (uint256);
/// @notice Adds a multiplier to the whitelist
/// @param _multiplier The multiplier contract to be added
function addMultiplier(IMultiplier _multiplier) external;
/// @notice Removes a multiplier from the whitelist
/// @param _multiplier The multiplier contract to be removed
function removeMultiplier(IMultiplier _multiplier) external;
}
13 changes: 13 additions & 0 deletions src/interfaces/multipliers/ICrossChainProveableMultiplier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {IProveableMultiplier} from "src/interfaces/multipliers/IProveableMultiplier.sol";

/// @title Cross-Chain Proveable Multiplier Interface
/// @notice Interface for contracts that provide a cross-chain proveable multiplying factor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line break

interface ICrossChainProveableMultiplier is IProveableMultiplier {
/// @notice Get the address of the bridge contract
/// @return The address of the contract used for cross-chain communication
function bridge() external view returns (address);
}
19 changes: 19 additions & 0 deletions src/interfaces/multipliers/IDynamicNFTMultiplier.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 {INFTMultiplier} from "src/interfaces/multipliers/INFTMultiplier.sol";
/// @title Dynamic NFT Multiplier Interface
/// @notice Interface for contracts that provide a dynamic multiplying factor for users based on NFT ownership
/// @dev Extends the INFTMultiplier interface with dynamic multiplier functionality

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line break

interface IDynamicNFTMultiplier is INFTMultiplier {
/// @notice Get the multiplying factor for a user
/// @param user The address of the user
/// @return The multiplying factor for the user
function userToFactor(address user) external view returns (uint256);

/// @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 userToValidity(address user) external view returns (uint256);
}
10 changes: 10 additions & 0 deletions src/interfaces/multipliers/IMultiplier.sol
Original file line number Diff line number Diff line change
@@ -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);
}
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 {IERC721} from "@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);
}
12 changes: 12 additions & 0 deletions src/interfaces/multipliers/IOffChainProveableMultiplier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {IProveableMultiplier} from "src/interfaces/multipliers/IProveableMultiplier.sol";

/// @title Off-Chain Proveable Multiplier Interface
/// @notice Interface for contracts that provide an off-chain proveable multiplying factor
interface IOffChainProveableMultiplier is IProveableMultiplier {
/// @notice Get the address of the pull oracle
/// @return The address of the oracle used for off-chain data verification
function oracle() external view returns (address);
}
12 changes: 12 additions & 0 deletions src/interfaces/multipliers/IOnChainProveableMultiplier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {IProveableMultiplier} from "src/interfaces/multipliers/IProveableMultiplier.sol";
/// @title On-Chain Proveable Multiplier Interface
/// @notice Interface for contracts that provide an on-chain proveable multiplying factor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line break

interface IOnChainProveableMultiplier is IProveableMultiplier {
/// @notice Get the address of the activity contract
/// @return The address of the contract used for verifying on-chain activities
function activityContract() external view returns (address);
}
13 changes: 13 additions & 0 deletions src/interfaces/multipliers/IProveableMultiplier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IDynamicNFTMultiplier} from "src/interfaces/multipliers/IDynamicNFTMultiplier.sol";
/// @title Proveable Multiplier Interface
/// @notice Interface for contracts that provide a proveable multiplying factor based on user activities

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line break

interface IProveableMultiplier is IERC721, IDynamicNFTMultiplier {
/// @notice Submit activities to potentially earn or upgrade an NFT
/// @param data Encoded data representing the activities
function submitActivities(bytes calldata data) external;
}
80 changes: 80 additions & 0 deletions src/multipliers/NFTMultiplier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {INFTMultiplier} from "src/interfaces/multipliers/INFTMultiplier.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

/// @title NFT Multiplier
/// @notice Implementation of INFTMultiplier interface
/// @dev Provides multiplying factors based on NFT ownership
contract NFTMultiplier is INFTMultiplier, Initializable, OwnableUpgradeable {
IERC721 public nftContract;
uint256 public multiplyingFactor;
uint256 public validUntilBlock;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

/// @notice Initializer function to set the NFT contract address and initial multiplying factor
/// @param _nftContract Address of the NFT contract
/// @param _initialMultiplyingFactor Initial multiplying factor
/// @param _validUntilBlock Block number until which the multiplier is valid
function initialize(IERC721 _nftContract, uint256 _initialMultiplyingFactor, uint256 _validUntilBlock)
public
initializer
{
__Ownable_init(msg.sender);

nftContract = _nftContract;
multiplyingFactor = _initialMultiplyingFactor;
validUntilBlock = _validUntilBlock;
}

/// @notice Get the address of the NFT contract
/// @return The address of the NFT contract used for checking ownership
function NFTAddress() external view override returns (IERC721) {
return nftContract;
}

/// @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 nftContract.balanceOf(user) > 0;
}

/// @notice Get the multiplying factor for a given user
/// @param user The address of the user
/// @return The multiplying factor if the user owns an NFT, 0 otherwise
function getMultiplyingFactor(address user) external view override returns (uint256) {
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
return hasNFT(user) ? multiplyingFactor : 0;
}

/// @notice Get the block number until which the multiplier is valid
/// @return The block number until which the multiplier is valid
function validUntil(address /* user */ ) external view override returns (uint256) {
return validUntilBlock;
}

/// @notice Update the multiplying factor
/// @param _newMultiplyingFactor New multiplying factor (in basis points)
function updateMultiplyingFactor(uint256 _newMultiplyingFactor) external onlyOwner {
multiplyingFactor = _newMultiplyingFactor;
}

/// @notice Update the valid until block
/// @param _newValidUntilBlock New block number until which the multiplier is valid
function updateValidUntilBlock(uint256 _newValidUntilBlock) external onlyOwner {
validUntilBlock = _newValidUntilBlock;
}

/// @notice Update the NFT contract address
/// @param _newNFTContract New NFT contract address
function updateNFTContract(IERC721 _newNFTContract) external onlyOwner {
nftContract = _newNFTContract;
}
}
Loading