Skip to content

Instantly share code, notes, and snippets.

@gitpusha
Created August 11, 2021 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitpusha/d209187e6d05466b5b2066ce20615c6c to your computer and use it in GitHub Desktop.
Save gitpusha/d209187e6d05466b5b2066ce20615c6c to your computer and use it in GitHub Desktop.
Wrapper that allows seascapeAdmin to operate all functions via the fallback and that allows the Wrapper to also call certain functions on the protocol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.6;
import "@openzeppelin/contracts/access/Ownable.sol";
import "../interfaces/INftRush.sol";
import "../gelato/Gelatofied.sol";
contract GelatoNftRushWrapper is Ownable, Gelatofied {
using SafeERC20 for IERC20;
INftRush public immutable nftRush;
IERC20 public immutable crowns;
constructor(
address _nftRush,
address _seascapeAdmin,
address _crowns,
address payable _gelato
) public Gelatofied(_gelato) {
require(_nftRush != address(0), "NftRush can not be zero address");
require(
_seascapeAdmin != address(0),
"Seascape can not be zero address"
);
require(_crowns != address(0), "Crowns can not be zero address");
transferOwnership(_seascapeAdmin);
crowns = IERC20(_crowns);
nftRush = INftRush(_nftRush);
}
/// @notice deposit eth
// solhint-disable-next-line no-empty-blocks
receive() external payable {}
/// @dev Call NftRush methods
/// @dev only owner can call NftRush methods
/// This function does not return to its internall call site, it will return directly to the external caller.
// solhint-disable-next-line no-complex-fallback
fallback() external payable onlyOwner {
address implementation = address(nftRush);
uint256 value = msg.value;
// solhint-disable-next-line no-inline-assembly
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
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation (nftRush).
// out and outsize are 0 because we don't know the size yet.
let result := call(
gas(),
implementation,
value,
0,
calldatasize(),
0,
0
)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// call returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/// @notice withdraw contract eth/token
/// @param _token the address of token to be withdrawn
/// @param _receiver the address to receive eth
/// @param _amount the amount of eth to be withdrawn
function withdraw(
address _token,
address payable _receiver,
uint256 _amount
) external onlyOwner {
_withdraw(_token, _receiver, _amount);
}
/// @notice set token to use as payment
/// @param _token the address of token to be set as default token payment
function setPaymentToken(address _token) external onlyOwner {
_setPaymentToken(_token);
}
function announceDailySpentWinners(
uint256 _sessionId,
address[10] calldata _winners,
uint8 _winnersAmount,
uint256 _allowanceAmount,
uint256 _gelatoFee,
address _gelatopPaymentToken
) external gelatofy(_gelatoFee, _gelatopPaymentToken) {
if (_allowanceAmount > 0)
crowns.safeIncreaseAllowance(address(nftRush), _allowanceAmount);
nftRush.announceDailySpentWinners(_sessionId, _winners, _winnersAmount);
}
function announceAllTimeMintedWinners(
uint256 _sessionId,
address[10] calldata _winners,
uint8 _winnersAmount,
uint256 _allowanceAmount,
uint256 _gelatoFee,
address _gelatopPaymentToken
) external gelatofy(_gelatoFee, _gelatopPaymentToken) {
if (_allowanceAmount > 0)
crowns.safeIncreaseAllowance(address(nftRush), _allowanceAmount);
nftRush.announceAllTimeMintedWinners(
_sessionId,
_winners,
_winnersAmount
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment