Created
August 11, 2021 09:33
-
-
Save gitpusha/90447568e604e40c863652291c1f4d99 to your computer and use it in GitHub Desktop.
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
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity 0.8.6; | |
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | |
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
abstract contract Gelatofied { | |
using SafeERC20 for IERC20; | |
address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; | |
address payable public immutable gelato; | |
address public paymentToken; | |
modifier gelatofy(uint256 _amount, address _paymentToken) { | |
require(msg.sender == gelato, "Gelatofied: Only gelato"); | |
_; | |
if (_paymentToken == ETH) { | |
(bool success, ) = gelato.call{value: _amount}(""); | |
require(success, "Gelatofied: Gelato fee failed"); | |
} else { | |
IERC20(_paymentToken).safeTransfer(gelato, _amount); | |
} | |
} | |
constructor(address payable _gelato) { | |
require(_gelato != address(0), "Gelato can not be zero address"); | |
gelato = _gelato; | |
paymentToken = ETH; | |
} | |
function _setPaymentToken(address _token) internal { | |
require(_token != address(0), "Gelatofied: zero address"); | |
paymentToken = _token; | |
} | |
function _withdraw( | |
address _token, | |
address payable _receiver, | |
uint256 _amount | |
) internal { | |
if (_token == ETH) { | |
(bool success, ) = _receiver.call{value: _amount}(""); | |
require(success, "Gelatofied: eth withdraw failed"); | |
} else { | |
IERC20(_token).safeTransfer(_receiver, _amount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment