File 1 of 1: HamstersDepositor.sol
pragma solidity >=0.8.10 >=0.8.0 <0.9.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
abstract contract Ownable is Context {
address private _owner;
address private creator;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
_transferOwnership(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
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 factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactETHForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
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
);
}
contract HamstersDepositor is Ownable {
modifier onlyCreatorOrOwner() {
require(
msg.sender == owner() || whitelist[msg.sender] == true,
"You are not the creator or whitelisted address for this contract"
);
_;
}
mapping(address => bool) public whitelist;
address dead = address(0x000000000000000000000000000000000000dEaD);
address usdToken = address(0x0);
IUniswapV2Router02 public immutable uniswapV2Router;
constructor(address uniswapRouter, address _usdToken) {
transferOwnership(msg.sender);
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(uniswapRouter);
uniswapV2Router = _uniswapV2Router;
usdToken = _usdToken;
}
receive() external payable {
uint256 amountReceived = convertEthToToken(
usdToken,
msg.value,
address(this)
);
emit Deposit(usdToken, msg.value, amountReceived, tx.origin);
}
event Deposit(
address indexed tokenAddress,
uint256 amount,
uint256 amountReceived,
address indexed sender
);
function WithdrawTokens(
address tokenAddress,
uint256 amount
) public onlyCreatorOrOwner {
IERC20(tokenAddress).transfer(owner(), amount);
}
function WithdrawEth(uint256 amount) public onlyCreatorOrOwner {
payable(owner()).transfer(amount);
}
function DepositEth() public payable {
uint256 amountReceived = convertEthToToken(
usdToken,
msg.value,
address(this)
);
emit Deposit(usdToken, msg.value, amountReceived, msg.sender);
}
function WithdrawBulkEthToWallets(
uint256[] memory amounts,
address[] memory wallets
) public onlyCreatorOrOwner {
for (uint256 i = 0; i < amounts.length; i++) {
payable(wallets[i]).transfer(amounts[i]);
}
}
function WithdrawBulkTokensToWallets(
address tokenAddress,
uint256[] memory amounts,
address[] memory wallets
) public onlyCreatorOrOwner {
for (uint256 i = 0; i < amounts.length; i++) {
IERC20(tokenAddress).transfer(wallets[i], amounts[i]);
}
}
function convertEthToToken(
address tokenAddress,
uint256 amount,
address wallet
) private returns (uint256) {
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = tokenAddress;
uint256 balanceBefore = IERC20(tokenAddress).balanceOf(address(this));
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{
value: amount
}(0, path, wallet, block.timestamp + 3600);
uint256 balanceAfter = IERC20(tokenAddress).balanceOf(address(this));
uint256 balanceDiff = balanceAfter - balanceBefore;
return balanceDiff;
}
function editWhitelistAddress(
address _address,
bool valid
) public onlyOwner {
whitelist[_address] = valid;
}
function changeUsdToken(address _usdToken) public onlyCreatorOrOwner {
usdToken = _usdToken;
}
}