编译器
0.8.20+commit.a1b79de6
文件 1 的 22:Address.sol
pragma solidity ^0.8.20;
library Address {
error AddressInsufficientBalance(address account);
error AddressEmptyCode(address target);
error FailedInnerCall();
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
function _revert(bytes memory returndata) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
文件 2 的 22:Amount.sol
pragma solidity =0.8.20;
type Amount is uint256;
using {add as +, sub as -, isZero} for Amount global;
function add(Amount a, Amount b) pure returns (Amount sum) {
sum = Amount.wrap(Amount.unwrap(a) + Amount.unwrap(b));
}
function sub(Amount a, Amount b) pure returns (Amount difference) {
difference = Amount.wrap(Amount.unwrap(a) - Amount.unwrap(b));
}
function isZero(Amount a) pure returns (bool result) {
result = Amount.unwrap(a) == 0;
}
文件 3 的 22:Context.sol
pragma solidity ^0.8.20;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 4 的 22:Create2.sol
pragma solidity ^0.8.20;
library Create2 {
error Create2InsufficientBalance(uint256 balance, uint256 needed);
error Create2EmptyBytecode();
error Create2FailedDeployment();
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
if (address(this).balance < amount) {
revert Create2InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create2EmptyBytecode();
}
assembly {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
}
if (addr == address(0)) {
revert Create2FailedDeployment();
}
}
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
return computeAddress(salt, bytecodeHash, address(this));
}
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
assembly {
let ptr := mload(0x40)
mstore(add(ptr, 0x40), bytecodeHash)
mstore(add(ptr, 0x20), salt)
mstore(ptr, deployer)
let start := add(ptr, 0x0b)
mstore8(start, 0xff)
addr := keccak256(start, 85)
}
}
}
文件 5 的 22: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);
}
文件 6 的 22:IERC20Permit.sol
pragma solidity ^0.8.20;
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);
}
文件 7 的 22:IMerkleDistributor.sol
pragma solidity =0.8.20;
interface IMerkleDistributor {
function token() external view returns (address);
function merkleRoot() external view returns (bytes32);
function isClaimed(uint256 index) external view returns (bool);
function claim(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof
) external;
event Claimed(uint256 index, address account, uint256 amount);
}
文件 8 的 22:IMerkleDistributorPeriphery.sol
pragma solidity =0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IMerkleDistributorWithDeadline} from "src/uniswap/interfaces/IMerkleDistributorWithDeadline.sol";
import {IOwnable2Step} from "src/interfaces/IOwnable2Step.sol";
import {Amount} from "src/types/Amount.sol";
import {Id} from "src/types/Id.sol";
import {Index} from "src/types/Index.sol";
import {MerkleProof} from "src/types/MerkleProof.sol";
import {MerkleRoot} from "src/types/MerkleRoot.sol";
import {Number} from "src/types/Number.sol";
import {Timestamp} from "src/types/Timestamp.sol";
interface IMerkleDistributorPeriphery is IOwnable2Step {
event Queue(
address indexed deployer,
IERC20 indexed token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
);
event Unqueue();
event CreateFromQueue(
Id indexed id,
IMerkleDistributorWithDeadline indexed distributor,
IERC20 indexed token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
);
event Create(
Id indexed id,
IMerkleDistributorWithDeadline indexed distributor,
IERC20 indexed token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
);
event Withdraw(
IMerkleDistributorWithDeadline indexed distributor,
Amount amount
);
error CannotQueueWithDeployerAsZeroAddress();
error CannotQueueWithTokenAsZeroAddress();
error CannotQueueWithTotalAmountAsZero();
error CannotQueueWithEndTimeInThePast();
error CannotCreateWithTokenAsZeroAddress();
error CannotCreateWithTotalAmountAsZero();
error CannotCreateWithEndTimeInThePast();
error OnlyAuthorizedOwner(address account);
error InconsistentQueuedToken();
error InconsistentQueuedTotalAmount();
error InconsistentQueuedMerkleRoot();
error InconsistentQueuedEndTime();
function merkleDistributor(
Id id
) external view returns (IMerkleDistributorWithDeadline);
function totalMerkleDistributors() external view returns (Number);
function ownerGivenId(Id id) external view returns (address);
struct Query {
IMerkleDistributorWithDeadline distributor;
Index index;
}
function areClaimed(
Query[] calldata queries
) external view returns (bool[] memory results);
function queued()
external
view
returns (
address deployer,
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
);
function queue(
address deployer,
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
) external;
function unqueue() external;
function createFromQueue(
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
) external returns (Id id, IMerkleDistributorWithDeadline distributor);
function create(
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
) external returns (Id id, IMerkleDistributorWithDeadline distributor);
struct Order {
IMerkleDistributorWithDeadline distributor;
Index index;
Amount amount;
MerkleProof[] merkleProof;
}
function claim(Order[] calldata orders) external;
function withdraw(
IMerkleDistributorWithDeadline[] calldata distributors
) external returns (Amount[] memory amounts);
}
文件 9 的 22:IMerkleDistributorWithDeadline.sol
pragma solidity =0.8.20;
import {IMerkleDistributor} from "./IMerkleDistributor.sol";
interface IMerkleDistributorWithDeadline is IMerkleDistributor {
function owner() external view returns (address);
function endTime() external returns (uint256);
function withdraw() external;
}
文件 10 的 22:IOwnable2Step.sol
pragma solidity =0.8.20;
interface IOwnable2Step {
function owner() external view returns (address);
function pendingOwner() external view returns (address);
function renounceOwnership() external;
function transferOwnership(address newOwner) external;
function acceptOwnership() external;
}
文件 11 的 22:Id.sol
pragma solidity =0.8.20;
type Id is uint256;
文件 12 的 22:Index.sol
pragma solidity =0.8.20;
type Index is uint256;
文件 13 的 22:MerkleDistributor.sol
pragma solidity =0.8.20;
import {IERC20, SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {MerkleProof} from "openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol";
import {IMerkleDistributor} from "./interfaces/IMerkleDistributor.sol";
error AlreadyClaimed();
error InvalidProof();
contract MerkleDistributor is IMerkleDistributor {
using SafeERC20 for IERC20;
address public immutable override token;
bytes32 public immutable override merkleRoot;
mapping(uint256 => uint256) private claimedBitMap;
constructor(address token_, bytes32 merkleRoot_) {
token = token_;
merkleRoot = merkleRoot_;
}
function isClaimed(uint256 index) public view override returns (bool) {
uint256 claimedWordIndex = index / 256;
uint256 claimedBitIndex = index % 256;
uint256 claimedWord = claimedBitMap[claimedWordIndex];
uint256 mask = (1 << claimedBitIndex);
return claimedWord & mask == mask;
}
function _setClaimed(uint256 index) private {
uint256 claimedWordIndex = index / 256;
uint256 claimedBitIndex = index % 256;
claimedBitMap[claimedWordIndex] =
claimedBitMap[claimedWordIndex] |
(1 << claimedBitIndex);
}
function claim(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof
) public virtual override {
if (isClaimed(index)) revert AlreadyClaimed();
bytes32 node = keccak256(abi.encodePacked(index, account, amount));
if (!MerkleProof.verify(merkleProof, merkleRoot, node))
revert InvalidProof();
_setClaimed(index);
IERC20(token).safeTransfer(account, amount);
emit Claimed(index, account, amount);
}
}
文件 14 的 22:MerkleDistributorPeriphery.sol
pragma solidity =0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {IMerkleDistributorWithDeadline} from "src/uniswap/interfaces/IMerkleDistributorWithDeadline.sol";
import {MerkleDistributorWithDeadline} from "src/uniswap/MerkleDistributorWithDeadline.sol";
import {IMerkleDistributorPeriphery} from "src/interfaces/IMerkleDistributorPeriphery.sol";
import {IOwnable2Step} from "src/interfaces/IOwnable2Step.sol";
import {Amount} from "src/types/Amount.sol";
import {Id} from "src/types/Id.sol";
import {Index} from "src/types/Index.sol";
import {MerkleProof} from "src/types/MerkleProof.sol";
import {MerkleRoot} from "src/types/MerkleRoot.sol";
import {Number} from "src/types/Number.sol";
import {Timestamp} from "src/types/Timestamp.sol";
contract MerkleDistributorPeriphery is
IMerkleDistributorPeriphery,
Ownable2Step
{
using SafeERC20 for IERC20;
IMerkleDistributorWithDeadline[] private storedDistributors;
mapping(Id => address) private ownerships;
mapping(IMerkleDistributorWithDeadline distributor => address)
private ownershipGivenDistributors;
address private queuedDeployer;
IERC20 private queuedToken;
Amount private queuedTotalAmount;
MerkleRoot private queuedMerkleRoot;
Timestamp private queuedEndTime;
constructor(address chosenOwner) Ownable(chosenOwner) {}
function merkleDistributor(
Id id
) external view override returns (IMerkleDistributorWithDeadline) {
return storedDistributors[Id.unwrap(id)];
}
function totalMerkleDistributors() external view override returns (Number) {
return Number.wrap(storedDistributors.length);
}
function ownerGivenId(Id id) external view override returns (address) {
if (Id.unwrap(id) >= storedDistributors.length) return address(0);
address ownership = ownerships[id];
return ownership == address(0) ? owner() : ownership;
}
function areClaimed(
Query[] calldata queries
) external view override returns (bool[] memory results) {
uint256 length = queries.length;
results = new bool[](length);
for (uint256 i; i < length; ) {
Query memory query = queries[i];
results[i] = query.distributor.isClaimed(Index.unwrap(query.index));
unchecked {
i++;
}
}
}
function queued()
external
view
override
returns (
address deployer,
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
)
{
deployer = queuedDeployer;
token = queuedToken;
totalAmount = queuedTotalAmount;
merkleRoot = queuedMerkleRoot;
endTime = queuedEndTime;
}
function queue(
address deployer,
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
) external override onlyOwner {
if (deployer == address(0))
revert CannotQueueWithDeployerAsZeroAddress();
if (address(token) == address(0))
revert CannotQueueWithTokenAsZeroAddress();
if (totalAmount.isZero()) revert CannotQueueWithTotalAmountAsZero();
if (endTime <= Timestamp.wrap(block.timestamp))
revert CannotQueueWithEndTimeInThePast();
queuedDeployer = deployer;
queuedToken = token;
queuedTotalAmount = totalAmount;
queuedMerkleRoot = merkleRoot;
queuedEndTime = endTime;
emit Queue(deployer, token, totalAmount, merkleRoot, endTime);
}
function unqueue() external override onlyOwner {
queuedDeployer = address(0);
queuedToken = IERC20(address(0));
queuedTotalAmount = Amount.wrap(0);
queuedMerkleRoot = MerkleRoot.wrap(0);
queuedEndTime = Timestamp.wrap(0);
emit Unqueue();
}
function createFromQueue(
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
)
external
override
returns (Id id, IMerkleDistributorWithDeadline distributor)
{
if (msg.sender != queuedDeployer)
revert OnlyAuthorizedOwner(msg.sender);
if (address(token) != address(queuedToken))
revert InconsistentQueuedToken();
if (Amount.unwrap(totalAmount) != Amount.unwrap(queuedTotalAmount))
revert InconsistentQueuedTotalAmount();
if (MerkleRoot.unwrap(merkleRoot) != MerkleRoot.unwrap(merkleRoot))
revert InconsistentQueuedMerkleRoot();
if (Timestamp.unwrap(endTime) != Timestamp.unwrap(queuedEndTime))
revert InconsistentQueuedEndTime();
if (queuedEndTime <= Timestamp.wrap(block.timestamp))
revert CannotCreateWithEndTimeInThePast();
id = Id.wrap(storedDistributors.length);
distributor = IMerkleDistributorWithDeadline(
Create2.deploy(
0,
bytes32(Id.unwrap(id)),
abi.encodePacked(
type(MerkleDistributorWithDeadline).creationCode,
abi.encode(
address(token),
MerkleRoot.unwrap(merkleRoot),
Timestamp.unwrap(endTime)
)
)
)
);
storedDistributors.push(distributor);
queuedDeployer = address(0);
queuedToken = IERC20(address(0));
queuedTotalAmount = Amount.wrap(0);
queuedMerkleRoot = MerkleRoot.wrap(0);
queuedEndTime = Timestamp.wrap(0);
ownerships[id] = msg.sender;
ownershipGivenDistributors[distributor] = msg.sender;
token.safeTransferFrom(
msg.sender,
address(distributor),
Amount.unwrap(totalAmount)
);
emit CreateFromQueue(
id,
distributor,
token,
totalAmount,
merkleRoot,
endTime
);
}
function create(
IERC20 token,
Amount totalAmount,
MerkleRoot merkleRoot,
Timestamp endTime
)
external
override
onlyOwner
returns (Id id, IMerkleDistributorWithDeadline distributor)
{
if (address(token) == address(0))
revert CannotCreateWithTokenAsZeroAddress();
if (totalAmount.isZero()) revert CannotCreateWithTotalAmountAsZero();
if (endTime <= Timestamp.wrap(block.timestamp))
revert CannotCreateWithEndTimeInThePast();
id = Id.wrap(storedDistributors.length);
distributor = IMerkleDistributorWithDeadline(
Create2.deploy(
0,
bytes32(Id.unwrap(id)),
abi.encodePacked(
type(MerkleDistributorWithDeadline).creationCode,
abi.encode(
address(token),
MerkleRoot.unwrap(merkleRoot),
Timestamp.unwrap(endTime)
)
)
)
);
storedDistributors.push(distributor);
token.safeTransferFrom(
msg.sender,
address(distributor),
Amount.unwrap(totalAmount)
);
emit Create(id, distributor, token, totalAmount, merkleRoot, endTime);
}
function claim(Order[] calldata orders) external override {
uint256 length = orders.length;
for (uint256 i; i < length; ) {
Order memory order = orders[i];
MerkleProof[] memory merkleProof = order.merkleProof;
uint256 lengthOfMerkleProof = merkleProof.length;
bytes32[] memory merkleProofInBytes32 = new bytes32[](
lengthOfMerkleProof
);
for (uint256 j; j < lengthOfMerkleProof; ) {
merkleProofInBytes32[j] = MerkleProof.unwrap(merkleProof[j]);
unchecked {
j++;
}
}
order.distributor.claim(
Index.unwrap(order.index),
msg.sender,
Amount.unwrap(order.amount),
merkleProofInBytes32
);
unchecked {
i++;
}
}
}
function withdraw(
IMerkleDistributorWithDeadline[] calldata distributors
) external override returns (Amount[] memory amounts) {
uint256 length = distributors.length;
amounts = new Amount[](length);
for (uint256 i; i < length; ) {
IMerkleDistributorWithDeadline distributor = distributors[i];
address deployer = ownershipGivenDistributors[distributor];
if (deployer == address(0)) deployer = owner();
if (deployer != msg.sender) revert OnlyAuthorizedOwner(msg.sender);
IERC20 token = IERC20(distributor.token());
Amount amount = Amount.wrap(token.balanceOf(address(distributor)));
if (!amount.isZero()) {
amounts[i] = amount;
distributor.withdraw();
token.safeTransfer(msg.sender, Amount.unwrap(amount));
emit Withdraw(distributor, amount);
}
unchecked {
i++;
}
}
}
function owner()
public
view
override(Ownable, IOwnable2Step)
returns (address)
{
return super.owner();
}
function renounceOwnership() public override(Ownable, IOwnable2Step) {
super.renounceOwnership();
}
function pendingOwner()
public
view
override(Ownable2Step, IOwnable2Step)
returns (address)
{
return super.pendingOwner();
}
function transferOwnership(
address newOwner
) public override(Ownable2Step, IOwnable2Step) {
super.transferOwnership(newOwner);
}
function acceptOwnership() public override(Ownable2Step, IOwnable2Step) {
super.acceptOwnership();
}
}
文件 15 的 22:MerkleDistributorWithDeadline.sol
pragma solidity =0.8.20;
import {MerkleDistributor} from "./MerkleDistributor.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
error EndTimeInPast();
error ClaimWindowFinished();
error NoWithdrawDuringClaim();
contract MerkleDistributorWithDeadline is MerkleDistributor, Ownable {
using SafeERC20 for IERC20;
uint256 public immutable endTime;
constructor(
address token_,
bytes32 merkleRoot_,
uint256 endTime_
) MerkleDistributor(token_, merkleRoot_) Ownable(msg.sender) {
if (endTime_ <= block.timestamp) revert EndTimeInPast();
endTime = endTime_;
}
function claim(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof
) public override {
if (block.timestamp > endTime) revert ClaimWindowFinished();
super.claim(index, account, amount, merkleProof);
}
function withdraw() external onlyOwner {
if (block.timestamp < endTime) revert NoWithdrawDuringClaim();
IERC20(token).safeTransfer(
msg.sender,
IERC20(token).balanceOf(address(this))
);
}
}
文件 16 的 22:MerkleProof.sol
pragma solidity =0.8.20;
type MerkleProof is bytes32;
文件 17 的 22:MerkleRoot.sol
pragma solidity =0.8.20;
type MerkleRoot is bytes32;
文件 18 的 22:Number.sol
pragma solidity =0.8.20;
type Number is uint256;
文件 19 的 22:Ownable.sol
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
error OwnableUnauthorizedAccount(address account);
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 20 的 22:Ownable2Step.sol
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
文件 21 的 22:SafeERC20.sol
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
error SafeERC20FailedOperation(address token);
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
文件 22 的 22:Timestamp.sol
pragma solidity =0.8.20;
type Timestamp is uint256;
using {add as +, sub as -, equal as ==, notEqual as !=, lessThan as <, lessThanOrEqual as <=, greaterThan as >, greaterThanOrEqual as >=} for Timestamp global;
function add(Timestamp a, Timestamp b) pure returns (Timestamp sum) {
sum = Timestamp.wrap(Timestamp.unwrap(a) + Timestamp.unwrap(b));
}
function sub(Timestamp a, Timestamp b) pure returns (Timestamp difference) {
difference = Timestamp.wrap(Timestamp.unwrap(a) - Timestamp.unwrap(b));
}
function equal(Timestamp a, Timestamp b) pure returns (bool result) {
result = Timestamp.unwrap(a) == Timestamp.unwrap(b);
}
function notEqual(Timestamp a, Timestamp b) pure returns (bool result) {
result = Timestamp.unwrap(a) != Timestamp.unwrap(b);
}
function lessThan(Timestamp a, Timestamp b) pure returns (bool result) {
result = Timestamp.unwrap(a) < Timestamp.unwrap(b);
}
function lessThanOrEqual(Timestamp a, Timestamp b) pure returns (bool result) {
result = Timestamp.unwrap(a) <= Timestamp.unwrap(b);
}
function greaterThan(Timestamp a, Timestamp b) pure returns (bool result) {
result = Timestamp.unwrap(a) > Timestamp.unwrap(b);
}
function greaterThanOrEqual(Timestamp a, Timestamp b) pure returns (bool result) {
result = Timestamp.unwrap(a) >= Timestamp.unwrap(b);
}
{
"compilationTarget": {
"src/MerkleDistributorPeriphery.sol": "MerkleDistributorPeriphery"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}
[{"inputs":[{"internalType":"address","name":"chosenOwner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"CannotCreateWithEndTimeInThePast","type":"error"},{"inputs":[],"name":"CannotCreateWithTokenAsZeroAddress","type":"error"},{"inputs":[],"name":"CannotCreateWithTotalAmountAsZero","type":"error"},{"inputs":[],"name":"CannotQueueWithDeployerAsZeroAddress","type":"error"},{"inputs":[],"name":"CannotQueueWithEndTimeInThePast","type":"error"},{"inputs":[],"name":"CannotQueueWithTokenAsZeroAddress","type":"error"},{"inputs":[],"name":"CannotQueueWithTotalAmountAsZero","type":"error"},{"inputs":[],"name":"Create2EmptyBytecode","type":"error"},{"inputs":[],"name":"Create2FailedDeployment","type":"error"},{"inputs":[{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"Create2InsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InconsistentQueuedEndTime","type":"error"},{"inputs":[],"name":"InconsistentQueuedMerkleRoot","type":"error"},{"inputs":[],"name":"InconsistentQueuedToken","type":"error"},{"inputs":[],"name":"InconsistentQueuedTotalAmount","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OnlyAuthorizedOwner","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"uint256"},{"indexed":true,"internalType":"contract IMerkleDistributorWithDeadline","name":"distributor","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"Amount","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"MerkleRoot","name":"merkleRoot","type":"bytes32"},{"indexed":false,"internalType":"Timestamp","name":"endTime","type":"uint256"}],"name":"Create","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"uint256"},{"indexed":true,"internalType":"contract IMerkleDistributorWithDeadline","name":"distributor","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"Amount","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"MerkleRoot","name":"merkleRoot","type":"bytes32"},{"indexed":false,"internalType":"Timestamp","name":"endTime","type":"uint256"}],"name":"CreateFromQueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","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":"address","name":"deployer","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"Amount","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"MerkleRoot","name":"merkleRoot","type":"bytes32"},{"indexed":false,"internalType":"Timestamp","name":"endTime","type":"uint256"}],"name":"Queue","type":"event"},{"anonymous":false,"inputs":[],"name":"Unqueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IMerkleDistributorWithDeadline","name":"distributor","type":"address"},{"indexed":false,"internalType":"Amount","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IMerkleDistributorWithDeadline","name":"distributor","type":"address"},{"internalType":"Index","name":"index","type":"uint256"}],"internalType":"struct IMerkleDistributorPeriphery.Query[]","name":"queries","type":"tuple[]"}],"name":"areClaimed","outputs":[{"internalType":"bool[]","name":"results","type":"bool[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IMerkleDistributorWithDeadline","name":"distributor","type":"address"},{"internalType":"Index","name":"index","type":"uint256"},{"internalType":"Amount","name":"amount","type":"uint256"},{"internalType":"MerkleProof[]","name":"merkleProof","type":"bytes32[]"}],"internalType":"struct IMerkleDistributorPeriphery.Order[]","name":"orders","type":"tuple[]"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"Amount","name":"totalAmount","type":"uint256"},{"internalType":"MerkleRoot","name":"merkleRoot","type":"bytes32"},{"internalType":"Timestamp","name":"endTime","type":"uint256"}],"name":"create","outputs":[{"internalType":"Id","name":"id","type":"uint256"},{"internalType":"contract IMerkleDistributorWithDeadline","name":"distributor","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"Amount","name":"totalAmount","type":"uint256"},{"internalType":"MerkleRoot","name":"merkleRoot","type":"bytes32"},{"internalType":"Timestamp","name":"endTime","type":"uint256"}],"name":"createFromQueue","outputs":[{"internalType":"Id","name":"id","type":"uint256"},{"internalType":"contract IMerkleDistributorWithDeadline","name":"distributor","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"uint256"}],"name":"merkleDistributor","outputs":[{"internalType":"contract IMerkleDistributorWithDeadline","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"uint256"}],"name":"ownerGivenId","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"deployer","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"Amount","name":"totalAmount","type":"uint256"},{"internalType":"MerkleRoot","name":"merkleRoot","type":"bytes32"},{"internalType":"Timestamp","name":"endTime","type":"uint256"}],"name":"queue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"queued","outputs":[{"internalType":"address","name":"deployer","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"Amount","name":"totalAmount","type":"uint256"},{"internalType":"MerkleRoot","name":"merkleRoot","type":"bytes32"},{"internalType":"Timestamp","name":"endTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalMerkleDistributors","outputs":[{"internalType":"Number","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unqueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMerkleDistributorWithDeadline[]","name":"distributors","type":"address[]"}],"name":"withdraw","outputs":[{"internalType":"Amount[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"}]