Skip to content
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
138 changes: 138 additions & 0 deletions contracts/grants/GrantsToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
pragma solidity 0.8.12;
// Copyright Ocean Protocol contributors
// SPDX-License-Identifier: Apache-2.0

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

/**
* @title GrantsToken
* @dev Implementation of the ERC20 token named "Grants" with additional features:
* - Burnable: allows token holders to burn their tokens
* - Capped: token supply has a maximum cap
* - Ownable: owner can manage the token (minting, pausing)
* - Pausable: owner can pause/unpause token transfers
* - Permit: allows gasless token approvals via EIP-2612
*/
contract GrantsToken is
ERC20,
ERC20Burnable,
ERC20Capped,
ERC20Permit,
Ownable,
Pausable
{
// Events
event TokensMinted(address indexed to, uint256 amount);
event TokensBurned(address indexed from, uint256 amount);

uint8 private constant _DECIMALS = 6;

/**
* @dev Constructor for GrantsToken
* @param initialSupply Initial amount of tokens to mint (in wei, accounting for 6 decimals)
* @param cap Maximum token supply cap (in wei, accounting for 6 decimals)
*/
constructor(uint256 initialSupply, uint256 cap)

Check notice

Code scanning / Slither

Local variable shadowing Low

ERC20("COMPY", "COMPY")
ERC20Permit("COMPY")
ERC20Capped(cap)
{
require(initialSupply <= cap, "GrantsToken: initial supply exceeds cap");
if (initialSupply > 0) {
_mint(msg.sender, initialSupply);
emit TokensMinted(msg.sender, initialSupply);
}
}

/**
* @dev Returns the number of decimals used for this token
* @return uint8 The number of decimals (6)
*/
function decimals() public view override returns (uint8) {
return _DECIMALS;
}

/**
* @dev Mint new tokens (only owner)
* @param to Address to mint tokens to
* @param amount Amount of tokens to mint
*/
function mint(address to, uint256 amount)
public
onlyOwner
{
require(to != address(0), "GrantsToken: cannot mint to zero address");
_mint(to, amount);
emit TokensMinted(to, amount);
}

/**
* @dev Pause all token transfers (only owner)
*/
function pause() public onlyOwner {
_pause();
}

/**
* @dev Unpause token transfers (only owner)
*/
function unpause() public onlyOwner {
_unpause();
}

/**
* @dev Get the current token cap
* @return uint256 The maximum token supply
*/
function cap() public view override(ERC20Capped) returns (uint256) {
return super.cap();
}

/**
* @dev Internal function to update balances before token transfer
* Ensures minting doesn't exceed cap and pausing works correctly
*/
function _mint(address to, uint256 amount)
internal
override(ERC20, ERC20Capped)
{
super._mint(to, amount);
}

/**
* @dev Internal function to handle before token transfer hook
* Implements pause functionality
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20) whenNotPaused {
super._beforeTokenTransfer(from, to, amount);
}

/**
* @dev Override burn to emit custom event
*/
function burn(uint256 amount) public override(ERC20Burnable) {
address burner = _msgSender();
super.burn(amount);
emit TokensBurned(burner, amount);
}

/**
* @dev Override burnFrom to emit custom event
*/
function burnFrom(address account, uint256 amount)
public
override(ERC20Burnable)
{
super.burnFrom(account, amount);
emit TokensBurned(account, amount);
}
}
105 changes: 105 additions & 0 deletions scripts/deploy_grants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const fs = require("fs");
const { address } = require("../test/helpers/constants");
const { Wallet } = require("ethers");
const { UV_FS_O_FILEMAP } = require("constants");
const ethers = hre.ethers;
require("dotenv").config();
const logging = true;
const show_verify = true;
const shouldDeployMock20 = false;
async function main() {
const url = process.env.NETWORK_RPC_URL;
console.log("Using RPC: " + url);
if (!url) {
console.error("Missing NETWORK_RPC_URL. Aborting..");
return null;
}

const provider = new ethers.providers.JsonRpcProvider(url);
const network = provider.getNetwork();
// utils
const networkDetails = await network;

let wallet;
if (process.env.MNEMONIC)
wallet = new Wallet.fromMnemonic(process.env.MNEMONIC);
if (process.env.PRIVATE_KEY) wallet = new Wallet(process.env.PRIVATE_KEY);
if (!wallet) {
console.error("Missing MNEMONIC or PRIVATE_KEY. Aborting..");
return null;
}
owner = wallet.connect(provider);
let gasLimit = 3000000;
let gasPrice = null;
let sleepAmount = 10;
let OPFOwner = null;
let RouterAddress = null;
gasLimit = 6500000;
gasPrice = ethers.utils.parseUnits("0.08", "gwei");
const networkName = "base";
const grantsOwner = "0x09b575B5eC7Fff24cbccC092DE9E36eADdDbEe71";

let options;
if (gasPrice) {
options = { gasLimit: gasLimit, gasPrice: gasPrice };
} else {
options = { gasLimit };
}
console.log("Deploying contracts with the account:", owner.address);
console.log("Deployer nonce:", await owner.getTransactionCount());

if (logging) console.info("Deploying GrantsToken");
const GrantsToken = await ethers.getContractFactory("GrantsToken", owner);
const initialSupply = ethers.utils.parseUnits("1000000", 6); // 1 million
const cap = ethers.utils.parseUnits("100000000", 6); // 100 million
const deployGrantsToken = await GrantsToken.connect(owner).deploy(
initialSupply, //1 million initial supply
cap, //100 million cap
options
);
await deployGrantsToken.deployTransaction.wait(5);

if (logging) console.info("GrantsToken deployed at:", deployGrantsToken.address);

// Transfer ownership if GRANTS_OWNER is set
if (grantsOwner) {
if (logging) console.info("Transferring ownership to:", grantsOwner);
const transferTx = await deployGrantsToken.transferOwnership(grantsOwner, options);
await transferTx.wait(5);
if (logging) console.info("Ownership transferred successfully");
const fundsTx = await deployGrantsToken.transfer(grantsOwner, initialSupply,options);
await fundsTx.wait(5);
if (logging) console.info("Tokens transferred successfully");
} else {
if (logging) console.warn("GRANTS_OWNER not set. Ownership remains with deployer:", owner.address);
}

if (show_verify) {
console.log("\tRun the following to verify on etherscan");
console.log(
"\tnpx hardhat verify --network " +
networkName +
" " +
deployGrantsToken.address +
" " +
initialSupply.toString() +
" " +
cap.toString()
);
}
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading
Loading