编译器
0.8.18+commit.87f61d96
文件 1 的 9:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 2 的 9: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;
}
}
文件 3 的 9: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);
}
文件 4 的 9:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 5 的 9: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);
}
}
文件 6 的 9:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
}
文件 7 的 9:SDAOClaimpad.sol
pragma solidity 0.8.18;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract SDAOClaimpad is Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
struct UserInfo {
uint256 allocated;
uint256 claimed;
}
struct EmissionPeriod {
uint256 startOfEmissions;
uint256 endOfVestingCliff;
uint256 endOfEmissions;
bool vestingCliffAccrues;
}
struct PoolInfo {
address claimToken;
uint256 allocatedAmount;
EmissionPeriod emissionPeriod;
uint256 instantUnlockRatio;
uint256 totalClaimed;
}
struct Allocation {
uint256 pid;
uint256 amount;
address user;
}
uint256 public constant MAX_BASIS_POINTS = 10000;
uint256 public constant MAX_POOLS_ALLOWED = 50;
PoolInfo[] public poolInfo;
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
mapping(address => uint256) public reservedAmount;
event PoolAdded(uint256 indexed pid, address indexed token, uint256 startOfEmissions, uint256 endOfEmissions);
event Allocated(address indexed user, uint256 indexed pid, uint256 amount, address indexed token);
event Deallocated(address indexed user, uint256 indexed pid, uint256 amount, address indexed token);
event Claimed(address indexed user, uint256 indexed pid, uint256 amount);
function createPool(address _token,
uint256 _startOfEmissions,
uint256 _endOfVestingCliff,
uint256 _endOfEmissions,
bool _vestingCliffAccrues,
uint256 _instantUnlockRatio)
external onlyOwner {
require(_token != address(0), "ERR_ZERO_ADDRESS");
require(_instantUnlockRatio < MAX_BASIS_POINTS, "ERR_INSTANT_UNLOCK_RATIO");
require(_startOfEmissions < _endOfEmissions, "ERR_START_EMISSIONS");
require(_endOfVestingCliff >= _startOfEmissions
&& _endOfVestingCliff <= _endOfEmissions,
"ERR_END_OF_VESTING_CLIFF");
require(_endOfEmissions > block.timestamp, "ERR_END_EMISSIONS");
uint256 pid = poolInfo.length;
require(pid <= MAX_POOLS_ALLOWED - 1, "ERR_MAX_POOLS_ALLOWED");
poolInfo.push(PoolInfo({
claimToken: _token,
allocatedAmount: 0,
emissionPeriod: EmissionPeriod({
startOfEmissions: _startOfEmissions,
endOfVestingCliff: _endOfVestingCliff,
endOfEmissions: _endOfEmissions,
vestingCliffAccrues: _vestingCliffAccrues
}),
instantUnlockRatio: _instantUnlockRatio,
totalClaimed: 0
}));
emit PoolAdded(pid, _token, _startOfEmissions, _endOfEmissions);
}
function recoverAnyTokens(address token) external onlyOwner {
require(token != address(0), "ERR_ZERO_ADDRESS");
if(address(this).balance > 0) {
(bool success, ) = (msg.sender).call{value: address(this).balance}("");
require(success, "ERR_TRANSFER_ETH");
}
uint256 reservedTokens = reservedAmount[token];
uint256 currentTokenBalance = IERC20(token).balanceOf(address(this));
require(currentTokenBalance > reservedTokens, "ERR_NO_EXCESS_TOKENS");
uint256 excessTokens = currentTokenBalance - reservedTokens;
IERC20(token).safeTransfer(msg.sender, excessTokens);
}
function nrOfPools() external view returns (uint256) {
return poolInfo.length;
}
function getPoolClaimToken(uint256 _pid) external view returns (address) {
return poolInfo[_pid].claimToken;
}
function allocateFor(uint256 _pid,
uint256 _amount,
address _to)
public onlyOwner {
require(_pid < poolInfo.length, "ERR_POOLID");
require(_to != address(0), "ERR_ZERO_ADDRESS");
address claimToken = poolInfo[_pid].claimToken;
UserInfo storage user = userInfo[_pid][_to];
uint256 reservedClaimTokens = reservedAmount[claimToken];
require(IERC20(claimToken).balanceOf(address(this)) >= _amount + reservedClaimTokens
, "ERR_CLAIMPAD_BALANCE");
user.allocated += _amount;
poolInfo[_pid].allocatedAmount += _amount;
reservedAmount[claimToken] += _amount;
emit Allocated(_to, _pid, _amount, claimToken);
}
function bulkAllocate(Allocation[] calldata allocations) external {
uint256 nrOfAllocations = allocations.length;
for (uint256 i = 0; i < nrOfAllocations; i++) {
allocateFor(allocations[i].pid, allocations[i].amount, allocations[i].user);
}
}
function remove(uint256 _pid, address _user) public onlyOwner {
require(_pid < poolInfo.length, "ERR_POOLID");
require(_user != address(0), "ERR_ZERO_ADDRESS");
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 left = user.allocated - user.claimed;
user.allocated -= left;
pool.allocatedAmount -= left;
reservedAmount[pool.claimToken] -= left;
emit Deallocated(_user, _pid, left, pool.claimToken);
}
function removeAll(address _user) external {
uint256 pids = poolInfo.length;
for (uint256 pid = 0; pid < pids; pid++) {
if (userInfo[pid][_user].allocated > 0) {
remove(pid, _user);
}
}
}
function claim(uint256 _pid, address _to) external {
require(_pid < poolInfo.length, "ERR_POOLID");
require(_to != address(0), "ERR_ZERO_ADDRESS");
uint256 claimable = claimableTokens(_pid, msg.sender);
require(claimable > 0, "ERR_ZERO_CLAIMABLE");
UserInfo storage user = userInfo[_pid][msg.sender];
user.claimed += claimable;
PoolInfo storage pool = poolInfo[_pid];
pool.totalClaimed += claimable;
reservedAmount[pool.claimToken] -= claimable;
IERC20(pool.claimToken).safeTransfer(_to, claimable);
emit Claimed(msg.sender, _pid, claimable);
}
function claimableTokens(uint256 _pid, address _user) public view returns (uint256 claimableAmount) {
require(_pid < poolInfo.length, "ERR_POOLID");
PoolInfo memory pool = poolInfo[_pid];
if (pool.emissionPeriod.startOfEmissions > block.timestamp) {
return 0;
}
UserInfo memory user = userInfo[_pid][_user];
uint256 allocatedAmount = user.allocated;
uint256 instantUnlockedAmount = allocatedAmount * pool.instantUnlockRatio / MAX_BASIS_POINTS;
uint256 vestedAmount = allocatedAmount - instantUnlockedAmount;
uint256 startOfEmissions = pool.emissionPeriod.vestingCliffAccrues
? pool.emissionPeriod.startOfEmissions
: pool.emissionPeriod.endOfVestingCliff;
uint256 totalEmissionSeconds = pool.emissionPeriod.endOfEmissions - startOfEmissions;
uint256 emissionPassed = (block.timestamp < pool.emissionPeriod.endOfEmissions)
? (block.timestamp > startOfEmissions ? block.timestamp - startOfEmissions : 0)
: totalEmissionSeconds;
uint256 vestedUnlockedAmount = (block.timestamp >= pool.emissionPeriod.endOfVestingCliff)
? vestedAmount * emissionPassed / totalEmissionSeconds
: 0;
uint256 unlockedAmount = instantUnlockedAmount + vestedUnlockedAmount;
claimableAmount = unlockedAmount - user.claimed;
}
}
文件 8 的 9:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 9 的 9:draft-IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
{
"compilationTarget": {
"contracts/SDAOClaimpad.sol": "SDAOClaimpad"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"Allocated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"Deallocated","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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"startOfEmissions","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endOfEmissions","type":"uint256"}],"name":"PoolAdded","type":"event"},{"inputs":[],"name":"MAX_BASIS_POINTS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_POOLS_ALLOWED","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"allocateFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"pid","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"user","type":"address"}],"internalType":"struct SDAOClaimpad.Allocation[]","name":"allocations","type":"tuple[]"}],"name":"bulkAllocate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"claimableTokens","outputs":[{"internalType":"uint256","name":"claimableAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_startOfEmissions","type":"uint256"},{"internalType":"uint256","name":"_endOfVestingCliff","type":"uint256"},{"internalType":"uint256","name":"_endOfEmissions","type":"uint256"},{"internalType":"bool","name":"_vestingCliffAccrues","type":"bool"},{"internalType":"uint256","name":"_instantUnlockRatio","type":"uint256"}],"name":"createPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"}],"name":"getPoolClaimToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nrOfPools","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"poolInfo","outputs":[{"internalType":"address","name":"claimToken","type":"address"},{"internalType":"uint256","name":"allocatedAmount","type":"uint256"},{"components":[{"internalType":"uint256","name":"startOfEmissions","type":"uint256"},{"internalType":"uint256","name":"endOfVestingCliff","type":"uint256"},{"internalType":"uint256","name":"endOfEmissions","type":"uint256"},{"internalType":"bool","name":"vestingCliffAccrues","type":"bool"}],"internalType":"struct SDAOClaimpad.EmissionPeriod","name":"emissionPeriod","type":"tuple"},{"internalType":"uint256","name":"instantUnlockRatio","type":"uint256"},{"internalType":"uint256","name":"totalClaimed","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"recoverAnyTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"remove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"removeAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"reservedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"allocated","type":"uint256"},{"internalType":"uint256","name":"claimed","type":"uint256"}],"stateMutability":"view","type":"function"}]