Skip to content

Commit

Permalink
Merge pull request #2 from 70nyIT/main
Browse files Browse the repository at this point in the history
CorGit submission for ETH Lisbon 2022 Hackathon
  • Loading branch information
uF4No authored Nov 9, 2022
2 parents 4b39449 + aa75b8b commit d3f2cbe
Show file tree
Hide file tree
Showing 85 changed files with 3,553 additions and 0 deletions.
Binary file added submissions/CorGit/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions submissions/CorGit/About.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Team

1. Antonio (Discord ID: t0n1x#7103)
2. Federico (Discord ID: Frenk_eth#7663)
53 changes: 53 additions & 0 deletions submissions/CorGit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# CorGit dApp

## Overview
Open Source projects have always problems in managing their funds, especially when it comes to proportionally distribute them among previous and future holders. CorGit is an OpenSource Project Tokenization solution that aims to fix this problem.

Each project can create its own token, and distribute to anyone included within a project. The token can be immediately, or later, collateralized. In this way projects are able to proportionally reward past, present and future contributors, by transparently manage funds collected.

## See our Demo

Video has been made connecting to Goerli, but the exact same functionalities are available on ZkSync (See contract addresses and instructions on how to run below)

[Video](https://youtu.be/kUXQLmH7JBY)

[Slides](https://drive.google.com/file/d/1QUoel0iwXg0FsOXTrtr1nlGrha1dh2_l/view)

## Smart Contracts

Currently our smart contracts have been deployed on ZkSync 2.0
* GithubAddressRegister - 0xa5B07286eA9a9f7deC44104Cb621f1cf55AA9634
* ContractTokenFactory - 0x84360Fc81b1be9860A37859Be3b48e505D494F38

**GithubAddressRegister** works as an Oracle and creates the match between a Github ID and a wallet address. This is required to claim rewards based on Github pull requests. Only admin can write to that contract, so if a new Github ID needs to be added, please open an issue with githubID + wallet address to associate

**ContractTokenFactory** is the contract called to deploy a custom Corgit contract. Each project will have its own token.


## How to deploy smart contracts

This step is optional as SCs are already deployed

Folder `/contracts-corgit-zksync` contains the smart contracts. If you want to deploy them, to create a second deployment, you need to create a file `.secrets.json` (See the `.secrets.example.json`). This file contains the RPC endpoints and the private keys of the wallets.

Then you need to run

```
yarn install
yarn hardhat compile
yarn hardhat deploy-zksync
```

Finally, to enable the match between githubID and a wallet address, run `ts-node scripts/associateGithubToWallet.ts` (After having correctly set the variables `GITHUB_ID` and `WALLET_ADDRESS_TO_ASSOCIATE` on top of the same file)

## How to run dApp

Enter in folder `/webapp`. To quick run the app just use the following commands

```
yarn install
yarn run start
```

You will find in the CorGit homepage. If you have deployed a new set of contracts, make sure to update their address in `src/utils/constants.ts` file

4 changes: 4 additions & 0 deletions submissions/CorGit/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.idea
yarn.lock
build
17 changes: 17 additions & 0 deletions submissions/CorGit/code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CorGit

Tokenize your OpenSource project, to proportionally reward past, present and future contributors

<img src="https://user-images.githubusercontent.com/12898752/198858642-94ede3c0-7bc9-4aa2-85f7-ea36052efc2d.png"/>


# How it works

By connecting a dedicated CorGit token to a project, contributors of any kind can be rewarded with the project native token.

cg Tokens (i.e., tokens created with CorGit) have an intrinsic mechanism to preserve value over time, and to incentivize token holdings.

Whenever funds reaches the project, through grants or other channels, they are used partly to give value
to the tokens owned by current token holders, and partly to mint new tokens.

Token holders can exchange their tokens for a guaranteed value, directly on our platform, at smart contract level.
29 changes: 29 additions & 0 deletions submissions/CorGit/code/contracts-corgit-zksync/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types
.idea
yarn.lock

#Hardhat files
cache
cache-zk
artifacts
artifacts-zk/


node_modules
.env
coverage
coverage.json
typechain
typechain-types

#Hardhat files
cache
artifacts

# Deployment secrets
.secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"nodeUrls": {
"goerli": "https://-----------------",
"zksync": "https://zksync2-testnet.zksync.dev"
},
"privateKeys": {
"hardhat": {
"deployer": "-----------"
},
"goerli": {
"deployer": "-------------"
},
"zksync": {
"deployer": "--------------"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/access/Ownable.sol";

contract GithubAddressRegister is Ownable {

// mappings
/// @dev stores the match between github ID and chain address. One github ID can have more than one chain address
mapping(uint256 => address[]) public githubIDToAddress;
/// @dev stores teh match between an address and a github ID. One address can have just one github ID connected
mapping(address => uint256) public addressToGithubID;

constructor() {

}

/**
* @notice Adds a new address to the list of github addresses.
* @dev Currently performed by the backend after a succesfull github login.
Should be implemented with call by the user, that publishes a sign (approval) sent by our authorized App.
In addition, it can be implemented via ChainLink oracle
* @param _githubID - id of github account
* @param _wallet - wallet address
**/
function addAddress(
uint256 _githubID,
address _wallet
) external onlyOwner {
require(addressToGithubID[_wallet] == 0, "Wallet already assigned to GithubID");
githubIDToAddress[_githubID].push(_wallet);
addressToGithubID[_wallet] = _githubID;
}

/**
* @notice Removes an address from the list of authorized addresses.
* @dev Only the wallet owner can remove it, calling from one of the wallets registered under that githubID
* @param _githubID - id of github account
* @param _addressToRemove - address to be removed
**/
function removeAddress(uint256 _githubID, address _addressToRemove) public {
bool validCaller = false;
bool validAddress = false;
uint indexToRemove = 0;
address[] memory addressList = githubIDToAddress[_githubID];
for(uint i=0; i<addressList.length; ++i) {
if (addressList[i] == _addressToRemove) {
indexToRemove = i;
validAddress = true;
}
if (addressList[i] == msg.sender) validCaller = true;
if (validCaller && validAddress) break;
}
require(validAddress && validCaller, "Cannot remove address");

addressToGithubID[_addressToRemove] = 0;
githubIDToAddress[_githubID][indexToRemove] = addressList[ addressList.length - 1 ];
githubIDToAddress[_githubID].pop();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pragma solidity ^0.8.17;

import "./cgToken.sol";

contract cgFactory {

// struct
struct CgToken {
cgToken tokenContract;
uint createdAt;
}

// contracts
/// @dev list of all the CgTokens created
CgToken[] public cgTokenList;
GithubAddressRegister public githubAddressRegister;

event NewCgTokenCreated(address _addr, string _name, string _symbol, uint16 _percFundingDistribute);

constructor(address _githubAddressRegister) {
githubAddressRegister = GithubAddressRegister(_githubAddressRegister);
}

function generate(
string memory _name,
string memory _symbol,
uint16 _percFundingDistribute
) external returns(address) {

cgToken cgt = new cgToken(
_name,
string.concat("cg", _symbol),
100000 * (10 ** 18),
_percFundingDistribute,
address(githubAddressRegister),
msg.sender
);

cgTokenList.push(CgToken({
tokenContract: cgt,
createdAt: block.timestamp
}));

emit NewCgTokenCreated(address(cgt), _name, _symbol, _percFundingDistribute);

return address(cgt);
}

}
Loading

0 comments on commit d3f2cbe

Please sign in to comment.