Skip to content

Commit

Permalink
feat: upgrade vebetter passport to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Agilulfo1820 committed Oct 21, 2024
1 parent 55d8726 commit b7e0016
Show file tree
Hide file tree
Showing 21 changed files with 5,659 additions and 89 deletions.
522 changes: 522 additions & 0 deletions contracts/deprecated/V1/interfaces/IVeBetterPassportV1.sol

Large diffs are not rendered by default.

817 changes: 817 additions & 0 deletions contracts/deprecated/V1/ve-better-passport/VeBetterPassportV1.sol

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// SPDX-License-Identifier: MIT

// #######
// ################
// ####################
// ########### #########
// ######### #########
// ####### ######### #########
// ######### ######### ##########
// ########## ######## ####################
// ########## ######### #########################
// ################### ############################
// ################# ########## ########
// ############## ### ########
// ############ #########
// ########## ##########
// ######## ###########
// ### ############
// ##############
// #################
// ##############
// #########

pragma solidity 0.8.20;

import { PassportStorageTypesV1 } from "./PassportStorageTypesV1.sol";
import { PassportTypesV1 } from "./PassportTypesV1.sol";

/**
* @title PassportChecksLogic
* @dev A library that manages various checks related to personhood in the Passport contract.
* It provides the ability to enable or disable specific personhood checks (such as whitelist, blacklist, signaling, etc.)
* and to update certain configurations such as the minimum Galaxy Member level.
* This library operates using a bitmask for efficient storage and toggling of checks.
*/
library PassportChecksLogicV1 {
// ---------- Consants ---------- //
uint256 constant WHITELIST_CHECK = 1 << 0; // Bitwise shift to the left by 0
uint256 constant BLACKLIST_CHECK = 1 << 1; // Bitwise shift to the left by 1
uint256 constant SIGNALING_CHECK = 1 << 2; // Bitwise shift to the left by 2
uint256 constant PARTICIPATION_SCORE_CHECK = 1 << 3; // Bitwise shift to the left by 3
uint256 constant GM_OWNERSHIP_CHECK = 1 << 4; // Bitwise shift to the left by 4

string constant WHITELIST_CHECK_NAME = "Whitelist Check";
string constant BLACKLIST_CHECK_NAME = "Blacklist Check";
string constant SIGNALING_CHECK_NAME = "Signaling Check";
string constant PARTICIPATION_SCORE_CHECK_NAME = "Participation Score Check";
string constant GM_OWNERSHIP_CHECK_NAME = "GM Ownership Check";

// ---------- Events ---------- //
/// @notice Emitted when a specific check is toggled.
/// @param checkName The name of the check being toggled.
/// @param enabled True if the check is enabled, false if disabled.
event CheckToggled(string indexed checkName, bool enabled);

/// @notice Emitted when the minimum galaxy member level is set.
/// @param minimumGalaxyMemberLevel The new minimum galaxy member level.
event MinimumGalaxyMemberLevelSet(uint256 minimumGalaxyMemberLevel);

// ---------- Private Functions ---------- //

/// @notice Maps the PassportTypesV1.CheckType enum to the corresponding bitmask constant.
/// @param checkType The type of check from the enum.
/// @return The bitmask constant and the check name for the specified check.
function _mapCheckTypeToBitmask(PassportTypesV1.CheckType checkType) private pure returns (uint256, string memory) {
if (checkType == PassportTypesV1.CheckType.WHITELIST_CHECK) return (WHITELIST_CHECK, WHITELIST_CHECK_NAME);
if (checkType == PassportTypesV1.CheckType.BLACKLIST_CHECK) return (BLACKLIST_CHECK, BLACKLIST_CHECK_NAME);
if (checkType == PassportTypesV1.CheckType.SIGNALING_CHECK) return (SIGNALING_CHECK, SIGNALING_CHECK_NAME);
if (checkType == PassportTypesV1.CheckType.PARTICIPATION_SCORE_CHECK)
return (PARTICIPATION_SCORE_CHECK, PARTICIPATION_SCORE_CHECK_NAME);
if (checkType == PassportTypesV1.CheckType.GM_OWNERSHIP_CHECK) return (GM_OWNERSHIP_CHECK, GM_OWNERSHIP_CHECK_NAME);
revert("Invalid PassportTypesV1");
}

/// @notice Checks if a specific check is enabled
/// @param checkType The type of check to query (from the enum)
/// @return True if the check is enabled, false otherwise
function _isCheckEnabled(
PassportStorageTypesV1.PassportStorage storage self,
PassportTypesV1.CheckType checkType
) internal view returns (bool) {
require(checkType != PassportTypesV1.CheckType.UNDEFINED, "Invalid check type");

(uint256 checkBit, ) = _mapCheckTypeToBitmask(checkType);
return (self.personhoodChecks & checkBit) != 0;
}

// ---------- Getters ---------- //

/// @notice Checks if a specific check is enabled.
/// @param self The storage object for the Passport contract containing all checks.
/// @param checkType The type of check to query (from the enum).
/// @return True if the check is enabled, false otherwise.
function isCheckEnabled(
PassportStorageTypesV1.PassportStorage storage self,
PassportTypesV1.CheckType checkType
) external view returns (bool) {
return _isCheckEnabled(self, checkType);
}

/// @notice Returns the minimum galaxy member level
function getMinimumGalaxyMemberLevel(
PassportStorageTypesV1.PassportStorage storage self
) internal view returns (uint256) {
return self.minimumGalaxyMemberLevel;
}

// ---------- Setters ---------- //
/// @notice Toggles the specified check between enabled and disabled.
/// @param self The storage object for the Passport contract containing all checks.
/// @param checkType The type of check to toggle (from the enum).
function toggleCheck(PassportStorageTypesV1.PassportStorage storage self, PassportTypesV1.CheckType checkType) external {
require(checkType != PassportTypesV1.CheckType.UNDEFINED, "Invalid check type");

(uint256 checkBit, string memory checkName) = _mapCheckTypeToBitmask(checkType);

// Check if the check is currently enabled
if ((self.personhoodChecks & checkBit) != 0) {
// Disable the check by clearing the bit
self.personhoodChecks &= ~checkBit;
emit CheckToggled(checkName, false);
} else {
// Enable the check by setting the bit
self.personhoodChecks |= checkBit;
emit CheckToggled(checkName, true);
}
}

/// @notice Sets the minimum galaxy member level
/// @param minimumGalaxyMemberLevel The new minimum galaxy member level
function setMinimumGalaxyMemberLevel(
PassportStorageTypesV1.PassportStorage storage self,
uint256 minimumGalaxyMemberLevel
) external {
require(minimumGalaxyMemberLevel > 0, "VeBetterPassport: minimum galaxy member level must be greater than 0");

self.minimumGalaxyMemberLevel = minimumGalaxyMemberLevel;
emit MinimumGalaxyMemberLevelSet(minimumGalaxyMemberLevel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT

// #######
// ################
// ####################
// ########### #########
// ######### #########
// ####### ######### #########
// ######### ######### ##########
// ########## ######## ####################
// ########## ######### #########################
// ################### ############################
// ################# ########## ########
// ############## ### ########
// ############ #########
// ########## ##########
// ######## ###########
// ### ############
// ##############
// #################
// ##############
// #########

pragma solidity 0.8.20;

import { PassportStorageTypesV1 } from "./PassportStorageTypesV1.sol";
import { Time } from "@openzeppelin/contracts/utils/types/Time.sol";

/// @title PassportClockLogic Library
/// @notice Library for managing the clock logic as specified in EIP-6372.
library PassportClockLogicV1 {
/**
* @notice Returns the current timepoint which is the current block number.
* @return The current block number.
*/
function clock() internal view returns (uint48) {
return Time.blockNumber();
}

/**
* @notice Returns the machine-readable description of the clock mode as specified in EIP-6372.
* @dev It returns the default block number mode.
* @return The clock mode as a string.
*/
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() internal pure returns (string memory) {
return "mode=blocknumber&from=default";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: MIT

// #######
// ################
// ####################
// ########### #########
// ######### #########
// ####### ######### #########
// ######### ######### ##########
// ########## ######## ####################
// ########## ######### #########################
// ################### ############################
// ################# ########## ########
// ############## ### ########
// ############ #########
// ########## ##########
// ######## ###########
// ### ############
// ##############
// #################
// ##############
// #########

pragma solidity 0.8.20;

import { PassportStorageTypesV1 } from "./PassportStorageTypesV1.sol";
import { PassportTypesV1 } from "./PassportTypesV1.sol";
import { PassportClockLogicV1} from "./PassportClockLogicV1.sol";
import { IX2EarnApps } from "../../../../interfaces/IX2EarnApps.sol";
import { IXAllocationVotingGovernor } from "../../../../interfaces/IXAllocationVotingGovernor.sol";
import { IGalaxyMember } from "../../../../interfaces/IGalaxyMember.sol";
import { Checkpoints } from "@openzeppelin/contracts/utils/structs/Checkpoints.sol";

/// @title PassportConfigurator Library
/// @notice Library for managing the configuration of a Passport contract.
/// @dev This library provides functions to set and get various configuration parameters and contracts used by the Passport contract.
library PassportConfiguratorV1 {
using Checkpoints for Checkpoints.Trace208;

// ---------- Getters ---------- //
/// @notice Gets the x2EarnApps contract address
function getX2EarnApps(PassportStorageTypesV1.PassportStorage storage self) internal view returns (IX2EarnApps) {
return self.x2EarnApps;
}

/// @notice Gets the xAllocationVoting contract address
function getXAllocationVoting(
PassportStorageTypesV1.PassportStorage storage self
) internal view returns (IXAllocationVotingGovernor) {
return self.xAllocationVoting;
}

/// @notice Gets the galaxy member contract address
function getGalaxyMember(PassportStorageTypesV1.PassportStorage storage self) internal view returns (IGalaxyMember) {
return self.galaxyMember;
}

// ---------- Setters ---------- //

/// @notice Initializes the PassportStorage struct with the provided initialization data
function initializePassportStorage(
PassportStorageTypesV1.PassportStorage storage self,
PassportTypesV1.InitializationData memory initializationData
) external {
// Initialize the external contracts
setX2EarnApps(self, initializationData.x2EarnApps);
setXAllocationVoting(self, initializationData.xAllocationVoting);
setGalaxyMember(self, initializationData.galaxyMember);

// Initialize the bot signals threshold
self.signalsThreshold = initializationData.signalingThreshold;

// Initialize the minimum Galaxy Member level to be considered human by Personhood checks
self.minimumGalaxyMemberLevel = initializationData.minimumGalaxyMemberLevel;

// Initialize the participant score threshold to be considered human by Personhood checks
self.popScoreThreshold.push(PassportClockLogicV1.clock(), 0);

// Initialize the number of rounds for cumulative score
self.roundsForCumulativeScore = initializationData.roundsForCumulativeScore;

// Initialize the secuirty multiplier
self.securityMultiplier[PassportTypesV1.APP_SECURITY.LOW] = 100;
self.securityMultiplier[PassportTypesV1.APP_SECURITY.MEDIUM] = 200;
self.securityMultiplier[PassportTypesV1.APP_SECURITY.HIGH] = 400;

// Decay
self.decayRate = initializationData.decayRate;

// Set the threshold percentage of blacklisted or whitelisted entities to consider a passport user as blacklisted or whitelisted
self.blacklistThreshold = initializationData.blacklistThreshold;
self.whitelistThreshold = initializationData.whitelistThreshold;

// Set the maximum number of entities per passport
self.maxEntitiesPerPassport = initializationData.maxEntitiesPerPassport;
}

/// @notice Sets the X2EarnApps contract address
/// @dev The X2EarnApps contract address can be modified by the CONTRACTS_ADDRESS_MANAGER_ROLE
/// @param _x2EarnApps - the X2EarnApps contract address
function setX2EarnApps(PassportStorageTypesV1.PassportStorage storage self, IX2EarnApps _x2EarnApps) public {
require(address(_x2EarnApps) != address(0), "VeBetterPassport: x2EarnApps is the zero address");

self.x2EarnApps = _x2EarnApps;
}

/// @dev Sets the xAllocationVoting contract
/// @param self - the PassportStorage struct
/// @param _xAllocationVoting - the xAllocationVoting contract address
function setXAllocationVoting(
PassportStorageTypesV1.PassportStorage storage self,
IXAllocationVotingGovernor _xAllocationVoting
) public {
require(address(_xAllocationVoting) != address(0), "VeBetterPassport: xAllocationVoting is the zero address");

self.xAllocationVoting = _xAllocationVoting;
}

/// @notice Sets the galaxy member contract address
/// @param self - the PassportStorage struct
/// @param _galaxyMember - the galaxy member contract address
function setGalaxyMember(PassportStorageTypesV1.PassportStorage storage self, IGalaxyMember _galaxyMember) public {
require(address(_galaxyMember) != address(0), "VeBetterPassport: galaxyMember is the zero address");

self.galaxyMember = _galaxyMember;
}
}
Loading

0 comments on commit b7e0016

Please sign in to comment.