-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,975 additions
and
77 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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,76 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "../i_erc20/IERC20.sol"; | ||
import "../ownable/Ownable.sol"; | ||
import "../erc20_registry/ERC20Registry.sol"; | ||
|
||
contract CustomERC20 is IERC20, Ownable, ERC20Registry { | ||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
event Approval( | ||
address indexed owner, | ||
address indexed spender, | ||
uint256 value | ||
); | ||
|
||
mapping(address => uint256) public balanceOf; | ||
mapping(address => mapping(address => uint256)) public allowance; | ||
string public name; | ||
string public symbol; | ||
uint8 public decimals; | ||
uint256 public totalSupply; | ||
|
||
constructor(string memory _name, string memory _symbol, uint8 _decimals) register_erc20 { | ||
name = _name; | ||
symbol = _symbol; | ||
decimals = _decimals; | ||
} | ||
|
||
function transfer( | ||
address recipient, | ||
uint256 amount | ||
) external register_erc20_store(recipient) returns (bool) { | ||
balanceOf[msg.sender] -= amount; | ||
balanceOf[recipient] += amount; | ||
emit Transfer(msg.sender, recipient, amount); | ||
return true; | ||
} | ||
|
||
function approve(address spender, uint256 amount) external returns (bool) { | ||
allowance[msg.sender][spender] = amount; | ||
emit Approval(msg.sender, spender, amount); | ||
return true; | ||
} | ||
|
||
function transferFrom( | ||
address sender, | ||
address recipient, | ||
uint256 amount | ||
) external register_erc20_store(recipient) returns (bool) { | ||
allowance[sender][msg.sender] -= amount; | ||
balanceOf[sender] -= amount; | ||
balanceOf[recipient] += amount; | ||
emit Transfer(sender, recipient, amount); | ||
return true; | ||
} | ||
|
||
function _mint(address to, uint256 amount) internal register_erc20_store(to) { | ||
balanceOf[to] += amount; | ||
totalSupply += amount; | ||
emit Transfer(address(0), to, amount); | ||
} | ||
|
||
function _burn(address from, uint256 amount) internal { | ||
balanceOf[from] -= amount; | ||
totalSupply -= amount; | ||
emit Transfer(from, address(0), amount); | ||
} | ||
|
||
function mint(address to, uint256 amount) external onlyOwner{ | ||
_mint(to, amount); | ||
} | ||
|
||
function burn(address from, uint256 amount) external onlyOwner { | ||
_burn(from, amount); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "../erc20/ERC20.sol"; | ||
import "../i_erc20_registry/IERC20Registry.sol"; | ||
|
||
contract ERC20Factory is ERC20Registry { | ||
event ERC20Created(address indexed erc20, address indexed owner); | ||
|
||
function createERC20( | ||
string memory name, | ||
string memory symbol, | ||
uint8 decimals | ||
) external returns (address) { | ||
ERC20 erc20 = new ERC20(name, symbol, decimals); | ||
|
||
// register the ERC20 contract with the ERC20 registry | ||
ERC20_REGISTRY_CONTRACT.register_erc20_from_factory(address(erc20)); | ||
|
||
// transfer ownership of the ERC20 contract to the sender | ||
erc20.transferOwnership(msg.sender); | ||
|
||
emit ERC20Created(address(erc20), msg.sender); | ||
return address(erc20); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.