diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index fa30163bad2..08e1efc6ac3 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -107,11 +107,12 @@ contract ERC20 is Context, IERC20, IERC20Metadata { * * Requirements: * - * - `recipient` cannot be the zero address. + * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ - function transfer(address recipient, uint256 amount) public virtual override returns (bool) { - _transfer(_msgSender(), recipient, amount); + function transfer(address to, uint256 amount) public virtual override returns (bool) { + address owner = _msgSender(); + _transfer(owner, to, amount); return true; } @@ -133,7 +134,8 @@ contract ERC20 is Context, IERC20, IERC20Metadata { * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { - _approve(_msgSender(), spender, amount); + address owner = _msgSender(); + _approve(owner, spender, amount); return true; } @@ -148,25 +150,26 @@ contract ERC20 is Context, IERC20, IERC20Metadata { * * Requirements: * - * - `sender` and `recipient` cannot be the zero address. - * - `sender` must have a balance of at least `amount`. - * - the caller must have allowance for ``sender``'s tokens of at least + * - `from` and `to` cannot be the zero address. + * - `from` must have a balance of at least `amount`. + * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( - address sender, - address recipient, + address from, + address to, uint256 amount ) public virtual override returns (bool) { - uint256 currentAllowance = _allowances[sender][_msgSender()]; + address spender = _msgSender(); + uint256 currentAllowance = allowance(from, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { - _approve(sender, _msgSender(), currentAllowance - amount); + _approve(from, spender, currentAllowance - amount); } } - _transfer(sender, recipient, amount); + _transfer(from, to, amount); return true; } @@ -184,7 +187,8 @@ contract ERC20 is Context, IERC20, IERC20Metadata { * - `spender` cannot be the zero address. */ 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; } @@ -203,10 +207,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata { * `subtractedValue`. */ 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"); unchecked { - _approve(_msgSender(), spender, currentAllowance - subtractedValue); + _approve(owner, spender, currentAllowance - subtractedValue); } return true; @@ -222,30 +227,30 @@ contract ERC20 is Context, IERC20, IERC20Metadata { * * Requirements: * - * - `sender` cannot be the zero address. - * - `recipient` cannot be the zero address. - * - `sender` must have a balance of at least `amount`. + * - `from` cannot be the zero address. + * - `to` cannot be the zero address. + * - `from` must have a balance of at least `amount`. */ function _transfer( - address sender, - address recipient, + address from, + address to, uint256 amount ) internal virtual { - require(sender != address(0), "ERC20: transfer from the zero address"); - require(recipient != address(0), "ERC20: transfer to the zero address"); + require(from != address(0), "ERC20: transfer from 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]; - require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); + uint256 fromBalance = _balances[from]; + require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); 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 diff --git a/contracts/token/ERC20/IERC20.sol b/contracts/token/ERC20/IERC20.sol index c89cd48daf6..b00b85bd7c4 100644 --- a/contracts/token/ERC20/IERC20.sol +++ b/contracts/token/ERC20/IERC20.sol @@ -18,13 +18,13 @@ interface IERC20 { 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. * * 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 @@ -52,7 +52,7 @@ interface IERC20 { 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. * @@ -61,8 +61,8 @@ interface IERC20 { * Emits a {Transfer} event. */ function transferFrom( - address sender, - address recipient, + address from, + address to, uint256 amount ) external returns (bool);