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 all 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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

24 changes: 0 additions & 24 deletions .eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ jobs:
cache-dependency-path: package-lock.json
- run: npm install

- run: npx eslint '**/*.{js,ts}'
- run: npx solhint 'contracts/**/*.sol'
- run: npx prettier '**/*.{json,sol,md}' --check
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ typings/
# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
Expand Down
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "^0.8.17"],
"compiler-version": ["error", "^0.8.19"],
"func-visibility": ["warn", { "ignoreConstructors": true }]
}
}
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ npx hardhat compile

Run unit tests:

```
export REPORT_GAS=true
```

```
npx hardhat test
```
Expand All @@ -43,13 +39,7 @@ Check if coverage threshold has been met:
npx istanbul check-coverage --lines 90
```

## Linters

Run ESLint:

```
npx eslint '**/*.{js,ts}' --fix
```
## Linting

Run Solhint:

Expand Down Expand Up @@ -111,18 +101,20 @@ npx hardhat run scripts/deploy-<contract>.ts --network mainnet
```

```
npx hardhat verify --network mainnet <address>
npx hardhat verify --network mainnet <address> <parameters>
```

## Deployments

### Goerli

- GitHub.sol: `0x7a0e37e6e64d4fc59207c163e0176e22a4072503`
- utils/PassportUtils.sol: `0xad42FC3fE04add6B4D177188E3B41677f03703a7`
- GitHubUsernames.sol: `0x1bDa420e57059FB7C97B13DE7F7Dd719371E0291`
- Discord.sol: `0x4BD52941D5C14035F49C93ab6EB3878DDa063119`

### Sepolia

- utils/PassportUtils.sol: `0x90EC93e8B5948b1F7759692fB3082ACd3abDa3F8`
- NationCred.sol: `0xff5F7A95D6dd29a0543f661a148ba1B9ac554763`

### Mainnet
Expand Down
2 changes: 1 addition & 1 deletion contracts/Discord.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

contract Discord {
mapping(address => string) public usernames;
Expand Down
2 changes: 1 addition & 1 deletion contracts/Discourse.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

contract Discourse {
mapping(address => string) public usernames;
Expand Down
22 changes: 0 additions & 22 deletions contracts/GitHub.sol

This file was deleted.

27 changes: 27 additions & 0 deletions contracts/GitHubUsernames.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.19;

import {IPassportUtils} from "./utils/IPassportUtils.sol";

contract GitHubUsernames {
string public constant VERSION = "0.6.1";
mapping(address => string) public usernames;
IPassportUtils public passportUtils;

error PassportExpired(address citizen);

event UsernameUpdated(address citizen, string username);

constructor(address passportUtils_) {
passportUtils = IPassportUtils(passportUtils_);
}

function updateUsername(string calldata username) public {
if (passportUtils.isExpired(msg.sender)) {
revert PassportExpired(msg.sender);
} else {
usernames[msg.sender] = username;
emit UsernameUpdated(msg.sender, username);
}
}
}
22 changes: 0 additions & 22 deletions contracts/Greeter.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/INationCred.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

interface INationCred {
/**
Expand Down
3 changes: 2 additions & 1 deletion contracts/NationCred.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

import "./INationCred.sol";
import "@openzeppelin/contracts/interfaces/IERC721.sol";
Expand All @@ -8,6 +8,7 @@ import "@openzeppelin/contracts/interfaces/IERC721.sol";
* @notice Stores the passport IDs of active Nation3 citizens.
*/
contract NationCred is INationCred {
string public constant VERSION = "0.6.1";
address public owner;
IERC721 public passport;
uint16[] private passportIDs;
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/IVotingEscrow.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/PassportIssuerMock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

import "../passport/IPassportIssuer.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/PassportMock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
Expand All @@ -10,7 +10,7 @@

Counters.Counter private _tokenIdCounter;

constructor() ERC721("Nation3 Genesis Passport", "PASS3") {}

Check warning on line 13 in contracts/mock/PassportMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Code contains empty blocks

Check warning on line 13 in contracts/mock/PassportMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Code contains empty blocks

function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/VotingEscrowMock.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

import "../governance/IVotingEscrow.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "hardhat/console.sol";

contract VotingEscrowMock is ERC20, IVotingEscrow {
mapping(address => LockedBalance) locks;

Check warning on line 9 in contracts/mock/VotingEscrowMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Explicitly mark visibility of state

Check warning on line 9 in contracts/mock/VotingEscrowMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Explicitly mark visibility of state

constructor() ERC20("Vote-escrowed NATION", "veNATION") {
_mint(msg.sender, 100 * 1e18);
}

function create_lock(int128 _value, uint256 _unlock_time) public {

Check warning on line 15 in contracts/mock/VotingEscrowMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Function name must be in mixedCase

Check warning on line 15 in contracts/mock/VotingEscrowMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Variable name must be in mixedCase

Check warning on line 15 in contracts/mock/VotingEscrowMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Function name must be in mixedCase

Check warning on line 15 in contracts/mock/VotingEscrowMock.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Variable name must be in mixedCase
console.log("create_lock");
console.log("uint256(int256(_value)):", uint256(int256(_value)));
console.log("_unlock_time:", _unlock_time);
Expand Down
2 changes: 1 addition & 1 deletion contracts/passport/IPassportIssuer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

interface IPassportIssuer {
function revokeUnderBalance() external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/IPassportUtils.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

interface IPassportUtils {
/**
Expand Down
6 changes: 2 additions & 4 deletions contracts/utils/PassportUtils.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
pragma solidity ^0.8.19;

import "./IPassportUtils.sol";
import "../passport/IPassportIssuer.sol";
import "../governance/IVotingEscrow.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "hardhat/console.sol";

contract PassportUtils is IPassportUtils {
using SafeERC20 for IERC20;

string public constant VERSION = "0.6.1";
IPassportIssuer public passportIssuer;
IVotingEscrow public votingEscrow;

Expand Down Expand Up @@ -57,8 +55,8 @@

uint256 maxLockPeriod = 4 * 365 days;
console.log("maxLockPeriod:", maxLockPeriod);
console.log("block.timestamp:", block.timestamp);

Check warning on line 58 in contracts/utils/PassportUtils.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Avoid to make time-based decisions in your business logic

Check warning on line 58 in contracts/utils/PassportUtils.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Avoid to make time-based decisions in your business logic
uint256 secondsUntilUnlock = lockEnd - block.timestamp;

Check warning on line 59 in contracts/utils/PassportUtils.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Avoid to make time-based decisions in your business logic

Check warning on line 59 in contracts/utils/PassportUtils.sol

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Avoid to make time-based decisions in your business logic
console.log("secondsUntilUnlock:", secondsUntilUnlock);

uint256 thresholdPercentageOfLocked = (100 ether *
Expand Down
15 changes: 4 additions & 11 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import * as dotenv from "dotenv";

import { HardhatUserConfig, task } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
import "hardhat-gas-reporter";
import "solidity-coverage";

dotenv.config();
import "@nomicfoundation/hardhat-toolbox";
require("dotenv").config();

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
Expand All @@ -23,7 +16,7 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
// Go to https://hardhat.org/config/ to learn more

const config: HardhatUserConfig = {
solidity: "0.8.17",
solidity: "0.8.19",
networks: {
goerli: {
url: process.env.GOERLI_URL || "",
Expand All @@ -42,7 +35,7 @@ const config: HardhatUserConfig = {
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
enabled: true,
currency: "USD",
},
etherscan: {
Expand Down
Loading