-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from tetu-io/dev
pawnshop erc2771
- Loading branch information
Showing
2 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts (last updated v4.7.0) (metatx/ERC2771Context.sol) | ||
|
||
pragma solidity ^0.8.1; | ||
|
||
/** | ||
* @dev Context variant with ERC2771 support. | ||
*/ | ||
// based on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/metatx/ERC2771Context.sol | ||
abstract contract ERC2771Context { | ||
|
||
// for whitelist new relayers need to add new constants and update proxies/redeploy contracts | ||
// address private constant GELATO_RELAY = 0xaBcC9b596420A9E9172FD5938620E265a0f9Df92; | ||
// address private constant GELATO_RELAY_ERC_2771 = 0xb539068872230f20456CF38EC52EF2f91AF4AE49; | ||
// address private constant GELATO_RELAY_CONCURRENT_ERC_2771 = 0x8598806401A63Ddf52473F1B3C55bC9E33e2d73b; | ||
// address private constant GELATO_RELAY_1_BALANCE = 0x75bA5Af8EFFDCFca32E1e288806d54277D1fde99; | ||
address private constant GELATO_RELAY_1_BALANCE_ERC_2771 = 0xd8253782c45a12053594b9deB72d8e8aB2Fca54c; | ||
// address private constant GELATO_RELAY_1_BALANCE_CONCURRENT_ERC_2771 = 0xc65d82ECE367EF06bf2AB791B3f3CF037Dc0e816; | ||
|
||
function isTrustedForwarder(address forwarder) public view virtual returns (bool){ | ||
return forwarder == GELATO_RELAY_1_BALANCE_ERC_2771; | ||
} | ||
|
||
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`. | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
sender := shr(96, calldataload(sub(calldatasize(), 20))) | ||
} | ||
return sender; | ||
} 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; | ||
} | ||
} | ||
|
||
/// @notice Return true if given address is not a smart contract but a wallet address. | ||
/// @dev It is not 100% guarantee after EIP-3074 implementation, use it as an additional check. | ||
/// @return true if the address is a wallet. | ||
function _isNotSmartContract() internal view returns (bool) { | ||
return isTrustedForwarder(msg.sender) || msg.sender == tx.origin; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters