编译器
0.8.20+commit.a1b79de6
文件 1 的 2:IERC20.sol
pragma solidity 0.8.20;
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 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
文件 2 的 2:PillRewards.sol
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
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);
}
}
contract PillRewards is Ownable {
IERC20 public immutable token;
mapping(address => uint256) public tier;
mapping(address => bool) public claimedOrBurned;
uint256 public constant DECIMALS = 18;
uint256 public constant tier1 = 500000 * (10 ** DECIMALS);
uint256 public constant tier2 = 250000 * (10 ** DECIMALS);
uint256 public constant tier3 = 50000 * (10 ** DECIMALS);
uint256 public constant threshold = 69000 * (10 ** DECIMALS);
error TheLengthDoesNotMatch();
error YourTierIsZero();
error TheBalanceIsLessThanThreshold();
error HaveYouAlreadyUsedClaimOrBurn();
event Claim(address indexed holder, uint256 tier);
event Burn(address indexed holder, uint256 tier);
constructor(address _token) {
token = IERC20(_token);
}
function claim() external {
uint256 balance = token.balanceOf(msg.sender);
uint256 _tier = tier[msg.sender];
uint256 amount;
if(_tier == 0) revert YourTierIsZero();
if(balance < threshold) revert TheBalanceIsLessThanThreshold();
if(claimedOrBurned[msg.sender]) revert HaveYouAlreadyUsedClaimOrBurn();
if(_tier == 1) {
amount = tier1;
} else if(_tier == 2) {
amount = tier2;
} else {
amount = tier3;
}
claimedOrBurned[msg.sender] = true;
token.transfer(msg.sender, amount);
emit Claim(msg.sender, amount);
}
function burn() external {
uint256 balance = token.balanceOf(msg.sender);
uint256 _tier = tier[msg.sender];
uint256 amount;
uint256 halfAmount;
if(_tier == 0) revert YourTierIsZero();
if(balance < threshold) revert TheBalanceIsLessThanThreshold();
if(claimedOrBurned[msg.sender]) revert HaveYouAlreadyUsedClaimOrBurn();
if(_tier == 1) {
amount = tier1;
} else if(_tier == 2) {
amount = tier2;
} else {
amount = tier3;
}
halfAmount = amount / 2;
claimedOrBurned[msg.sender] = true;
token.transfer(msg.sender, halfAmount);
token.transfer(0x8b8E219439bd31761A81333ae1dd041376EC22C8, halfAmount);
emit Burn(msg.sender, halfAmount);
}
function setWhitelist(address[] calldata holders, uint256[] calldata tiers) external onlyOwner {
if(holders.length != tiers.length) {
revert TheLengthDoesNotMatch();
}
uint256 length = holders.length;
for(uint256 i; i < length; ) {
tier[holders[i]] = tiers[i];
unchecked {
++i;
}
}
}
function withdrawTokens() external onlyOwner {
uint256 balance = token.balanceOf(address(this));
token.transfer(msg.sender, balance);
}
}
{
"compilationTarget": {
"src/PillRewards.sol": "PillRewards"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@openzeppelin/=node_modules/@openzeppelin/",
":forge-std/=lib/forge-std/src/"
]
}
[{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"HaveYouAlreadyUsedClaimOrBurn","type":"error"},{"inputs":[],"name":"TheBalanceIsLessThanThreshold","type":"error"},{"inputs":[],"name":"TheLengthDoesNotMatch","type":"error"},{"inputs":[],"name":"YourTierIsZero","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"holder","type":"address"},{"indexed":false,"internalType":"uint256","name":"tier","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"holder","type":"address"},{"indexed":false,"internalType":"uint256","name":"tier","type":"uint256"}],"name":"Claim","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"},{"inputs":[],"name":"DECIMALS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"claimedOrBurned","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"holders","type":"address[]"},{"internalType":"uint256[]","name":"tiers","type":"uint256[]"}],"name":"setWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"threshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tier1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tier2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tier3","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}]