编译器
0.8.19+commit.7dd6d404
文件 1 的 4:Context.sol
pragma solidity ^0.8.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;
}
}
文件 2 的 4:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, 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 from, address to, uint256 amount) external returns (bool);
}
文件 3 的 4:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
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);
}
}
文件 4 的 4:PHDeposit.sol
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract PHDeposit is Ownable {
address public kcalAddress;
address public soulAddress;
address public treasuryAddress;
error ETHTransferFailed();
error ZeroAddress();
error BalanceIsZero();
event DepositKCAL(
address indexed sender,
string phAddress,
uint256 kcalAmount
);
event DepositSoul(
address indexed sender,
string phAddress,
uint256 soulAmount
);
modifier NotZeroAddress(address _address) {
if (_address == address(0)) revert ZeroAddress();
_;
}
constructor(
address _kcalAddress,
address _soulAddress,
address _treasuryAddress
)
NotZeroAddress(_kcalAddress)
NotZeroAddress(_soulAddress)
NotZeroAddress(_treasuryAddress)
{
kcalAddress = _kcalAddress;
soulAddress = _soulAddress;
treasuryAddress = _treasuryAddress;
}
function depositAll(string calldata phAddress) external {
if (bytes(phAddress).length == 0) revert ZeroAddress();
uint256 kcalBalance = IERC20(kcalAddress).balanceOf(_msgSender());
uint256 soulBalance = IERC20(soulAddress).balanceOf(_msgSender());
if (kcalBalance == 0 && soulBalance == 0) revert BalanceIsZero();
if (kcalBalance > 0) {
IERC20(kcalAddress).transferFrom(
_msgSender(),
treasuryAddress,
kcalBalance
);
emit DepositKCAL(_msgSender(), phAddress, kcalBalance);
}
if (soulBalance > 0) {
IERC20(soulAddress).transferFrom(
_msgSender(),
treasuryAddress,
soulBalance
);
emit DepositSoul(_msgSender(), phAddress, soulBalance);
}
}
function depositKCAL(string calldata phAddress) external {
if (bytes(phAddress).length == 0) revert ZeroAddress();
uint256 balance = IERC20(kcalAddress).balanceOf(_msgSender());
if (balance == 0) revert BalanceIsZero();
IERC20(kcalAddress).transferFrom(
_msgSender(),
treasuryAddress,
balance
);
emit DepositKCAL(_msgSender(), phAddress, balance);
}
function depositSoul(string calldata phAddress) external {
if (bytes(phAddress).length == 0) revert ZeroAddress();
uint256 balance = IERC20(soulAddress).balanceOf(_msgSender());
if (balance == 0) revert BalanceIsZero();
IERC20(soulAddress).transferFrom(
_msgSender(),
treasuryAddress,
balance
);
emit DepositSoul(_msgSender(), phAddress, balance);
}
function recoverETH(uint ethAmount) external onlyOwner {
(bool success, ) = treasuryAddress.call{value: ethAmount}("");
if (!success) revert ETHTransferFailed();
}
function recoverTokens(
address tokenAddress,
uint tokenAmount
) external onlyOwner {
IERC20(tokenAddress).transfer(treasuryAddress, tokenAmount);
}
function setKCALAddress(
address value
) external onlyOwner NotZeroAddress(value) {
kcalAddress = value;
}
function setSoulAddress(
address value
) external onlyOwner NotZeroAddress(value) {
soulAddress = value;
}
function setTreasuryAddress(
address value
) external onlyOwner NotZeroAddress(value) {
treasuryAddress = value;
}
receive() external payable {}
fallback() external payable {}
}
{
"compilationTarget": {
"contracts/PHDeposit.sol": "PHDeposit"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_kcalAddress","type":"address"},{"internalType":"address","name":"_soulAddress","type":"address"},{"internalType":"address","name":"_treasuryAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BalanceIsZero","type":"error"},{"inputs":[],"name":"ETHTransferFailed","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"string","name":"phAddress","type":"string"},{"indexed":false,"internalType":"uint256","name":"kcalAmount","type":"uint256"}],"name":"DepositKCAL","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"string","name":"phAddress","type":"string"},{"indexed":false,"internalType":"uint256","name":"soulAmount","type":"uint256"}],"name":"DepositSoul","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"string","name":"phAddress","type":"string"}],"name":"depositAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"phAddress","type":"string"}],"name":"depositKCAL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"phAddress","type":"string"}],"name":"depositSoul","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"kcalAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"ethAmount","type":"uint256"}],"name":"recoverETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"recoverTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"value","type":"address"}],"name":"setKCALAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"value","type":"address"}],"name":"setSoulAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"value","type":"address"}],"name":"setTreasuryAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"soulAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasuryAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]