diff --git a/CHANGELOG.md b/CHANGELOG.md index 05d423147..6f2576c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * `ERC20Permit`: added an implementation of the ERC20 permit extension for gasless token approvals. ([#2237](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2237)) * Presets: added token presets with preminted fixed supply `ERC20PresetFixedSupply` and `ERC777PresetFixedSupply`. ([#2399](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2399)) * `Address`: added `functionDelegateCall`, similar to the existing `functionCall`. ([#2333](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2333)) + * `Context`: moved from `contracts/GSN` to `contracts/utils`. ([#2453](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2453)) * `PaymentSplitter`: replace usage of `.transfer()` with `Address.sendValue` for improved compatibility with smart wallets. ([#2455](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2455)) * `UpgradeableProxy`: bubble revert reasons from initialization calls. ([#2454](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2454)) diff --git a/contracts/GSN/Context.sol b/contracts/GSN/Context.sol index 3d07c4aad..7362ffb67 100644 --- a/contracts/GSN/Context.sol +++ b/contracts/GSN/Context.sol @@ -2,23 +2,4 @@ pragma solidity >=0.6.0 <0.8.0; -/* - * @dev Provides information about the current execution context, including the - * sender of the transaction and its data. While these are generally available - * via msg.sender and msg.data, they should not be accessed in such a direct - * manner, since when dealing with GSN meta-transactions the account sending and - * paying for execution may not be the actual sender (as far as an application - * is concerned). - * - * This contract is only required for intermediate, library-like contracts. - */ -abstract contract Context { - function _msgSender() internal view virtual returns (address payable) { - return msg.sender; - } - - function _msgData() internal view virtual returns (bytes memory) { - this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 - return msg.data; - } -} +import "../utils/Context.sol"; diff --git a/contracts/GSN/GSNRecipient.sol b/contracts/GSN/GSNRecipient.sol index ae0c795b3..4a6570ccf 100644 --- a/contracts/GSN/GSNRecipient.sol +++ b/contracts/GSN/GSNRecipient.sol @@ -2,9 +2,9 @@ pragma solidity >=0.6.0 <0.8.0; +import "../utils/Context.sol"; import "./IRelayRecipient.sol"; import "./IRelayHub.sol"; -import "./Context.sol"; /** * @dev Base GSN recipient contract: includes the {IRelayRecipient} interface diff --git a/contracts/access/AccessControl.sol b/contracts/access/AccessControl.sol index 395e9a413..de3082233 100644 --- a/contracts/access/AccessControl.sol +++ b/contracts/access/AccessControl.sol @@ -4,7 +4,7 @@ pragma solidity >=0.6.0 <0.8.0; import "../utils/EnumerableSet.sol"; import "../utils/Address.sol"; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; /** * @dev Contract module that allows children to implement role-based access diff --git a/contracts/access/Ownable.sol b/contracts/access/Ownable.sol index 0223a15fe..918a952a8 100644 --- a/contracts/access/Ownable.sol +++ b/contracts/access/Ownable.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to diff --git a/contracts/mocks/ContextMock.sol b/contracts/mocks/ContextMock.sol index daae264fc..dd6fb656d 100644 --- a/contracts/mocks/ContextMock.sol +++ b/contracts/mocks/ContextMock.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; contract ContextMock is Context { event Sender(address sender); diff --git a/contracts/mocks/ERC777Mock.sol b/contracts/mocks/ERC777Mock.sol index db624cc06..757e6597c 100644 --- a/contracts/mocks/ERC777Mock.sol +++ b/contracts/mocks/ERC777Mock.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; import "../token/ERC777/ERC777.sol"; contract ERC777Mock is Context, ERC777 { diff --git a/contracts/mocks/ERC777SenderRecipientMock.sol b/contracts/mocks/ERC777SenderRecipientMock.sol index e4ce53f89..43fdf3bfa 100644 --- a/contracts/mocks/ERC777SenderRecipientMock.sol +++ b/contracts/mocks/ERC777SenderRecipientMock.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; import "../token/ERC777/IERC777.sol"; import "../token/ERC777/IERC777Sender.sol"; import "../token/ERC777/IERC777Recipient.sol"; diff --git a/contracts/mocks/ReentrancyAttack.sol b/contracts/mocks/ReentrancyAttack.sol index ce528e482..69249bbc8 100644 --- a/contracts/mocks/ReentrancyAttack.sol +++ b/contracts/mocks/ReentrancyAttack.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; contract ReentrancyAttack is Context { function callSender(bytes4 data) public { // solhint-disable-next-line avoid-low-level-calls diff --git a/contracts/mocks/SafeERC20Helper.sol b/contracts/mocks/SafeERC20Helper.sol index fbd05d3e0..f8547d3f2 100644 --- a/contracts/mocks/SafeERC20Helper.sol +++ b/contracts/mocks/SafeERC20Helper.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; import "../token/ERC20/IERC20.sol"; import "../token/ERC20/SafeERC20.sol"; diff --git a/contracts/payment/PaymentSplitter.sol b/contracts/payment/PaymentSplitter.sol index 5a5d0a106..27e89dd65 100644 --- a/contracts/payment/PaymentSplitter.sol +++ b/contracts/payment/PaymentSplitter.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; import "../math/SafeMath.sol"; import "../utils/Address.sol"; diff --git a/contracts/presets/ERC1155PresetMinterPauser.sol b/contracts/presets/ERC1155PresetMinterPauser.sol index 45d59f239..adb1332bb 100644 --- a/contracts/presets/ERC1155PresetMinterPauser.sol +++ b/contracts/presets/ERC1155PresetMinterPauser.sol @@ -3,7 +3,7 @@ pragma solidity >=0.6.0 <0.8.0; import "../access/AccessControl.sol"; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; import "../token/ERC1155/ERC1155.sol"; import "../token/ERC1155/ERC1155Burnable.sol"; import "../token/ERC1155/ERC1155Pausable.sol"; diff --git a/contracts/presets/ERC20PresetMinterPauser.sol b/contracts/presets/ERC20PresetMinterPauser.sol index a3c332d78..d10b95d09 100644 --- a/contracts/presets/ERC20PresetMinterPauser.sol +++ b/contracts/presets/ERC20PresetMinterPauser.sol @@ -3,7 +3,7 @@ pragma solidity >=0.6.0 <0.8.0; import "../access/AccessControl.sol"; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20Burnable.sol"; import "../token/ERC20/ERC20Pausable.sol"; diff --git a/contracts/presets/ERC721PresetMinterPauserAutoId.sol b/contracts/presets/ERC721PresetMinterPauserAutoId.sol index 461e014a1..a700cf4c7 100644 --- a/contracts/presets/ERC721PresetMinterPauserAutoId.sol +++ b/contracts/presets/ERC721PresetMinterPauserAutoId.sol @@ -3,7 +3,7 @@ pragma solidity >=0.6.0 <0.8.0; import "../access/AccessControl.sol"; -import "../GSN/Context.sol"; +import "../utils/Context.sol"; import "../utils/Counters.sol"; import "../token/ERC721/ERC721.sol"; import "../token/ERC721/ERC721Burnable.sol"; diff --git a/contracts/token/ERC1155/ERC1155.sol b/contracts/token/ERC1155/ERC1155.sol index fa849009b..4a98ce915 100644 --- a/contracts/token/ERC1155/ERC1155.sol +++ b/contracts/token/ERC1155/ERC1155.sol @@ -5,7 +5,7 @@ pragma solidity >=0.6.0 <0.8.0; import "./IERC1155.sol"; import "./IERC1155MetadataURI.sol"; import "./IERC1155Receiver.sol"; -import "../../GSN/Context.sol"; +import "../../utils/Context.sol"; import "../../introspection/ERC165.sol"; import "../../math/SafeMath.sol"; import "../../utils/Address.sol"; diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index f688ed6d7..ba62e81de 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../../GSN/Context.sol"; +import "../../utils/Context.sol"; import "./IERC20.sol"; import "../../math/SafeMath.sol"; diff --git a/contracts/token/ERC20/ERC20Burnable.sol b/contracts/token/ERC20/ERC20Burnable.sol index 4383f2168..5c14bed48 100644 --- a/contracts/token/ERC20/ERC20Burnable.sol +++ b/contracts/token/ERC20/ERC20Burnable.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../../GSN/Context.sol"; +import "../../utils/Context.sol"; import "./ERC20.sol"; /** diff --git a/contracts/token/ERC721/ERC721.sol b/contracts/token/ERC721/ERC721.sol index 15a0619c5..fe2404f7e 100644 --- a/contracts/token/ERC721/ERC721.sol +++ b/contracts/token/ERC721/ERC721.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../../GSN/Context.sol"; +import "../../utils/Context.sol"; import "./IERC721.sol"; import "./IERC721Metadata.sol"; import "./IERC721Enumerable.sol"; diff --git a/contracts/token/ERC721/ERC721Burnable.sol b/contracts/token/ERC721/ERC721Burnable.sol index 69bec7107..290118ade 100644 --- a/contracts/token/ERC721/ERC721Burnable.sol +++ b/contracts/token/ERC721/ERC721Burnable.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../../GSN/Context.sol"; +import "../../utils/Context.sol"; import "./ERC721.sol"; /** diff --git a/contracts/token/ERC777/ERC777.sol b/contracts/token/ERC777/ERC777.sol index 91f6f1ec2..2bf757980 100644 --- a/contracts/token/ERC777/ERC777.sol +++ b/contracts/token/ERC777/ERC777.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../../GSN/Context.sol"; +import "../../utils/Context.sol"; import "./IERC777.sol"; import "./IERC777Recipient.sol"; import "./IERC777Sender.sol"; diff --git a/contracts/utils/Context.sol b/contracts/utils/Context.sol new file mode 100644 index 000000000..3d07c4aad --- /dev/null +++ b/contracts/utils/Context.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.6.0 <0.8.0; + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} diff --git a/contracts/utils/Pausable.sol b/contracts/utils/Pausable.sol index c16e22e45..424d5ca15 100644 --- a/contracts/utils/Pausable.sol +++ b/contracts/utils/Pausable.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.0 <0.8.0; -import "../GSN/Context.sol"; +import "./Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop