-
Notifications
You must be signed in to change notification settings - Fork 66
Feature/grants_token #992
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
Open
alexcos20
wants to merge
6
commits into
main
Choose a base branch
from
feature/grants_token
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/grants_token #992
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff04f3d
add grants token
alexcos20 559aa5e
transfer ownership after deployment
alexcos20 63c6334
token name and symbol
alexcos20 3ea0fe2
increase timeout in tests
alexcos20 898d854
use blockchain time
alexcos20 3cf90bb
update deploy script
alexcos20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 noticeCode scanning / Slither Local variable shadowing Low
GrantsToken.constructor(uint256,uint256).cap shadows:
- GrantsToken.cap() (function) - ERC20Capped.cap() (function) |
||
| 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.