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
8f88a907
Commit
8f88a907
authored
Feb 02, 2021
by
Francisco Giordano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transpile
c22f9909
parent
8674b47f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
49 additions
and
23 deletions
+49
-23
EIP712Upgradeable.sol
contracts/drafts/EIP712Upgradeable.sol
+2
-0
ERC20PermitUpgradeable.sol
contracts/drafts/ERC20PermitUpgradeable.sol
+2
-0
ERC165CheckerUpgradeable.sol
contracts/introspection/ERC165CheckerUpgradeable.sol
+2
-0
SafeMathUpgradeable.sol
contracts/math/SafeMathUpgradeable.sol
+10
-0
SafeMathMockUpgradeable.sol
contracts/mocks/SafeMathMockUpgradeable.sol
+7
-5
ERC20PresetFixedSupplyUpgradeable.sol
contracts/presets/ERC20PresetFixedSupplyUpgradeable.sol
+2
-0
ERC777PresetFixedSupplyUpgradeable.sol
contracts/presets/ERC777PresetFixedSupplyUpgradeable.sol
+2
-0
ClonesUpgradeable.sol
contracts/proxy/ClonesUpgradeable.sol
+2
-0
EnumerableMapUpgradeable.sol
contracts/utils/EnumerableMapUpgradeable.sol
+2
-0
01-remove-address-functiondelegatecall.patch
...deable/patch/01-remove-address-functiondelegatecall.patch
+2
-2
SafeMath.test.js
test/math/SafeMath.test.js
+16
-16
No files found.
contracts/drafts/EIP712Upgradeable.sol
View file @
8f88a907
...
...
@@ -19,6 +19,8 @@ import "../proxy/Initializable.sol";
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712Upgradeable is Initializable {
/* solhint-disable var-name-mixedcase */
...
...
contracts/drafts/ERC20PermitUpgradeable.sol
View file @
8f88a907
...
...
@@ -16,6 +16,8 @@ import "../proxy/Initializable.sol";
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* _Available since v3.4._
*/
abstract contract ERC20PermitUpgradeable is Initializable, ERC20Upgradeable, IERC20PermitUpgradeable, EIP712Upgradeable {
using CountersUpgradeable for CountersUpgradeable.Counter;
...
...
contracts/introspection/ERC165CheckerUpgradeable.sol
View file @
8f88a907
...
...
@@ -47,6 +47,8 @@ library ERC165CheckerUpgradeable {
* is that some interfaces may not be supported.
*
* See {IERC165-supportsInterface}.
*
* _Available since v3.4._
*/
function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool[] memory) {
// an array of booleans corresponding to interfaceIds and whether they're supported or not
...
...
contracts/math/SafeMathUpgradeable.sol
View file @
8f88a907
...
...
@@ -18,6 +18,8 @@ pragma solidity >=0.6.0 <0.8.0;
library SafeMathUpgradeable {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
...
...
@@ -27,6 +29,8 @@ library SafeMathUpgradeable {
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
...
...
@@ -35,6 +39,8 @@ library SafeMathUpgradeable {
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
...
...
@@ -48,6 +54,8 @@ library SafeMathUpgradeable {
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
...
...
@@ -56,6 +64,8 @@ library SafeMathUpgradeable {
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
...
...
contracts/mocks/SafeMathMockUpgradeable.sol
View file @
8f88a907
...
...
@@ -32,23 +32,25 @@ contract SafeMathMockUpgradeable is Initializable {
return SafeMathUpgradeable.tryMod(a, b);
}
function add(uint256 a, uint256 b) public pure returns (uint256) {
// using the do* naming convention to avoid warnings due to clashing opcode names
function doAdd(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMathUpgradeable.add(a, b);
}
function
s
ub(uint256 a, uint256 b) public pure returns (uint256) {
function
doS
ub(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMathUpgradeable.sub(a, b);
}
function
m
ul(uint256 a, uint256 b) public pure returns (uint256) {
function
doM
ul(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMathUpgradeable.mul(a, b);
}
function div(uint256 a, uint256 b) public pure returns (uint256) {
function d
oD
iv(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMathUpgradeable.div(a, b);
}
function
m
od(uint256 a, uint256 b) public pure returns (uint256) {
function
doM
od(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMathUpgradeable.mod(a, b);
}
...
...
contracts/presets/ERC20PresetFixedSupplyUpgradeable.sol
View file @
8f88a907
...
...
@@ -13,6 +13,8 @@ import "../proxy/Initializable.sol";
*
* This contract uses {ERC20Burnable} to include burn capabilities - head to
* its documentation for details.
*
* _Available since v3.4._
*/
contract ERC20PresetFixedSupplyUpgradeable is Initializable, ERC20BurnableUpgradeable {
function initialize(
...
...
contracts/presets/ERC777PresetFixedSupplyUpgradeable.sol
View file @
8f88a907
...
...
@@ -9,6 +9,8 @@ import "../proxy/Initializable.sol";
*
* - Preminted initial supply
* - No access control mechanism (for minting/pausing) and hence no governance
*
* _Available since v3.4._
*/
contract ERC777PresetFixedSupplyUpgradeable is Initializable, ERC777Upgradeable {
function initialize(
...
...
contracts/proxy/ClonesUpgradeable.sol
View file @
8f88a907
...
...
@@ -12,6 +12,8 @@ pragma solidity >=0.6.0 <0.8.0;
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*
* _Available since v3.4._
*/
library ClonesUpgradeable {
/**
...
...
contracts/utils/EnumerableMapUpgradeable.sol
View file @
8f88a907
...
...
@@ -235,6 +235,8 @@ library EnumerableMapUpgradeable {
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*
* _Available since v3.4._
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
...
...
scripts/upgradeable/patch/01-remove-address-functiondelegatecall.patch
View file @
8f88a907
...
...
@@ -26,7 +26,7 @@ index 75acb96f..08a59041 100644
- * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
- * but performing a delegate call.
- *
- * _Available since v3.
3
._
- * _Available since v3.
4
._
- */
- function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
- return functionDelegateCall(target, data, "Address: low-level delegate call failed");
...
...
@@ -36,7 +36,7 @@ index 75acb96f..08a59041 100644
- * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
- * but performing a delegate call.
- *
- * _Available since v3.
3
._
- * _Available since v3.
4
._
- */
- function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
- require(isContract(target), "Address: delegate call to non-contract");
...
...
test/math/SafeMath.test.js
View file @
8f88a907
...
...
@@ -167,14 +167,14 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'1234'
);
await
testCommutative
(
this
.
safeMath
.
a
dd
,
a
,
b
,
a
.
add
(
b
));
await
testCommutative
(
this
.
safeMath
.
doA
dd
,
a
,
b
,
a
.
add
(
b
));
});
it
(
'reverts on addition overflow'
,
async
function
()
{
const
a
=
MAX_UINT256
;
const
b
=
new
BN
(
'1'
);
await
testFailsCommutative
(
this
.
safeMath
.
a
dd
,
a
,
b
,
'SafeMath: addition overflow'
);
await
testFailsCommutative
(
this
.
safeMath
.
doA
dd
,
a
,
b
,
'SafeMath: addition overflow'
);
});
});
...
...
@@ -183,14 +183,14 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'1234'
);
expect
(
await
this
.
safeMath
.
s
ub
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
sub
(
b
));
expect
(
await
this
.
safeMath
.
doS
ub
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
sub
(
b
));
});
it
(
'reverts if subtraction result would be negative'
,
async
function
()
{
const
a
=
new
BN
(
'1234'
);
const
b
=
new
BN
(
'5678'
);
await
expectRevert
(
this
.
safeMath
.
s
ub
(
a
,
b
),
'SafeMath: subtraction overflow'
);
await
expectRevert
(
this
.
safeMath
.
doS
ub
(
a
,
b
),
'SafeMath: subtraction overflow'
);
});
});
...
...
@@ -199,21 +199,21 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'1234'
);
const
b
=
new
BN
(
'5678'
);
await
testCommutative
(
this
.
safeMath
.
m
ul
,
a
,
b
,
a
.
mul
(
b
));
await
testCommutative
(
this
.
safeMath
.
doM
ul
,
a
,
b
,
a
.
mul
(
b
));
});
it
(
'multiplies by zero correctly'
,
async
function
()
{
const
a
=
new
BN
(
'0'
);
const
b
=
new
BN
(
'5678'
);
await
testCommutative
(
this
.
safeMath
.
m
ul
,
a
,
b
,
'0'
);
await
testCommutative
(
this
.
safeMath
.
doM
ul
,
a
,
b
,
'0'
);
});
it
(
'reverts on multiplication overflow'
,
async
function
()
{
const
a
=
MAX_UINT256
;
const
b
=
new
BN
(
'2'
);
await
testFailsCommutative
(
this
.
safeMath
.
m
ul
,
a
,
b
,
'SafeMath: multiplication overflow'
);
await
testFailsCommutative
(
this
.
safeMath
.
doM
ul
,
a
,
b
,
'SafeMath: multiplication overflow'
);
});
});
...
...
@@ -222,28 +222,28 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
div
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
div
(
b
));
expect
(
await
this
.
safeMath
.
d
oD
iv
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
div
(
b
));
});
it
(
'divides zero correctly'
,
async
function
()
{
const
a
=
new
BN
(
'0'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
div
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'0'
);
expect
(
await
this
.
safeMath
.
d
oD
iv
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'0'
);
});
it
(
'returns complete number result on non-even division'
,
async
function
()
{
const
a
=
new
BN
(
'7000'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
div
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'1'
);
expect
(
await
this
.
safeMath
.
d
oD
iv
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'1'
);
});
it
(
'reverts on division by zero'
,
async
function
()
{
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'0'
);
await
expectRevert
(
this
.
safeMath
.
div
(
a
,
b
),
'SafeMath: division by zero'
);
await
expectRevert
(
this
.
safeMath
.
d
oD
iv
(
a
,
b
),
'SafeMath: division by zero'
);
});
});
...
...
@@ -253,28 +253,28 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'284'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
it
(
'when the dividend is equal to the divisor'
,
async
function
()
{
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
it
(
'when the dividend is larger than the divisor'
,
async
function
()
{
const
a
=
new
BN
(
'7000'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
it
(
'when the dividend is a multiple of the divisor'
,
async
function
()
{
const
a
=
new
BN
(
'17034'
);
// 17034 == 5678 * 3
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
});
...
...
@@ -282,7 +282,7 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'0'
);
await
expectRevert
(
this
.
safeMath
.
m
od
(
a
,
b
),
'SafeMath: modulo by zero'
);
await
expectRevert
(
this
.
safeMath
.
doM
od
(
a
,
b
),
'SafeMath: modulo by zero'
);
});
});
});
...
...
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