Skip to content

Commit

Permalink
chore: cleanup (#23)
Browse files Browse the repository at this point in the history
* chore: remove redundant comments

* remove splitpayout

* remove autogenerated docs

* chore: remove tests + deploy scripts

* chore: update hardhat config to remove redundant config

* cleanup .env.sample file

* chore: update hardhat config

* chore: add prettier script + remove extra scripts

* chore: recreate Registry based on interface

* chore: address feedback commit

Co-authored-by: codenamejason <codenamejason@outlook.com>

---------

Co-authored-by: codenamejason <codenamejason@outlook.com>
  • Loading branch information
thelostone-mc and codenamejason committed Jun 22, 2023
1 parent f1b105b commit 060c154
Show file tree
Hide file tree
Showing 27 changed files with 86 additions and 1,718 deletions.
25 changes: 16 additions & 9 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
GOERLI_RPC_URL=https://rpc.ankr.com/eth_goerli
# Testnet RPC URL
SEPOLIA_RPC_URL=https://rpc.sepolia.org

# Mainnet RPC URL
MAINNET_RPC_URL=https://rpc.ankr.com/eth
PRIVATE_KEY=
ANVIL_PRIVATE_KEY=

# Deployer private key
DEPLOYER_PRIVATE_KEY=0x0000000000000000000000000000000000000000000000000000000000000001

# Contract Verification
ETHERSCAN_API_KEY=
ALCHEMY_API_KEY=
SEPOLIA_RPC_URL=https://rpc.sepolia.org
OPTIMISM_RPC_URL=https://optimism.alchemyapi.io/v2/
POLYGON_API_KEY=
MUMBAI_RPC_URL=https://rpc-mumbai.maticvigil.com
OPTIMISM_API_KEY=

# Local Node
ANVIL_PRIVATE_KEY=

# Gas Reporter
COINMARKETCAP_API_KEY=
REPORT_GAS=true
243 changes: 24 additions & 219 deletions contracts/core/Registry.sol
Original file line number Diff line number Diff line change
@@ -1,242 +1,47 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.19;

import {Metadata} from "../core/libraries/Metadata.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract Registry is Initializable {
// A linked list of owners of a identity
// The use of a linked list allows us to easily add and remove owners,
// access them directly in O(1), and loop through them.
//
// {
// count: 3,
// list: {
// OWNERS_LIST_SENTINEL => owner1Address,
// owner1Address => owner2Address,
// owner2Address => owner3Address,
// owner3Address => OWNERS_LIST_SENTINEL
// }
// }
struct OwnerList {
uint256 count;
mapping(uint => address) list;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// use Solady Roles for ownership of projects: https://github.com/Vectorized/solady/blob/main/src/auth/OwnableRoles.sol
contract Registry {
struct IdentityDetails {
uint id;
string name;
Metadata.MetaPtr metadata;
address attestationAddress;
}

// State variables

// Used as sentinel value in the owners linked list.
address constant _OWNERS_LIST_SENTINEL = address(0x1);

// The mapping of identities, from identityId to IdentityDetails
mapping(uint => IdentityDetails) public identities;

// The mapping identities owners, from identityId to OwnerList
mapping(address => OwnerList) public identityOwners;

// Events

event IdentityCreated(uint indexed identityId, address indexed owner);
event MetadataUpdated(uint indexed identityId, IdentityDetails metaPtr);
event OwnerAdded(uint indexed identityId, address indexed owner);
event OwnerRemoved(uint indexed identityId, address indexed owner);

// Modifiers

modifier onlyIdentityOwner(uint identityId) {
require(
identityOwners[identityId].list[msg.sender] != address(0),
"PR000"
);
_;
string metadata; // @todo update to MetaPtr
address attestationAddr;
}

/**
* @notice Initializes the contract after an upgrade
* @dev In future deploys of the implementation, an higher version should be passed to reinitializer
*/
function initialize() public reinitializer(1) {}

// External functions
// getter for projects mapping
function identities(uint _identityId) external view returns (IdentityDetails memory) {

// This function will retrieve the identity details associated with the provided identityId.
function getIdentity(
uint _identityId
) external view returns (IdentityDetails memory) {
return identities[_identityId];
}

// create a new identity with metadata
// set identityId using an incrementer
// attestationAddr = addr(hash(id, name)) => this confirms that neither can change while keepign address the same
// @todo think about whether there's any value to deploying an address using CREATE2, we think not
function createIdentity(
IdentityDetails memory _identityDetails,
address[] memory _owners
) external returns (uint256) {
// Implement the function here, including updating the mapping and handling the owners array.
}
// create a new project with metadata
// hash some unique value to create the identityId - is there enough immutable to do this or just use incrementer?
// @todo if owners were immutable, we could make it a merkle proof of addresses and prove ownership that way? probably overkill
// sets roles so that all owners are owners of the project
// attestationAddr = addr(hash(id, name, owner))
// OR deploy right away with CREATE2 as proxy so they can do anything (or just forward ERC20s and ETH)
// id => IdentityDetails
function createIdentity(IdentityDetails memory _identityDetails, address[] memory _owners) external returns (uint256) {

// this will use solmate ROLES to check if the msg.sender is an owner of the identity
// @todo figure out how to best represent identity ownership and details
function isOwnerOfIdentity(
uint _identityId,
address _owner
) external view returns (bool) {
// Implement the function here, possibly using the Solmate Roles library as mentioned in the comments.
}

// updates the name of the identity
// note that this will also change the attestation address, since it's a hash that includes the name
function updateIdentityName(
uint _identityId,
string memory _name
) external {
// check if the caller has the right to update the identity
require(
this.isOwnerOfIdentity(_identityId, msg.sender),
"Caller is not owner of this identity"
);
function updateIdentityName(uint _identityId, string memory _name) external {

// update the name of the identity
identities[_identityId].name = _name;
// Also may want to update the attestation address. This will depend on how we generate our attestation addresses.
// identities[_identityId].attestationAddress = ... ;
}

// @todo override changing owners (core owner, not contributors) to make sure it updates attestation address

// update the metadata of the identity
// checks ownership role first, probably separate roles for this vs using it (owner vs user?)
/**
* @notice Updates Metadata for singe identity
* @param identityId ID of previously created identity
* @param metadata Updated pointer to external metadata
*/
function updateIdentityMetadata(
uint identityId,
string calldata metadata
) external onlyIdentityOwner(identityId) {
// this is a permissionless update
// ZACH: this should just be updating metadata string, not that no permissions/permissionless split
// identities[identityId].permissionlessMetadata = metadata
// .permissionlessMetadata;
// emit MetadataUpdated(identityId, metadata);
}

/**
* @notice Associate a new owner with a identity
* @param identityId ID of previously created identity
* @param newOwner address of new identity owner
*/
function addIdentityOwner(
uint identityId,
address newOwner
) external onlyIdentityOwner(identityId) {
require(
newOwner != address(0) &&
newOwner != _OWNERS_LIST_SENTINEL &&
newOwner != address(this),
"PR001"
);

OwnerList storage owners = identityOwners[identityId];

require(owners.list[newOwner] == address(0), "PR002");

owners.list[newOwner] = owners.list[_OWNERS_LIST_SENTINEL];
owners.list[_OWNERS_LIST_SENTINEL] = newOwner;
owners.count++;
function updateIdentityMetadata(uint _identityId, string memory _metadata) external {

emit OwnerAdded(identityId, newOwner);
}

/**
* @notice Disassociate an existing owner from a identity
* @param identityId ID of previously created identity
* @param prevOwner Address of previous owner in OwnerList
* @param owner Address of new Owner
*/
function removeIdentityOwner(
uint identityId,
address prevOwner,
address owner
) external onlyIdentityOwner(identityId) {
require(owner != address(0) && owner != _OWNERS_LIST_SENTINEL, "PR001");

OwnerList storage owners = identityOwners[identityId];

require(owners.list[prevOwner] == owner, "PR003");
require(owners.count > 1, "PR004");

owners.list[prevOwner] = owners.list[owner];
delete owners.list[owner];
owners.count--;

emit OwnerRemoved(identityId, owner);
}

// Public functions

/**
* @notice Retrieve count of existing identity owners
* @param identityId ID of identity
* @return Count of owners for given identity
*/
function identityOwnersCount(
uint identityId
) external view returns (uint256) {
return identityOwners[identityId].count;
// this will use solmate ROLES to check if the msg.sender is an owner of the project
// @todo figure out how to best represent project ownership and details
function isOwnerOfProject(uint _identityId, address _owner) external view returns (bool) {

}

/**
* @notice Retrieve list of identity owners
* @param identityId ID of identity
* @return List of current owners of given identity
*/
function getProjectOwners(
uint identityId
) external view returns (address[] memory) {
OwnerList storage owners = identityOwners[identityId];

address[] memory list = new address[](owners.count);

uint256 index = 0;
address current = owners.list[_OWNERS_LIST_SENTINEL];

if (current == address(0x0)) {
return list;
}

while (current != _OWNERS_LIST_SENTINEL) {
list[index] = current;
current = owners.list[current];
index++;
}

return list;
}

// Internal functions

/**
* @notice Create initial OwnerList for passed identity
* @param identityId ID of identity
*/
function _initIdentityOwners(uint identityId) internal {
OwnerList storage owners = identityOwners[identityId];

owners.list[_OWNERS_LIST_SENTINEL] = msg.sender;
owners.list[msg.sender] = _OWNERS_LIST_SENTINEL;
owners.count = 1;
}

// Private functions
// ...
}
}
9 changes: 3 additions & 6 deletions contracts/interfaces/IAllocationStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ interface IAllocationStrategy {
STORAGE (with public getters)
uint256 poolId;
address allo;
uint64 applicationStart;
uint64 applicationEnd;
uint64 votingStart;
uint64 votingEnd;
*/

enum ApplicationStatus {
Expand All @@ -32,8 +28,6 @@ interface IAllocationStrategy {

// return whether application is pending, accepted, or rejected
// strategies will need to add their own logic to translate to these categories if they use different ones
// @todo should this be bytes memory or can we assume application is bytes32 / uint?
// ZACH RESPONSE: changed to uint, applications should just be trakced by id
function getApplicationStatus(uint applicationId) external view returns (ApplicationStatus);

// decode the _data into what's relevant for this strategy
Expand All @@ -51,4 +45,7 @@ interface IAllocationStrategy {
// @todo there will be other return formats
// define formats for returns here so we can explicitly say which distribution strategies are compatible
function generatePayouts() external payable returns (bytes memory);

// many owners will probably want a way to add custom application approval logic
// but all of that will be in specific implementations, not requried interface
}
Empty file.
21 changes: 0 additions & 21 deletions contracts/strategies/distribution/SplitPayouts.sol

This file was deleted.

Loading

0 comments on commit 060c154

Please sign in to comment.