Skip to content

Instantly share code, notes, and snippets.

@novaknole
Created April 13, 2021 12:10
Show Gist options
  • Save novaknole/eefcb4a8d666a00362f94aba63813632 to your computer and use it in GitHub Desktop.
Save novaknole/eefcb4a8d666a00362f94aba63813632 to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.8;
contract Finance {
address owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
receive() {
}
function transfer(address payable _to, address _token, uint256 _amount) onlyOwner external {
if (_token == address(0)) {
require(_to.send(_amount), ERROR_ETH_TRANSFER_FAILED);
} else {
require(IERC20(_token).safeTransfer(_to, _amount), ERROR_TOKEN_TRANSFER_FAILED);
}
}
function deposit(address _token, uint256 amount) onlyOwner payable external {
if (msg.value > 0) {
require(_token == address(0), ERROR_ETH_DEPOSIT_TOKEN_MISMATCH);
require(msg.value == _amount, ERROR_ETH_DEPOSIT_AMOUNT_MISMATCH);
} else {
require(isContract(_token), ERROR_TOKEN_NOT_CONTRACT);
require(IERC20(_token).safeTransferFrom(_from, address(this), _amount), ERROR_TOKEN_DEPOSIT_FAILED);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment