Skip to content

Commit

Permalink
DAO-385: Implement Upgradable veRIF ERC20 contract with ERC20 Votes (#2)
Browse files Browse the repository at this point in the history
* remove Lock files

* add prettier

* add veRIF contract

* implement upgradeable veRIF ERC20 contract

* update README

* RIFTokenTest

* deploy DAO

* fix sol lint

* fix solhint

* add a comment

* change to deploy-veRif

* remove semicolons

* rename file
  • Loading branch information
rodrigoncalves authored Jun 17, 2024
1 parent aa7406a commit 699b0cb
Show file tree
Hide file tree
Showing 18 changed files with 1,206 additions and 562 deletions.
19 changes: 19 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"semi": false,
"singleQuote": true,
"arrowParens": "avoid",
"trailingComma": "all",
"printWidth": 110,
"useTabs": false,
"tabWidth": 2,
"bracketSpacing": true,
"overrides": [
{
"files": "*.sol",
"options": {
"singleQuote": false,
"explicitTypes": "always"
}
}
]
}
6 changes: 5 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "solhint:recommended"
"extends": "solhint:recommended",
"rules": {
"no-global-import": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }]
}
}
2 changes: 1 addition & 1 deletion .solhintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
contracts/RIFTokenTest.sol
contracts/RIFToken.sol
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.24+commit.e11b9ed9"
}
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.ts
```

## veRIF

The veRIF contract is a contract that allows users to stake RIF tokens in order to get voting power in the RIF DAO.

## RIF Token

The first contract that has been brought to the project is the RIF Token contract [RIFLabs RIF-Token](https://github.com/riflabs/RIF-Token)
This contract has been brought to the project is the RIF Token contract [RIFLabs RIF-Token](https://github.com/riflabs/RIF-Token)

A few simple tests have been created to make sure that the token works.

Refer to ```test/RIFToken.ts```
Refer to ```test/RIFToken.test.ts```

What is tested:

Expand All @@ -35,4 +39,4 @@ The repository does not contain a package.json, causing hardhat to error when ru

We decided (in the meantime) to fork the repository and add it there [Forked Repository](https://github.com/Freshenext/RIF-Token)

**In the future we must add a package.json to the main repository, and remove the forked repository.**
**In the future we must add a package.json to the main repository, and remove the forked repository.**
35 changes: 0 additions & 35 deletions contracts/Lock.sol

This file was deleted.

6 changes: 6 additions & 0 deletions contracts/RIFToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.4.24;

import "rif-token-contracts/contracts/RIF/RIFToken.sol";

/* File must exist, else test/RIFToken.test.ts will fail */
10 changes: 0 additions & 10 deletions contracts/RIFTokenTest.sol

This file was deleted.

58 changes: 58 additions & 0 deletions contracts/VeRIFToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20WrapperUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract VeRIFToken is
Initializable,
ERC20Upgradeable,
ERC20PermitUpgradeable,
ERC20VotesUpgradeable,
ERC20WrapperUpgradeable,
OwnableUpgradeable,
UUPSUpgradeable
{
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(address rifToken, address initialOwner) public initializer {
__ERC20_init("VeRIFToken", "veRIF");
__ERC20Permit_init("VeRIFToken");
__ERC20Votes_init();
__ERC20Wrapper_init(ERC20Upgradeable(rifToken));
__Ownable_init(initialOwner);
__UUPSUpgradeable_init();
}

// The following functions are overrides required by Solidity.

//solhint-disable-next-line no-empty-blocks
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function decimals() public view override(ERC20Upgradeable, ERC20WrapperUpgradeable) returns (uint8) {
return super.decimals();
}

function _update(
address from,
address to,
uint256 value
) internal override(ERC20Upgradeable, ERC20VotesUpgradeable) {
super._update(from, to, value);
}

function nonces(
address owner
) public view override(ERC20PermitUpgradeable, NoncesUpgradeable) returns (uint256) {
return super.nonces(owner);
}
}
8 changes: 4 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import globals from "globals";
import tseslint from "typescript-eslint";
import globals from 'globals'
import tseslint from 'typescript-eslint'

export default [
{
languageOptions: {
languageOptions: {
globals: globals.browser,
},
},
...tseslint.configs.recommended,
];
]
14 changes: 6 additions & 8 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import { HardhatUserConfig } from 'hardhat/config'
import '@nomicfoundation/hardhat-toolbox'
import '@openzeppelin/hardhat-upgrades'

const config: HardhatUserConfig = {
solidity: {
compilers: [
{ version: '0.8.24' },
{ version: '0.4.24' }
]
compilers: [{ version: '0.8.24' }, { version: '0.4.24' }],
},
};
}

export default config;
export default config
17 changes: 0 additions & 17 deletions ignition/modules/Lock.ts

This file was deleted.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "MIT",
"scripts": {
"compile": "hardhat compile",
"clean": "hardhat clean",
"lint:ts": "eslint 'test/**/*.ts'",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint": "yarn lint:ts && yarn lint:sol",
Expand All @@ -15,12 +16,15 @@
"devDependencies": {
"@eslint/js": "^9.3.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-ignition": "^0.15.0",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2",
"@openzeppelin/hardhat-upgrades": "^3.1.1",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.2.0",
Expand Down
13 changes: 13 additions & 0 deletions scripts/deploy-verif.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ethers, upgrades } from 'hardhat'

export const deployVeRif = async (rifTokenAddress: string, deployerAddress: string) => {
const VeRIFTokenFactory = await ethers.getContractFactory('VeRIFToken')
const veRIFToken = await upgrades.deployProxy(VeRIFTokenFactory, [rifTokenAddress, deployerAddress], {
initializer: 'initialize',
kind: 'uups',
timeout: 0, // wait indefinitely
unsafeAllow: ['internal-function-storage'],
})

return await veRIFToken.waitForDeployment()
}
18 changes: 18 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ethers } from 'hardhat'
import { deployVeRif } from './deploy-verif'

const deploy = async () => {
const rifToken = await ethers.deployContract('RIFToken')
const rifAddress = await rifToken.getAddress()
const [deployer] = await ethers.getSigners()
const deployerAddress = await deployer.getAddress()
const veRIFToken = await deployVeRif(rifAddress, deployerAddress)

console.log(`RIFToken deployed at: ${rifAddress}`)
console.log(`VeRIFToken deployed at: ${await veRIFToken.getAddress()}`)
}

deploy().catch(err => {
console.log('deployment error: ', err)
process.exit(1)
})
Loading

0 comments on commit 699b0cb

Please sign in to comment.