Skip to content

Commit

Permalink
Merge pull request #99 from SecureSECODAO/dev
Browse files Browse the repository at this point in the history
v1.0.0 release
  • Loading branch information
Plopmenz authored Jun 29, 2023
2 parents d88bf08 + 626e51a commit b9bbf60
Show file tree
Hide file tree
Showing 41 changed files with 713 additions and 189 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ETHERSCAN_API_KEY="your-etherscan-api-key"
POLYGONSCAN_API_KEY="your-polygonscan-api-key"
MUMBAI_PRIVATE_KEY="0000000000000000000000000000000000000000000000000000000000000000"
MUMBAI_PRIVATE_KEY="0000000000000000000000000000000000000000000000000000000000000000"
POLYGON_PRIVATE_KEY="0000000000000000000000000000000000000000000000000000000000000000"
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface IMembershipExtended is IMembership {
function isMember(address _account) external view override returns (bool);

/// Returns whether an account was a member at a given timestamp
function isMemberAt(address _account, uint256 _timestamp) external view returns (bool);
function isMemberAt(address _account, uint256 _blockNumber) external view returns (bool);

/// Returns all accounts that were a member at some point
/// @dev Can be used to loop over all members, loop over this array with filter isMember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ import { IMembershipExtended, IMembership } from "./IMembershipExtended.sol";
abstract contract ITieredMembershipStructure is IMembershipExtended {
/// @inheritdoc IMembershipExtended
function isMember(address _account) external view virtual override returns (bool) {
return _isMemberAt(_account, block.timestamp);
return _isMemberAt(_account, block.number);
}

/// @inheritdoc IMembershipExtended
function isMemberAt(address _account, uint256 _timestamp) external view override returns (bool) {
return _isMemberAt(_account, _timestamp);
function isMemberAt(address _account, uint256 _blockNumber) external view override returns (bool) {
return _isMemberAt(_account, _blockNumber);
}

/// @dev This internal copy is needed to be able to call the function from inside the contract
/// This function is used by the isMember function given the latest block timestamp
function _isMemberAt(address _account, uint256 _timestamp) internal view virtual returns (bool) {
return getTierAt(_account, _timestamp) > 0;
function _isMemberAt(address _account, uint256 _blockNumber) internal view virtual returns (bool) {
return getTierAt(_account, _blockNumber) > 0;
}

/// @inheritdoc IMembershipExtended
function getMembers() external view virtual override returns (address[] memory);

/// @notice Returns the tier score for an accout at a given timestamp
function getTierAt(address _account, uint256 _timestamp) public view virtual returns (uint256);
function getTierAt(address _account, uint256 _blockNumber) public view virtual returns (uint256);
}
29 changes: 26 additions & 3 deletions contracts/facets/membership/IVerificationFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,43 @@ interface IVerificationFacet {
/// @return stamps The stamps of the account.
function getStamps(address _address) external view returns (SignVerification.Stamp[] memory);

/// @notice Returns stamps of an account at a given timestamp
/// @notice Returns stamps of an account at a given block number
/// @param _address The address to get stamps from
/// @param _timestamp The timestamp to get stamps at
/// @param _blockNumber The block number to get stamps at
/// @return stamps The stamps of the account.
function getStampsAt(address _address, uint _timestamp) external view returns (SignVerification.Stamp[] memory);
function getStampsAt(address _address, uint _blockNumber) external view returns (SignVerification.Stamp[] memory);

/// @notice Returns the current verification contract address
/// @return address of the verification contract
function getVerificationContractAddress() external view returns (address);

/// @notice Updates the verification contract address
/// @param _verificationContractAddress The new verification contract address
function setVerificationContractAddress(address _verificationContractAddress) external;

/// @notice Returns the current verification contract address
function getTierMapping(string calldata _providerId) external view returns (uint256);

/// @notice Updates a "tier" score for a given provider. This can be used to either score new providers or update
/// scores of already scored providers
/// @dev This maps a providerId to a uint256 tier
function setTierMapping(string calldata _providerId, uint256 _tier) external;

/// @notice Returns the amount of days that a stamp is valid for (latest value)
/// @dev This function interacts with the verification contract to get the day threshold
function getVerifyThreshold() external view returns (uint);

/// @notice Updates the amount of days that a stamp is valid for
/// @dev This function interacts with the verification contract to update the day threshold
/// @param _verifyThreshold The new amount of days that a stamp is valid for
function setVerifyThreshold(uint _verifyThreshold) external;

/// @notice Returns the amount of days that a stamp is valid for
/// @dev This function interacts with the verification contract to get the reverification threshold
function getReverifyThreshold() external view returns (uint);

/// @notice Updates the amount of days that a stamp is valid for
/// @dev This function interacts with the verification contract to update the reverification threshold
/// @param _reverifyThreshold The new amount of days that a stamp is valid for
function setReverifyThreshold(uint _reverifyThreshold) external;
}
61 changes: 48 additions & 13 deletions contracts/facets/membership/VerificationFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ contract VerificationFacet is ITieredMembershipStructure, IMembershipWhitelistin
bytes32 public constant UPDATE_TIER_MAPPING_PERMISSION_ID = keccak256("UPDATE_TIER_MAPPING_PERMISSION");
// Permission used by the whitelist function
bytes32 public constant WHITELIST_MEMBER_PERMISSION_ID = keccak256("WHITELIST_MEMBER_PERMISSION");
// Permission used to update the verification contract address
bytes32 public constant UPDATE_VERIFICATION_CONTRACT_PERMISSION_ID = keccak256("UPDATE_VERIFICATION_CONTRACT_PERMISSION");
// Permission used to update the verification day threshold
bytes32 public constant UPDATE_VERIFY_DAY_THRESHOLD_PERMISSION_ID = keccak256("UPDATE_VERIFY_DAY_THRESHOLD_PERMISSION");
// Permission used to update the reverification day threshold
bytes32 public constant UPDATE_REVERIFICATION_THRESHOLD_PERMISSION_ID = keccak256("UPDATE_REVERIFICATION_THRESHOLD_PERMISSION");

struct VerificationFacetInitParams {
address verificationContractAddress;
Expand Down Expand Up @@ -72,7 +78,7 @@ contract VerificationFacet is ITieredMembershipStructure, IMembershipWhitelistin
/// @notice Whitelist a given account
/// @inheritdoc IMembershipWhitelisting
function whitelist(address _address) external virtual override auth(WHITELIST_MEMBER_PERMISSION_ID) {
LibVerificationStorage.getStorage().whitelistTimestamps[_address] = uint64(block.timestamp);
LibVerificationStorage.getStorage().whitelistBlockNumbers[_address] = block.number;
}

/// @notice Returns the given address as a string
Expand Down Expand Up @@ -100,26 +106,26 @@ contract VerificationFacet is ITieredMembershipStructure, IMembershipWhitelistin
/// @inheritdoc IVerificationFacet
function getStampsAt(
address _address,
uint _timestamp
uint _blockNumber
) public view virtual override returns (SignVerification.Stamp[] memory) {
LibVerificationStorage.Storage storage ds = LibVerificationStorage.getStorage();
SignVerification verificationContract = SignVerification(ds.verificationContractAddress);
SignVerification.Stamp[] memory stamps = verificationContract.getStampsAt(
_address,
_timestamp
_blockNumber
);

// Check if this account was whitelisted and add a "whitelist" stamp if applicable
uint64 whitelistTimestamp = ds.whitelistTimestamps[_address];
if (whitelistTimestamp == 0) {
uint whitelistBlockNumber = ds.whitelistBlockNumbers[_address];
if (whitelistBlockNumber == 0) {
return stamps;
} else {
SignVerification.Stamp[] memory stamps2 = new SignVerification.Stamp[](
stamps.length + 1
);

uint64[] memory verifiedAt = new uint64[](1);
verifiedAt[0] = whitelistTimestamp;
uint[] memory verifiedAt = new uint[](1);
verifiedAt[0] = whitelistBlockNumber;

SignVerification.Stamp memory stamp = SignVerification.Stamp(
"whitelist",
Expand All @@ -144,16 +150,16 @@ contract VerificationFacet is ITieredMembershipStructure, IMembershipWhitelistin
SignVerification.Stamp[] memory stamps = verificationContract.getStamps(_address);

// Check if this account was whitelisted and add a "whitelist" stamp if applicable
uint64 whitelistTimestamp = ds.whitelistTimestamps[_address];
if (whitelistTimestamp == 0) {
uint whitelistBlockNumber = ds.whitelistBlockNumbers[_address];
if (whitelistBlockNumber == 0) {
return stamps;
} else {
SignVerification.Stamp[] memory stamps2 = new SignVerification.Stamp[](
stamps.length + 1
);

uint64[] memory verifiedAt = new uint64[](1);
verifiedAt[0] = whitelistTimestamp;
uint[] memory verifiedAt = new uint[](1);
verifiedAt[0] = whitelistBlockNumber;

SignVerification.Stamp memory stamp = SignVerification.Stamp(
"whitelist",
Expand All @@ -180,8 +186,8 @@ contract VerificationFacet is ITieredMembershipStructure, IMembershipWhitelistin

/// @inheritdoc ITieredMembershipStructure
/// @notice Returns the highest tier included in the stamps of a given account
function getTierAt(address _account, uint256 _timestamp) public view virtual override returns (uint256) {
SignVerification.Stamp[] memory stampsAt = getStampsAt(_account, _timestamp);
function getTierAt(address _account, uint256 _blockNumber) public view virtual override returns (uint256) {
SignVerification.Stamp[] memory stampsAt = getStampsAt(_account, _blockNumber);

LibVerificationStorage.Storage storage ds = LibVerificationStorage.getStorage();
mapping (string => uint256) storage tierMapping = ds.tierMapping;
Expand Down Expand Up @@ -212,4 +218,33 @@ contract VerificationFacet is ITieredMembershipStructure, IMembershipWhitelistin
function getVerificationContractAddress() external view virtual override returns (address) {
return LibVerificationStorage.getStorage().verificationContractAddress;
}

/// @inheritdoc IVerificationFacet
function setVerificationContractAddress(address _verificationContractAddress) external virtual override auth(UPDATE_VERIFICATION_CONTRACT_PERMISSION_ID) {
LibVerificationStorage.getStorage().verificationContractAddress = _verificationContractAddress;
}

/// @inheritdoc IVerificationFacet
function getVerifyThreshold() external view returns (uint) {
SignVerification verificationContract = SignVerification(LibVerificationStorage.getStorage().verificationContractAddress);
return verificationContract.getVerifyThreshold();
}

/// @inheritdoc IVerificationFacet
function setVerifyThreshold(uint _verifyThreshold) external auth(UPDATE_VERIFY_DAY_THRESHOLD_PERMISSION_ID) {
SignVerification verificationContract = SignVerification(LibVerificationStorage.getStorage().verificationContractAddress);
verificationContract.setVerifyThreshold(_verifyThreshold);
}

/// @inheritdoc IVerificationFacet
function getReverifyThreshold() external view returns (uint) {
SignVerification verificationContract = SignVerification(LibVerificationStorage.getStorage().verificationContractAddress);
return verificationContract.getReverifyThreshold();
}

/// @inheritdoc IVerificationFacet
function setReverifyThreshold(uint _reverifyThreshold) external auth(UPDATE_REVERIFICATION_THRESHOLD_PERMISSION_ID) {
SignVerification verificationContract = SignVerification(LibVerificationStorage.getStorage().verificationContractAddress);
verificationContract.setReverifyThreshold(_reverifyThreshold);
}
}
14 changes: 14 additions & 0 deletions contracts/facets/multiplier/IRewardMultiplierFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@ abstract contract IRewardMultiplierFacet {
uint _initialAmount,
uint _base // 18 dec
) external virtual;


// Specific get/set functions for the "inflation" multiplier, this is useful for the auto expose
function setInflationStartTimestamp(uint _inflationStartTimestamp) external virtual;

function getInflationStartTimestamp() external view virtual returns (uint);

function setInflationBase(uint _inflationBase) external virtual;

function getInflationBase() external view virtual returns (uint);

function setInflationInitialAmount(uint _inflationInitialAmount) external virtual;

function getInflationInitialAmount() external view virtual returns (uint);
}
44 changes: 44 additions & 0 deletions contracts/facets/multiplier/RewardMultiplierFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,50 @@ contract RewardMultiplierFacet is AuthConsumer, IRewardMultiplierFacet, IFacet {
);
}

/// @inheritdoc IRewardMultiplierFacet
function setInflationStartTimestamp(uint _inflationTimestamp) external override auth(UPDATE_MULTIPLIER_TYPE_MEMBER_PERMISSION_ID) {
LibRewardMultiplierStorage.Storage
storage s = LibRewardMultiplierStorage.getStorage();
s.rewardMultiplier["inflation"].startTimestamp = _inflationTimestamp;
}

/// @inheritdoc IRewardMultiplierFacet
function getInflationStartTimestamp() external view override returns (uint) {
LibRewardMultiplierStorage.Storage
storage s = LibRewardMultiplierStorage.getStorage();
return s.rewardMultiplier["inflation"].startTimestamp;
}

/// @inheritdoc IRewardMultiplierFacet
function setInflationBase(uint _inflationBase) external override auth(UPDATE_MULTIPLIER_TYPE_MEMBER_PERMISSION_ID) {
LibRewardMultiplierStorage.Storage
storage s = LibRewardMultiplierStorage.getStorage();

bytes16 _baseQuad = LibABDKHelper.from18DecimalsQuad(_inflationBase);
s.exponentialParams["inflation"] = ExponentialParams(_baseQuad);
}

/// @inheritdoc IRewardMultiplierFacet
function getInflationBase() external view override returns (uint) {
LibRewardMultiplierStorage.Storage
storage s = LibRewardMultiplierStorage.getStorage();
return LibABDKHelper.to18DecimalsQuad(s.exponentialParams["inflation"].base);
}

/// @inheritdoc IRewardMultiplierFacet
function setInflationInitialAmount(uint _inflationInitialAmount) external override {
LibRewardMultiplierStorage.Storage
storage s = LibRewardMultiplierStorage.getStorage();
s.rewardMultiplier["inflation"].initialAmount = LibABDKHelper.from18DecimalsQuad(_inflationInitialAmount);
}

/// @inheritdoc IRewardMultiplierFacet
function getInflationInitialAmount() external view override returns (uint) {
LibRewardMultiplierStorage.Storage
storage s = LibRewardMultiplierStorage.getStorage();
return LibABDKHelper.to18DecimalsQuad(s.rewardMultiplier["inflation"].initialAmount);
}

function _setMultiplierTypeConstant(
string memory _name,
uint _startTimestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ interface ISearchSECORewardingFacet {

/// @notice Returns the hash reward (REP), in 18 decimals precision
/// @return The hash reward
function getHashReward() external view returns (uint);
function getHashRepReward() external view returns (uint);

/// @notice Sets the hash reward (REP)
/// @param _hashReward The new hash reward
function setHashReward(uint _hashReward) external;
/// @param _hashRepReward The new hash reward
function setHashRepReward(uint _hashRepReward) external;

/// @notice Returns the signer used for signature verification
/// @return address signer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract SearchSECORewardingFacet is
ISearchSECORewardingFacet,
IFacet
{
// Permission used by the setHashReward function
// Permission used by the setHashRepReward function
bytes32 public constant UPDATE_HASH_REWARD_PERMISSION_ID =
keccak256("UPDATE_HASH_REWARD_PERMISSION_ID");

Expand All @@ -42,7 +42,7 @@ contract SearchSECORewardingFacet is
address signer;
uint miningRewardPoolPayoutRatio;
uint hashDevaluationFactor;
uint hashReward;
uint hashRepReward;
}

/// @inheritdoc IFacet
Expand All @@ -61,7 +61,7 @@ contract SearchSECORewardingFacet is
LibSearchSECORewardingStorage.Storage
storage s = LibSearchSECORewardingStorage.getStorage();
s.signer = _params.signer;
s.hashReward = _params.hashReward;
s.hashRepReward = _params.hashRepReward;
_setMiningRewardPoolPayoutRatio(_params.miningRewardPoolPayoutRatio);
_setHashDevaluationFactor(_params.hashDevaluationFactor);

Expand Down Expand Up @@ -107,7 +107,7 @@ contract SearchSECORewardingFacet is
// for the REP reward (calculated in step 1) to the hash reward (from storage)
bytes16 repReward = ABDKMathQuad.mul(
numHashDivided,
ABDKMathQuad.fromUInt(s.hashReward)
ABDKMathQuad.fromUInt(s.hashRepReward)
);
// Multiply for inflation
repReward = ABDKMathQuad.mul(
Expand Down Expand Up @@ -228,15 +228,15 @@ contract SearchSECORewardingFacet is
}

/// @inheritdoc ISearchSECORewardingFacet
function getHashReward() external view virtual override returns (uint) {
return LibSearchSECORewardingStorage.getStorage().hashReward;
function getHashRepReward() external view virtual override returns (uint) {
return LibSearchSECORewardingStorage.getStorage().hashRepReward;
}

/// @inheritdoc ISearchSECORewardingFacet
function setHashReward(
uint _hashReward
function setHashRepReward(
uint _hashRepReward
) public virtual override auth(UPDATE_HASH_REWARD_PERMISSION_ID) {
LibSearchSECORewardingStorage.getStorage().hashReward = _hashReward;
LibSearchSECORewardingStorage.getStorage().hashRepReward = _hashRepReward;
}

/// @inheritdoc ISearchSECORewardingFacet
Expand Down
Loading

0 comments on commit b9bbf60

Please sign in to comment.