forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add erc20 and erc777 presets OpenZeppelin#2377
- Loading branch information
1 parent
8533499
commit d9c67f7
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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); | ||
} | ||
} |
This file contains 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,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, "", ""); | ||
} | ||
} |
This file contains 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,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); | ||
}); | ||
}); | ||
}); |
This file contains 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,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'); | ||
}); | ||
}); | ||
}); | ||
}); |