-
Notifications
You must be signed in to change notification settings - Fork 175
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
Implement a compliant ERC20 without a name / symbol / decimal functions #27
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (C) 2017, 2018, 2019, 2020, 2024 dbrock, rain, mrchico, d-xo, sqrlfirst | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
pragma solidity >=0.6.12; | ||
|
||
contract Math { | ||
// --- Math --- | ||
function add(uint x, uint y) internal pure returns (uint z) { | ||
require((z = x + y) >= x); | ||
} | ||
|
||
function sub(uint x, uint y) internal pure returns (uint z) { | ||
require((z = x - y) <= x); | ||
} | ||
} | ||
|
||
contract ERC20WithoutOptional is Math { | ||
// --- ERC20 Data --- | ||
string private constant name = "Token"; | ||
string private constant symbol = "TKN"; | ||
uint8 private decimals = 18; | ||
uint256 public totalSupply; | ||
|
||
mapping(address => uint) public balanceOf; | ||
mapping(address => mapping(address => uint)) public allowance; | ||
|
||
event Approval(address indexed src, address indexed guy, uint wad); | ||
event Transfer(address indexed src, address indexed dst, uint wad); | ||
|
||
// --- Init --- | ||
constructor(uint _totalSupply) public { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @luislucena16 but if you look line 4, (3 below the copyright), it mentions Solidity 0.6.12 which according to the documentation still mention « public » There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, of course, but will the old version still be used even for the new features?.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's accurate for the solidity compiler version specified, not sure what your words means. |
||
totalSupply = _totalSupply; | ||
balanceOf[msg.sender] = _totalSupply; | ||
emit Transfer(address(0), msg.sender, _totalSupply); | ||
} | ||
|
||
// --- Token --- | ||
function transfer(address dst, uint wad) public virtual returns (bool) { | ||
return transferFrom(msg.sender, dst, wad); | ||
} | ||
|
||
function transferFrom( | ||
address src, | ||
address dst, | ||
uint wad | ||
) public virtual returns (bool) { | ||
require(balanceOf[src] >= wad, "insufficient-balance"); | ||
if (src != msg.sender && allowance[src][msg.sender] != type(uint).max) { | ||
require( | ||
allowance[src][msg.sender] >= wad, | ||
"insufficient-allowance" | ||
); | ||
allowance[src][msg.sender] = sub(allowance[src][msg.sender], wad); | ||
} | ||
balanceOf[src] = sub(balanceOf[src], wad); | ||
balanceOf[dst] = add(balanceOf[dst], wad); | ||
emit Transfer(src, dst, wad); | ||
return true; | ||
} | ||
|
||
function approve(address usr, uint wad) public virtual returns (bool) { | ||
allowance[msg.sender][usr] = wad; | ||
emit Approval(msg.sender, usr, wad); | ||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @sqrlfirst I believe that copyright should always go to the owner of the repository!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nop, it shall go depending on the CONTRIBUTING.md (which is absent from this repository) and who's doing the code writing... you know the author :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @Magicking well! I leave it up to the repository owner :)