Skip to content

Commit

Permalink
Feature/gov tokens (#216)
Browse files Browse the repository at this point in the history
* burnable pausable

* capped

* tokens

* removed old tests
  • Loading branch information
todesstille authored Jul 19, 2024
1 parent 3fc9285 commit 5629eb1
Show file tree
Hide file tree
Showing 9 changed files with 616 additions and 27 deletions.
24 changes: 24 additions & 0 deletions contracts/gov/ERC20/ERC20GovBurnable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";

contract ERC20GovBurnable is ERC20Upgradeable, ERC20BurnableUpgradeable {
struct InitMint {
address user;
uint256 amount;
}

function __ERC20GovBurnable_init(
string calldata name,
string calldata symbol,
InitMint[] calldata distributions
) external initializer {
__ERC20_init(name, symbol);

for (uint256 i = 0; i < distributions.length; i++) {
_mint(distributions[i].user, distributions[i].amount);
}
}
}
49 changes: 49 additions & 0 deletions contracts/gov/ERC20/ERC20GovCapped.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20CappedUpgradeable.sol";

contract ERC20GovCapped is
ERC20Upgradeable,
OwnableUpgradeable,
ERC20BurnableUpgradeable,
ERC20CappedUpgradeable
{
struct InitMint {
address user;
uint256 amount;
}

function __ERC20GovCapped_init(
string calldata name,
string calldata symbol,
InitMint[] calldata distributions,
address newOwner,
uint256 cap_
) external initializer {
__ERC20_init(name, symbol);

__Ownable_init();
transferOwnership(newOwner);

__ERC20Capped_init(cap_);

for (uint256 i = 0; i < distributions.length; i++) {
_mint(distributions[i].user, distributions[i].amount);
}
}

function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}

function _mint(
address account,
uint256 amount
) internal virtual override(ERC20Upgradeable, ERC20CappedUpgradeable) {
ERC20CappedUpgradeable._mint(account, amount);
}
}
67 changes: 67 additions & 0 deletions contracts/gov/ERC20/ERC20GovCappedPausable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20CappedUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";

contract ERC20GovCappedPausable is
ERC20Upgradeable,
OwnableUpgradeable,
ERC20BurnableUpgradeable,
ERC20CappedUpgradeable,
ERC20PausableUpgradeable
{
struct InitMint {
address user;
uint256 amount;
}

function __ERC20GovCappedPausable_init(
string calldata name,
string calldata symbol,
InitMint[] calldata distributions,
address newOwner,
uint256 cap_
) external initializer {
__ERC20_init(name, symbol);

__Ownable_init();
transferOwnership(newOwner);

__ERC20Capped_init(cap_);

for (uint256 i = 0; i < distributions.length; i++) {
_mint(distributions[i].user, distributions[i].amount);
}
}

function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}

function pause() external onlyOwner {
_pause();
}

function unpause() external onlyOwner {
_unpause();
}

function _mint(
address account,
uint256 amount
) internal virtual override(ERC20Upgradeable, ERC20CappedUpgradeable) {
ERC20CappedUpgradeable._mint(account, amount);
}

function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20Upgradeable, ERC20PausableUpgradeable) {
ERC20PausableUpgradeable._beforeTokenTransfer(from, to, amount);
}
}
6 changes: 3 additions & 3 deletions contracts/gov/ERC20/ERC20GovMinimal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ contract ERC20GovMinimal is ERC20Upgradeable {
function __ERC20GovMinimal_init(
string calldata name,
string calldata symbol,
InitMint[] calldata initMint
InitMint[] calldata distributions
) external initializer {
__ERC20_init(name, symbol);

for (uint256 i = 0; i < initMint.length; i++) {
_mint(initMint[i].user, initMint[i].amount);
for (uint256 i = 0; i < distributions.length; i++) {
_mint(distributions[i].user, distributions[i].amount);
}
}
}
33 changes: 33 additions & 0 deletions contracts/gov/ERC20/ERC20GovMintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract ERC20GovMintable is ERC20Upgradeable, ERC20BurnableUpgradeable, OwnableUpgradeable {
struct InitMint {
address user;
uint256 amount;
}

function __ERC20GovMintable_init(
string calldata name,
string calldata symbol,
InitMint[] calldata distributions,
address newOwner
) external initializer {
__ERC20_init(name, symbol);

__Ownable_init();
transferOwnership(newOwner);

for (uint256 i = 0; i < distributions.length; i++) {
_mint(distributions[i].user, distributions[i].amount);
}
}

function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}
}
55 changes: 55 additions & 0 deletions contracts/gov/ERC20/ERC20GovMintablePausable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";

contract ERC20GovMintablePausable is
ERC20Upgradeable,
ERC20BurnableUpgradeable,
OwnableUpgradeable,
ERC20PausableUpgradeable
{
struct InitMint {
address user;
uint256 amount;
}

function __ERC20GovMintablePausable_init(
string calldata name,
string calldata symbol,
InitMint[] calldata distributions,
address newOwner
) external initializer {
__ERC20_init(name, symbol);

__Ownable_init();
transferOwnership(newOwner);

for (uint256 i = 0; i < distributions.length; i++) {
_mint(distributions[i].user, distributions[i].amount);
}
}

function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}

function pause() external onlyOwner {
_pause();
}

function unpause() external onlyOwner {
_unpause();
}

function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20Upgradeable, ERC20PausableUpgradeable) {
ERC20PausableUpgradeable._beforeTokenTransfer(from, to, amount);
}
}
44 changes: 44 additions & 0 deletions contracts/gov/ERC20/ERC20GovPausable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";

contract ERC20GovPausable is ERC20Upgradeable, OwnableUpgradeable, ERC20PausableUpgradeable {
struct InitMint {
address user;
uint256 amount;
}

function __ERC20GovPausable_init(
string calldata name,
string calldata symbol,
InitMint[] calldata distributions,
address newOwner
) external initializer {
__Ownable_init();
transferOwnership(newOwner);
__ERC20_init(name, symbol);

for (uint256 i = 0; i < distributions.length; i++) {
_mint(distributions[i].user, distributions[i].amount);
}
}

function pause() external onlyOwner {
_pause();
}

function unpause() external onlyOwner {
_unpause();
}

function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20Upgradeable, ERC20PausableUpgradeable) {
ERC20PausableUpgradeable._beforeTokenTransfer(from, to, amount);
}
}
24 changes: 0 additions & 24 deletions test/gov/ERC20/ERC20Gov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ const truffleAssert = require("truffle-assertions");
const Reverter = require("../../helpers/reverter");

const ERC20Gov = artifacts.require("ERC20Gov");
const ERC20GovMinimal = artifacts.require("ERC20GovMinimal");

ERC20Gov.numberFormat = "BigNumber";
ERC20GovMinimal.numberFormat = "BigNumber";

describe("ERC20Gov", () => {
let OWNER;
Expand Down Expand Up @@ -250,26 +248,4 @@ describe("ERC20Gov", () => {
});
});
});

describe("ERC20GovMinimal", () => {
let erc20GovMinimal;

beforeEach("", async () => {
erc20GovMinimal = await ERC20GovMinimal.new();
await erc20GovMinimal.__ERC20GovMinimal_init("Token", "TKN", [[OWNER, wei("1")]]);
});

it("can't initialize twice", async () => {
await truffleAssert.reverts(
erc20GovMinimal.__ERC20GovMinimal_init("Token", "TKN", [[OWNER, wei("1")]]),
"Initializable: contract is already initialized",
);
});

it("initializes correctly", async () => {
assert.equal(await erc20GovMinimal.name(), "Token");
assert.equal(await erc20GovMinimal.symbol(), "TKN");
assert.equal((await erc20GovMinimal.balanceOf(OWNER)).toFixed(), wei("1"));
});
});
});
Loading

0 comments on commit 5629eb1

Please sign in to comment.