Unverified Commit 63b46690 by Micah Zoltu Committed by GitHub

Rename some ERC20 parameters to match the standard document. (#3167)

* Renames `sender` to `source`.

The naming variable was incorrect.  The source of the funds is *not* necessarily (and in most cases isn't) the sender of the transaction.  Also, this code has a `msgSender` which further adds confusion.

* Changes to `from/to` instead of `source`.

* Function documentation matches new names

* Changed other instances of sender/recipient to from/to.

Also changed `msgSender` to `owner` in the approval related methods.

* apply changes to IERC20.sol + minor renaming in ERC20.sol

Co-authored-by: Daniel Von Fange <daniel@leancoder.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
parent defcf200
...@@ -107,11 +107,12 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -107,11 +107,12 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* *
* Requirements: * Requirements:
* *
* - `recipient` cannot be the zero address. * - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`. * - the caller must have a balance of at least `amount`.
*/ */
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { function transfer(address to, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount); address owner = _msgSender();
_transfer(owner, to, amount);
return true; return true;
} }
...@@ -133,7 +134,8 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -133,7 +134,8 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* - `spender` cannot be the zero address. * - `spender` cannot be the zero address.
*/ */
function approve(address spender, uint256 amount) public virtual override returns (bool) { function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount); address owner = _msgSender();
_approve(owner, spender, amount);
return true; return true;
} }
...@@ -148,25 +150,26 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -148,25 +150,26 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* *
* Requirements: * Requirements:
* *
* - `sender` and `recipient` cannot be the zero address. * - `from` and `to` cannot be the zero address.
* - `sender` must have a balance of at least `amount`. * - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least * - the caller must have allowance for ``from``'s tokens of at least
* `amount`. * `amount`.
*/ */
function transferFrom( function transferFrom(
address sender, address from,
address recipient, address to,
uint256 amount uint256 amount
) public virtual override returns (bool) { ) public virtual override returns (bool) {
uint256 currentAllowance = _allowances[sender][_msgSender()]; address spender = _msgSender();
uint256 currentAllowance = allowance(from, spender);
if (currentAllowance != type(uint256).max) { if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked { unchecked {
_approve(sender, _msgSender(), currentAllowance - amount); _approve(from, spender, currentAllowance - amount);
} }
} }
_transfer(sender, recipient, amount); _transfer(from, to, amount);
return true; return true;
} }
...@@ -184,7 +187,8 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -184,7 +187,8 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* - `spender` cannot be the zero address. * - `spender` cannot be the zero address.
*/ */
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); address owner = _msgSender();
_approve(owner, spender, _allowances[owner][spender] + addedValue);
return true; return true;
} }
...@@ -203,10 +207,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -203,10 +207,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* `subtractedValue`. * `subtractedValue`.
*/ */
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender]; address owner = _msgSender();
uint256 currentAllowance = _allowances[owner][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked { unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue); _approve(owner, spender, currentAllowance - subtractedValue);
} }
return true; return true;
...@@ -222,30 +227,30 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -222,30 +227,30 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* *
* Requirements: * Requirements:
* *
* - `sender` cannot be the zero address. * - `from` cannot be the zero address.
* - `recipient` cannot be the zero address. * - `to` cannot be the zero address.
* - `sender` must have a balance of at least `amount`. * - `from` must have a balance of at least `amount`.
*/ */
function _transfer( function _transfer(
address sender, address from,
address recipient, address to,
uint256 amount uint256 amount
) internal virtual { ) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address"); require(from != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address"); require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount); _beforeTokenTransfer(from, to, amount);
uint256 senderBalance = _balances[sender]; uint256 fromBalance = _balances[from];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked { unchecked {
_balances[sender] = senderBalance - amount; _balances[from] = fromBalance - amount;
} }
_balances[recipient] += amount; _balances[to] += amount;
emit Transfer(sender, recipient, amount); emit Transfer(from, to, amount);
_afterTokenTransfer(sender, recipient, amount); _afterTokenTransfer(from, to, amount);
} }
/** @dev Creates `amount` tokens and assigns them to `account`, increasing /** @dev Creates `amount` tokens and assigns them to `account`, increasing
......
...@@ -18,13 +18,13 @@ interface IERC20 { ...@@ -18,13 +18,13 @@ interface IERC20 {
function balanceOf(address account) external view returns (uint256); function balanceOf(address account) external view returns (uint256);
/** /**
* @dev Moves `amount` tokens from the caller's account to `recipient`. * @dev Moves `amount` tokens from the caller's account to `to`.
* *
* Returns a boolean value indicating whether the operation succeeded. * Returns a boolean value indicating whether the operation succeeded.
* *
* Emits a {Transfer} event. * Emits a {Transfer} event.
*/ */
function transfer(address recipient, uint256 amount) external returns (bool); function transfer(address to, uint256 amount) external returns (bool);
/** /**
* @dev Returns the remaining number of tokens that `spender` will be * @dev Returns the remaining number of tokens that `spender` will be
...@@ -52,7 +52,7 @@ interface IERC20 { ...@@ -52,7 +52,7 @@ interface IERC20 {
function approve(address spender, uint256 amount) external returns (bool); function approve(address spender, uint256 amount) external returns (bool);
/** /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the * @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's * allowance mechanism. `amount` is then deducted from the caller's
* allowance. * allowance.
* *
...@@ -61,8 +61,8 @@ interface IERC20 { ...@@ -61,8 +61,8 @@ interface IERC20 {
* Emits a {Transfer} event. * Emits a {Transfer} event.
*/ */
function transferFrom( function transferFrom(
address sender, address from,
address recipient, address to,
uint256 amount uint256 amount
) external returns (bool); ) external returns (bool);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment