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

Rename #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ALCHEMY_API_KEY=OC1jcFclXkR7LbjMUSfSP-v08nbbhsFF
INFURA_KEY=fc92f5e472a3467cb8b9abd6d0aca04b
ALCHEMY_API_KEY=
INFURA_KEY=
; if PRIVATE_KEY is set mnemonic will be ignored
PRIVATE_KEY=
MNEMONIC=
Expand Down
27 changes: 19 additions & 8 deletions contracts/MeTokens.sol → contracts/ME.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/draft-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";

/// @title meTokens erc20 contract (ME)
/// @author @CBobRobison, @cartercarlson, @cryptounico
/// @title meTokens erc20 governance contract (ME)
/// @author @CBobRobison, @cartercarlson, @parvgarg, @zgorrizzo69, @cryptounico
/// @notice Base erc20 token used for meTokens protocol governance
contract MeTokens is ERC20Votes, ERC20Snapshot, ERC20Burnable, Ownable {
contract ME is ERC20Votes, ERC20Snapshot, ERC20Burnable, Ownable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we decide to name it MeTokens?

uint256 public constant PRECISION = 1e18;
uint256 public constant MAX_PCT_MINTABLE = 5 * 1e16; // 5%
uint256 public lastMintTimestamp;
uint256 public lastMintPct;

/**
* @dev Constructor.
* @param name The name for this token.
* @param symbol The symbol for this token.
*/
constructor(string memory name, string memory symbol)
ERC20(name, symbol)
ERC20Permit(name)
Expand All @@ -26,9 +31,13 @@ contract MeTokens is ERC20Votes, ERC20Snapshot, ERC20Burnable, Ownable {
lastMintTimestamp = block.timestamp;
}

/// @notice Mint new tokens, up to a rate of 5% of supply per rolling year
/// @param account Address to receive the minted ME
/// @param pctMint Percentage of supply to mint where 1e18 is 100%
/// @param max True if minting the max permitted
function mint(
address account,
uint256 _pctMint,
uint256 pctMint,
bool max
) external onlyOwner {
uint256 pctMintable = getPctMintable();
Expand All @@ -37,21 +46,23 @@ contract MeTokens is ERC20Votes, ERC20Snapshot, ERC20Burnable, Ownable {
if (max) {
amount = (totalSupply() * pctMintable) / PRECISION;
} else {
require(_pctMint <= pctMintable, "amount exceeds max");
require(_pctMint != 0, "_pctMint == 0");
amount = (totalSupply() * _pctMint) / PRECISION;
require(pctMint <= pctMintable, "amount exceeds max");
require(pctMint != 0, "pctMint == 0");
amount = (totalSupply() * pctMint) / PRECISION;
}

lastMintPct = pctMintable - _pctMint;
lastMintPct = pctMintable - pctMint;
lastMintTimestamp = block.timestamp;

_mint(account, amount);
}

/// @notice Returns the chain id used by this contract.
function getChainId() external view returns (uint256) {
return block.chainid;
}

/// @notice Get the percent of supply that can be minted at the current timestamp
function getPctMintable() public view returns (uint256) {
uint256 period = block.timestamp - lastMintTimestamp;
uint256 pctOfYear = (PRECISION * period) / 365 days;
Expand Down
17 changes: 8 additions & 9 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deploy } from "../test/utils/helpers";
import { MeTokens } from "../artifacts/types";
import { ME } from "../artifacts/types";
import { ethers, network } from "hardhat";
import fs from "fs";
import { verifyContract } from "./utils";
Expand All @@ -14,19 +14,19 @@ async function main() {
const constructorParams = ["meTokens", "ME"];

// deploy erc20 contract
let meTokens = await deploy<MeTokens>(
"MeTokens",
let me = await deploy<ME>(
"ME",
undefined,
constructorParams[0],
constructorParams[1]
);
console.log(`MeTokens deployed at ${meTokens.address}`);
console.log(`ME deployed at ${me.address}`);

const deploymentInfo = {
deployer: deployer.address,
owner: deployer.address,
chainId,
meTokensContract: meTokens.address,
meContract: me.address,
};

console.log("Deployment Info: ", deploymentInfo);
Expand All @@ -36,13 +36,12 @@ async function main() {
JSON.stringify(deploymentInfo, undefined, 2)
);

// TODO can also add mainnet here
if (network.name === "rinkeby") {
if (network.name === "rinkeby" || network.name === "mainnet") {
console.log(
"wait for 5 blocks until bytecodes are uploaded into etherscan"
);
await meTokens.deployTransaction.wait(5);
await verifyContract("MeTokens", meTokens.address, constructorParams);
await me.deployTransaction.wait(5);
await verifyContract("ME", me.address, constructorParams);
}
}

Expand Down
15 changes: 5 additions & 10 deletions test/MeTokens.ts → test/ME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect } from "chai";
import { BigNumber } from "ethers";
import { mineBlock, setAutomine } from "./utils/hardhatNode";
import { deploy, fromETHNumber } from "./utils/helpers";
import { MeTokens } from "../artifacts/types";
import { ME } from "../artifacts/types";

const calGetPctMintable = async (
timestamp: BigNumber,
Expand All @@ -29,19 +29,14 @@ const setup = async () => {
const ONE_PCT = fromETHNumber(0.01);
const RANDOM_PCT = fromETHNumber(0.0000069);
const PRECISION = fromETHNumber(1);
let meTokens: MeTokens;
let meTokens: ME;
let account0: SignerWithAddress;
let account1: SignerWithAddress;
let account2: SignerWithAddress;
describe("MeTokens.sol", () => {
describe("ME.sol", () => {
before(async () => {
[account0, account1, account2] = await ethers.getSigners();
meTokens = await deploy<MeTokens>(
"MeTokens",
undefined,
"meTokens",
"ME"
);
meTokens = await deploy<ME>("ME", undefined, "meTokens", "ME");
});

it("Correct initial state", async () => {
Expand Down Expand Up @@ -102,7 +97,7 @@ const setup = async () => {

it("Cannot mint 0", async () => {
const tx = meTokens.mint(account2.address, 0, false);
await expect(tx).to.be.revertedWith("_pctMint == 0");
await expect(tx).to.be.revertedWith("pctMint == 0");
});

it("Owner cannot mint more than mintable supply", async () => {
Expand Down