编译器
0.8.24+commit.e11b9ed9
文件 1 的 8: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;
}
}
文件 2 的 8:FeeCollector.sol
pragma solidity ^0.8.13;
import "openzeppelin-contracts/contracts/access/Ownable.sol";
import "openzeppelin-contracts/contracts/interfaces/IERC20.sol";
import "./interfaces/uniswap-v3-periphery/INonfungiblePositionManager.sol";
import "./interfaces/uniswap-v3-periphery/ISwapRouter.sol";
import "./interfaces/IEthCoin.sol";
import "./interfaces/IVRFCoordinator.sol";
contract FeeCollector is Ownable {
ISwapRouter public immutable swapRouter;
INonfungiblePositionManager public immutable nonfungiblePositionManager;
address public immutable ETHC;
address public immutable WETH;
uint256 public immutable tokenId;
uint24 public immutable fee;
IVRFCoordinator public immutable vrfCoordinator;
uint256 public subscriptionId;
address public operator;
modifier onlyOperator() {
require(msg.sender == operator, "FeeCollector: not operator");
_;
}
constructor(
address _ETHC,
address _WETH,
address _swapRouter,
address _nonfungiblePositionManager,
uint256 _tokenId,
address _vrfCoordinator,
uint256 _subscriptionId,
address _operator
) Ownable(msg.sender) {
ETHC = _ETHC;
WETH = _WETH;
swapRouter = ISwapRouter(_swapRouter);
nonfungiblePositionManager = INonfungiblePositionManager(_nonfungiblePositionManager);
tokenId = _tokenId;
(,,,, fee,,,,,,,) = nonfungiblePositionManager.positions(tokenId);
vrfCoordinator = IVRFCoordinator(_vrfCoordinator);
IERC20(ETHC).approve(address(nonfungiblePositionManager), type(uint256).max);
subscriptionId = _subscriptionId;
operator = _operator;
}
function collect() external onlyOperator {
IEthCoin(ETHC).collect(ETHC.balance);
}
function fundSubscription(uint256 amount) external onlyOperator {
vrfCoordinator.fundSubscriptionWithNative{value: amount}(subscriptionId);
}
function buyEthcoin(uint256 amountIn, uint256 amountOutMinimum) external onlyOperator returns (uint256) {
return swapRouter.exactInputSingle{value: amountIn}(
ISwapRouter.ExactInputSingleParams({
tokenIn: WETH,
tokenOut: ETHC,
fee: fee,
recipient: address(this),
deadline: block.timestamp,
amountIn: amountIn,
amountOutMinimum: amountOutMinimum,
sqrtPriceLimitX96: 0
})
);
}
function withdrawEthcoin(uint256 amount) external onlyOperator {
uint256 balance = IERC20(ETHC).balanceOf(address(this));
require(balance >= amount, "FeeCollector: insufficient balance");
IERC20(ETHC).transfer(owner(), amount);
}
function increaseLiquidity(
uint256 amountEthcoinDesired,
uint256 amountEthDesired,
uint256 amountEthcoinMin,
uint256 amountEthMin
) external onlyOperator {
nonfungiblePositionManager.increaseLiquidity{value: address(this).balance}(
INonfungiblePositionManager.IncreaseLiquidityParams({
tokenId: tokenId,
amount0Desired: amountEthDesired,
amount1Desired: amountEthcoinDesired,
amount0Min: amountEthMin,
amount1Min: amountEthcoinMin,
deadline: block.timestamp
})
);
nonfungiblePositionManager.refundETH();
}
function rescue() external onlyOwner {
payable(owner()).transfer(address(this).balance);
}
function setOperator(address _operator) external onlyOwner {
operator = _operator;
}
receive() external payable {}
}
文件 3 的 8: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);
}
文件 4 的 8:IEthCoin.sol
pragma solidity ^0.8.13;
interface IEthCoin {
function collect(uint256 amount) external;
}
文件 5 的 8:INonfungiblePositionManager.sol
pragma solidity ^0.8.13;
interface INonfungiblePositionManager {
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
function mint(MintParams calldata params)
external
payable
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
function increaseLiquidity(IncreaseLiquidityParams calldata params)
external
payable
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
function positions(uint256 tokenId)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint256 tokensOwed0,
uint256 tokensOwed1
);
function refundETH() external;
}
文件 6 的 8:ISwapRouter.sol
pragma solidity ^0.8.13;
interface ISwapRouter {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
}
文件 7 的 8:IVRFCoordinator.sol
pragma solidity ^0.8.13;
interface IVRFCoordinator {
function fundSubscriptionWithNative(uint256 subId) external payable;
}
文件 8 的 8: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);
}
}
{
"compilationTarget": {
"src/FeeCollector.sol": "FeeCollector"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@chainlink/contracts/=lib/foundry-chainlink-toolkit/lib/chainlink-brownie-contracts/contracts/src/",
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":chainlink-brownie-contracts/=lib/foundry-chainlink-toolkit/lib/chainlink-brownie-contracts/contracts/src/v0.6/vendor/@arbitrum/nitro-contracts/src/",
":ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":foundry-chainlink-toolkit/=lib/foundry-chainlink-toolkit/",
":halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}
[{"inputs":[{"internalType":"address","name":"_ETHC","type":"address"},{"internalType":"address","name":"_WETH","type":"address"},{"internalType":"address","name":"_swapRouter","type":"address"},{"internalType":"address","name":"_nonfungiblePositionManager","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_vrfCoordinator","type":"address"},{"internalType":"uint256","name":"_subscriptionId","type":"uint256"},{"internalType":"address","name":"_operator","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"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":"ETHC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"}],"name":"buyEthcoin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collect","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"fundSubscription","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountEthcoinDesired","type":"uint256"},{"internalType":"uint256","name":"amountEthDesired","type":"uint256"},{"internalType":"uint256","name":"amountEthcoinMin","type":"uint256"},{"internalType":"uint256","name":"amountEthMin","type":"uint256"}],"name":"increaseLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nonfungiblePositionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"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":[],"name":"rescue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"setOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"subscriptionId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapRouter","outputs":[{"internalType":"contract ISwapRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenId","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":[],"name":"vrfCoordinator","outputs":[{"internalType":"contract IVRFCoordinator","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawEthcoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]