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

Add ERC20 and ERC777 fixed supply presets #2377 #2399

Merged
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/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 ERC20Burnable {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply,
address owner
) public ERC20(name, symbol) {
_mint(owner, initialSupply);
}
}
22 changes: 22 additions & 0 deletions contracts/presets/ERC777PresetFixedSupply.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 owner,
address[] memory defaultOperators
) public ERC777(name, symbol, defaultOperators) {
_mint(owner, initialSupply, "", "");
}
}
33 changes: 33 additions & 0 deletions test/presets/ERC20PresetFixedSupply.test.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, owner] = accounts;

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

const intialSupply = new BN('50000');

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

it('deployer has the balance equal to initial supply', async function () {
expect(await this.token.balanceOf(owner)).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: owner });
expectEvent(receipt, 'Transfer', { from: owner, to: ZERO_ADDRESS, value: amount });
expect(await this.token.balanceOf(owner)).to.be.bignumber.equal(remainingBalance);
});
});
});
57 changes: 57 additions & 0 deletions test/presets/ERC777PresetFixedSupply.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { BN } = require('@openzeppelin/test-helpers');

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

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

contract('ERC777PresetFixedSupply', function (accounts) {
const [owner, 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, owner, 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 the balance of owner equal to initial supply', async function () {
expect(await this.token.balanceOf(owner)).to.be.bignumber.equal(initialSupply);
});

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