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

Make decimal as constant as WEI #52

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions contracts/ERC404.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ abstract contract ERC404 is IERC404 {
/// @dev Token symbol
string public symbol;

/// @dev Decimals for ERC-20 representation
uint8 public immutable decimals;

/// @dev Units for ERC-20 representation
uint256 public immutable units;

Expand Down Expand Up @@ -72,15 +69,13 @@ abstract contract ERC404 is IERC404 {
/// @dev Constant for token id encoding
uint256 public constant ID_ENCODING_PREFIX = 1 << 255;

constructor(string memory name_, string memory symbol_, uint8 decimals_) {
/// @dev Decimals for ERC-20 representation
uint8 public constant decimals = 18;

constructor(string memory name_, string memory symbol_) {
name = name_;
symbol = symbol_;

if (decimals_ < 18) {
revert DecimalsTooLow();
}

decimals = decimals_;
units = 10 ** decimals;

// EIP-2612 initialization
Expand Down
13 changes: 4 additions & 9 deletions contracts/ERC404U16.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ abstract contract ERC404U16 is IERC404 {
/// @dev Token symbol
string public symbol;

/// @dev Decimals for ERC-20 representation
uint8 public immutable decimals;

/// @dev Units for ERC-20 representation
uint256 public immutable units;

Expand Down Expand Up @@ -74,15 +71,13 @@ abstract contract ERC404U16 is IERC404 {
/// @dev Constant for token id encoding
uint256 public constant ID_ENCODING_PREFIX = 1 << 255;

constructor(string memory name_, string memory symbol_, uint8 decimals_) {
/// @dev Decimals for ERC-20 representation
uint8 public constant decimals = 18;

constructor(string memory name_, string memory symbol_) {
name = name_;
symbol = symbol_;

if (decimals_ < 18) {
revert DecimalsTooLow();
}

decimals = decimals_;
units = 10 ** decimals;

// EIP-2612 initialization
Expand Down
3 changes: 1 addition & 2 deletions contracts/examples/ERC404Example.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ contract ERC404Example is Ownable, ERC404 {
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
uint256 maxTotalSupplyERC721_,
address initialOwner_,
address initialMintRecipient_
) ERC404(name_, symbol_, decimals_) Ownable(initialOwner_) {
) ERC404(name_, symbol_) Ownable(initialOwner_) {
// Do not mint the ERC721s to the initial owner, as it's a waste of gas.
_setERC721TransferExempt(initialMintRecipient_, true);
_mintERC20(initialMintRecipient_, maxTotalSupplyERC721_ * units);
Expand Down
3 changes: 1 addition & 2 deletions contracts/examples/ERC404ExampleU16.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ contract ERC404ExampleU16 is Ownable, ERC404U16 {
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
uint256 maxTotalSupplyERC721_,
address initialOwner_,
address initialMintRecipient_
) ERC404U16(name_, symbol_, decimals_) Ownable(initialOwner_) {
) ERC404U16(name_, symbol_) Ownable(initialOwner_) {
// Do not mint the ERC721s to the initial owner, as it's a waste of gas.
_setERC721TransferExempt(initialMintRecipient_, true);
_mintERC20(initialMintRecipient_, maxTotalSupplyERC721_ * units);
Expand Down
3 changes: 1 addition & 2 deletions contracts/examples/ERC404ExampleUniswapV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ contract ERC404ExampleUniswapV2 is Ownable, ERC404, ERC404UniswapV2Exempt {
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
uint256 maxTotalSupplyERC721_,
address initialOwner_,
address initialMintRecipient_,
address uniswapV2Router_
)
ERC404(name_, symbol_, decimals_)
ERC404(name_, symbol_)
Ownable(initialOwner_)
ERC404UniswapV2Exempt(uniswapV2Router_)
{
Expand Down
3 changes: 1 addition & 2 deletions contracts/examples/ERC404ExampleUniswapV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ contract ERC404ExampleUniswapV3 is Ownable, ERC404, ERC404UniswapV3Exempt {
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
uint256 maxTotalSupplyERC721_,
address initialOwner_,
address initialMintRecipient_,
address uniswapSwapRouter_,
address uniswapV3NonfungiblePositionManager_
)
ERC404(name_, symbol_, decimals_)
ERC404(name_, symbol_)
Ownable(initialOwner_)
ERC404UniswapV3Exempt(
uniswapSwapRouter_,
Expand Down
1 change: 0 additions & 1 deletion contracts/interfaces/IERC404.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface IERC404 is IERC165 {
error RecipientIsERC721TransferExempt();
error Unauthorized();
error InsufficientAllowance();
error DecimalsTooLow();
error PermitDeadlineExpired();
error InvalidSigner();
error InvalidApproval();
Expand Down
3 changes: 1 addition & 2 deletions contracts/mocks/MinimalERC404.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ contract MinimalERC404 is Ownable, ERC404 {
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
address initialOwner_
) ERC404(name_, symbol_, decimals_) Ownable(initialOwner_) {}
) ERC404(name_, symbol_) Ownable(initialOwner_) {}

function mintERC20(address account_, uint256 value_) external onlyOwner {
_mintERC20(account_, value_);
Expand Down
2 changes: 0 additions & 2 deletions scripts/gas-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async function main() {
const erc404V2Contract = await erc404V2Factory.deploy(
"ERC404Example",
"ERC404",
18,
500,
signers[0].address,
signers[0].address,
Expand All @@ -33,7 +32,6 @@ async function main() {
const erc404U16V2Contract = await erc404U16V2Factory.deploy(
"ERC404ExampleU16",
"ERC404U16",
18,
500,
signers[0].address,
signers[0].address,
Expand Down
2 changes: 0 additions & 2 deletions test/ERC404.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe("ERC404", function () {
const contract = await factory.deploy(
name,
symbol,
decimals,
maxTotalSupplyERC721,
initialOwner.address,
initialMintRecipient.address,
Expand Down Expand Up @@ -147,7 +146,6 @@ describe("ERC404", function () {
const contract = await factory.deploy(
name,
symbol,
decimals,
initialOwner.address,
)
await contract.waitForDeployment()
Expand Down
1 change: 0 additions & 1 deletion test/ERC404UniswapV2Exempt.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe("ERC404UniswapV2Exempt", function () {
const contract = await factory.deploy(
name,
symbol,
decimals,
maxTotalSupplyERC721,
initialOwner.address,
initialMintRecipient.address,
Expand Down
1 change: 0 additions & 1 deletion test/ERC404UniswapV3Exempt.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ describe("ERC404UniswapV3Exempt", function () {
const contract = await factory.deploy(
name,
symbol,
decimals,
maxTotalSupplyERC721,
initialOwner.address,
initialMintRecipient.address,
Expand Down