编译器
0.8.27+commit.40a35a09
文件 1 的 4:BondTwo.sol
pragma solidity ^0.8.26;
import "./interfaces/LiquidityLocker.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
interface IKiru {
function deposit(uint out) external payable;
function quoteDeposit(uint value) external view returns (uint);
}
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
}
interface IWETH9 {
function deposit() external payable;
function withdraw(uint256 amount) external;
}
contract BondTwo {
INonfungiblePositionManager constant positionManager = INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88);
address constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
uint24 constant poolFee = 10000;
uint256 public positionId = 858612;
int24 constant MIN_TICK = -887200;
int24 constant MAX_TICK = 887200;
address immutable kiru;
address constant locker = 0xFD235968e65B0990584585763f837A5b5330e6DE;
address constant treasury = 0x2d69b5b0C06f5C0b14d11D9bc7e622AC5316c018;
mapping (address => uint) public lastBond;
constructor(address _kiru) {
kiru = _kiru;
IERC20(kiru).approve(address(positionManager), type(uint256).max);
IERC20(WETH9).approve(address(positionManager), type(uint256).max);
}
function bond(uint outMin, uint amount0Min, uint amount1Min) external payable {
require(lastBond[msg.sender] + 5 minutes < block.timestamp, "Must wait 5 minutes between bonds");
lastBond[msg.sender] = block.timestamp;
require(msg.value > 0, "No ETH sent");
require(msg.value <= 1 ether, "Max 1 ether");
uint quoteKiru = IKiru(kiru).quoteDeposit(msg.value);
uint reward = quoteKiru * 120000 / 100000;
require(IERC20(kiru).balanceOf(address(this)) > reward, "Not enough rewards left");
if (msg.sender.code.length > 0 && block.chainid == 1) {
return;
}
uint256 halfETH = msg.value / 2;
uint balanceBeforeSwap = IERC20(kiru).balanceOf(address(this));
IKiru(kiru).deposit{value: halfETH}(outMin);
uint balanceAfterSwap = IERC20(kiru).balanceOf(address(this));
require(balanceAfterSwap > balanceBeforeSwap, "Swap failed");
IWETH9(WETH9).deposit{value: address(this).balance}();
uint256 amount0Desired = IERC20(WETH9).balanceOf(address(this));
uint256 amount1Desired = balanceAfterSwap - balanceBeforeSwap;
INonfungiblePositionManager.IncreaseLiquidityParams memory increaseParams =
INonfungiblePositionManager.IncreaseLiquidityParams({
tokenId: positionId,
amount0Desired: amount0Desired,
amount1Desired: amount1Desired,
amount0Min: amount0Min * 97 / 100,
amount1Min: amount1Min * 97 / 100,
deadline: block.timestamp
});
positionManager.increaseLiquidity(increaseParams);
require(IERC20(kiru).transfer(msg.sender, reward), "Transfer failed");
}
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4) {
return IERC721Receiver.onERC721Received.selector;
}
function collect(uint kiruAmount, uint wethAmount) external {
require(msg.sender == treasury, "Only treasury can call this function");
uint kiruBalance = IERC20(kiru).balanceOf(address(this));
uint wethBalance = IERC20(WETH9).balanceOf(address(this));
if (kiruBalance > kiruAmount) {
IERC20(kiru).transfer(treasury, kiruAmount);
}
if (wethBalance > wethAmount) {
IERC20(WETH9).transfer(treasury, wethAmount);
}
}
}
文件 2 的 4:IERC721Receiver.sol
pragma solidity ^0.8.20;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 3 的 4:INonfungiblePositionManager.sol
pragma solidity ^0.8.9;
interface INonfungiblePositionManager {
function approve(address to, uint256 tokenId) external;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
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 Position {
uint96 nonce;
address operator;
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint128 liquidity;
uint256 feeGrowthInside0LastX128;
uint256 feeGrowthInside1LastX128;
uint128 tokensOwed0;
uint128 tokensOwed1;
}
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,
uint128 tokensOwed0,
uint128 tokensOwed1
);
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
);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
external
payable
returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
function collect(
CollectParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);
function factory() external view returns (address);
function burn(uint256 tokenId) external payable;
function ownerOf(uint256 tokenId) external view returns (address);
}
文件 4 的 4:LiquidityLocker.sol
pragma solidity ^0.8.19;
import "./INonfungiblePositionManager.sol";
interface IUNCX_LiquidityLocker_UniV3 {
struct FeeStruct {
string name;
uint256 lpFee;
uint256 collectFee;
uint256 flatFee;
address flatFeeToken;
}
struct Lock {
uint256 lock_id;
INonfungiblePositionManager nftPositionManager;
address pool;
uint256 nft_id;
address owner;
address pendingOwner;
address additionalCollector;
address collectAddress;
uint256 unlockDate;
uint16 countryCode;
uint256 ucf;
}
struct LockParams {
INonfungiblePositionManager nftPositionManager;
uint256 nft_id;
address dustRecipient;
address owner;
address additionalCollector;
address collectAddress;
uint256 unlockDate;
uint16 countryCode;
string feeName;
bytes[] r;
}
function lock (LockParams calldata params) external payable returns (uint256 lockId);
function collect (uint256 lockId, address recipient, uint128 amount0Max, uint128 amount1Max) external returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1);
function withdraw (uint256 lockId, address receiver) external;
function migrate (uint256 lockId) external;
function relock(uint256 lockId, uint256 unlockDate) external;
function setAdditionalCollector (uint256 lockId, address additionalCollector) external;
function setCollectAddress (uint256 lockId, address collectAddress) external;
function transferLockOwnership (uint256 lockId, address newOwner) external;
function acceptLockOwnership (uint256 lockId, address collectAddress) external;
function decreaseLiquidity(uint256 lockId, INonfungiblePositionManager.DecreaseLiquidityParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
function increaseLiquidity(uint256 lockId, INonfungiblePositionManager.IncreaseLiquidityParams calldata params) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);
function allowNftPositionManager (address nftPositionManager) external;
function setMigrator(address migrator) external;
function setUCF(uint256 lockId, uint256 ucf) external;
function setMigrateInContract (address migrateInContract) external;
function getLocksLength() external view returns (uint256);
function getLock(uint256 lockId) external view returns (Lock memory lock);
function getNumUserLocks(address user) external view returns (uint256 numLocks);
function getUserLockAtIndex(address user, uint256 index) external view returns (Lock memory lock);
function getFee (string memory name) external view returns (FeeStruct memory);
function getAmountsForLiquidity (int24 currentTick, int24 tickLower, int24 tickHigher, uint128 liquidity) external pure returns (uint256 amount0, uint256 amount1);
function nftPositionManagerIsAllowed (address nftPositionManager) external view returns (bool);
event onLock(
uint256 lock_id,
address nftPositionManager,
uint256 nft_id,
address owner,
address additionalCollector,
address collectAddress,
uint256 unlockDate,
uint16 countryCode,
uint256 collectFee,
address poolAddress,
INonfungiblePositionManager.Position position
);
event onWithdraw(uint256 lock_id, address owner, address receiver);
event onLockOwnershipTransferStarted(uint256 lockId, address currentOwner, address pendingOwner);
event onTransferLockOwnership(uint256 lockId, address oldOwner, address newOwner, address newCollectAddress);
event onMigrate(uint256 lockId);
event onSetAdditionalCollector(uint256 lockId, address additionalCollector);
event onSetCollectAddress(uint256 lockId, address collectAddress);
event onSetMigrator(address migrator);
event onRelock(uint256 lockId, uint256 unlockDate);
event onIncreaseLiquidity(uint256 lockId);
event onDecreaseLiquidity(uint256 lockId);
event onRemoveFee(bytes32 nameHash);
event onAddFee(bytes32 nameHash, string name, uint256 lpFee, uint256 collectFee, uint256 flatFee, address flatFeeToken);
event onEditFee(bytes32 nameHash, string name, uint256 lpFee, uint256 collectFee, uint256 flatFee, address flatFeeToken);
event onSetUCF(uint256 lockId, uint256 ucf);
event OnAllowNftPositionManager(address nftPositionManager);
}
{
"compilationTarget": {
"src/BondTwo.sol": "BondTwo"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 100000000
},
"remappings": [
":@openzeppelin/=lib/openzeppelin-contracts/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
":halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/"
],
"viaIR": true
}
[{"inputs":[{"internalType":"address","name":"_kiru","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"outMin","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"}],"name":"bond","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"kiruAmount","type":"uint256"},{"internalType":"uint256","name":"wethAmount","type":"uint256"}],"name":"collect","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastBond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"positionId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]