Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require valid passport when setting GitHub username #71

Merged
merged 17 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions contracts/GitHub.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import { IVotingEscrow } from "./governance/IVotingEscrow.sol";

contract GitHub {
mapping(address => string) public usernames;
IVotingEscrow public veToken;

error PassportExpired();

constructor() {
// Include usernames that have been previously added to SourceCred
usernames[0x4e3072f7b5C075EA5FdEb423DA95312C4B99dc22] = "aahna-ashina";
usernames[
0xEf736f0036647A1B6828c92A9fEe27a6DDC2B250
] = "anastasiyabelyaeva";
usernames[0xEdd000B7Db3cb8931d4E0cb1D0DBe6B947Ceb09A] = "johnmark13";
usernames[0x327b0c1Ecd110651dC9994b6764b695c9cdC29bA] = "luisivan";
usernames[0xD153751aCDBB6c2c7645671dcC2Cef98A83F5327] = "RayomndC";
usernames[0x636d65212C815b93B8E5b069f7082169cec851b7] = "xPi2";
constructor(address veToken_) {
veToken = IVotingEscrow(veToken_);
}

function updateUsername(string calldata username) public {
usernames[msg.sender] = username;
if (isPassportExpired(msg.sender)) {
revert PassportExpired();
} else {
usernames[msg.sender] = username;
}
}

function isPassportExpired(address passportOwner) public view returns (bool) {
uint256 veTokenBalance = veToken.balanceOf(passportOwner);
if (veTokenBalance < (1.5 * 1e18)) {
return false;
} else {
return true;
}
}
}
6 changes: 6 additions & 0 deletions contracts/governance/IVotingEscrow.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

interface IVotingEscrow {
function balanceOf(address) external view returns (uint256);
}
3 changes: 2 additions & 1 deletion scripts/deploy-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ async function main() {

// We get the contract to deploy
const GitHub = await ethers.getContractFactory("GitHub");
const github = await GitHub.deploy();
const veTokenAddress = "0xF7deF1D2FBDA6B74beE7452fdf7894Da9201065d";
const github = await GitHub.deploy(veTokenAddress);

await github.deployed();

Expand Down
21 changes: 13 additions & 8 deletions test/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@ import { ethers } from "hardhat";
describe("GitHub", function () {
it("Deploy contract", async function () {
const GitHub = await ethers.getContractFactory("GitHub");
const gitHub = await GitHub.deploy();
const veTokenAddress = "0xF7deF1D2FBDA6B74beE7452fdf7894Da9201065d";
const gitHub = await GitHub.deploy(veTokenAddress);
await gitHub.deployed();

const username = await gitHub.usernames(
"0x4e3072f7b5C075EA5FdEb423DA95312C4B99dc22"
);
const [owner] = await ethers.getSigners();
console.log("owner.address:", owner.address);

const username = await gitHub.usernames(owner.address);
console.log("username:", username);
expect(username).to.equal("aahna-ashina");
expect(username).to.equal("");
});

it("updateUsername", async function () {
const GitHub = await ethers.getContractFactory("GitHub");
const gitHub = await GitHub.deploy();
const veTokenAddress = "0xF7deF1D2FBDA6B74beE7452fdf7894Da9201065d";
const gitHub = await GitHub.deploy(veTokenAddress);
await gitHub.deployed();

const [owner] = await ethers.getSigners();
console.log("owner.address:", owner.address);

await gitHub.updateUsername("test");
// await gitHub.updateUsername("test");
await expect(gitHub.updateUsername("test")).to.be.reverted;

const usernameAfterUpdate = await gitHub.usernames(owner.address);
console.log("usernameAfterUpdate:", usernameAfterUpdate);
expect(usernameAfterUpdate).to.equal("test");
// expect(usernameAfterUpdate).to.equal("test");
expect(usernameAfterUpdate).to.equal("");
});
});