文件 1 的 1:FeeReceiver.sol
pragma solidity 0.8.20;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function symbol() external view returns(string memory);
function name() external view returns(string memory);
function balanceOf(address account) external view returns (uint256);
function decimals() external view returns (uint8);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IOwnedContract {
function getOwner() external view returns (address);
}
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
interface IStaking {
function depositRewards(uint256 amount) external;
}
contract FeeReceiver {
address public constant token = 0x57a7338BC72b8a7EB1c02E270DA40161aF3c6748;
address public router = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address public team = 0x8e72b0145972B7609685e50fa08130cA355608e6;
address public staking1 = 0x9aE90248Ef7ebb4622df195C70c4E7BC54c91A0f;
address public staking2 = 0x388D92b0be46111411CAdcEF3f7A640D9425d7Ce;
address public staking3 = 0xc9075deFdBaD1eE320CB0b16BE3d74B7f2a65812;
address public marketing = 0x034532c965794232a98e01b363cd7Bb05fC5C396;
uint256 public teamShare = 20;
uint256 public stakingShare = 40;
mapping ( address => bool ) public canTrigger;
modifier onlyOwner(){
require(
msg.sender == IOwnedContract(token).getOwner(),
'Only Token Owner'
);
_;
}
constructor() {
canTrigger[msg.sender] = true;
}
function setShares(uint256 _teamShare, uint256 _stakingShare) external onlyOwner {
teamShare = _teamShare;
stakingShare = _stakingShare;
}
function setTeam(address _team) external onlyOwner {
team = _team;
}
function setStaking1(address _staking1) external onlyOwner {
staking1 = _staking1;
}
function setStaking2(address _staking2) external onlyOwner {
staking2 = _staking2;
}
function setStaking3(address _staking3) external onlyOwner {
staking3 = _staking3;
}
function setMarketing(address _marketing) external onlyOwner {
marketing = _marketing;
}
function setRouter(address _router) external onlyOwner {
router = _router;
}
function setCanTrigger(address _address, bool _canTrigger) external onlyOwner {
canTrigger[_address] = _canTrigger;
}
function withdrawToken(address _token, address _to, uint256 _amount) external onlyOwner {
TransferHelper.safeTransfer(_token, _to, _amount);
}
function withdrawETH(address _to, uint256 _amount) external onlyOwner {
TransferHelper.safeTransferETH(_to, _amount);
}
function trigger(uint256 minOut) external {
require(
canTrigger[msg.sender] || canTrigger[address(0)],
'Not Allowed'
);
uint256 bal = IERC20(token).balanceOf(address(this));
if (bal == 0) {
return;
}
uint256 stakingAmount = ( bal * stakingShare ) / 100;
if (stakingAmount > 0) {
(uint256 amount3, uint256 amount2, uint256 amount1) = splitRewards(stakingAmount);
if (amount3 > 0) {
IERC20(token).approve(staking3, amount3);
IStaking(staking3).depositRewards(amount3);
}
if (amount2 > 0) {
IERC20(token).approve(staking2, amount2);
IStaking(staking2).depositRewards(amount2);
}
if (amount1 > 0) {
IERC20(token).approve(staking1, amount1);
IStaking(staking1).depositRewards(amount1);
}
}
uint256 newBal = IERC20(token).balanceOf(address(this));
if (newBal == 0) {
return;
}
_swap(newBal, minOut);
uint256 teamAmount = ( address(this).balance * teamShare ) / 100;
uint256 marketingAmount = address(this).balance - teamAmount;
if (teamAmount > 0) {
TransferHelper.safeTransferETH(team, teamAmount);
}
if (marketingAmount > 0) {
TransferHelper.safeTransferETH(marketing, marketingAmount);
}
}
function splitRewards(uint256 numRewards) public view returns (uint256 amountForPool3, uint256 amountForPool2, uint256 amountForPool1) {
uint256 tvlPool1 = IERC20(token).balanceOf(staking1);
uint256 tvlPool2 = IERC20(token).balanceOf(staking2);
uint256 tvlPool3 = IERC20(token).balanceOf(staking3);
uint256 weightedPool1 = tvlPool1 * 1;
uint256 weightedPool2 = tvlPool2 * 2;
uint256 weightedPool3 = tvlPool3 * 4;
uint256 totalWeight = weightedPool1 + weightedPool2 + weightedPool3;
if (totalWeight == 0) {
return (0, 0, 0);
}
amountForPool1 = (numRewards * weightedPool1) / totalWeight;
amountForPool2 = (numRewards * weightedPool2) / totalWeight;
amountForPool3 = (numRewards * weightedPool3) / totalWeight;
return (amountForPool3, amountForPool2, amountForPool1);
}
function _swap(uint256 amount, uint256 minOut) internal {
IERC20(token).approve(router, amount);
address[] memory path = new address[](2);
path[0] = token;
path[1] = IUniswapV2Router02(router).WETH();
IUniswapV2Router02(router).swapExactTokensForETHSupportingFeeOnTransferTokens(
amount,
minOut,
path,
address(this),
block.timestamp + 1000
);
delete path;
}
receive() external payable {}
}