Skip to content

Commit

Permalink
properly moved old raffle contrats (first versions)
Browse files Browse the repository at this point in the history
  • Loading branch information
abarbatei committed Sep 28, 2023
1 parent 35f92bc commit 1add64c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
// solhint-disable-next-line compiler-version
pragma solidity 0.8.2;

/// @dev minimal ERC2771 handler to keep bytecode-size down
/// based on: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.6.0/contracts/metatx/ERC2771Context.sol
/// with an initializer for proxies and a mutable forwarder
/// @dev same as ERC2771Handler.sol but with gap

contract ERC2771HandlerUpgradeable {
address internal _trustedForwarder;
uint256[49] private __gap;

function __ERC2771Handler_initialize(address forwarder) internal {
_trustedForwarder = forwarder;
}

function isTrustedForwarder(address forwarder) public view returns (bool) {
return forwarder == _trustedForwarder;
}

function getTrustedForwarder() external view returns (address trustedForwarder) {
return _trustedForwarder;
}

function _msgSender() internal view virtual returns (address sender) {
if (isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
// solhint-disable-next-line no-inline-assembly
assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
return msg.sender;
}
}

function _msgData() internal view virtual returns (bytes calldata) {
if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length - 20];
} else {
return msg.data;
}
}
}

0 comments on commit 1add64c

Please sign in to comment.