Skip to content

Commit

Permalink
add erc20 and erc777 presets OpenZeppelin#2377
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinYardi committed Nov 3, 2020
1 parent 8533499 commit d9c67f7
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contracts/presets/ERC20PresetFixedSupply.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;

import "../token/ERC20/ERC20.sol";
import "../token/ERC20/ERC20Burnable.sol";

/**
* @dev Extension of {ERC20} and {ERC20Burnable} with fixed initialSupply.
*
* Tip: Contract is preconfigured with fixed initial supply.
* minting / pausing functionality is not supported. This removes the need of access control and thereby governance.
*/
contract ERC20PresetFixedSupply is ERC20, ERC20Burnable {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply
) public ERC20(name, symbol) {
_mint(msg.sender, initialSupply);
}
}
21 changes: 21 additions & 0 deletions contracts/presets/ERC777PresetFixedSupply.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;

import "../token/ERC777/ERC777.sol";

/**
* @dev Extension of {ERC777} with fixed initialSupply.
*
* Tip: Contract is preconfigured with fixed initial supply.
*
*/
contract ERC777PresetFixedSupply is ERC777 {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply,
address[] memory defaultOperators
) public ERC777(name, symbol, defaultOperators) {
_mint(msg.sender, initialSupply, "", "");
}
}
33 changes: 33 additions & 0 deletions test/presets/ERC20PresetFixedSupply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { BN, constants, expectEvent } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;

const { expect } = require('chai');

const ERC20PresetFixedSupply = artifacts.require('ERC20PresetFixedSupply');

contract('ERC20PresetFixedSupply', function (accounts) {
const [deployer] = accounts;

const name = 'PresetFixedSupply';
const symbol = 'PFS';

const intialSupply = new BN('50000');

beforeEach(async function () {
this.token = await ERC20PresetFixedSupply.new(name, symbol, intialSupply, { from: deployer });
});

it('deployer has the balance equal to initial supply', async function () {
expect(await this.token.balanceOf(deployer)).to.be.bignumber.equal(intialSupply);
});

describe('burning', function () {
it('holders can burn their tokens', async function () {
const amount = new BN('10000');
const remainingBalance = intialSupply.sub(amount);
const receipt = await this.token.burn(amount, { from: deployer });
expectEvent(receipt, 'Transfer', { from: deployer, to: ZERO_ADDRESS, value: amount });
expect(await this.token.balanceOf(deployer)).to.be.bignumber.equal(remainingBalance);
});
});
});
53 changes: 53 additions & 0 deletions test/presets/ERC777PresetFixedSupply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const { BN } = require('@openzeppelin/test-helpers');

const { expect } = require('chai');

const ERC777PresetFixedSupply = artifacts.require('ERC777PresetFixedSupply');

contract('ERC777', function (accounts) {
const [defaultOperatorA, defaultOperatorB, anyone] = accounts;

const initialSupply = new BN('10000');
const name = 'ERC777Preset';
const symbol = '777P';

const defaultOperators = [defaultOperatorA, defaultOperatorB];

context('with default operators', function () {
beforeEach(async function () {
this.token = await ERC777PresetFixedSupply.new(name, symbol, initialSupply, defaultOperators);
});

describe('token is created', function () {
it('returns the name', async function () {
expect(await this.token.name()).to.equal(name);
});

it('returns the symbol', async function () {
expect(await this.token.symbol()).to.equal(symbol);
});

it('returns a granularity of 1', async function () {
expect(await this.token.granularity()).to.be.bignumber.equal('1');
});

it('returns the default operators', async function () {
expect(await this.token.defaultOperators()).to.deep.equal(defaultOperators);
});

it('default operators are operators for all accounts', async function () {
for (const operator of defaultOperators) {
expect(await this.token.isOperatorFor(operator, anyone)).to.equal(true);
}
});

it('returns the total supply equal to initial supply', async function () {
expect(await this.token.totalSupply()).to.be.bignumber.equal(initialSupply);
});

it('returns 18 when decimals is called', async function () {
expect(await this.token.decimals()).to.be.bignumber.equal('18');
});
});
});
});

0 comments on commit d9c67f7

Please sign in to comment.