Skip to content

Commit

Permalink
Merge pull request #41 from Aut-Labs/test-dev-2
Browse files Browse the repository at this point in the history
required configs, allows and LR init val set
  • Loading branch information
parseb authored Oct 6, 2023
2 parents f469fc4 + 8a4d66b commit cbdd233
Show file tree
Hide file tree
Showing 475 changed files with 352,010 additions and 248,597 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ jobs:
# - name: Build with Hardhat
# run: npm run test

# - name: Install TypeScript type generator
# run: npm install --save-dev typechain

# - name: Generate TypeScript types
# run: npx hardhat typechain
- name: generate types
run: npx typechain --target ethers-v5 './out/*.sol/*'

- name: Commit changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add .
git commit -m "ci:gh test&abi gen"
git commit -m "ci: forge test and typechain"
git push
72 changes: 36 additions & 36 deletions contracts/LocalReputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import "./ILocalReputation.sol";
/// @title Local Reputation Framework for ĀutID holders

contract LocalReputation is ILocalReputation {
/// @notice stores plugin(or authorised address)-dao relation on initialization
mapping(address plugin => address dao) public daoOfPlugin;
/// @notice stores plugin(or authorised address)-nova relation on initialization
mapping(address plugin => address nova) public novaOfPlugin;

/// @notice stores Group State
mapping(uint256 contextID => groupState) getGS;
Expand All @@ -30,7 +30,7 @@ contract LocalReputation is ILocalReputation {
///////////////////////////////////////////////////////////////
modifier onlyPlugin() {
//// @dev is this sufficient?
if (daoOfPlugin[_msgSender()] == address(0)) revert Unauthorised();
if (novaOfPlugin[_msgSender()] == address(0)) revert Unauthorised();
_;
}

Expand All @@ -54,7 +54,7 @@ contract LocalReputation is ILocalReputation {

updateCommitmentLevels(nova_);

daoOfPlugin[_msgSender()] = nova_;
novaOfPlugin[_msgSender()] = nova_;

emit LocalRepInit(nova_, _msgSender());
}
Expand Down Expand Up @@ -96,19 +96,19 @@ contract LocalReputation is ILocalReputation {
}

/// @notice updates group state to latest to account for latest interactions
/// @param group_ target address to update group state for
function periodicGroupStateUpdate(address group_) public returns (uint256 nextUpdateAt) {
uint256 context = getContextID(group_, group_);
uint256 membersLen = updateCommitmentLevels(group_).length;
/// @param nova_ target address to update group state for
function periodicGroupStateUpdate(address nova_) public returns (uint256 nextUpdateAt) {
uint256 context = getContextID(nova_, nova_);
uint256 membersLen = updateCommitmentLevels(nova_).length;

groupState memory gs = getGS[context];
nextUpdateAt = gs.p + gs.lastPeriod;

if (gs.lrUpdatesPerPeriod >= INova(group_).memberCount()) {
if (gs.lrUpdatesPerPeriod >= INova(nova_).memberCount()) {
gs.lastPeriod = uint64(block.timestamp);
gs.lrUpdatesPerPeriod = 0;
gs.periodNovaParameters.ePerformanceLP = gs.TCP > 0
? uint64(pointsPerInteraction[getContextID(group_, group_)] * membersLen * 1 ether / gs.TCP)
? uint64(pointsPerInteraction[getContextID(nova_, nova_)] * membersLen * 1 ether / gs.TCP)
: 1 ether;
gs.TCP = 0;
getGS[context] = gs;
Expand All @@ -120,11 +120,11 @@ contract LocalReputation is ILocalReputation {

/// @notice updates local reputation of a specific individual context
/// @param who_ agent address to update local reputation for
/// @param group_ target group context for local repuatation update
function updateIndividualLR(address who_, address group_) public returns (uint256) {
if (!INova(group_).isAdmin(_msgSender())) revert Unauthorised();
uint256 Icontext = getContextID(who_, group_);
uint256 Gcontext = getContextID(group_, group_);
/// @param nova_ target group context for local repuatation update
function updateIndividualLR(address who_, address nova_) public returns (uint256) {
if (!INova(nova_).isAdmin(_msgSender())) revert Unauthorised();
uint256 Icontext = getContextID(who_, nova_);
uint256 Gcontext = getContextID(nova_, nova_);
individualState memory ISS = getIS[Icontext];
groupState memory GSS = getGS[Gcontext];

Expand All @@ -136,7 +136,7 @@ contract LocalReputation is ILocalReputation {

GSS.lrUpdatesPerPeriod += 1;
getGS[Gcontext] = GSS;
if (GSS.lrUpdatesPerPeriod >= INova(group_).memberCount()) periodicGroupStateUpdate(group_);
if (GSS.lrUpdatesPerPeriod >= INova(nova_).memberCount()) periodicGroupStateUpdate(nova_);

ISS.score = calculateLocalReputation(ISS.GC, ISS.iCL, GSS.TCL, GSS.TCP, GSS.k, ISS.score, GSS.penalty);
ISS.GC = 0;
Expand Down Expand Up @@ -182,20 +182,20 @@ contract LocalReputation is ILocalReputation {

/// @dev consider dos vectors and changing return type
/// @notice updates the local reputation of all members in the given nova
/// @param group_ address of nova
function bulkPeriodicUpdate(address group_) external returns (uint256[] memory localReputationScores) {
uint256 context = getContextID(group_, group_);
/// @param nova_ address of nova
function bulkPeriodicUpdate(address nova_) external returns (uint256[] memory localReputationScores) {
uint256 context = getContextID(nova_, nova_);
groupState memory startGS = getGS[context];
if ((startGS.lastPeriod + startGS.p) > block.timestamp) revert PeriodUnelapsed();

periodicGroupStateUpdate(group_);
periodicGroupStateUpdate(nova_);

address[] memory members = IAutID(INova(group_).getAutIDAddress()).getAllActiveMembers(group_);
address[] memory members = IAutID(INova(nova_).getAutIDAddress()).getAllActiveMembers(nova_);
localReputationScores = new uint256[](members.length);
uint256 sumLR;
uint256 i;
for (i; i < members.length;) {
localReputationScores[i] = updateIndividualLR(members[i], group_);
localReputationScores[i] = updateIndividualLR(members[i], nova_);
sumLR += localReputationScores[i];

unchecked {
Expand All @@ -212,8 +212,8 @@ contract LocalReputation is ILocalReputation {
/// @param datas_, array of selector encoded (msg.data) bytes
/// @param points_, amount of points to be awared for each of datas_, 0 to remove and readjust for performance
function setInteractionWeights(address plugin_, bytes[] memory datas_, uint16[] memory points_) external {
if (daoOfPlugin[plugin_] == address(0)) revert UninitializedPair();
address nova = daoOfPlugin[plugin_];
if (novaOfPlugin[plugin_] == address(0)) revert UninitializedPair();
address nova = novaOfPlugin[plugin_];
if (!(INova(nova).isAdmin(_msgSender())) && (_msgSender() != plugin_)) revert OnlyAdmin();
if (datas_.length != points_.length) revert ArgLenMismatch();
uint256 interact;
Expand Down Expand Up @@ -244,10 +244,10 @@ contract LocalReputation is ILocalReputation {
if (datas_.length == 2) repPoints = uint16(bytes2(datas_[:2]));

if (repPoints == 0) return;
address dao = daoOfPlugin[_msgSender()];
address nova = novaOfPlugin[_msgSender()];

getIS[getContextID(callerAgent_, dao)].GC += uint64(repPoints);
getGS[getContextID(dao, dao)].TCP += uint64(repPoints);
getIS[getContextID(callerAgent_, nova)].GC += uint64(repPoints);
getGS[getContextID(nova, nova)].TCP += uint64(repPoints);

emit Interaction(interactID, callerAgent_);
}
Expand Down Expand Up @@ -276,9 +276,9 @@ contract LocalReputation is ILocalReputation {

/// @notice context specific ID
/// @param subject_ address of the subject
/// @param group_ address of the group
function getContextID(address subject_, address group_) public pure returns (uint256) {
return uint256(uint160(subject_)) + uint256(uint160(group_));
/// @param nova_ address of the group
function getContextID(address subject_, address nova_) public pure returns (uint256) {
return uint256(uint160(subject_)) + uint256(uint160(nova_));
}

/// @notice context specific ID
Expand All @@ -294,17 +294,17 @@ contract LocalReputation is ILocalReputation {

/// @notice get the individual state of a subject in a group
/// @param subject_ address of the subject
/// @param group_ address of the group
function getLRof(address subject_, address group_) public view returns (individualState memory) {
return getIS[getContextID(subject_, group_)];
/// @param nova_ address of the group
function getLRof(address subject_, address nova_) public view returns (individualState memory) {
return getIS[getContextID(subject_, nova_)];
}

/// @notice get the local reputation score of an agent withoin a specified group.
/// @dev defaut value is 1 ether. Score should be parsed as ether with two decimals in expected range (0.01 - 9.99)
/// @param subject_ address of target agent
/// @param group_ address of nova instance
function getLocalReputationScore(address subject_, address group_) public view returns (uint256 score) {
score = getLRof(subject_, group_).score;
/// @param nova_ address of nova instance
function getLocalReputationScore(address subject_, address nova_) public view returns (uint256 score) {
score = getLRof(subject_, nova_).score;
if (score == 0) score = 1 ether;
}

Expand Down
6 changes: 5 additions & 1 deletion contracts/daoUtils/abstracts/DAOMembers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity 0.8.19;
import "./AutIDAddress.sol";
import "../interfaces/get/IDAOAdmin.sol";
import "../interfaces/get/IDAOMembership.sol";
import "../interfaces/get/IDAOModules.sol";
import "../../plugins/registry/IPluginRegistry.sol";
import "../interfaces/set/IDAOMembershipSet.sol";
import "../interfaces/set/IDAOAdminSet.sol";

Expand Down Expand Up @@ -42,8 +44,10 @@ abstract contract DAOMembers is IDAOAdmin, IDAOMembership, IDAOMembershipSet, ID
}

/// Admins
/// @notice adds admins provided a member address. Plugins do not have to be members.
/// @param member address to add as member.
function addAdmin(address member) public override onlyAdmin {
require(isMember[member], "Not a member");
if ((! isMember[member] ) && (IPluginRegistry(IDAOModules(address(this)).pluginRegistry()).tokenIdFromAddress(member) == 0) ) revert("Not a member");
isAdmin[member] = true;
admins.push(member);
emit AdminMemberAdded(member);
Expand Down
10 changes: 0 additions & 10 deletions contracts/daoUtils/interfaces/get/IDAOInteractions.sol

This file was deleted.

1 change: 0 additions & 1 deletion contracts/expander/DAOExpander.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ contract DAOExpander is
DAOMembers,
DAOUrls,
DAOMetadata,
// DAOInteractions,
DAOCommitment,
DAOMarket,
DAOModules,
Expand Down
8 changes: 8 additions & 0 deletions contracts/modules/registry/IModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ interface IModuleRegistry {
* @param uri the new metadata URI for the module
*/
function updateMetadataURI(uint256 moduleId, string calldata uri) external;


/// @notice checks if an address is authorised to perform maintenance functions
/// @param subject address to check
function isProtocolMaintaier(address subject) external view returns (bool);

/// @notice
function getAllowListAddress() external view returns (address);
}
17 changes: 15 additions & 2 deletions contracts/modules/registry/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ pragma solidity 0.8.19;

import "./IModuleRegistry.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import {IAllowlist} from "../../utils/IAllowlist.sol";

contract ModuleRegistry is IModuleRegistry, Ownable {
ModuleDefinition[] public modules;

constructor() {
IAllowlist AllowList;
constructor(address allList) {
_transferOwnership(msg.sender);
AllowList = IAllowlist(allList);

modules.push(ModuleDefinition("none", 0));
modules.push(ModuleDefinition("ipfs://bafkreia2si4nhqjdxg543z7pp5kchvx4auwm7gn54wftfa2vykfkjc4ppe", 1));
modules.push(ModuleDefinition("ipfs://bafkreihxcz6eytmf6lm5oyqee67jujxepuczl42lw2orlfsw6yds5gm46i", 2));
Expand All @@ -34,4 +37,14 @@ contract ModuleRegistry is IModuleRegistry, Ownable {
function updateMetadataURI(uint256 moduleId, string calldata uri) public override onlyOwner {
modules[moduleId].metadataURI = uri;
}

function isProtocolMaintaier(address subject) external view override returns (bool) {
if (address(AllowList) == address(0)) return false;
return AllowList.isAllowedOwner(subject);
}

function getAllowListAddress() external view returns (address) {
return address(AllowList);
}

}
5 changes: 5 additions & 0 deletions contracts/nova/NovaRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity 0.8.19;
import "./interfaces/INovaFactory.sol";
import "./interfaces/INovaRegistry.sol";
import "../utils/IAllowlist.sol";
import {IModuleRegistry} from "../modules/registry/IModuleRegistry.sol";
import {IPluginRegistry} from "../plugins/registry/IPluginRegistry.sol";
import "@opengsn/contracts/src/ERC2771Recipient.sol";

contract NovaRegistry is ERC2771Recipient, INovaRegistry {
Expand All @@ -28,6 +30,7 @@ contract NovaRegistry is ERC2771Recipient, INovaRegistry {
_setTrustedForwarder(trustedForwarder);
pluginRegistry = _pluginRegistry;
deployerAddress = msg.sender;
AllowList = IAllowlist(IModuleRegistry(IPluginRegistry(_pluginRegistry).modulesRegistry()).getAllowListAddress());
}

/// @notice Deploys a new Nova
Expand Down Expand Up @@ -66,4 +69,6 @@ contract NovaRegistry is ERC2771Recipient, INovaRegistry {
function getNovaByDeployer(address deployer) public view returns (address[] memory) {
return novaDeployers[deployer];
}


}
4 changes: 0 additions & 4 deletions contracts/nova/interfaces/INova.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ interface INova {

function getAutIDAddress() external view returns (address);

function getInteractionsAddr() external view returns (address);

function getInteractionsPerUser(address member) external view returns (uint256);

function getCommitment() external view returns (uint256 commitment);

function addAdmin(address member) external;
Expand Down
13 changes: 5 additions & 8 deletions contracts/plugins/PluginRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "../plugins/IPlugin.sol";
import "../plugins/registry/IPluginRegistry.sol";
import "../daoUtils/interfaces/get/IDAOInteractions.sol";
import "../daoUtils/interfaces/get/IDAOAdmin.sol";
import "../daoUtils/interfaces/get/IDAOModules.sol";
import "../nova/interfaces/INova.sol";



/// @title PluginRegistry
/// @notice Stores all plugins available and allows them to be added to a dao
contract PluginRegistry is ERC721URIStorage, Ownable, ReentrancyGuard, IPluginRegistry {
Expand Down Expand Up @@ -64,7 +64,8 @@ contract PluginRegistry is ERC721URIStorage, Ownable, ReentrancyGuard, IPluginRe
uint256 fee = (pluginDefinition.price * feeBase1000) / 1000;

feeReciever.transfer(fee);
pluginDefinitionsById[pluginDefinitionId].creator.transfer(msg.value - fee);
(bool s, ) = pluginDefinition.creator.call{value: msg.value - fee}("");
if (!s) revert("Value transfer failed");

emit PluginAddedToDAO(tokenId, pluginDefinitionId, nova);

Expand All @@ -73,7 +74,6 @@ contract PluginRegistry is ERC721URIStorage, Ownable, ReentrancyGuard, IPluginRe
tokenIdByPluginAddress[pluginAddress] = tokenId;

IPlugin(pluginAddress).setPluginId(tokenId);
// allow interactions to be used from plugin

if (IModule(pluginAddress).moduleId() == 1) {
INova(nova).setOnboardingStrategy(pluginAddress);
Expand Down Expand Up @@ -119,6 +119,7 @@ contract PluginRegistry is ERC721URIStorage, Ownable, ReentrancyGuard, IPluginRe
) external onlyOwner returns (uint256 pluginDefinitionId) {
require(bytes(metadataURI).length > 0, "AUT: Metadata URI is empty");
require(canBeStandalone || price == 0, "AUT: Should be free if not standalone");


_numPluginDefinitions++;
pluginDefinitionId = _numPluginDefinitions;
Expand All @@ -129,10 +130,6 @@ contract PluginRegistry is ERC721URIStorage, Ownable, ReentrancyGuard, IPluginRe
emit PluginDefinitionAdded(pluginDefinitionId);
}

function setDefaultReputationAlgo(address newRepAlgoAddr_) external onlyOwner returns (address) {
return defaultLRAddr = newRepAlgoAddr_;
}

function setPrice(uint256 pluginDefinitionId, uint256 newPrice) public {
PluginDefinition storage pluginDefinition = pluginDefinitionsById[pluginDefinitionId];
require(msg.sender == pluginDefinition.creator, "AUT: Only creator can set price");
Expand Down
6 changes: 6 additions & 0 deletions contracts/utils/Allowlist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ contract Allowlist is IAllowlist {
function addOwner(address owner_) external isSenderOwner {
isOwner[owner_] = !isOwner[owner_];
}

/// @notice checks if is owner for protocol maintainance priviledges
/// @param subject address to check
function isAllowedOwner(address subject) external view returns(bool) {
return isOwner[subject];
}
}
1 change: 1 addition & 0 deletions contracts/utils/IAllowlist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ interface IAllowlist {
function addBatchToAllowlist(address[] memory addrsToAdd_) external;
function removeBatchFromAllowlist(address[] memory _addrs) external;
function addOwner(address owner_) external;
function isAllowedOwner(address subject) external view returns(bool);
}
Loading

0 comments on commit cbdd233

Please sign in to comment.