Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Created February 4, 2022 04:31
Show Gist options
  • Select an option

  • Save z0r0z/2132ac653fe42a1c4bb1d9eeab620e4a to your computer and use it in GitHub Desktop.

Select an option

Save z0r0z/2132ac653fe42a1c4bb1d9eeab620e4a to your computer and use it in GitHub Desktop.
simple ETH receiver that automates fees
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.4;
contract ETHfeed {
uint256 feeRate;
address feeReceiver;
constructor(uint256 feeRate_) {
feeRate = feeRate_;
}
receive() external payable {
deposit();
}
function deposit() public payable {
uint256 fee = msg.value / feeRate;
_safeTransferETH(feeReceiver, fee);
}
/// @dev ETH tranfer helper - optimized in assembly:
function _safeTransferETH(address to, uint256 amount) internal {
bool callStatus;
assembly {
// transfer the ETH and store if it succeeded or not
callStatus := call(gas(), to, amount, 0, 0, 0, 0)
}
require(callStatus, 'ETH_TRANSFER_FAILED');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment