Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
49641eaa
Commit
49641eaa
authored
Feb 07, 2022
by
github-actions
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transpile
117afb22
parent
361356c4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
34 deletions
+39
-34
ERC20Upgradeable.sol
contracts/token/ERC20/ERC20Upgradeable.sol
+34
-29
IERC20Upgradeable.sol
contracts/token/ERC20/IERC20Upgradeable.sol
+5
-5
No files found.
contracts/token/ERC20/ERC20Upgradeable.sol
View file @
49641eaa
...
@@ -112,11 +112,12 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
...
@@ -112,11 +112,12 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
*
*
* 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;
}
}
...
@@ -138,7 +139,8 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
...
@@ -138,7 +139,8 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
* - `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;
}
}
...
@@ -153,25 +155,26 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
...
@@ -153,25 +155,26 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
*
*
* 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;
}
}
...
@@ -189,7 +192,8 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
...
@@ -189,7 +192,8 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
* - `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;
}
}
...
@@ -208,10 +212,11 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
...
@@ -208,10 +212,11 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
* `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;
...
@@ -227,30 +232,30 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
...
@@ -227,30 +232,30 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
*
*
* 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(
sender
Balance >= amount, "ERC20: transfer amount exceeds balance");
require(
from
Balance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
unchecked {
_balances[
sender] = sender
Balance - amount;
_balances[
from] = from
Balance - 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
...
...
contracts/token/ERC20/IERC20Upgradeable.sol
View file @
49641eaa
...
@@ -18,13 +18,13 @@ interface IERC20Upgradeable {
...
@@ -18,13 +18,13 @@ interface IERC20Upgradeable {
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 IERC20Upgradeable {
...
@@ -52,7 +52,7 @@ interface IERC20Upgradeable {
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 IERC20Upgradeable {
...
@@ -61,8 +61,8 @@ interface IERC20Upgradeable {
* 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);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment