Commit ed467f82 by Francisco Giordano

Merge upstream openzeppelin-contracts into upstream-patched

parents 69632d3e 9d5f77db
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 120,
"explicitTypes": "always"
}
}
]
}
{ {
"extends": "solhint:recommended",
"rules": { "rules": {
"func-order": "off", "no-unused-vars": "error",
"mark-callable-contracts": "off",
"no-empty-blocks": "off",
"compiler-version": "off",
"private-vars-leading-underscore": "error", "private-vars-leading-underscore": "error",
"reason-string": "off", "const-name-snakecase": "error",
"func-visibility": ["error", { "ignoreConstructors": true }] "contract-name-camelcase": "error",
"event-name-camelcase": "error",
"func-name-mixedcase": "error",
"func-param-name-mixedcase": "error",
"modifier-name-mixedcase": "error",
"private-vars-leading-underscore": "error",
"var-name-mixedcase": "error",
"imports-on-top": "error"
} }
} }
...@@ -11,9 +11,13 @@ import "../utils/introspection/ERC165.sol"; ...@@ -11,9 +11,13 @@ import "../utils/introspection/ERC165.sol";
*/ */
interface IAccessControl { interface IAccessControl {
function hasRole(bytes32 role, address account) external view returns (bool); function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32); function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external; function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external; function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external; function renounceRole(bytes32 role, address account) external;
} }
...@@ -57,11 +61,11 @@ interface IAccessControl { ...@@ -57,11 +61,11 @@ interface IAccessControl {
*/ */
abstract contract AccessControl is Context, IAccessControl, ERC165 { abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData { struct RoleData {
mapping (address => bool) members; mapping(address => bool) members;
bytes32 adminRole; bytes32 adminRole;
} }
mapping (bytes32 => RoleData) private _roles; mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
...@@ -111,8 +115,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 { ...@@ -111,8 +115,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
* @dev See {IERC165-supportsInterface}. * @dev See {IERC165-supportsInterface}.
*/ */
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
|| super.supportsInterface(interfaceId);
} }
/** /**
...@@ -130,13 +133,17 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 { ...@@ -130,13 +133,17 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
* /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/
*/ */
function _checkRole(bytes32 role, address account) internal view { function _checkRole(bytes32 role, address account) internal view {
if(!hasRole(role, account)) { if (!hasRole(role, account)) {
revert(string(abi.encodePacked( revert(
"AccessControl: account ", string(
Strings.toHexString(uint160(account), 20), abi.encodePacked(
" is missing role ", "AccessControl: account ",
Strings.toHexString(uint256(role), 32) Strings.toHexString(uint160(account), 20),
))); " is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
} }
} }
......
...@@ -10,6 +10,7 @@ import "../utils/structs/EnumerableSet.sol"; ...@@ -10,6 +10,7 @@ import "../utils/structs/EnumerableSet.sol";
*/ */
interface IAccessControlEnumerable { interface IAccessControlEnumerable {
function getRoleMember(bytes32 role, uint256 index) external view returns (address); function getRoleMember(bytes32 role, uint256 index) external view returns (address);
function getRoleMemberCount(bytes32 role) external view returns (uint256); function getRoleMemberCount(bytes32 role) external view returns (uint256);
} }
...@@ -19,14 +20,13 @@ interface IAccessControlEnumerable { ...@@ -19,14 +20,13 @@ interface IAccessControlEnumerable {
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl { abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.AddressSet;
mapping (bytes32 => EnumerableSet.AddressSet) private _roleMembers; mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;
/** /**
* @dev See {IERC165-supportsInterface}. * @dev See {IERC165-supportsInterface}.
*/ */
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
|| super.supportsInterface(interfaceId);
} }
/** /**
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/Context.sol"; import "../utils/Context.sol";
/** /**
* @dev Contract module which provides a basic access control mechanism, where * @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to * there is an account (an owner) that can be granted exclusive access to
...@@ -23,7 +24,7 @@ abstract contract Ownable is Context { ...@@ -23,7 +24,7 @@ abstract contract Ownable is Context {
/** /**
* @dev Initializes the contract setting the deployer as the initial owner. * @dev Initializes the contract setting the deployer as the initial owner.
*/ */
constructor () { constructor() {
address msgSender = _msgSender(); address msgSender = _msgSender();
_owner = msgSender; _owner = msgSender;
emit OwnershipTransferred(address(0), msgSender); emit OwnershipTransferred(address(0), msgSender);
......
...@@ -38,8 +38,7 @@ contract PaymentSplitter is Context { ...@@ -38,8 +38,7 @@ contract PaymentSplitter is Context {
* All addresses in `payees` must be non-zero. Both arrays must have the same non-zero length, and there must be no * All addresses in `payees` must be non-zero. Both arrays must have the same non-zero length, and there must be no
* duplicates in `payees`. * duplicates in `payees`.
*/ */
constructor (address[] memory payees, uint256[] memory shares_) payable { constructor(address[] memory payees, uint256[] memory shares_) payable {
// solhint-disable-next-line max-line-length
require(payees.length == shares_.length, "PaymentSplitter: payees and shares length mismatch"); require(payees.length == shares_.length, "PaymentSplitter: payees and shares length mismatch");
require(payees.length > 0, "PaymentSplitter: no payees"); require(payees.length > 0, "PaymentSplitter: no payees");
...@@ -57,7 +56,7 @@ contract PaymentSplitter is Context { ...@@ -57,7 +56,7 @@ contract PaymentSplitter is Context {
* https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback * https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback
* functions]. * functions].
*/ */
receive () external payable virtual { receive() external payable virtual {
emit PaymentReceived(_msgSender(), msg.value); emit PaymentReceived(_msgSender(), msg.value);
} }
...@@ -104,7 +103,7 @@ contract PaymentSplitter is Context { ...@@ -104,7 +103,7 @@ contract PaymentSplitter is Context {
require(_shares[account] > 0, "PaymentSplitter: account has no shares"); require(_shares[account] > 0, "PaymentSplitter: account has no shares");
uint256 totalReceived = address(this).balance + _totalReleased; uint256 totalReceived = address(this).balance + _totalReleased;
uint256 payment = totalReceived * _shares[account] / _totalShares - _released[account]; uint256 payment = (totalReceived * _shares[account]) / _totalShares - _released[account];
require(payment != 0, "PaymentSplitter: account is not due payment"); require(payment != 0, "PaymentSplitter: account is not due payment");
......
...@@ -31,7 +31,15 @@ contract TimelockController is AccessControl { ...@@ -31,7 +31,15 @@ contract TimelockController is AccessControl {
/** /**
* @dev Emitted when a call is scheduled as part of operation `id`. * @dev Emitted when a call is scheduled as part of operation `id`.
*/ */
event CallScheduled(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data, bytes32 predecessor, uint256 delay); event CallScheduled(
bytes32 indexed id,
uint256 indexed index,
address target,
uint256 value,
bytes data,
bytes32 predecessor,
uint256 delay
);
/** /**
* @dev Emitted when a call is performed as part of operation `id`. * @dev Emitted when a call is performed as part of operation `id`.
...@@ -51,7 +59,11 @@ contract TimelockController is AccessControl { ...@@ -51,7 +59,11 @@ contract TimelockController is AccessControl {
/** /**
* @dev Initializes the contract with a given `minDelay`. * @dev Initializes the contract with a given `minDelay`.
*/ */
constructor(uint256 minDelay, address[] memory proposers, address[] memory executors) { constructor(
uint256 minDelay,
address[] memory proposers,
address[] memory executors
) {
_setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE); _setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE); _setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE); _setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE);
...@@ -112,7 +124,6 @@ contract TimelockController is AccessControl { ...@@ -112,7 +124,6 @@ contract TimelockController is AccessControl {
*/ */
function isOperationReady(bytes32 id) public view virtual returns (bool ready) { function isOperationReady(bytes32 id) public view virtual returns (bool ready) {
uint256 timestamp = getTimestamp(id); uint256 timestamp = getTimestamp(id);
// solhint-disable-next-line not-rely-on-time
return timestamp > _DONE_TIMESTAMP && timestamp <= block.timestamp; return timestamp > _DONE_TIMESTAMP && timestamp <= block.timestamp;
} }
...@@ -144,7 +155,13 @@ contract TimelockController is AccessControl { ...@@ -144,7 +155,13 @@ contract TimelockController is AccessControl {
* @dev Returns the identifier of an operation containing a single * @dev Returns the identifier of an operation containing a single
* transaction. * transaction.
*/ */
function hashOperation(address target, uint256 value, bytes calldata data, bytes32 predecessor, bytes32 salt) public pure virtual returns (bytes32 hash) { function hashOperation(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt
) public pure virtual returns (bytes32 hash) {
return keccak256(abi.encode(target, value, data, predecessor, salt)); return keccak256(abi.encode(target, value, data, predecessor, salt));
} }
...@@ -152,7 +169,13 @@ contract TimelockController is AccessControl { ...@@ -152,7 +169,13 @@ contract TimelockController is AccessControl {
* @dev Returns the identifier of an operation containing a batch of * @dev Returns the identifier of an operation containing a batch of
* transactions. * transactions.
*/ */
function hashOperationBatch(address[] calldata targets, uint256[] calldata values, bytes[] calldata datas, bytes32 predecessor, bytes32 salt) public pure virtual returns (bytes32 hash) { function hashOperationBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt
) public pure virtual returns (bytes32 hash) {
return keccak256(abi.encode(targets, values, datas, predecessor, salt)); return keccak256(abi.encode(targets, values, datas, predecessor, salt));
} }
...@@ -165,7 +188,14 @@ contract TimelockController is AccessControl { ...@@ -165,7 +188,14 @@ contract TimelockController is AccessControl {
* *
* - the caller must have the 'proposer' role. * - the caller must have the 'proposer' role.
*/ */
function schedule(address target, uint256 value, bytes calldata data, bytes32 predecessor, bytes32 salt, uint256 delay) public virtual onlyRole(PROPOSER_ROLE) { function schedule(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt); bytes32 id = hashOperation(target, value, data, predecessor, salt);
_schedule(id, delay); _schedule(id, delay);
emit CallScheduled(id, 0, target, value, data, predecessor, delay); emit CallScheduled(id, 0, target, value, data, predecessor, delay);
...@@ -180,7 +210,14 @@ contract TimelockController is AccessControl { ...@@ -180,7 +210,14 @@ contract TimelockController is AccessControl {
* *
* - the caller must have the 'proposer' role. * - the caller must have the 'proposer' role.
*/ */
function scheduleBatch(address[] calldata targets, uint256[] calldata values, bytes[] calldata datas, bytes32 predecessor, bytes32 salt, uint256 delay) public virtual onlyRole(PROPOSER_ROLE) { function scheduleBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
require(targets.length == values.length, "TimelockController: length mismatch"); require(targets.length == values.length, "TimelockController: length mismatch");
require(targets.length == datas.length, "TimelockController: length mismatch"); require(targets.length == datas.length, "TimelockController: length mismatch");
...@@ -197,7 +234,6 @@ contract TimelockController is AccessControl { ...@@ -197,7 +234,6 @@ contract TimelockController is AccessControl {
function _schedule(bytes32 id, uint256 delay) private { function _schedule(bytes32 id, uint256 delay) private {
require(!isOperation(id), "TimelockController: operation already scheduled"); require(!isOperation(id), "TimelockController: operation already scheduled");
require(delay >= getMinDelay(), "TimelockController: insufficient delay"); require(delay >= getMinDelay(), "TimelockController: insufficient delay");
// solhint-disable-next-line not-rely-on-time
_timestamps[id] = block.timestamp + delay; _timestamps[id] = block.timestamp + delay;
} }
...@@ -224,7 +260,13 @@ contract TimelockController is AccessControl { ...@@ -224,7 +260,13 @@ contract TimelockController is AccessControl {
* *
* - the caller must have the 'executor' role. * - the caller must have the 'executor' role.
*/ */
function execute(address target, uint256 value, bytes calldata data, bytes32 predecessor, bytes32 salt) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) { function execute(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt); bytes32 id = hashOperation(target, value, data, predecessor, salt);
_beforeCall(predecessor); _beforeCall(predecessor);
_call(id, 0, target, value, data); _call(id, 0, target, value, data);
...@@ -240,7 +282,13 @@ contract TimelockController is AccessControl { ...@@ -240,7 +282,13 @@ contract TimelockController is AccessControl {
* *
* - the caller must have the 'executor' role. * - the caller must have the 'executor' role.
*/ */
function executeBatch(address[] calldata targets, uint256[] calldata values, bytes[] calldata datas, bytes32 predecessor, bytes32 salt) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) { function executeBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
require(targets.length == values.length, "TimelockController: length mismatch"); require(targets.length == values.length, "TimelockController: length mismatch");
require(targets.length == datas.length, "TimelockController: length mismatch"); require(targets.length == datas.length, "TimelockController: length mismatch");
...@@ -272,9 +320,14 @@ contract TimelockController is AccessControl { ...@@ -272,9 +320,14 @@ contract TimelockController is AccessControl {
* *
* Emits a {CallExecuted} event. * Emits a {CallExecuted} event.
*/ */
function _call(bytes32 id, uint256 index, address target, uint256 value, bytes calldata data) private { function _call(
// solhint-disable-next-line avoid-low-level-calls bytes32 id,
(bool success,) = target.call{value: value}(data); uint256 index,
address target,
uint256 value,
bytes calldata data
) private {
(bool success, ) = target.call{value: value}(data);
require(success, "TimelockController: underlying transaction reverted"); require(success, "TimelockController: underlying transaction reverted");
emit CallExecuted(id, index, target, value, data); emit CallExecuted(id, index, target, value, data);
......
...@@ -9,10 +9,10 @@ pragma solidity ^0.8.0; ...@@ -9,10 +9,10 @@ pragma solidity ^0.8.0;
* _Available since v4.1._ * _Available since v4.1._
*/ */
interface IERC1271 { interface IERC1271 {
/** /**
* @dev Should return whether the signature provided is valid for the provided data * @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed * @param hash Hash of the data to be signed
* @param signature Signature byte array associated with _data * @param signature Signature byte array associated with _data
*/ */
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
} }
...@@ -37,9 +37,7 @@ interface IERC3156FlashLender { ...@@ -37,9 +37,7 @@ interface IERC3156FlashLender {
* @param token The loan currency. * @param token The loan currency.
* @return The amount of `token` that can be borrowed. * @return The amount of `token` that can be borrowed.
*/ */
function maxFlashLoan( function maxFlashLoan(address token) external view returns (uint256);
address token
) external view returns (uint256);
/** /**
* @dev The fee to be charged for a given loan. * @dev The fee to be charged for a given loan.
...@@ -47,10 +45,7 @@ interface IERC3156FlashLender { ...@@ -47,10 +45,7 @@ interface IERC3156FlashLender {
* @param amount The amount of tokens lent. * @param amount The amount of tokens lent.
* @return The amount of `token` to be charged for the loan, on top of the returned principal. * @return The amount of `token` to be charged for the loan, on top of the returned principal.
*/ */
function flashFee( function flashFee(address token, uint256 amount) external view returns (uint256);
address token,
uint256 amount
) external view returns (uint256);
/** /**
* @dev Initiate a flash loan. * @dev Initiate a flash loan.
...@@ -65,4 +60,4 @@ interface IERC3156FlashLender { ...@@ -65,4 +60,4 @@ interface IERC3156FlashLender {
uint256 amount, uint256 amount,
bytes calldata data bytes calldata data
) external returns (bool); ) external returns (bool);
} }
...@@ -14,14 +14,16 @@ abstract contract ERC2771Context is Context { ...@@ -14,14 +14,16 @@ abstract contract ERC2771Context is Context {
_trustedForwarder = trustedForwarder; _trustedForwarder = trustedForwarder;
} }
function isTrustedForwarder(address forwarder) public view virtual returns(bool) { function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
return forwarder == _trustedForwarder; return forwarder == _trustedForwarder;
} }
function _msgSender() internal view virtual override returns (address sender) { function _msgSender() internal view virtual override returns (address sender) {
if (isTrustedForwarder(msg.sender)) { if (isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`. // The assembly code is more direct than the Solidity version using `abi.decode`.
assembly { sender := shr(96, calldataload(sub(calldatasize(), 20))) } assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else { } else {
return super._msgSender(); return super._msgSender();
} }
...@@ -29,7 +31,7 @@ abstract contract ERC2771Context is Context { ...@@ -29,7 +31,7 @@ abstract contract ERC2771Context is Context {
function _msgData() internal view virtual override returns (bytes calldata) { function _msgData() internal view virtual override returns (bytes calldata) {
if (isTrustedForwarder(msg.sender)) { if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length-20]; return msg.data[:msg.data.length - 20];
} else { } else {
return super._msgData(); return super._msgData();
} }
......
...@@ -20,7 +20,8 @@ contract MinimalForwarder is EIP712 { ...@@ -20,7 +20,8 @@ contract MinimalForwarder is EIP712 {
bytes data; bytes data;
} }
bytes32 private constant TYPEHASH = keccak256("ForwardRequest(address from,address to,uint256 value,uint256 gas,uint256 nonce,bytes data)"); bytes32 private constant _TYPEHASH =
keccak256("ForwardRequest(address from,address to,uint256 value,uint256 gas,uint256 nonce,bytes data)");
mapping(address => uint256) private _nonces; mapping(address => uint256) private _nonces;
...@@ -31,24 +32,23 @@ contract MinimalForwarder is EIP712 { ...@@ -31,24 +32,23 @@ contract MinimalForwarder is EIP712 {
} }
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
address signer = _hashTypedDataV4(keccak256(abi.encode( address signer = _hashTypedDataV4(
TYPEHASH, keccak256(abi.encode(_TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
req.from, ).recover(signature);
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
))).recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from; return _nonces[req.from] == req.nonce && signer == req.from;
} }
function execute(ForwardRequest calldata req, bytes calldata signature) public payable returns (bool, bytes memory) { function execute(ForwardRequest calldata req, bytes calldata signature)
public
payable
returns (bool, bytes memory)
{
require(verify(req, signature), "MinimalForwarder: signature does not match request"); require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1; _nonces[req.from] = req.nonce + 1;
// solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = req.to.call{gas: req.gas, value: req.value}(
(bool success, bytes memory returndata) = req.to.call{gas: req.gas, value: req.value}(abi.encodePacked(req.data, req.from)); abi.encodePacked(req.data, req.from)
);
// Validate that the relayer has sent enough gas for the call. // Validate that the relayer has sent enough gas for the call.
// See https://ronan.eth.link/blog/ethereum-gas-dangers/ // See https://ronan.eth.link/blog/ethereum-gas-dangers/
assert(gasleft() > req.gas / 63); assert(gasleft() > req.gas / 63);
......
...@@ -22,7 +22,11 @@ contract AddressImpl { ...@@ -22,7 +22,11 @@ contract AddressImpl {
emit CallReturnValue(abi.decode(returnData, (string))); emit CallReturnValue(abi.decode(returnData, (string)));
} }
function functionCallWithValue(address target, bytes calldata data, uint256 value) external payable { function functionCallWithValue(
address target,
bytes calldata data,
uint256 value
) external payable {
bytes memory returnData = Address.functionCallWithValue(target, data, value); bytes memory returnData = Address.functionCallWithValue(target, data, value);
emit CallReturnValue(abi.decode(returnData, (string))); emit CallReturnValue(abi.decode(returnData, (string)));
} }
...@@ -33,5 +37,5 @@ contract AddressImpl { ...@@ -33,5 +37,5 @@ contract AddressImpl {
} }
// sendValue's tests require the contract to hold Ether // sendValue's tests require the contract to hold Ether
receive () external payable { } receive() external payable {}
} }
...@@ -9,7 +9,7 @@ contract ArraysImpl { ...@@ -9,7 +9,7 @@ contract ArraysImpl {
uint256[] private _array; uint256[] private _array;
constructor (uint256[] memory array) { constructor(uint256[] memory array) {
_array = array; _array = array;
} }
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
contract BadBeaconNoImpl { contract BadBeaconNoImpl {}
}
contract BadBeaconNotContract { contract BadBeaconNotContract {
function implementation() external pure returns (address) { function implementation() external pure returns (address) {
......
...@@ -2,19 +2,17 @@ ...@@ -2,19 +2,17 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
/** /**
* @dev Implementation contract with an admin() function made to clash with * @dev Implementation contract with an admin() function made to clash with
* @dev TransparentUpgradeableProxy's to test correct functioning of the * @dev TransparentUpgradeableProxy's to test correct functioning of the
* @dev Transparent Proxy feature. * @dev Transparent Proxy feature.
*/ */
contract ClashingImplementation { contract ClashingImplementation {
function admin() external pure returns (address) {
return 0x0000000000000000000000000000000011111142;
}
function admin() external pure returns (address) { function delegatedFunction() external pure returns (bool) {
return 0x0000000000000000000000000000000011111142; return true;
} }
function delegatedFunction() external pure returns (bool) {
return true;
}
} }
...@@ -15,7 +15,11 @@ contract ClonesMock { ...@@ -15,7 +15,11 @@ contract ClonesMock {
_initAndEmit(implementation.clone(), initdata); _initAndEmit(implementation.clone(), initdata);
} }
function cloneDeterministic(address implementation, bytes32 salt, bytes calldata initdata) public payable { function cloneDeterministic(
address implementation,
bytes32 salt,
bytes calldata initdata
) public payable {
_initAndEmit(implementation.cloneDeterministic(salt), initdata); _initAndEmit(implementation.cloneDeterministic(salt), initdata);
} }
......
...@@ -23,7 +23,11 @@ contract ContextMockCaller { ...@@ -23,7 +23,11 @@ contract ContextMockCaller {
context.msgSender(); context.msgSender();
} }
function callData(ContextMock context, uint256 integerValue, string memory stringValue) public { function callData(
ContextMock context,
uint256 integerValue,
string memory stringValue
) public {
context.msgData(integerValue, stringValue); context.msgData(integerValue, stringValue);
} }
} }
...@@ -6,12 +6,15 @@ import "../utils/Create2.sol"; ...@@ -6,12 +6,15 @@ import "../utils/Create2.sol";
import "../utils/introspection/ERC1820Implementer.sol"; import "../utils/introspection/ERC1820Implementer.sol";
contract Create2Impl { contract Create2Impl {
function deploy(uint256 value, bytes32 salt, bytes memory code) public { function deploy(
uint256 value,
bytes32 salt,
bytes memory code
) public {
Create2.deploy(value, salt, code); Create2.deploy(value, salt, code);
} }
function deployERC1820Implementer(uint256 value, bytes32 salt) public { function deployERC1820Implementer(uint256 value, bytes32 salt) public {
// solhint-disable-next-line indent
Create2.deploy(value, salt, type(ERC1820Implementer).creationCode); Create2.deploy(value, salt, type(ERC1820Implementer).creationCode);
} }
...@@ -19,7 +22,11 @@ contract Create2Impl { ...@@ -19,7 +22,11 @@ contract Create2Impl {
return Create2.computeAddress(salt, codeHash); return Create2.computeAddress(salt, codeHash);
} }
function computeAddressWithDeployer(bytes32 salt, bytes32 codeHash, address deployer) public pure returns (address) { function computeAddressWithDeployer(
bytes32 salt,
bytes32 codeHash,
address deployer
) public pure returns (address) {
return Create2.computeAddress(salt, codeHash, deployer); return Create2.computeAddress(salt, codeHash, deployer);
} }
......
...@@ -3,55 +3,59 @@ ...@@ -3,55 +3,59 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
abstract contract Impl { abstract contract Impl {
function version() public pure virtual returns (string memory); function version() public pure virtual returns (string memory);
} }
contract DummyImplementation { contract DummyImplementation {
uint256 public value; uint256 public value;
string public text; string public text;
uint256[] public values; uint256[] public values;
function initializeNonPayable() public { function initializeNonPayable() public {
value = 10; value = 10;
} }
function initializePayable() public payable { function initializePayable() public payable {
value = 100; value = 100;
} }
function initializeNonPayableWithValue(uint256 _value) public { function initializeNonPayableWithValue(uint256 _value) public {
value = _value; value = _value;
} }
function initializePayableWithValue(uint256 _value) public payable { function initializePayableWithValue(uint256 _value) public payable {
value = _value; value = _value;
} }
function initialize(uint256 _value, string memory _text, uint256[] memory _values) public { function initialize(
value = _value; uint256 _value,
text = _text; string memory _text,
values = _values; uint256[] memory _values
} ) public {
value = _value;
function get() public pure returns (bool) { text = _text;
return true; values = _values;
} }
function version() public pure virtual returns (string memory) { function get() public pure returns (bool) {
return "V1"; return true;
} }
function reverts() public pure { function version() public pure virtual returns (string memory) {
require(false, "DummyImplementation reverted"); return "V1";
} }
function reverts() public pure {
require(false, "DummyImplementation reverted");
}
} }
contract DummyImplementationV2 is DummyImplementation { contract DummyImplementationV2 is DummyImplementation {
function migrate(uint256 newVal) public payable { function migrate(uint256 newVal) public payable {
value = newVal; value = newVal;
} }
function version() public pure override returns (string memory) { function version() public pure override returns (string memory) {
return "V2"; return "V2";
} }
} }
...@@ -12,12 +12,15 @@ contract EIP712External is EIP712 { ...@@ -12,12 +12,15 @@ contract EIP712External is EIP712 {
return _domainSeparatorV4(); return _domainSeparatorV4();
} }
function verify(bytes memory signature, address signer, address mailTo, string memory mailContents) external view { function verify(
bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( bytes memory signature,
keccak256("Mail(address to,string contents)"), address signer,
mailTo, address mailTo,
keccak256(bytes(mailContents)) string memory mailContents
))); ) external view {
bytes32 digest = _hashTypedDataV4(
keccak256(abi.encode(keccak256("Mail(address to,string contents)"), mailTo, keccak256(bytes(mailContents))))
);
address recoveredSigner = ECDSA.recover(digest, signature); address recoveredSigner = ECDSA.recover(digest, signature);
require(recoveredSigner == signer); require(recoveredSigner == signer);
} }
......
...@@ -5,9 +5,14 @@ pragma solidity ^0.8.0; ...@@ -5,9 +5,14 @@ pragma solidity ^0.8.0;
import "../token/ERC1155/extensions/ERC1155Burnable.sol"; import "../token/ERC1155/extensions/ERC1155Burnable.sol";
contract ERC1155BurnableMock is ERC1155Burnable { contract ERC1155BurnableMock is ERC1155Burnable {
constructor(string memory uri) ERC1155(uri) { } constructor(string memory uri) ERC1155(uri) {}
function mint(address to, uint256 id, uint256 value, bytes memory data) public { function mint(
address to,
uint256 id,
uint256 value,
bytes memory data
) public {
_mint(to, id, value, data); _mint(to, id, value, data);
} }
} }
...@@ -9,27 +9,43 @@ import "../token/ERC1155/ERC1155.sol"; ...@@ -9,27 +9,43 @@ import "../token/ERC1155/ERC1155.sol";
* This mock just publicizes internal functions for testing purposes * This mock just publicizes internal functions for testing purposes
*/ */
contract ERC1155Mock is ERC1155 { contract ERC1155Mock is ERC1155 {
constructor (string memory uri) ERC1155(uri) { constructor(string memory uri) ERC1155(uri) {}
// solhint-disable-previous-line no-empty-blocks
}
function setURI(string memory newuri) public { function setURI(string memory newuri) public {
_setURI(newuri); _setURI(newuri);
} }
function mint(address to, uint256 id, uint256 value, bytes memory data) public { function mint(
address to,
uint256 id,
uint256 value,
bytes memory data
) public {
_mint(to, id, value, data); _mint(to, id, value, data);
} }
function mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) public { function mintBatch(
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) public {
_mintBatch(to, ids, values, data); _mintBatch(to, ids, values, data);
} }
function burn(address owner, uint256 id, uint256 value) public { function burn(
address owner,
uint256 id,
uint256 value
) public {
_burn(owner, id, value); _burn(owner, id, value);
} }
function burnBatch(address owner, uint256[] memory ids, uint256[] memory values) public { function burnBatch(
address owner,
uint256[] memory ids,
uint256[] memory values
) public {
_burnBatch(owner, ids, values); _burnBatch(owner, ids, values);
} }
} }
...@@ -6,7 +6,7 @@ import "./ERC1155Mock.sol"; ...@@ -6,7 +6,7 @@ import "./ERC1155Mock.sol";
import "../token/ERC1155/extensions/ERC1155Pausable.sol"; import "../token/ERC1155/extensions/ERC1155Pausable.sol";
contract ERC1155PausableMock is ERC1155Mock, ERC1155Pausable { contract ERC1155PausableMock is ERC1155Mock, ERC1155Pausable {
constructor(string memory uri) ERC1155Mock(uri) { } constructor(string memory uri) ERC1155Mock(uri) {}
function pause() external { function pause() external {
_pause(); _pause();
...@@ -23,9 +23,7 @@ contract ERC1155PausableMock is ERC1155Mock, ERC1155Pausable { ...@@ -23,9 +23,7 @@ contract ERC1155PausableMock is ERC1155Mock, ERC1155Pausable {
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) ) internal virtual override(ERC1155, ERC1155Pausable) {
internal virtual override(ERC1155, ERC1155Pausable)
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
} }
} }
...@@ -14,13 +14,12 @@ contract ERC1155ReceiverMock is IERC1155Receiver, ERC165 { ...@@ -14,13 +14,12 @@ contract ERC1155ReceiverMock is IERC1155Receiver, ERC165 {
event Received(address operator, address from, uint256 id, uint256 value, bytes data, uint256 gas); event Received(address operator, address from, uint256 id, uint256 value, bytes data, uint256 gas);
event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data, uint256 gas); event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data, uint256 gas);
constructor ( constructor(
bytes4 recRetval, bytes4 recRetval,
bool recReverts, bool recReverts,
bytes4 batRetval, bytes4 batRetval,
bool batReverts bool batReverts
) ) {
{
_recRetval = recRetval; _recRetval = recRetval;
_recReverts = recReverts; _recReverts = recReverts;
_batRetval = batRetval; _batRetval = batRetval;
...@@ -33,11 +32,7 @@ contract ERC1155ReceiverMock is IERC1155Receiver, ERC165 { ...@@ -33,11 +32,7 @@ contract ERC1155ReceiverMock is IERC1155Receiver, ERC165 {
uint256 id, uint256 id,
uint256 value, uint256 value,
bytes calldata data bytes calldata data
) ) external override returns (bytes4) {
external
override
returns(bytes4)
{
require(!_recReverts, "ERC1155ReceiverMock: reverting on receive"); require(!_recReverts, "ERC1155ReceiverMock: reverting on receive");
emit Received(operator, from, id, value, data, gasleft()); emit Received(operator, from, id, value, data, gasleft());
return _recRetval; return _recRetval;
...@@ -49,11 +44,7 @@ contract ERC1155ReceiverMock is IERC1155Receiver, ERC165 { ...@@ -49,11 +44,7 @@ contract ERC1155ReceiverMock is IERC1155Receiver, ERC165 {
uint256[] calldata ids, uint256[] calldata ids,
uint256[] calldata values, uint256[] calldata values,
bytes calldata data bytes calldata data
) ) external override returns (bytes4) {
external
override
returns(bytes4)
{
require(!_batReverts, "ERC1155ReceiverMock: reverting on batch receive"); require(!_batReverts, "ERC1155ReceiverMock: reverting on batch receive");
emit BatchReceived(operator, from, ids, values, data, gasleft()); emit BatchReceived(operator, from, ids, values, data, gasleft());
return _batRetval; return _batRetval;
......
...@@ -6,21 +6,39 @@ import "./ERC1155Mock.sol"; ...@@ -6,21 +6,39 @@ import "./ERC1155Mock.sol";
import "../token/ERC1155/extensions/ERC1155Supply.sol"; import "../token/ERC1155/extensions/ERC1155Supply.sol";
contract ERC1155SupplyMock is ERC1155Mock, ERC1155Supply { contract ERC1155SupplyMock is ERC1155Mock, ERC1155Supply {
constructor(string memory uri) ERC1155Mock(uri) { } constructor(string memory uri) ERC1155Mock(uri) {}
function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual override(ERC1155, ERC1155Supply) { function _mint(
address account,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual override(ERC1155, ERC1155Supply) {
super._mint(account, id, amount, data); super._mint(account, id, amount, data);
} }
function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual override(ERC1155, ERC1155Supply) { function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Supply) {
super._mintBatch(to, ids, amounts, data); super._mintBatch(to, ids, amounts, data);
} }
function _burn(address account, uint256 id, uint256 amount) internal virtual override(ERC1155, ERC1155Supply) { function _burn(
address account,
uint256 id,
uint256 amount
) internal virtual override(ERC1155, ERC1155Supply) {
super._burn(account, id, amount); super._burn(account, id, amount);
} }
function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual override(ERC1155, ERC1155Supply) { function _burnBatch(
address account,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual override(ERC1155, ERC1155Supply) {
super._burnBatch(account, ids, amounts); super._burnBatch(account, ids, amounts);
} }
} }
...@@ -29,7 +29,7 @@ contract SupportsInterfaceWithLookupMock is IERC165 { ...@@ -29,7 +29,7 @@ contract SupportsInterfaceWithLookupMock is IERC165 {
* @dev A contract implementing SupportsInterfaceWithLookup * @dev A contract implementing SupportsInterfaceWithLookup
* implement ERC165 itself. * implement ERC165 itself.
*/ */
constructor () { constructor() {
_registerInterface(INTERFACE_ID_ERC165); _registerInterface(INTERFACE_ID_ERC165);
} }
...@@ -50,7 +50,7 @@ contract SupportsInterfaceWithLookupMock is IERC165 { ...@@ -50,7 +50,7 @@ contract SupportsInterfaceWithLookupMock is IERC165 {
} }
contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock { contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock {
constructor (bytes4[] memory interfaceIds) { constructor(bytes4[] memory interfaceIds) {
for (uint256 i = 0; i < interfaceIds.length; i++) { for (uint256 i = 0; i < interfaceIds.length; i++) {
_registerInterface(interfaceIds[i]); _registerInterface(interfaceIds[i]);
} }
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
contract ERC165NotSupported { } contract ERC165NotSupported {}
...@@ -4,5 +4,4 @@ pragma solidity ^0.8.0; ...@@ -4,5 +4,4 @@ pragma solidity ^0.8.0;
import "../utils/introspection/ERC165.sol"; import "../utils/introspection/ERC165.sol";
contract ERC165Mock is ERC165 { contract ERC165Mock is ERC165 {}
}
...@@ -5,7 +5,7 @@ pragma solidity ^0.8.0; ...@@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
import "../token/ERC20/extensions/ERC20Burnable.sol"; import "../token/ERC20/extensions/ERC20Burnable.sol";
contract ERC20BurnableMock is ERC20Burnable { contract ERC20BurnableMock is ERC20Burnable {
constructor ( constructor(
string memory name, string memory name,
string memory symbol, string memory symbol,
address initialAccount, address initialAccount,
......
...@@ -5,9 +5,11 @@ pragma solidity ^0.8.0; ...@@ -5,9 +5,11 @@ pragma solidity ^0.8.0;
import "../token/ERC20/extensions/ERC20Capped.sol"; import "../token/ERC20/extensions/ERC20Capped.sol";
contract ERC20CappedMock is ERC20Capped { contract ERC20CappedMock is ERC20Capped {
constructor (string memory name, string memory symbol, uint256 cap) constructor(
ERC20(name, symbol) ERC20Capped(cap) string memory name,
{ } string memory symbol,
uint256 cap
) ERC20(name, symbol) ERC20Capped(cap) {}
function mint(address to, uint256 tokenId) public { function mint(address to, uint256 tokenId) public {
_mint(to, tokenId); _mint(to, tokenId);
......
...@@ -5,9 +5,13 @@ pragma solidity ^0.8.0; ...@@ -5,9 +5,13 @@ pragma solidity ^0.8.0;
import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20.sol";
contract ERC20DecimalsMock is ERC20 { contract ERC20DecimalsMock is ERC20 {
uint8 immutable private _decimals; uint8 private immutable _decimals;
constructor (string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) { constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) ERC20(name_, symbol_) {
_decimals = decimals_; _decimals = decimals_;
} }
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/extensions/ERC20FlashMint.sol"; import "../token/ERC20/extensions/ERC20FlashMint.sol";
contract ERC20FlashMintMock is ERC20FlashMint { contract ERC20FlashMintMock is ERC20FlashMint {
constructor ( constructor(
string memory name, string memory name,
string memory symbol, string memory symbol,
address initialAccount, address initialAccount,
......
...@@ -6,7 +6,7 @@ import "../token/ERC20/ERC20.sol"; ...@@ -6,7 +6,7 @@ import "../token/ERC20/ERC20.sol";
// mock class using ERC20 // mock class using ERC20
contract ERC20Mock is ERC20 { contract ERC20Mock is ERC20 {
constructor ( constructor(
string memory name, string memory name,
string memory symbol, string memory symbol,
address initialAccount, address initialAccount,
...@@ -23,11 +23,19 @@ contract ERC20Mock is ERC20 { ...@@ -23,11 +23,19 @@ contract ERC20Mock is ERC20 {
_burn(account, amount); _burn(account, amount);
} }
function transferInternal(address from, address to, uint256 value) public { function transferInternal(
address from,
address to,
uint256 value
) public {
_transfer(from, to, value); _transfer(from, to, value);
} }
function approveInternal(address owner, address spender, uint256 value) public { function approveInternal(
address owner,
address spender,
uint256 value
) public {
_approve(owner, spender, value); _approve(owner, spender, value);
} }
} }
...@@ -6,7 +6,7 @@ import "../token/ERC20/extensions/ERC20Pausable.sol"; ...@@ -6,7 +6,7 @@ import "../token/ERC20/extensions/ERC20Pausable.sol";
// mock class using ERC20Pausable // mock class using ERC20Pausable
contract ERC20PausableMock is ERC20Pausable { contract ERC20PausableMock is ERC20Pausable {
constructor ( constructor(
string memory name, string memory name,
string memory symbol, string memory symbol,
address initialAccount, address initialAccount,
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/extensions/draft-ERC20Permit.sol"; import "../token/ERC20/extensions/draft-ERC20Permit.sol";
contract ERC20PermitMock is ERC20Permit { contract ERC20PermitMock is ERC20Permit {
constructor ( constructor(
string memory name, string memory name,
string memory symbol, string memory symbol,
address initialAccount, address initialAccount,
......
...@@ -4,7 +4,6 @@ pragma solidity ^0.8.0; ...@@ -4,7 +4,6 @@ pragma solidity ^0.8.0;
import "../token/ERC20/extensions/ERC20Snapshot.sol"; import "../token/ERC20/extensions/ERC20Snapshot.sol";
contract ERC20SnapshotMock is ERC20Snapshot { contract ERC20SnapshotMock is ERC20Snapshot {
constructor( constructor(
string memory name, string memory name,
......
...@@ -2,14 +2,10 @@ ...@@ -2,14 +2,10 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/extensions/ERC20VotesComp.sol"; import "../token/ERC20/extensions/ERC20VotesComp.sol";
contract ERC20VotesCompMock is ERC20VotesComp { contract ERC20VotesCompMock is ERC20VotesComp {
constructor (string memory name, string memory symbol) constructor(string memory name, string memory symbol) ERC20(name, symbol) ERC20Permit(name) {}
ERC20(name, symbol)
ERC20Permit(name)
{}
function mint(address account, uint256 amount) public { function mint(address account, uint256 amount) public {
_mint(account, amount); _mint(account, amount);
......
...@@ -2,14 +2,10 @@ ...@@ -2,14 +2,10 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/extensions/ERC20Votes.sol"; import "../token/ERC20/extensions/ERC20Votes.sol";
contract ERC20VotesMock is ERC20Votes { contract ERC20VotesMock is ERC20Votes {
constructor (string memory name, string memory symbol) constructor(string memory name, string memory symbol) ERC20(name, symbol) ERC20Permit(name) {}
ERC20(name, symbol)
ERC20Permit(name)
{}
function mint(address account, uint256 amount) public { function mint(address account, uint256 amount) public {
_mint(account, amount); _mint(account, amount);
......
...@@ -9,11 +9,11 @@ import "../metatx/ERC2771Context.sol"; ...@@ -9,11 +9,11 @@ import "../metatx/ERC2771Context.sol";
contract ERC2771ContextMock is ContextMock, ERC2771Context { contract ERC2771ContextMock is ContextMock, ERC2771Context {
constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {} constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {}
function _msgSender() internal override(Context, ERC2771Context) view virtual returns (address) { function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address) {
return ERC2771Context._msgSender(); return ERC2771Context._msgSender();
} }
function _msgData() internal override(Context, ERC2771Context) view virtual returns (bytes calldata) { function _msgData() internal view virtual override(Context, ERC2771Context) returns (bytes calldata) {
return ERC2771Context._msgData(); return ERC2771Context._msgData();
} }
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../interfaces/IERC3156.sol"; import "../interfaces/IERC3156.sol";
import "../utils/Address.sol"; import "../utils/Address.sol";
...@@ -15,7 +14,7 @@ import "../utils/Address.sol"; ...@@ -15,7 +14,7 @@ import "../utils/Address.sol";
* live networks. * live networks.
*/ */
contract ERC3156FlashBorrowerMock is IERC3156FlashBorrower { contract ERC3156FlashBorrowerMock is IERC3156FlashBorrower {
bytes32 constant internal RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan"); bytes32 internal constant _RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");
bool immutable _enableApprove; bool immutable _enableApprove;
bool immutable _enableReturn; bool immutable _enableReturn;
...@@ -29,7 +28,7 @@ contract ERC3156FlashBorrowerMock is IERC3156FlashBorrower { ...@@ -29,7 +28,7 @@ contract ERC3156FlashBorrowerMock is IERC3156FlashBorrower {
} }
function onFlashLoan( function onFlashLoan(
address /*initiator*/, address, /*initiator*/
address token, address token,
uint256 amount, uint256 amount,
uint256 fee, uint256 fee,
...@@ -49,6 +48,6 @@ contract ERC3156FlashBorrowerMock is IERC3156FlashBorrower { ...@@ -49,6 +48,6 @@ contract ERC3156FlashBorrowerMock is IERC3156FlashBorrower {
IERC20(token).approve(token, amount + fee); IERC20(token).approve(token, amount + fee);
} }
return _enableReturn ? RETURN_VALUE : bytes32(0); return _enableReturn ? _RETURN_VALUE : bytes32(0);
} }
} }
...@@ -5,7 +5,7 @@ pragma solidity ^0.8.0; ...@@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
import "../token/ERC721/extensions/ERC721Burnable.sol"; import "../token/ERC721/extensions/ERC721Burnable.sol";
contract ERC721BurnableMock is ERC721Burnable { contract ERC721BurnableMock is ERC721Burnable {
constructor(string memory name, string memory symbol) ERC721(name, symbol) { } constructor(string memory name, string memory symbol) ERC721(name, symbol) {}
function exists(uint256 tokenId) public view returns (bool) { function exists(uint256 tokenId) public view returns (bool) {
return _exists(tokenId); return _exists(tokenId);
...@@ -19,7 +19,11 @@ contract ERC721BurnableMock is ERC721Burnable { ...@@ -19,7 +19,11 @@ contract ERC721BurnableMock is ERC721Burnable {
_safeMint(to, tokenId); _safeMint(to, tokenId);
} }
function safeMint(address to, uint256 tokenId, bytes memory _data) public { function safeMint(
address to,
uint256 tokenId,
bytes memory _data
) public {
_safeMint(to, tokenId, _data); _safeMint(to, tokenId, _data);
} }
} }
...@@ -11,7 +11,7 @@ import "../token/ERC721/extensions/ERC721Enumerable.sol"; ...@@ -11,7 +11,7 @@ import "../token/ERC721/extensions/ERC721Enumerable.sol";
contract ERC721EnumerableMock is ERC721Enumerable { contract ERC721EnumerableMock is ERC721Enumerable {
string private _baseTokenURI; string private _baseTokenURI;
constructor (string memory name, string memory symbol) ERC721(name, symbol) { } constructor(string memory name, string memory symbol) ERC721(name, symbol) {}
function _baseURI() internal view virtual override returns (string memory) { function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI; return _baseTokenURI;
...@@ -37,7 +37,11 @@ contract ERC721EnumerableMock is ERC721Enumerable { ...@@ -37,7 +37,11 @@ contract ERC721EnumerableMock is ERC721Enumerable {
_safeMint(to, tokenId); _safeMint(to, tokenId);
} }
function safeMint(address to, uint256 tokenId, bytes memory _data) public { function safeMint(
address to,
uint256 tokenId,
bytes memory _data
) public {
_safeMint(to, tokenId, _data); _safeMint(to, tokenId, _data);
} }
......
...@@ -9,7 +9,7 @@ import "../token/ERC721/ERC721.sol"; ...@@ -9,7 +9,7 @@ import "../token/ERC721/ERC721.sol";
* This mock just provides a public safeMint, mint, and burn functions for testing purposes * This mock just provides a public safeMint, mint, and burn functions for testing purposes
*/ */
contract ERC721Mock is ERC721 { contract ERC721Mock is ERC721 {
constructor (string memory name, string memory symbol) ERC721(name, symbol) { } constructor(string memory name, string memory symbol) ERC721(name, symbol) {}
function baseURI() public view returns (string memory) { function baseURI() public view returns (string memory) {
return _baseURI(); return _baseURI();
...@@ -27,7 +27,11 @@ contract ERC721Mock is ERC721 { ...@@ -27,7 +27,11 @@ contract ERC721Mock is ERC721 {
_safeMint(to, tokenId); _safeMint(to, tokenId);
} }
function safeMint(address to, uint256 tokenId, bytes memory _data) public { function safeMint(
address to,
uint256 tokenId,
bytes memory _data
) public {
_safeMint(to, tokenId, _data); _safeMint(to, tokenId, _data);
} }
......
...@@ -9,7 +9,7 @@ import "../token/ERC721/extensions/ERC721Pausable.sol"; ...@@ -9,7 +9,7 @@ import "../token/ERC721/extensions/ERC721Pausable.sol";
* This mock just provides a public mint, burn and exists functions for testing purposes * This mock just provides a public mint, burn and exists functions for testing purposes
*/ */
contract ERC721PausableMock is ERC721Pausable { contract ERC721PausableMock is ERC721Pausable {
constructor (string memory name, string memory symbol) ERC721(name, symbol) { } constructor(string memory name, string memory symbol) ERC721(name, symbol) {}
function pause() external { function pause() external {
_pause(); _pause();
...@@ -31,7 +31,11 @@ contract ERC721PausableMock is ERC721Pausable { ...@@ -31,7 +31,11 @@ contract ERC721PausableMock is ERC721Pausable {
_safeMint(to, tokenId); _safeMint(to, tokenId);
} }
function safeMint(address to, uint256 tokenId, bytes memory _data) public { function safeMint(
address to,
uint256 tokenId,
bytes memory _data
) public {
_safeMint(to, tokenId, _data); _safeMint(to, tokenId, _data);
} }
......
...@@ -17,14 +17,17 @@ contract ERC721ReceiverMock is IERC721Receiver { ...@@ -17,14 +17,17 @@ contract ERC721ReceiverMock is IERC721Receiver {
event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas); event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas);
constructor (bytes4 retval, Error error) { constructor(bytes4 retval, Error error) {
_retval = retval; _retval = retval;
_error = error; _error = error;
} }
function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data) function onERC721Received(
public override returns (bytes4) address operator,
{ address from,
uint256 tokenId,
bytes memory data
) public override returns (bytes4) {
if (_error == Error.RevertWithMessage) { if (_error == Error.RevertWithMessage) {
revert("ERC721ReceiverMock: reverting"); revert("ERC721ReceiverMock: reverting");
} else if (_error == Error.RevertWithoutMessage) { } else if (_error == Error.RevertWithoutMessage) {
......
...@@ -11,7 +11,7 @@ import "../token/ERC721/extensions/ERC721URIStorage.sol"; ...@@ -11,7 +11,7 @@ import "../token/ERC721/extensions/ERC721URIStorage.sol";
contract ERC721URIStorageMock is ERC721URIStorage { contract ERC721URIStorageMock is ERC721URIStorage {
string private _baseTokenURI; string private _baseTokenURI;
constructor (string memory name, string memory symbol) ERC721(name, symbol) { } constructor(string memory name, string memory symbol) ERC721(name, symbol) {}
function _baseURI() internal view virtual override returns (string memory) { function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI; return _baseTokenURI;
...@@ -41,7 +41,11 @@ contract ERC721URIStorageMock is ERC721URIStorage { ...@@ -41,7 +41,11 @@ contract ERC721URIStorageMock is ERC721URIStorage {
_safeMint(to, tokenId); _safeMint(to, tokenId);
} }
function safeMint(address to, uint256 tokenId, bytes memory _data) public { function safeMint(
address to,
uint256 tokenId,
bytes memory _data
) public {
_safeMint(to, tokenId, _data); _safeMint(to, tokenId, _data);
} }
......
...@@ -18,7 +18,7 @@ contract ERC777Mock is Context, ERC777 { ...@@ -18,7 +18,7 @@ contract ERC777Mock is Context, ERC777 {
_mint(initialHolder, initialBalance, "", ""); _mint(initialHolder, initialBalance, "", "");
} }
function mintInternal ( function mintInternal(
address to, address to,
uint256 amount, uint256 amount,
bytes memory userData, bytes memory userData,
...@@ -27,7 +27,7 @@ contract ERC777Mock is Context, ERC777 { ...@@ -27,7 +27,7 @@ contract ERC777Mock is Context, ERC777 {
_mint(to, amount, userData, operatorData); _mint(to, amount, userData, operatorData);
} }
function mintInternalExtended ( function mintInternalExtended(
address to, address to,
uint256 amount, uint256 amount,
bytes memory userData, bytes memory userData,
...@@ -37,11 +37,20 @@ contract ERC777Mock is Context, ERC777 { ...@@ -37,11 +37,20 @@ contract ERC777Mock is Context, ERC777 {
_mint(to, amount, userData, operatorData, requireReceptionAck); _mint(to, amount, userData, operatorData, requireReceptionAck);
} }
function approveInternal(address holder, address spender, uint256 value) public { function approveInternal(
address holder,
address spender,
uint256 value
) public {
_approve(holder, spender, value); _approve(holder, spender, value);
} }
function _beforeTokenTransfer(address, address, address, uint256) internal override { function _beforeTokenTransfer(
address,
address,
address,
uint256
) internal override {
emit BeforeTokenTransfer(); emit BeforeTokenTransfer();
} }
} }
...@@ -42,8 +42,8 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient, ...@@ -42,8 +42,8 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
IERC1820Registry private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24); IERC1820Registry private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
bytes32 constant private _TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender"); bytes32 private constant _TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
bytes32 constant private _TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient"); bytes32 private constant _TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
function tokensToSend( function tokensToSend(
address operator, address operator,
...@@ -141,12 +141,21 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient, ...@@ -141,12 +141,21 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
_shouldRevertReceive = shouldRevert; _shouldRevertReceive = shouldRevert;
} }
function send(IERC777 token, address to, uint256 amount, bytes memory data) public { function send(
IERC777 token,
address to,
uint256 amount,
bytes memory data
) public {
// This is 777's send function, not the Solidity send function // This is 777's send function, not the Solidity send function
token.send(to, amount, data); // solhint-disable-line check-send-result token.send(to, amount, data); // solhint-disable-line check-send-result
} }
function burn(IERC777 token, uint256 amount, bytes memory data) public { function burn(
IERC777 token,
uint256 amount,
bytes memory data
) public {
token.burn(amount, data); token.burn(amount, data);
} }
} }
...@@ -33,7 +33,6 @@ contract EnumerableMapMock { ...@@ -33,7 +33,6 @@ contract EnumerableMapMock {
return _map.at(index); return _map.at(index);
} }
function tryGet(uint256 key) public view returns (bool, address) { function tryGet(uint256 key) public view returns (bool, address) {
return _map.tryGet(key); return _map.tryGet(key);
} }
......
...@@ -9,7 +9,7 @@ contract EtherReceiverMock { ...@@ -9,7 +9,7 @@ contract EtherReceiverMock {
_acceptEther = acceptEther; _acceptEther = acceptEther;
} }
receive () external payable { receive() external payable {
if (!_acceptEther) { if (!_acceptEther) {
revert(); revert();
} }
......
...@@ -9,28 +9,26 @@ import "../proxy/utils/Initializable.sol"; ...@@ -9,28 +9,26 @@ import "../proxy/utils/Initializable.sol";
* @dev This contract is a mock to test initializable functionality * @dev This contract is a mock to test initializable functionality
*/ */
contract InitializableMock is Initializable { contract InitializableMock is Initializable {
bool public initializerRan;
uint256 public x;
bool public initializerRan; function initialize() public initializer {
uint256 public x; initializerRan = true;
}
function initialize() public initializer { function initializeNested() public initializer {
initializerRan = true; initialize();
} }
function initializeNested() public initializer { function initializeWithX(uint256 _x) public payable initializer {
initialize(); x = _x;
} }
function initializeWithX(uint256 _x) public payable initializer { function nonInitializable(uint256 _x) public payable {
x = _x; x = _x;
} }
function nonInitializable(uint256 _x) public payable {
x = _x;
}
function fail() public pure {
require(false, "InitializableMock forced failure");
}
function fail() public pure {
require(false, "InitializableMock forced failure");
}
} }
...@@ -5,7 +5,11 @@ pragma solidity ^0.8.0; ...@@ -5,7 +5,11 @@ pragma solidity ^0.8.0;
import "../utils/cryptography/MerkleProof.sol"; import "../utils/cryptography/MerkleProof.sol";
contract MerkleProofWrapper { contract MerkleProofWrapper {
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) public pure returns (bool) { function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) public pure returns (bool) {
return MerkleProof.verify(proof, root, leaf); return MerkleProof.verify(proof, root, leaf);
} }
} }
...@@ -5,14 +5,18 @@ pragma solidity ^0.8.0; ...@@ -5,14 +5,18 @@ pragma solidity ^0.8.0;
import "./MulticallTokenMock.sol"; import "./MulticallTokenMock.sol";
contract MulticallTest { contract MulticallTest {
function testReturnValues(MulticallTokenMock multicallToken, address[] calldata recipients, uint256[] calldata amounts) external { function testReturnValues(
MulticallTokenMock multicallToken,
address[] calldata recipients,
uint256[] calldata amounts
) external {
bytes[] memory calls = new bytes[](recipients.length); bytes[] memory calls = new bytes[](recipients.length);
for (uint i = 0; i < recipients.length; i++) { for (uint256 i = 0; i < recipients.length; i++) {
calls[i] = abi.encodeWithSignature("transfer(address,uint256)", recipients[i], amounts[i]); calls[i] = abi.encodeWithSignature("transfer(address,uint256)", recipients[i], amounts[i]);
} }
bytes[] memory results = multicallToken.multicall(calls); bytes[] memory results = multicallToken.multicall(calls);
for (uint i = 0; i < results.length; i++) { for (uint256 i = 0; i < results.length; i++) {
require(abi.decode(results[i], (bool))); require(abi.decode(results[i], (bool)));
} }
} }
......
...@@ -6,5 +6,5 @@ import "../utils/Multicall.sol"; ...@@ -6,5 +6,5 @@ import "../utils/Multicall.sol";
import "./ERC20Mock.sol"; import "./ERC20Mock.sol";
contract MulticallTokenMock is ERC20Mock, Multicall { contract MulticallTokenMock is ERC20Mock, Multicall {
constructor (uint256 initialBalance) ERC20Mock("MulticallToken", "BCT", msg.sender, initialBalance) {} constructor(uint256 initialBalance) ERC20Mock("MulticallToken", "BCT", msg.sender, initialBalance) {}
} }
...@@ -19,58 +19,63 @@ import "../proxy/utils/Initializable.sol"; ...@@ -19,58 +19,63 @@ import "../proxy/utils/Initializable.sol";
* Sample base intializable contract that is a human * Sample base intializable contract that is a human
*/ */
contract SampleHuman is Initializable { contract SampleHuman is Initializable {
bool public isHuman; bool public isHuman;
function initialize() public initializer { function initialize() public initializer {
isHuman = true; isHuman = true;
} }
} }
/** /**
* Sample base intializable contract that defines a field mother * Sample base intializable contract that defines a field mother
*/ */
contract SampleMother is Initializable, SampleHuman { contract SampleMother is Initializable, SampleHuman {
uint256 public mother; uint256 public mother;
function initialize(uint256 value) public initializer virtual { function initialize(uint256 value) public virtual initializer {
SampleHuman.initialize(); SampleHuman.initialize();
mother = value; mother = value;
} }
} }
/** /**
* Sample base intializable contract that defines a field gramps * Sample base intializable contract that defines a field gramps
*/ */
contract SampleGramps is Initializable, SampleHuman { contract SampleGramps is Initializable, SampleHuman {
string public gramps; string public gramps;
function initialize(string memory value) public initializer virtual { function initialize(string memory value) public virtual initializer {
SampleHuman.initialize(); SampleHuman.initialize();
gramps = value; gramps = value;
} }
} }
/** /**
* Sample base intializable contract that defines a field father and extends from gramps * Sample base intializable contract that defines a field father and extends from gramps
*/ */
contract SampleFather is Initializable, SampleGramps { contract SampleFather is Initializable, SampleGramps {
uint256 public father; uint256 public father;
function initialize(string memory _gramps, uint256 _father) public initializer { function initialize(string memory _gramps, uint256 _father) public initializer {
SampleGramps.initialize(_gramps); SampleGramps.initialize(_gramps);
father = _father; father = _father;
} }
} }
/** /**
* Child extends from mother, father (gramps) * Child extends from mother, father (gramps)
*/ */
contract SampleChild is Initializable, SampleMother, SampleFather { contract SampleChild is Initializable, SampleMother, SampleFather {
uint256 public child; uint256 public child;
function initialize(uint256 _mother, string memory _gramps, uint256 _father, uint256 _child) public initializer { function initialize(
SampleMother.initialize(_mother); uint256 _mother,
SampleFather.initialize(_gramps, _father); string memory _gramps,
child = _child; uint256 _father,
} uint256 _child
) public initializer {
SampleMother.initialize(_mother);
SampleFather.initialize(_gramps, _father);
child = _child;
}
} }
...@@ -4,4 +4,4 @@ pragma solidity ^0.8.0; ...@@ -4,4 +4,4 @@ pragma solidity ^0.8.0;
import "../access/Ownable.sol"; import "../access/Ownable.sol";
contract OwnableMock is Ownable { } contract OwnableMock is Ownable {}
...@@ -8,7 +8,7 @@ contract PausableMock is Pausable { ...@@ -8,7 +8,7 @@ contract PausableMock is Pausable {
bool public drasticMeasureTaken; bool public drasticMeasureTaken;
uint256 public count; uint256 public count;
constructor () { constructor() {
drasticMeasureTaken = false; drasticMeasureTaken = false;
count = 0; count = 0;
} }
......
...@@ -6,7 +6,7 @@ import "../security/PullPayment.sol"; ...@@ -6,7 +6,7 @@ import "../security/PullPayment.sol";
// mock class using PullPayment // mock class using PullPayment
contract PullPaymentMock is PullPayment { contract PullPaymentMock is PullPayment {
constructor () payable { } constructor() payable {}
// test helper function to call asyncTransfer // test helper function to call asyncTransfer
function callTransfer(address dest, uint256 amount) public { function callTransfer(address dest, uint256 amount) public {
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/Context.sol"; import "../utils/Context.sol";
contract ReentrancyAttack is Context { contract ReentrancyAttack is Context {
function callSender(bytes4 data) public { function callSender(bytes4 data) public {
// solhint-disable-next-line avoid-low-level-calls (bool success, ) = _msgSender().call(abi.encodeWithSelector(data));
(bool success,) = _msgSender().call(abi.encodeWithSelector(data));
require(success, "ReentrancyAttack: failed call"); require(success, "ReentrancyAttack: failed call");
} }
} }
...@@ -8,7 +8,7 @@ import "./ReentrancyAttack.sol"; ...@@ -8,7 +8,7 @@ import "./ReentrancyAttack.sol";
contract ReentrancyMock is ReentrancyGuard { contract ReentrancyMock is ReentrancyGuard {
uint256 public counter; uint256 public counter;
constructor () { constructor() {
counter = 0; counter = 0;
} }
...@@ -26,8 +26,7 @@ contract ReentrancyMock is ReentrancyGuard { ...@@ -26,8 +26,7 @@ contract ReentrancyMock is ReentrancyGuard {
function countThisRecursive(uint256 n) public nonReentrant { function countThisRecursive(uint256 n) public nonReentrant {
if (n > 0) { if (n > 0) {
_count(); _count();
// solhint-disable-next-line avoid-low-level-calls (bool success, ) = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1));
(bool success,) = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1));
require(success, "ReentrancyMock: failed call"); require(success, "ReentrancyMock: failed call");
} }
} }
......
...@@ -5,62 +5,57 @@ pragma solidity ^0.8.0; ...@@ -5,62 +5,57 @@ pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol"; import "../proxy/utils/Initializable.sol";
contract Implementation1 is Initializable { contract Implementation1 is Initializable {
uint internal _value; uint256 internal _value;
function initialize() public initializer { function initialize() public initializer {}
}
function setValue(uint _number) public { function setValue(uint256 _number) public {
_value = _number; _value = _number;
} }
} }
contract Implementation2 is Initializable { contract Implementation2 is Initializable {
uint internal _value; uint256 internal _value;
function initialize() public initializer { function initialize() public initializer {}
}
function setValue(uint _number) public { function setValue(uint256 _number) public {
_value = _number; _value = _number;
} }
function getValue() public view returns (uint) { function getValue() public view returns (uint256) {
return _value; return _value;
} }
} }
contract Implementation3 is Initializable { contract Implementation3 is Initializable {
uint internal _value; uint256 internal _value;
function initialize() public initializer { function initialize() public initializer {}
}
function setValue(uint _number) public { function setValue(uint256 _number) public {
_value = _number; _value = _number;
} }
function getValue(uint _number) public view returns (uint) { function getValue(uint256 _number) public view returns (uint256) {
return _value + _number; return _value + _number;
} }
} }
contract Implementation4 is Initializable { contract Implementation4 is Initializable {
uint internal _value; uint256 internal _value;
function initialize() public initializer { function initialize() public initializer {}
}
function setValue(uint _number) public { function setValue(uint256 _number) public {
_value = _number; _value = _number;
} }
function getValue() public view returns (uint) { function getValue() public view returns (uint256) {
return _value; return _value;
} }
// solhint-disable-next-line payable-fallback fallback() external {
fallback() external { _value = 1;
_value = 1; }
}
} }
...@@ -5,62 +5,62 @@ pragma solidity ^0.8.0; ...@@ -5,62 +5,62 @@ pragma solidity ^0.8.0;
import "../utils/math/SafeCast.sol"; import "../utils/math/SafeCast.sol";
contract SafeCastMock { contract SafeCastMock {
using SafeCast for uint; using SafeCast for uint256;
using SafeCast for int; using SafeCast for int256;
function toUint256(int a) public pure returns (uint256) { function toUint256(int256 a) public pure returns (uint256) {
return a.toUint256(); return a.toUint256();
} }
function toUint224(uint a) public pure returns (uint224) { function toUint224(uint256 a) public pure returns (uint224) {
return a.toUint224(); return a.toUint224();
} }
function toUint128(uint a) public pure returns (uint128) { function toUint128(uint256 a) public pure returns (uint128) {
return a.toUint128(); return a.toUint128();
} }
function toUint96(uint a) public pure returns (uint96) { function toUint96(uint256 a) public pure returns (uint96) {
return a.toUint96(); return a.toUint96();
} }
function toUint64(uint a) public pure returns (uint64) { function toUint64(uint256 a) public pure returns (uint64) {
return a.toUint64(); return a.toUint64();
} }
function toUint32(uint a) public pure returns (uint32) { function toUint32(uint256 a) public pure returns (uint32) {
return a.toUint32(); return a.toUint32();
} }
function toUint16(uint a) public pure returns (uint16) { function toUint16(uint256 a) public pure returns (uint16) {
return a.toUint16(); return a.toUint16();
} }
function toUint8(uint a) public pure returns (uint8) { function toUint8(uint256 a) public pure returns (uint8) {
return a.toUint8(); return a.toUint8();
} }
function toInt256(uint a) public pure returns (int256) { function toInt256(uint256 a) public pure returns (int256) {
return a.toInt256(); return a.toInt256();
} }
function toInt128(int a) public pure returns (int128) { function toInt128(int256 a) public pure returns (int128) {
return a.toInt128(); return a.toInt128();
} }
function toInt64(int a) public pure returns (int64) { function toInt64(int256 a) public pure returns (int64) {
return a.toInt64(); return a.toInt64();
} }
function toInt32(int a) public pure returns (int32) { function toInt32(int256 a) public pure returns (int32) {
return a.toInt32(); return a.toInt32();
} }
function toInt16(int a) public pure returns (int16) { function toInt16(int256 a) public pure returns (int16) {
return a.toInt16(); return a.toInt16();
} }
function toInt8(int a) public pure returns (int8) { function toInt8(int256 a) public pure returns (int8) {
return a.toInt8(); return a.toInt8();
} }
} }
...@@ -18,7 +18,11 @@ contract ERC20ReturnFalseMock is Context { ...@@ -18,7 +18,11 @@ contract ERC20ReturnFalseMock is Context {
return false; return false;
} }
function transferFrom(address, address, uint256) public returns (bool) { function transferFrom(
address,
address,
uint256
) public returns (bool) {
_dummy = 0; _dummy = 0;
return false; return false;
} }
...@@ -35,7 +39,7 @@ contract ERC20ReturnFalseMock is Context { ...@@ -35,7 +39,7 @@ contract ERC20ReturnFalseMock is Context {
} }
contract ERC20ReturnTrueMock is Context { contract ERC20ReturnTrueMock is Context {
mapping (address => uint256) private _allowances; mapping(address => uint256) private _allowances;
// IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings, // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
// we write to a dummy state variable. // we write to a dummy state variable.
...@@ -46,7 +50,11 @@ contract ERC20ReturnTrueMock is Context { ...@@ -46,7 +50,11 @@ contract ERC20ReturnTrueMock is Context {
return true; return true;
} }
function transferFrom(address, address, uint256) public returns (bool) { function transferFrom(
address,
address,
uint256
) public returns (bool) {
_dummy = 0; _dummy = 0;
return true; return true;
} }
...@@ -66,7 +74,7 @@ contract ERC20ReturnTrueMock is Context { ...@@ -66,7 +74,7 @@ contract ERC20ReturnTrueMock is Context {
} }
contract ERC20NoReturnMock is Context { contract ERC20NoReturnMock is Context {
mapping (address => uint256) private _allowances; mapping(address => uint256) private _allowances;
// IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings, // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
// we write to a dummy state variable. // we write to a dummy state variable.
...@@ -76,7 +84,11 @@ contract ERC20NoReturnMock is Context { ...@@ -76,7 +84,11 @@ contract ERC20NoReturnMock is Context {
_dummy = 0; _dummy = 0;
} }
function transferFrom(address, address, uint256) public { function transferFrom(
address,
address,
uint256
) public {
_dummy = 0; _dummy = 0;
} }
...@@ -98,7 +110,7 @@ contract SafeERC20Wrapper is Context { ...@@ -98,7 +110,7 @@ contract SafeERC20Wrapper is Context {
IERC20 private _token; IERC20 private _token;
constructor (IERC20 token) { constructor(IERC20 token) {
_token = token; _token = token;
} }
......
...@@ -47,61 +47,92 @@ contract SafeMathMock { ...@@ -47,61 +47,92 @@ contract SafeMathMock {
return SafeMath.mod(a, b); return SafeMath.mod(a, b);
} }
function subWithMessage(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { function subWithMessage(
uint256 a,
uint256 b,
string memory errorMessage
) public pure returns (uint256) {
return SafeMath.sub(a, b, errorMessage); return SafeMath.sub(a, b, errorMessage);
} }
function divWithMessage(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { function divWithMessage(
uint256 a,
uint256 b,
string memory errorMessage
) public pure returns (uint256) {
return SafeMath.div(a, b, errorMessage); return SafeMath.div(a, b, errorMessage);
} }
function modWithMessage(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { function modWithMessage(
uint256 a,
uint256 b,
string memory errorMessage
) public pure returns (uint256) {
return SafeMath.mod(a, b, errorMessage); return SafeMath.mod(a, b, errorMessage);
} }
function addMemoryCheck() public pure returns (uint256 mem) { function addMemoryCheck() public pure returns (uint256 mem) {
uint256 length = 32; uint256 length = 32;
// solhint-disable-next-line no-inline-assembly assembly {
assembly { mem := mload(0x40) } mem := mload(0x40)
for (uint256 i = 0; i < length; ++i) { SafeMath.add(1, 1); } }
// solhint-disable-next-line no-inline-assembly for (uint256 i = 0; i < length; ++i) {
assembly { mem := sub(mload(0x40), mem) } SafeMath.add(1, 1);
}
assembly {
mem := sub(mload(0x40), mem)
}
} }
function subMemoryCheck() public pure returns (uint256 mem) { function subMemoryCheck() public pure returns (uint256 mem) {
uint256 length = 32; uint256 length = 32;
// solhint-disable-next-line no-inline-assembly assembly {
assembly { mem := mload(0x40) } mem := mload(0x40)
for (uint256 i = 0; i < length; ++i) { SafeMath.sub(1, 1); } }
// solhint-disable-next-line no-inline-assembly for (uint256 i = 0; i < length; ++i) {
assembly { mem := sub(mload(0x40), mem) } SafeMath.sub(1, 1);
}
assembly {
mem := sub(mload(0x40), mem)
}
} }
function mulMemoryCheck() public pure returns (uint256 mem) { function mulMemoryCheck() public pure returns (uint256 mem) {
uint256 length = 32; uint256 length = 32;
// solhint-disable-next-line no-inline-assembly assembly {
assembly { mem := mload(0x40) } mem := mload(0x40)
for (uint256 i = 0; i < length; ++i) { SafeMath.mul(1, 1); } }
// solhint-disable-next-line no-inline-assembly for (uint256 i = 0; i < length; ++i) {
assembly { mem := sub(mload(0x40), mem) } SafeMath.mul(1, 1);
}
assembly {
mem := sub(mload(0x40), mem)
}
} }
function divMemoryCheck() public pure returns (uint256 mem) { function divMemoryCheck() public pure returns (uint256 mem) {
uint256 length = 32; uint256 length = 32;
// solhint-disable-next-line no-inline-assembly assembly {
assembly { mem := mload(0x40) } mem := mload(0x40)
for (uint256 i = 0; i < length; ++i) { SafeMath.div(1, 1); } }
// solhint-disable-next-line no-inline-assembly for (uint256 i = 0; i < length; ++i) {
assembly { mem := sub(mload(0x40), mem) } SafeMath.div(1, 1);
}
assembly {
mem := sub(mload(0x40), mem)
}
} }
function modMemoryCheck() public pure returns (uint256 mem) { function modMemoryCheck() public pure returns (uint256 mem) {
uint256 length = 32; uint256 length = 32;
// solhint-disable-next-line no-inline-assembly assembly {
assembly { mem := mload(0x40) } mem := mload(0x40)
for (uint256 i = 0; i < length; ++i) { SafeMath.mod(1, 1); } }
// solhint-disable-next-line no-inline-assembly for (uint256 i = 0; i < length; ++i) {
assembly { mem := sub(mload(0x40), mem) } SafeMath.mod(1, 1);
}
assembly {
mem := sub(mload(0x40), mem)
}
} }
} }
...@@ -7,7 +7,11 @@ import "../utils/cryptography/SignatureChecker.sol"; ...@@ -7,7 +7,11 @@ import "../utils/cryptography/SignatureChecker.sol";
contract SignatureCheckerMock { contract SignatureCheckerMock {
using SignatureChecker for address; using SignatureChecker for address;
function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) public view returns (bool) { function isValidSignatureNow(
address signer,
bytes32 hash,
bytes memory signature
) public view returns (bool) {
return signer.isValidSignatureNow(hash, signature); return signer.isValidSignatureNow(hash, signature);
} }
} }
...@@ -9,11 +9,11 @@ import "../proxy/utils/Initializable.sol"; ...@@ -9,11 +9,11 @@ import "../proxy/utils/Initializable.sol";
* @dev This contract is a mock to test initializable functionality through migrations * @dev This contract is a mock to test initializable functionality through migrations
*/ */
contract MigratableMockV1 is Initializable { contract MigratableMockV1 is Initializable {
uint256 public x; uint256 public x;
function initialize(uint256 value) public payable initializer { function initialize(uint256 value) public payable initializer {
x = value; x = value;
} }
} }
/** /**
...@@ -21,15 +21,15 @@ contract MigratableMockV1 is Initializable { ...@@ -21,15 +21,15 @@ contract MigratableMockV1 is Initializable {
* @dev This contract is a mock to test migratable functionality with params * @dev This contract is a mock to test migratable functionality with params
*/ */
contract MigratableMockV2 is MigratableMockV1 { contract MigratableMockV2 is MigratableMockV1 {
bool internal _migratedV2; bool internal _migratedV2;
uint256 public y; uint256 public y;
function migrate(uint256 value, uint256 anotherValue) public payable { function migrate(uint256 value, uint256 anotherValue) public payable {
require(!_migratedV2); require(!_migratedV2);
x = value; x = value;
y = anotherValue; y = anotherValue;
_migratedV2 = true; _migratedV2 = true;
} }
} }
/** /**
...@@ -37,13 +37,13 @@ contract MigratableMockV2 is MigratableMockV1 { ...@@ -37,13 +37,13 @@ contract MigratableMockV2 is MigratableMockV1 {
* @dev This contract is a mock to test migratable functionality without params * @dev This contract is a mock to test migratable functionality without params
*/ */
contract MigratableMockV3 is MigratableMockV2 { contract MigratableMockV3 is MigratableMockV2 {
bool internal _migratedV3; bool internal _migratedV3;
function migrate() public payable { function migrate() public payable {
require(!_migratedV3); require(!_migratedV3);
uint256 oldX = x; uint256 oldX = x;
x = y; x = y;
y = oldX; y = oldX;
_migratedV3 = true; _migratedV3 = true;
} }
} }
...@@ -6,12 +6,36 @@ import "../utils/StorageSlot.sol"; ...@@ -6,12 +6,36 @@ import "../utils/StorageSlot.sol";
contract StorageSlotMock { contract StorageSlotMock {
using StorageSlot for bytes32; using StorageSlot for bytes32;
function setBoolean(bytes32 slot, bool value) public { slot.getBooleanSlot().value = value; }
function setAddress(bytes32 slot, address value) public { slot.getAddressSlot().value = value; } function setBoolean(bytes32 slot, bool value) public {
function setBytes32(bytes32 slot, bytes32 value) public { slot.getBytes32Slot().value = value; } slot.getBooleanSlot().value = value;
function setUint256(bytes32 slot, uint256 value) public { slot.getUint256Slot().value = value; } }
function getBoolean(bytes32 slot) public view returns (bool) { return slot.getBooleanSlot().value; }
function getAddress(bytes32 slot) public view returns (address) { return slot.getAddressSlot().value; } function setAddress(bytes32 slot, address value) public {
function getBytes32(bytes32 slot) public view returns (bytes32) { return slot.getBytes32Slot().value; } slot.getAddressSlot().value = value;
function getUint256(bytes32 slot) public view returns (uint256) { return slot.getUint256Slot().value; } }
function setBytes32(bytes32 slot, bytes32 value) public {
slot.getBytes32Slot().value = value;
}
function setUint256(bytes32 slot, uint256 value) public {
slot.getUint256Slot().value = value;
}
function getBoolean(bytes32 slot) public view returns (bool) {
return slot.getBooleanSlot().value;
}
function getAddress(bytes32 slot) public view returns (address) {
return slot.getAddressSlot().value;
}
function getBytes32(bytes32 slot) public view returns (bytes32) {
return slot.getBytes32Slot().value;
}
function getUint256(bytes32 slot) public view returns (uint256) {
return slot.getUint256Slot().value;
}
} }
...@@ -8,9 +8,11 @@ contract StringsMock { ...@@ -8,9 +8,11 @@ contract StringsMock {
function fromUint256(uint256 value) public pure returns (string memory) { function fromUint256(uint256 value) public pure returns (string memory) {
return Strings.toString(value); return Strings.toString(value);
} }
function fromUint256Hex(uint256 value) public pure returns (string memory) { function fromUint256Hex(uint256 value) public pure returns (string memory) {
return Strings.toHexString(value); return Strings.toHexString(value);
} }
function fromUint256HexFixed(uint256 value, uint256 length) public pure returns (string memory) { function fromUint256HexFixed(uint256 value, uint256 length) public pure returns (string memory) {
return Strings.toHexString(value, length); return Strings.toHexString(value, length);
} }
......
...@@ -28,5 +28,4 @@ contract UUPSUpgradeableBrokenMock is UUPSUpgradeableMock { ...@@ -28,5 +28,4 @@ contract UUPSUpgradeableBrokenMock is UUPSUpgradeableMock {
function upgradeToAndCall(address, bytes memory) external payable virtual override { function upgradeToAndCall(address, bytes memory) external payable virtual override {
// pass // pass
} }
} }
...@@ -22,7 +22,6 @@ library Clones { ...@@ -22,7 +22,6 @@ library Clones {
* This function uses the create opcode, which should never revert. * This function uses the create opcode, which should never revert.
*/ */
function clone(address implementation) internal returns (address instance) { function clone(address implementation) internal returns (address instance) {
// solhint-disable-next-line no-inline-assembly
assembly { assembly {
let ptr := mload(0x40) let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
...@@ -41,7 +40,6 @@ library Clones { ...@@ -41,7 +40,6 @@ library Clones {
* the clones cannot be deployed twice at the same address. * the clones cannot be deployed twice at the same address.
*/ */
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
// solhint-disable-next-line no-inline-assembly
assembly { assembly {
let ptr := mload(0x40) let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
...@@ -55,8 +53,11 @@ library Clones { ...@@ -55,8 +53,11 @@ library Clones {
/** /**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/ */
function predictDeterministicAddress(address implementation, bytes32 salt, address deployer) internal pure returns (address predicted) { function predictDeterministicAddress(
// solhint-disable-next-line no-inline-assembly address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
assembly { assembly {
let ptr := mload(0x40) let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
...@@ -72,7 +73,11 @@ library Clones { ...@@ -72,7 +73,11 @@ library Clones {
/** /**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/ */
function predictDeterministicAddress(address implementation, bytes32 salt) internal view returns (address predicted) { function predictDeterministicAddress(address implementation, bytes32 salt)
internal
view
returns (address predicted)
{
return predictDeterministicAddress(implementation, salt, address(this)); return predictDeterministicAddress(implementation, salt, address(this));
} }
} }
...@@ -60,7 +60,11 @@ abstract contract ERC1967Upgrade { ...@@ -60,7 +60,11 @@ abstract contract ERC1967Upgrade {
* *
* Emits an {Upgraded} event. * Emits an {Upgraded} event.
*/ */
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal { function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_setImplementation(newImplementation); _setImplementation(newImplementation);
emit Upgraded(newImplementation); emit Upgraded(newImplementation);
if (data.length > 0 || forceCall) { if (data.length > 0 || forceCall) {
...@@ -73,7 +77,11 @@ abstract contract ERC1967Upgrade { ...@@ -73,7 +77,11 @@ abstract contract ERC1967Upgrade {
* *
* Emits an {Upgraded} event. * Emits an {Upgraded} event.
*/ */
function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal { function _upgradeToAndCallSecure(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
address oldImplementation = _getImplementation(); address oldImplementation = _getImplementation();
// Initial upgrade and setup call // Initial upgrade and setup call
...@@ -89,10 +97,7 @@ abstract contract ERC1967Upgrade { ...@@ -89,10 +97,7 @@ abstract contract ERC1967Upgrade {
rollbackTesting.value = true; rollbackTesting.value = true;
_functionDelegateCall( _functionDelegateCall(
newImplementation, newImplementation,
abi.encodeWithSignature( abi.encodeWithSignature("upgradeTo(address)", oldImplementation)
"upgradeTo(address)",
oldImplementation
)
); );
rollbackTesting.value = false; rollbackTesting.value = false;
// Check rollback was effective // Check rollback was effective
...@@ -109,7 +114,11 @@ abstract contract ERC1967Upgrade { ...@@ -109,7 +114,11 @@ abstract contract ERC1967Upgrade {
* *
* Emits a {BeaconUpgraded} event. * Emits a {BeaconUpgraded} event.
*/ */
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal { function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon); _setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon); emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) { if (data.length > 0 || forceCall) {
...@@ -176,10 +185,7 @@ abstract contract ERC1967Upgrade { ...@@ -176,10 +185,7 @@ abstract contract ERC1967Upgrade {
* @dev Stores a new beacon in the EIP1967 beacon slot. * @dev Stores a new beacon in the EIP1967 beacon slot.
*/ */
function _setBeacon(address newBeacon) private { function _setBeacon(address newBeacon) private {
require( require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
Address.isContract(newBeacon),
"ERC1967: new beacon is not a contract"
);
require( require(
Address.isContract(IBeacon(newBeacon).implementation()), Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract" "ERC1967: beacon implementation is not a contract"
......
...@@ -19,7 +19,6 @@ abstract contract Proxy { ...@@ -19,7 +19,6 @@ abstract contract Proxy {
* This function does not return to its internall call site, it will return directly to the external caller. * This function does not return to its internall call site, it will return directly to the external caller.
*/ */
function _delegate(address implementation) internal virtual { function _delegate(address implementation) internal virtual {
// solhint-disable-next-line no-inline-assembly
assembly { assembly {
// Copy msg.data. We take full control of memory in this inline assembly // Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the // block because it will not return to Solidity code. We overwrite the
...@@ -35,8 +34,12 @@ abstract contract Proxy { ...@@ -35,8 +34,12 @@ abstract contract Proxy {
switch result switch result
// delegatecall returns 0 on error. // delegatecall returns 0 on error.
case 0 { revert(0, returndatasize()) } case 0 {
default { return(0, returndatasize()) } revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
} }
} }
...@@ -60,7 +63,7 @@ abstract contract Proxy { ...@@ -60,7 +63,7 @@ abstract contract Proxy {
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data. * function in the contract matches the call data.
*/ */
fallback () external payable virtual { fallback() external payable virtual {
_fallback(); _fallback();
} }
...@@ -68,7 +71,7 @@ abstract contract Proxy { ...@@ -68,7 +71,7 @@ abstract contract Proxy {
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty. * is empty.
*/ */
receive () external payable virtual { receive() external payable virtual {
_fallback(); _fallback();
} }
...@@ -78,6 +81,5 @@ abstract contract Proxy { ...@@ -78,6 +81,5 @@ abstract contract Proxy {
* *
* If overriden should call `super._beforeFallback()`. * If overriden should call `super._beforeFallback()`.
*/ */
function _beforeFallback() internal virtual { function _beforeFallback() internal virtual {}
}
} }
...@@ -10,7 +10,6 @@ import "../../access/Ownable.sol"; ...@@ -10,7 +10,6 @@ import "../../access/Ownable.sol";
* explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}. * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
*/ */
contract ProxyAdmin is Ownable { contract ProxyAdmin is Ownable {
/** /**
* @dev Returns the current implementation of `proxy`. * @dev Returns the current implementation of `proxy`.
* *
...@@ -71,7 +70,11 @@ contract ProxyAdmin is Ownable { ...@@ -71,7 +70,11 @@ contract ProxyAdmin is Ownable {
* *
* - This contract must be the admin of `proxy`. * - This contract must be the admin of `proxy`.
*/ */
function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual onlyOwner { function upgradeAndCall(
TransparentUpgradeableProxy proxy,
address implementation,
bytes memory data
) public payable virtual onlyOwner {
proxy.upgradeToAndCall{value: msg.value}(implementation, data); proxy.upgradeToAndCall{value: msg.value}(implementation, data);
} }
} }
...@@ -30,7 +30,11 @@ contract TransparentUpgradeableProxy is ERC1967Proxy { ...@@ -30,7 +30,11 @@ contract TransparentUpgradeableProxy is ERC1967Proxy {
* @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
* optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}. * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}.
*/ */
constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data) { constructor(
address _logic,
address admin_,
bytes memory _data
) payable ERC1967Proxy(_logic, _data) {
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1)); assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
_changeAdmin(admin_); _changeAdmin(admin_);
} }
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// solhint-disable-next-line compiler-version
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
/** /**
...@@ -16,7 +15,6 @@ pragma solidity ^0.8.0; ...@@ -16,7 +15,6 @@ pragma solidity ^0.8.0;
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/ */
abstract contract Initializable { abstract contract Initializable {
/** /**
* @dev Indicates that the contract has been initialized. * @dev Indicates that the contract has been initialized.
*/ */
......
...@@ -29,7 +29,7 @@ abstract contract Pausable is Context { ...@@ -29,7 +29,7 @@ abstract contract Pausable is Context {
/** /**
* @dev Initializes the contract in unpaused state. * @dev Initializes the contract in unpaused state.
*/ */
constructor () { constructor() {
_paused = false; _paused = false;
} }
......
...@@ -23,9 +23,9 @@ import "../utils/escrow/Escrow.sol"; ...@@ -23,9 +23,9 @@ import "../utils/escrow/Escrow.sol";
* payments with {payments}, and retrieve them with {withdrawPayments}. * payments with {payments}, and retrieve them with {withdrawPayments}.
*/ */
abstract contract PullPayment { abstract contract PullPayment {
Escrow immutable private _escrow; Escrow private immutable _escrow;
constructor () { constructor() {
_escrow = new Escrow(); _escrow = new Escrow();
} }
...@@ -64,6 +64,6 @@ abstract contract PullPayment { ...@@ -64,6 +64,6 @@ abstract contract PullPayment {
* @param amount The amount to transfer. * @param amount The amount to transfer.
*/ */
function _asyncTransfer(address dest, uint256 amount) internal virtual { function _asyncTransfer(address dest, uint256 amount) internal virtual {
_escrow.deposit{ value: amount }(dest); _escrow.deposit{value: amount}(dest);
} }
} }
...@@ -35,7 +35,7 @@ abstract contract ReentrancyGuard { ...@@ -35,7 +35,7 @@ abstract contract ReentrancyGuard {
uint256 private _status; uint256 private _status;
constructor () { constructor() {
_status = _NOT_ENTERED; _status = _NOT_ENTERED;
} }
......
...@@ -20,10 +20,10 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -20,10 +20,10 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address; using Address for address;
// Mapping from token ID to account balances // Mapping from token ID to account balances
mapping (uint256 => mapping(address => uint256)) private _balances; mapping(uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals // Mapping from account to operator approvals
mapping (address => mapping(address => bool)) private _operatorApprovals; mapping(address => mapping(address => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri; string private _uri;
...@@ -31,7 +31,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -31,7 +31,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
/** /**
* @dev See {_setURI}. * @dev See {_setURI}.
*/ */
constructor (string memory uri_) { constructor(string memory uri_) {
_setURI(uri_); _setURI(uri_);
} }
...@@ -39,9 +39,10 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -39,9 +39,10 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
* @dev See {IERC165-supportsInterface}. * @dev See {IERC165-supportsInterface}.
*/ */
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155).interfaceId return
|| interfaceId == type(IERC1155MetadataURI).interfaceId interfaceId == type(IERC1155).interfaceId ||
|| super.supportsInterface(interfaceId); interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
} }
/** /**
...@@ -77,10 +78,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -77,10 +78,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
* *
* - `accounts` and `ids` must have the same length. * - `accounts` and `ids` must have the same length.
*/ */
function balanceOfBatch( function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
address[] memory accounts,
uint256[] memory ids
)
public public
view view
virtual virtual
...@@ -124,11 +122,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -124,11 +122,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256 id, uint256 id,
uint256 amount, uint256 amount,
bytes memory data bytes memory data
) ) public virtual override {
public
virtual
override
{
require( require(
from == _msgSender() || isApprovedForAll(from, _msgSender()), from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved" "ERC1155: caller is not owner nor approved"
...@@ -145,11 +139,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -145,11 +139,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) ) public virtual override {
public
virtual
override
{
require( require(
from == _msgSender() || isApprovedForAll(from, _msgSender()), from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved" "ERC1155: transfer caller is not owner nor approved"
...@@ -175,10 +165,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -175,10 +165,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256 id, uint256 id,
uint256 amount, uint256 amount,
bytes memory data bytes memory data
) ) internal virtual {
internal
virtual
{
require(to != address(0), "ERC1155: transfer to the zero address"); require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender(); address operator = _msgSender();
...@@ -213,10 +200,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -213,10 +200,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) ) internal virtual {
internal
virtual
{
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address"); require(to != address(0), "ERC1155: transfer to the zero address");
...@@ -275,7 +259,12 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -275,7 +259,12 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
* - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value. * acceptance magic value.
*/ */
function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual { function _mint(
address account,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(account != address(0), "ERC1155: mint to the zero address"); require(account != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender(); address operator = _msgSender();
...@@ -297,7 +286,12 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -297,7 +286,12 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value. * acceptance magic value.
*/ */
function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual { function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address"); require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
...@@ -305,7 +299,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -305,7 +299,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data); _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint i = 0; i < ids.length; i++) { for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i]; _balances[ids[i]][to] += amounts[i];
} }
...@@ -322,7 +316,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -322,7 +316,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
* - `account` cannot be the zero address. * - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens of token type `id`. * - `account` must have at least `amount` tokens of token type `id`.
*/ */
function _burn(address account, uint256 id, uint256 amount) internal virtual { function _burn(
address account,
uint256 id,
uint256 amount
) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address"); require(account != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender(); address operator = _msgSender();
...@@ -345,7 +343,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -345,7 +343,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
* *
* - `ids` and `amounts` must have the same length. * - `ids` and `amounts` must have the same length.
*/ */
function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual { function _burnBatch(
address account,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address"); require(account != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
...@@ -353,7 +355,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -353,7 +355,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
_beforeTokenTransfer(operator, account, address(0), ids, amounts, ""); _beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
for (uint i = 0; i < ids.length; i++) { for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i]; uint256 id = ids[i];
uint256 amount = amounts[i]; uint256 amount = amounts[i];
...@@ -394,10 +396,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -394,10 +396,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) ) internal virtual {}
internal
virtual
{ }
function _doSafeTransferAcceptanceCheck( function _doSafeTransferAcceptanceCheck(
address operator, address operator,
...@@ -406,9 +405,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -406,9 +405,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256 id, uint256 id,
uint256 amount, uint256 amount,
bytes memory data bytes memory data
) ) private {
private
{
if (to.isContract()) { if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) { try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155Received.selector) { if (response != IERC1155Receiver(to).onERC1155Received.selector) {
...@@ -429,11 +426,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -429,11 +426,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) ) private {
private
{
if (to.isContract()) { if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) { try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) { if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens"); revert("ERC1155: ERC1155Receiver rejected tokens");
} }
......
...@@ -20,7 +20,13 @@ interface IERC1155 is IERC165 { ...@@ -20,7 +20,13 @@ interface IERC1155 is IERC165 {
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers. * transfers.
*/ */
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values); event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/** /**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
...@@ -53,7 +59,10 @@ interface IERC1155 is IERC165 { ...@@ -53,7 +59,10 @@ interface IERC1155 is IERC165 {
* *
* - `accounts` and `ids` must have the same length. * - `accounts` and `ids` must have the same length.
*/ */
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
/** /**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
...@@ -86,7 +95,13 @@ interface IERC1155 is IERC165 { ...@@ -86,7 +95,13 @@ interface IERC1155 is IERC165 {
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value. * acceptance magic value.
*/ */
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external; function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
/** /**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
...@@ -99,5 +114,11 @@ interface IERC1155 is IERC165 { ...@@ -99,5 +114,11 @@ interface IERC1155 is IERC165 {
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value. * acceptance magic value.
*/ */
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external; function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
} }
...@@ -8,7 +8,6 @@ import "../../utils/introspection/IERC165.sol"; ...@@ -8,7 +8,6 @@ import "../../utils/introspection/IERC165.sol";
* @dev _Available since v3.1._ * @dev _Available since v3.1._
*/ */
interface IERC1155Receiver is IERC165 { interface IERC1155Receiver is IERC165 {
/** /**
@dev Handles the receipt of a single ERC1155 token type. This function is @dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated. called at the end of a `safeTransferFrom` after the balance has been updated.
...@@ -28,9 +27,7 @@ interface IERC1155Receiver is IERC165 { ...@@ -28,9 +27,7 @@ interface IERC1155Receiver is IERC165 {
uint256 id, uint256 id,
uint256 value, uint256 value,
bytes calldata data bytes calldata data
) ) external returns (bytes4);
external
returns(bytes4);
/** /**
@dev Handles the receipt of a multiple ERC1155 token types. This function @dev Handles the receipt of a multiple ERC1155 token types. This function
...@@ -51,7 +48,5 @@ interface IERC1155Receiver is IERC165 { ...@@ -51,7 +48,5 @@ interface IERC1155Receiver is IERC165 {
uint256[] calldata ids, uint256[] calldata ids,
uint256[] calldata values, uint256[] calldata values,
bytes calldata data bytes calldata data
) ) external returns (bytes4);
external
returns(bytes4);
} }
...@@ -11,7 +11,11 @@ import "../ERC1155.sol"; ...@@ -11,7 +11,11 @@ import "../ERC1155.sol";
* _Available since v3.1._ * _Available since v3.1._
*/ */
abstract contract ERC1155Burnable is ERC1155 { abstract contract ERC1155Burnable is ERC1155 {
function burn(address account, uint256 id, uint256 value) public virtual { function burn(
address account,
uint256 id,
uint256 value
) public virtual {
require( require(
account == _msgSender() || isApprovedForAll(account, _msgSender()), account == _msgSender() || isApprovedForAll(account, _msgSender()),
"ERC1155: caller is not owner nor approved" "ERC1155: caller is not owner nor approved"
...@@ -20,7 +24,11 @@ abstract contract ERC1155Burnable is ERC1155 { ...@@ -20,7 +24,11 @@ abstract contract ERC1155Burnable is ERC1155 {
_burn(account, id, value); _burn(account, id, value);
} }
function burnBatch(address account, uint256[] memory ids, uint256[] memory values) public virtual { function burnBatch(
address account,
uint256[] memory ids,
uint256[] memory values
) public virtual {
require( require(
account == _msgSender() || isApprovedForAll(account, _msgSender()), account == _msgSender() || isApprovedForAll(account, _msgSender()),
"ERC1155: caller is not owner nor approved" "ERC1155: caller is not owner nor approved"
......
...@@ -29,11 +29,7 @@ abstract contract ERC1155Pausable is ERC1155, Pausable { ...@@ -29,11 +29,7 @@ abstract contract ERC1155Pausable is ERC1155, Pausable {
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) ) internal virtual override {
internal
virtual
override
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
require(!paused(), "ERC1155Pausable: token transfer while paused"); require(!paused(), "ERC1155Pausable: token transfer while paused");
......
...@@ -13,7 +13,7 @@ import "../ERC1155.sol"; ...@@ -13,7 +13,7 @@ import "../ERC1155.sol";
* same id are not going to be minted. * same id are not going to be minted.
*/ */
abstract contract ERC1155Supply is ERC1155 { abstract contract ERC1155Supply is ERC1155 {
mapping (uint256 => uint256) private _totalSupply; mapping(uint256 => uint256) private _totalSupply;
/** /**
* @dev Total amount of tokens in with a given id. * @dev Total amount of tokens in with a given id.
...@@ -25,14 +25,19 @@ abstract contract ERC1155Supply is ERC1155 { ...@@ -25,14 +25,19 @@ abstract contract ERC1155Supply is ERC1155 {
/** /**
* @dev Indicates weither any token exist with a given id, or not. * @dev Indicates weither any token exist with a given id, or not.
*/ */
function exists(uint256 id) public view virtual returns(bool) { function exists(uint256 id) public view virtual returns (bool) {
return ERC1155Supply.totalSupply(id) > 0; return ERC1155Supply.totalSupply(id) > 0;
} }
/** /**
* @dev See {ERC1155-_mint}. * @dev See {ERC1155-_mint}.
*/ */
function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual override { function _mint(
address account,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual override {
super._mint(account, id, amount, data); super._mint(account, id, amount, data);
_totalSupply[id] += amount; _totalSupply[id] += amount;
} }
...@@ -40,7 +45,12 @@ abstract contract ERC1155Supply is ERC1155 { ...@@ -40,7 +45,12 @@ abstract contract ERC1155Supply is ERC1155 {
/** /**
* @dev See {ERC1155-_mintBatch}. * @dev See {ERC1155-_mintBatch}.
*/ */
function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual override { function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
super._mintBatch(to, ids, amounts, data); super._mintBatch(to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) { for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i]; _totalSupply[ids[i]] += amounts[i];
...@@ -50,7 +60,11 @@ abstract contract ERC1155Supply is ERC1155 { ...@@ -50,7 +60,11 @@ abstract contract ERC1155Supply is ERC1155 {
/** /**
* @dev See {ERC1155-_burn}. * @dev See {ERC1155-_burn}.
*/ */
function _burn(address account, uint256 id, uint256 amount) internal virtual override { function _burn(
address account,
uint256 id,
uint256 amount
) internal virtual override {
super._burn(account, id, amount); super._burn(account, id, amount);
_totalSupply[id] -= amount; _totalSupply[id] -= amount;
} }
...@@ -58,7 +72,11 @@ abstract contract ERC1155Supply is ERC1155 { ...@@ -58,7 +72,11 @@ abstract contract ERC1155Supply is ERC1155 {
/** /**
* @dev See {ERC1155-_burnBatch}. * @dev See {ERC1155-_burnBatch}.
*/ */
function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual override { function _burnBatch(
address account,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual override {
super._burnBatch(account, ids, amounts); super._burnBatch(account, ids, amounts);
for (uint256 i = 0; i < ids.length; ++i) { for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] -= amounts[i]; _totalSupply[ids[i]] -= amounts[i];
......
...@@ -46,7 +46,12 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B ...@@ -46,7 +46,12 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B
* *
* - the caller must have the `MINTER_ROLE`. * - the caller must have the `MINTER_ROLE`.
*/ */
function mint(address to, uint256 id, uint256 amount, bytes memory data) public virtual { function mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual {
require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint"); require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
_mint(to, id, amount, data); _mint(to, id, amount, data);
...@@ -55,7 +60,12 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B ...@@ -55,7 +60,12 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B
/** /**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] variant of {mint}. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] variant of {mint}.
*/ */
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public virtual { function mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual {
require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint"); require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
_mintBatch(to, ids, amounts, data); _mintBatch(to, ids, amounts, data);
...@@ -92,7 +102,13 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B ...@@ -92,7 +102,13 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B
/** /**
* @dev See {IERC165-supportsInterface}. * @dev See {IERC165-supportsInterface}.
*/ */
function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControlEnumerable, ERC1155) returns (bool) { function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(AccessControlEnumerable, ERC1155)
returns (bool)
{
return super.supportsInterface(interfaceId); return super.supportsInterface(interfaceId);
} }
...@@ -103,9 +119,7 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B ...@@ -103,9 +119,7 @@ contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155B
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) ) internal virtual override(ERC1155, ERC1155Pausable) {
internal virtual override(ERC1155, ERC1155Pausable)
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
} }
} }
...@@ -8,11 +8,23 @@ import "./ERC1155Receiver.sol"; ...@@ -8,11 +8,23 @@ import "./ERC1155Receiver.sol";
* @dev _Available since v3.1._ * @dev _Available since v3.1._
*/ */
contract ERC1155Holder is ERC1155Receiver { contract ERC1155Holder is ERC1155Receiver {
function onERC1155Received(address, address, uint256, uint256, bytes memory) public virtual override returns (bytes4) { function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector; return this.onERC1155Received.selector;
} }
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) public virtual override returns (bytes4) { function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector; return this.onERC1155BatchReceived.selector;
} }
} }
...@@ -13,7 +13,6 @@ abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { ...@@ -13,7 +13,6 @@ abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
* @dev See {IERC165-supportsInterface}. * @dev See {IERC165-supportsInterface}.
*/ */
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
|| super.supportsInterface(interfaceId);
} }
} }
...@@ -31,9 +31,9 @@ import "../../utils/Context.sol"; ...@@ -31,9 +31,9 @@ import "../../utils/Context.sol";
* allowances. See {IERC20-approve}. * allowances. See {IERC20-approve}.
*/ */
contract ERC20 is Context, IERC20, IERC20Metadata { contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances; mapping(address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances; mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply; uint256 private _totalSupply;
...@@ -49,7 +49,7 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -49,7 +49,7 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* All two of these values are immutable: they can only be set once during * All two of these values are immutable: they can only be set once during
* construction. * construction.
*/ */
constructor (string memory name_, string memory symbol_) { constructor(string memory name_, string memory symbol_) {
_name = name_; _name = name_;
_symbol = symbol_; _symbol = symbol_;
} }
...@@ -145,7 +145,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -145,7 +145,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* - the caller must have allowance for ``sender``'s tokens of at least * - the caller must have allowance for ``sender``'s tokens of at least
* `amount`. * `amount`.
*/ */
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount); _transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()]; uint256 currentAllowance = _allowances[sender][_msgSender()];
...@@ -212,7 +216,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -212,7 +216,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* - `recipient` cannot be the zero address. * - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`. * - `sender` must have a balance of at least `amount`.
*/ */
function _transfer(address sender, address recipient, uint256 amount) internal virtual { function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address"); require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address");
...@@ -286,7 +294,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -286,7 +294,11 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* - `owner` cannot be the zero address. * - `owner` cannot be the zero address.
* - `spender` cannot be the zero address. * - `spender` cannot be the zero address.
*/ */
function _approve(address owner, address spender, uint256 amount) internal virtual { function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address"); require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address"); require(spender != address(0), "ERC20: approve to the zero address");
...@@ -308,5 +320,9 @@ contract ERC20 is Context, IERC20, IERC20Metadata { ...@@ -308,5 +320,9 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* *
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/ */
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
} }
...@@ -59,7 +59,11 @@ interface IERC20 { ...@@ -59,7 +59,11 @@ interface IERC20 {
* *
* Emits a {Transfer} event. * Emits a {Transfer} event.
*/ */
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/** /**
* @dev Emitted when `value` tokens are moved from one account (`from`) to * @dev Emitted when `value` tokens are moved from one account (`from`) to
......
...@@ -8,13 +8,13 @@ import "../ERC20.sol"; ...@@ -8,13 +8,13 @@ import "../ERC20.sol";
* @dev Extension of {ERC20} that adds a cap to the supply of tokens. * @dev Extension of {ERC20} that adds a cap to the supply of tokens.
*/ */
abstract contract ERC20Capped is ERC20 { abstract contract ERC20Capped is ERC20 {
uint256 immutable private _cap; uint256 private immutable _cap;
/** /**
* @dev Sets the value of the `cap`. This value is immutable, it can only be * @dev Sets the value of the `cap`. This value is immutable, it can only be
* set once during construction. * set once during construction.
*/ */
constructor (uint256 cap_) { constructor(uint256 cap_) {
require(cap_ > 0, "ERC20Capped: cap is 0"); require(cap_ > 0, "ERC20Capped: cap is 0");
_cap = cap_; _cap = cap_;
} }
......
...@@ -15,7 +15,7 @@ import "../ERC20.sol"; ...@@ -15,7 +15,7 @@ import "../ERC20.sol";
* _Available since v4.1._ * _Available since v4.1._
*/ */
abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender { abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
bytes32 constant private RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan"); bytes32 private constant _RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");
/** /**
* @dev Returns the maximum amount of tokens available for loan. * @dev Returns the maximum amount of tokens available for loan.
...@@ -60,12 +60,13 @@ abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender { ...@@ -60,12 +60,13 @@ abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
address token, address token,
uint256 amount, uint256 amount,
bytes calldata data bytes calldata data
) ) public virtual override returns (bool) {
public virtual override returns (bool)
{
uint256 fee = flashFee(token, amount); uint256 fee = flashFee(token, amount);
_mint(address(receiver), amount); _mint(address(receiver), amount);
require(receiver.onFlashLoan(msg.sender, token, amount, fee, data) == RETURN_VALUE, "ERC20FlashMint: invalid return value"); require(
receiver.onFlashLoan(msg.sender, token, amount, fee, data) == _RETURN_VALUE,
"ERC20FlashMint: invalid return value"
);
uint256 currentAllowance = allowance(address(receiver), address(this)); uint256 currentAllowance = allowance(address(receiver), address(this));
require(currentAllowance >= amount + fee, "ERC20FlashMint: allowance does not allow refund"); require(currentAllowance >= amount + fee, "ERC20FlashMint: allowance does not allow refund");
_approve(address(receiver), address(this), currentAllowance - amount - fee); _approve(address(receiver), address(this), currentAllowance - amount - fee);
......
...@@ -20,7 +20,11 @@ abstract contract ERC20Pausable is ERC20, Pausable { ...@@ -20,7 +20,11 @@ abstract contract ERC20Pausable is ERC20, Pausable {
* *
* - the contract must not be paused. * - the contract must not be paused.
*/ */
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override { function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
super._beforeTokenTransfer(from, to, amount); super._beforeTokenTransfer(from, to, amount);
require(!paused(), "ERC20Pausable: token transfer while paused"); require(!paused(), "ERC20Pausable: token transfer while paused");
......
...@@ -52,7 +52,7 @@ abstract contract ERC20Snapshot is ERC20 { ...@@ -52,7 +52,7 @@ abstract contract ERC20Snapshot is ERC20 {
uint256[] values; uint256[] values;
} }
mapping (address => Snapshots) private _accountBalanceSnapshots; mapping(address => Snapshots) private _accountBalanceSnapshots;
Snapshots private _totalSupplySnapshots; Snapshots private _totalSupplySnapshots;
// Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid. // Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
...@@ -111,7 +111,7 @@ abstract contract ERC20Snapshot is ERC20 { ...@@ -111,7 +111,7 @@ abstract contract ERC20Snapshot is ERC20 {
/** /**
* @dev Retrieves the total supply at the time `snapshotId` was created. * @dev Retrieves the total supply at the time `snapshotId` was created.
*/ */
function totalSupplyAt(uint256 snapshotId) public view virtual returns(uint256) { function totalSupplyAt(uint256 snapshotId) public view virtual returns (uint256) {
(bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnapshots); (bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnapshots);
return snapshotted ? value : totalSupply(); return snapshotted ? value : totalSupply();
...@@ -119,27 +119,29 @@ abstract contract ERC20Snapshot is ERC20 { ...@@ -119,27 +119,29 @@ abstract contract ERC20Snapshot is ERC20 {
// Update balance and/or total supply snapshots before the values are modified. This is implemented // Update balance and/or total supply snapshots before the values are modified. This is implemented
// in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations. // in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override { function _beforeTokenTransfer(
super._beforeTokenTransfer(from, to, amount); address from,
address to,
if (from == address(0)) { uint256 amount
// mint ) internal virtual override {
_updateAccountSnapshot(to); super._beforeTokenTransfer(from, to, amount);
_updateTotalSupplySnapshot();
} else if (to == address(0)) { if (from == address(0)) {
// burn // mint
_updateAccountSnapshot(from); _updateAccountSnapshot(to);
_updateTotalSupplySnapshot(); _updateTotalSupplySnapshot();
} else { } else if (to == address(0)) {
// transfer // burn
_updateAccountSnapshot(from); _updateAccountSnapshot(from);
_updateAccountSnapshot(to); _updateTotalSupplySnapshot();
} } else {
// transfer
_updateAccountSnapshot(from);
_updateAccountSnapshot(to);
}
} }
function _valueAt(uint256 snapshotId, Snapshots storage snapshots) function _valueAt(uint256 snapshotId, Snapshots storage snapshots) private view returns (bool, uint256) {
private view returns (bool, uint256)
{
require(snapshotId > 0, "ERC20Snapshot: id is 0"); require(snapshotId > 0, "ERC20Snapshot: id is 0");
require(snapshotId <= _getCurrentSnapshotId(), "ERC20Snapshot: nonexistent id"); require(snapshotId <= _getCurrentSnapshotId(), "ERC20Snapshot: nonexistent id");
......
...@@ -26,14 +26,15 @@ import "../../../utils/cryptography/ECDSA.sol"; ...@@ -26,14 +26,15 @@ import "../../../utils/cryptography/ECDSA.sol";
*/ */
abstract contract ERC20Votes is ERC20Permit { abstract contract ERC20Votes is ERC20Permit {
struct Checkpoint { struct Checkpoint {
uint32 fromBlock; uint32 fromBlock;
uint224 votes; uint224 votes;
} }
bytes32 private constant _DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); bytes32 private constant _DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
mapping (address => address) private _delegates; mapping(address => address) private _delegates;
mapping (address => Checkpoint[]) private _checkpoints; mapping(address => Checkpoint[]) private _checkpoints;
Checkpoint[] private _totalSupplyCheckpoints; Checkpoint[] private _totalSupplyCheckpoints;
/** /**
...@@ -139,18 +140,20 @@ abstract contract ERC20Votes is ERC20Permit { ...@@ -139,18 +140,20 @@ abstract contract ERC20Votes is ERC20Permit {
/** /**
* @dev Delegates votes from signer to `delegatee` * @dev Delegates votes from signer to `delegatee`
*/ */
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) function delegateBySig(
public virtual address delegatee,
{ uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(block.timestamp <= expiry, "ERC20Votes: signature expired"); require(block.timestamp <= expiry, "ERC20Votes: signature expired");
address signer = ECDSA.recover( address signer = ECDSA.recover(
_hashTypedDataV4(keccak256(abi.encode( _hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
_DELEGATION_TYPEHASH, v,
delegatee, r,
nonce, s
expiry
))),
v, r, s
); );
require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce"); require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
return _delegate(signer, delegatee); return _delegate(signer, delegatee);
...@@ -170,7 +173,7 @@ abstract contract ERC20Votes is ERC20Permit { ...@@ -170,7 +173,7 @@ abstract contract ERC20Votes is ERC20Permit {
super._mint(account, amount); super._mint(account, amount);
require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes"); require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
_writeCheckpoint(_totalSupplyCheckpoints, add, amount); _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
} }
/** /**
...@@ -179,7 +182,7 @@ abstract contract ERC20Votes is ERC20Permit { ...@@ -179,7 +182,7 @@ abstract contract ERC20Votes is ERC20Permit {
function _burn(address account, uint256 amount) internal virtual override { function _burn(address account, uint256 amount) internal virtual override {
super._burn(account, amount); super._burn(account, amount);
_writeCheckpoint(_totalSupplyCheckpoints, subtract, amount); _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
} }
/** /**
...@@ -187,7 +190,11 @@ abstract contract ERC20Votes is ERC20Permit { ...@@ -187,7 +190,11 @@ abstract contract ERC20Votes is ERC20Permit {
* *
* Emits a {DelegateVotesChanged} event. * Emits a {DelegateVotesChanged} event.
*/ */
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override { function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
_moveVotingPower(delegates(from), delegates(to), amount); _moveVotingPower(delegates(from), delegates(to), amount);
} }
...@@ -206,15 +213,19 @@ abstract contract ERC20Votes is ERC20Permit { ...@@ -206,15 +213,19 @@ abstract contract ERC20Votes is ERC20Permit {
_moveVotingPower(currentDelegate, delegatee, delegatorBalance); _moveVotingPower(currentDelegate, delegatee, delegatorBalance);
} }
function _moveVotingPower(address src, address dst, uint256 amount) private { function _moveVotingPower(
address src,
address dst,
uint256 amount
) private {
if (src != dst && amount > 0) { if (src != dst && amount > 0) {
if (src != address(0)) { if (src != address(0)) {
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], subtract, amount); (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
emit DelegateVotesChanged(src, oldWeight, newWeight); emit DelegateVotesChanged(src, oldWeight, newWeight);
} }
if (dst != address(0)) { if (dst != address(0)) {
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], add, amount); (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
emit DelegateVotesChanged(dst, oldWeight, newWeight); emit DelegateVotesChanged(dst, oldWeight, newWeight);
} }
} }
...@@ -222,11 +233,9 @@ abstract contract ERC20Votes is ERC20Permit { ...@@ -222,11 +233,9 @@ abstract contract ERC20Votes is ERC20Permit {
function _writeCheckpoint( function _writeCheckpoint(
Checkpoint[] storage ckpts, Checkpoint[] storage ckpts,
function (uint256, uint256) view returns (uint256) op, function(uint256, uint256) view returns (uint256) op,
uint256 delta uint256 delta
) ) private returns (uint256 oldWeight, uint256 newWeight) {
private returns (uint256 oldWeight, uint256 newWeight)
{
uint256 pos = ckpts.length; uint256 pos = ckpts.length;
oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes; oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
newWeight = op(oldWeight, delta); newWeight = op(oldWeight, delta);
...@@ -234,18 +243,15 @@ abstract contract ERC20Votes is ERC20Permit { ...@@ -234,18 +243,15 @@ abstract contract ERC20Votes is ERC20Permit {
if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) { if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
ckpts[pos - 1].votes = SafeCast.toUint224(newWeight); ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
} else { } else {
ckpts.push(Checkpoint({ ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
fromBlock: SafeCast.toUint32(block.number),
votes: SafeCast.toUint224(newWeight)
}));
} }
} }
function add(uint256 a, uint256 b) private pure returns (uint256) { function _add(uint256 a, uint256 b) private pure returns (uint256) {
return a + b; return a + b;
} }
function subtract(uint256 a, uint256 b) private pure returns (uint256) { function _subtract(uint256 a, uint256 b) private pure returns (uint256) {
return a - b; return a - b;
} }
} }
...@@ -30,6 +30,7 @@ abstract contract ERC20VotesComp is ERC20Votes { ...@@ -30,6 +30,7 @@ abstract contract ERC20VotesComp is ERC20Votes {
function getCurrentVotes(address account) external view returns (uint96) { function getCurrentVotes(address account) external view returns (uint96) {
return SafeCast.toUint96(getVotes(account)); return SafeCast.toUint96(getVotes(account));
} }
/** /**
* @dev Comp version of the {getPastVotes} accessor, with `uint96` return type. * @dev Comp version of the {getPastVotes} accessor, with `uint96` return type.
*/ */
......
...@@ -21,36 +21,34 @@ import "../../../utils/Counters.sol"; ...@@ -21,36 +21,34 @@ import "../../../utils/Counters.sol";
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
using Counters for Counters.Counter; using Counters for Counters.Counter;
mapping (address => Counters.Counter) private _nonces; mapping(address => Counters.Counter) private _nonces;
// solhint-disable-next-line var-name-mixedcase // solhint-disable-next-line var-name-mixedcase
bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 private immutable _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/** /**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
* *
* It's a good idea to use the same `name` that is defined as the ERC20 token name. * It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/ */
constructor(string memory name) EIP712(name, "1") { constructor(string memory name) EIP712(name, "1") {}
}
/** /**
* @dev See {IERC20Permit-permit}. * @dev See {IERC20Permit-permit}.
*/ */
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override { function permit(
// solhint-disable-next-line not-rely-on-time address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
bytes32 structHash = keccak256( bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
abi.encode(
_PERMIT_TYPEHASH,
owner,
spender,
value,
_useNonce(owner),
deadline
)
);
bytes32 hash = _hashTypedDataV4(structHash); bytes32 hash = _hashTypedDataV4(structHash);
......
...@@ -32,7 +32,15 @@ interface IERC20Permit { ...@@ -32,7 +32,15 @@ interface IERC20Permit {
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section]. * section].
*/ */
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/** /**
* @dev Returns the current nonce for `owner`. This value must be * @dev Returns the current nonce for `owner`. This value must be
......
...@@ -81,7 +81,11 @@ contract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burna ...@@ -81,7 +81,11 @@ contract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burna
_unpause(); _unpause();
} }
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Pausable) { function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override(ERC20, ERC20Pausable) {
super._beforeTokenTransfer(from, to, amount); super._beforeTokenTransfer(from, to, amount);
} }
} }
...@@ -17,11 +17,20 @@ import "../../../utils/Address.sol"; ...@@ -17,11 +17,20 @@ import "../../../utils/Address.sol";
library SafeERC20 { library SafeERC20 {
using Address for address; using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal { function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
} }
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
} }
...@@ -32,23 +41,35 @@ library SafeERC20 { ...@@ -32,23 +41,35 @@ library SafeERC20 {
* Whenever possible, use {safeIncreaseAllowance} and * Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead. * {safeDecreaseAllowance} instead.
*/ */
function safeApprove(IERC20 token, address spender, uint256 value) internal { function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance, // safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use // or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length require(
require((value == 0) || (token.allowance(address(this), spender) == 0), (value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance" "SafeERC20: approve from non-zero to non-zero allowance"
); );
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
} }
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value; uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
} }
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked { unchecked {
uint256 oldAllowance = token.allowance(address(this), spender); uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
...@@ -69,8 +90,8 @@ library SafeERC20 { ...@@ -69,8 +90,8 @@ library SafeERC20 {
// the target address contains contract code and also asserts for success in the low-level call. // the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional if (returndata.length > 0) {
// solhint-disable-next-line max-line-length // Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
} }
} }
......
...@@ -15,16 +15,19 @@ contract TokenTimelock { ...@@ -15,16 +15,19 @@ contract TokenTimelock {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
// ERC20 basic token contract being held // ERC20 basic token contract being held
IERC20 immutable private _token; IERC20 private immutable _token;
// beneficiary of tokens after they are released // beneficiary of tokens after they are released
address immutable private _beneficiary; address private immutable _beneficiary;
// timestamp when token release is enabled // timestamp when token release is enabled
uint256 immutable private _releaseTime; uint256 private immutable _releaseTime;
constructor (IERC20 token_, address beneficiary_, uint256 releaseTime_) { constructor(
// solhint-disable-next-line not-rely-on-time IERC20 token_,
address beneficiary_,
uint256 releaseTime_
) {
require(releaseTime_ > block.timestamp, "TokenTimelock: release time is before current time"); require(releaseTime_ > block.timestamp, "TokenTimelock: release time is before current time");
_token = token_; _token = token_;
_beneficiary = beneficiary_; _beneficiary = beneficiary_;
...@@ -56,7 +59,6 @@ contract TokenTimelock { ...@@ -56,7 +59,6 @@ contract TokenTimelock {
* @notice Transfers tokens held by timelock to beneficiary. * @notice Transfers tokens held by timelock to beneficiary.
*/ */
function release() public virtual { function release() public virtual {
// solhint-disable-next-line not-rely-on-time
require(block.timestamp >= releaseTime(), "TokenTimelock: current time is before release time"); require(block.timestamp >= releaseTime(), "TokenTimelock: current time is before release time");
uint256 amount = token().balanceOf(address(this)); uint256 amount = token().balanceOf(address(this));
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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