Locking v3 Position and claiming fee functionality
There is NO WARRANTY provided with this code reference. The concept here is to transfer a Koi Finance v3 position NFT into this contract which permanently locks liquidity, yet allows the deployed owner to collect trading fees on this position in perpetuity until the owner is relinquished.
When calling collect, the recipient param should be the account that is receiving the fees.
pragmasolidity =0.7.6;pragmaabicoder v2;/// @title V3 Locker & Fee Claimercontract V3PositionLocker {addresspublic owner;addresspublicimmutable nonfungiblePositionManager;constructor(address_nonfungiblePositionManager) { owner = msg.sender; nonfungiblePositionManager = _nonfungiblePositionManager; }functionsetOwner(address_owner) external {require(msg.sender == owner); owner = _owner; }functioncollect(INonfungiblePositionManager.CollectParamscalldata params) external {require(msg.sender == owner,"Not owner"); (uint256 amount0,uint256 amount1) =INonfungiblePositionManager(nonfungiblePositionManager).collect(params); }functionsaveToken(address_token,address_destination,uint_amount) external {require(msg.sender == owner,"Not owner");IERC20(_token).transfer(_destination, _amount); }}interface INonfungiblePositionManager {structCollectParams {uint256 tokenId;address recipient;uint128 amount0Max;uint128 amount1Max; }/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient/// @param params tokenId The ID of the NFT for which tokens are being collected,/// recipient The account that should receive the tokens,/// amount0Max The maximum amount of token0 to collect,/// amount1Max The maximum amount of token1 to collect/// @return amount0 The amount of fees collected in token0/// @return amount1 The amount of fees collected in token1functioncollect(CollectParamscalldata params) externalpayablereturns (uint256 amount0,uint256 amount1);}interface IERC20 {functiontransfer(address recipient,uint256 amount) externalreturns (bool);}