流動性提供
コントラクトのセットアップ
Uniswap V3のカストディアルコントラクトポジションに関するサンプルです。 このカストディアルコントラクトを使用することで、以下の操作が可能になります。
- ポジションの発行
- Uniswap V3でトークンの取引を行うためのポジションを作成します。
- ポジションへの流動性の追加
- 作成したポジションに流動性(トークン)を追加して、取引の準備を整えます。
- 流動性の減少
- 一部またはすべての流動性を撤回して、ポジションからトークンを取り戻します。
- 手数料の収集
- 取引手数料を受け取ります。
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import '@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol';
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import '@uniswap/v3-periphery/contracts/base/LiquidityManagement.sol';
contract LiquidityExamples is IERC721Receiver {
address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
uint24 public constant poolFee = 3000;
INonfungiblePositionManager public immutable nonfungiblePositionManager;
...ERC721との相互運用
各NFT(非代替トークン)は、ERC721スマートコントラクト内で一意のtokenIdによって識別されます。
ERC721トークンをデポジットするには以下の手順を実行します。
-
Deposit(デポジット)構造体の作成 デポジット情報を格納するための「
Deposit」という構造体を作成します。 -
NFTとDeposit構造体の紐付け 次に、各NFTの
tokenIdをキー、Deposit構造体を値にしたマッピング配列を作成します。
...
struct Deposit {
address owner;
uint128 liquidity;
address token0;
address token1;
}
mapping(uint256 => Deposit) public deposits;
...Constructor
...
constructor(
INonfungiblePositionManager _nonfungiblePositionManager,
address _factory,
address _WETH9
) PeripheryImmutableState(_factory, _WETH9) {
nonfungiblePositionManager = _nonfungiblePositionManager;
}
...ERC721トークンの保管を許可
コントラクトがERC721トークンを保管できるようにするには、継承した IERC721Receiver.solコントラクト内のonERC721Received関数を実装します。
引数のfromは使用されないので省略しても問題ないです。
...
function onERC721Received(
address operator,
address,
uint256 tokenId,
bytes calldata
) external override returns (bytes4) {
// get position information
_createDeposit(operator, tokenId);
return this.onERC721Received.selector;
}
...デポジットの作成
depositsマッピング配列にデータを追加するには、_createDepositという内部関数を作成し、nonfungiblePositionManager.solのpositions構造体を取得します。
取得したtoken0、token1、liquidityをdeposits`マッピング配列に格納します。
function _createDeposit(address owner, uint256 tokenId) internal {
(, , address token0, address token1, , , , uint128 liquidity, , , , ) = nonfungiblePositionManager.positions(tokenId);
// set the owner and data for position
// operator is msg.sender
deposits[tokenId] = Deposit({owner: owner, liquidity: liquidity, token0: token0, token1: token1});
}流動性提供コントラクト
LiquidityExamples.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '../libraries/TransferHelper.sol';
import '../interfaces/INonfungiblePositionManager.sol';
import '../base/LiquidityManagement.sol';
contract LiquidityExamples is IERC721Receiver {
address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
uint24 public constant poolFee = 3000;
INonfungiblePositionManager public immutable nonfungiblePositionManager;
/// @notice Represents the deposit of an NFT
struct Deposit {
address owner;
uint128 liquidity;
address token0;
address token1;
}
/// @dev deposits[tokenId] => Deposit
mapping(uint256 => Deposit) public deposits;
constructor(
INonfungiblePositionManager _nonfungiblePositionManager
) {
nonfungiblePositionManager = _nonfungiblePositionManager;
}
// Implementing `onERC721Received` so this contract can receive custody of erc721 tokens
function onERC721Received(
address operator,
address,
uint256 tokenId,
bytes calldata
) external override returns (bytes4) {
// get position information
_createDeposit(operator, tokenId);
return this.onERC721Received.selector;
}
function _createDeposit(address owner, uint256 tokenId) internal {
(, , address token0, address token1, , , , uint128 liquidity, , , , ) =
nonfungiblePositionManager.positions(tokenId);
// set the owner and data for position
// operator is msg.sender
deposits[tokenId] = Deposit({owner: owner, liquidity: liquidity, token0: token0, token1: token1});
}
}新しいポジションの作成
パラメーター
新しいポジションを作成するには、nonFungiblePositionManagerのmint関数を呼び出す。
この例では、ミントするトークンの量をハードコーディングしています。
この例は学習のためのものであり、実際に使用されているコードではありません。
/// @notice Calls the mint function defined in periphery, mints the same amount of each token. For this example we are providing 1000 DAI and 1000 USDC in liquidity
/// @return tokenId The id of the newly minted ERC721
/// @return liquidity The amount of liquidity for the position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mintNewPosition()
external
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
{
// For this example, we will provide equal amounts of liquidity in both assets.
// Providing liquidity in both assets means liquidity will be earning fees and is considered in-range.
uint256 amount0ToMint = 1000;
uint256 amount1ToMint = 1000;ミント呼び出し
nonfungiblePositionManagerがコントラクトのトークンを使用できるように承認し、MintParams構造体を設定し、それをparams変数に割り当てます。
その後、mint関数を呼び出す時にこのparamsをnonfungiblePositionManagerに渡します。
TickMath.MIN_TICKとTickMath.MAX_TICKを使用することで、プール全範囲に流動性を提供しています。
本番環境では、より集中的なポジションを指定できます。
amount0Minとamount1Minはこの例で0に設定されていますが、本番環境では脆弱性の原因となります。
スリッページ保護のないmint呼び出しは、価格が正確でない状況でmint呼び出しを実行するフロントランニング攻撃に対して脆弱性を持つ可能性があります。
より安全な実装を行うためには、開発者はスリッページの推定プロセスを実装する必要があります。
// Approve the position manager
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), amount0ToMint);
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), amount1ToMint);
INonfungiblePositionManager.MintParams memory params =
INonfungiblePositionManager.MintParams({
token0: DAI,
token1: USDC,
fee: poolFee,
tickLower: TickMath.MIN_TICK,
tickUpper: TickMath.MAX_TICK,
amount0Desired: amount0ToMint,
amount1Desired: amount1ToMint,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
});
// Note that the pool defined by DAI/USDC and fee tier 0.3% must already be created and initialized in order to mint
(tokenId, liquidity, amount0, amount1) = nonfungiblePositionManager.mint(params);Depositマッピングの更新と払い戻し
前章の「コントラクトのセットアップ」の内部関数を呼び出すことができます。
その後、ミント処理で残った流動性をmsg.senderに払い戻します。
// Create a deposit
_createDeposit(msg.sender, tokenId);
// Remove allowance and refund in both assets.
if (amount0 < amount0ToMint) {
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), 0);
uint256 refund0 = amount0ToMint - amount0;
TransferHelper.safeTransfer(DAI, msg.sender, refund0);
}
if (amount1 < amount1ToMint) {
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), 0);
uint256 refund1 = amount1ToMint - amount1;
TransferHelper.safeTransfer(USDC, msg.sender, refund1);
}
}コントラクトの例
詳細
/// @notice Calls the mint function defined in periphery, mints the same amount of each token. For this example we are providing 1000 DAI and 1000 USDC in liquidity
/// @return tokenId The id of the newly minted ERC721
/// @return liquidity The amount of liquidity for the position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mintNewPosition()
external
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
{
// For this example, we will provide equal amounts of liquidity in both assets.
// Providing liquidity in both assets means liquidity will be earning fees and is considered in-range.
uint256 amount0ToMint = 1000;
uint256 amount1ToMint = 1000;
// Approve the position manager
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), amount0ToMint);
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), amount1ToMint);
INonfungiblePositionManager.MintParams memory params =
INonfungiblePositionManager.MintParams({
token0: DAI,
token1: USDC,
fee: poolFee,
tickLower: TickMath.MIN_TICK,
tickUpper: TickMath.MAX_TICK,
amount0Desired: amount0ToMint,
amount1Desired: amount1ToMint,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
});
// Note that the pool defined by DAI/USDC and fee tier 0.3% must already be created and initialized in order to mint
(tokenId, liquidity, amount0, amount1) = nonfungiblePositionManager.mint(params);
// Create a deposit
_createDeposit(msg.sender, tokenId);
// Remove allowance and refund in both assets.
if (amount0 < amount0ToMint) {
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), 0);
uint256 refund0 = amount0ToMint - amount0;
TransferHelper.safeTransfer(DAI, msg.sender, refund0);
}
if (amount1 < amount1ToMint) {
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), 0);
uint256 refund1 = amount1ToMint - amount1;
TransferHelper.safeTransfer(USDC, msg.sender, refund1);
}
}手数料の徴収
手数料の徴収
流動性の相互作用において、コントラクトが流動性ポジションNFTを保有している必要があります。 したがって、NFTのdepositが関数にコード化されていない例では、コントラクトがすでにNFTを所有していると見なされます。
オーナーポジションの手数料を徴収するには、呼び出し元のアドレスからNFTを転送し、NFTから関連する情報を関数内のローカル変数に代入し、それらの変数をthenonfungiblePositionManagerに渡してcollectを呼び出します。
この関数は、ポジションNFTの保管を維持しながら、すべての手数料を回収し、NFTの元の所有者に送ります。
/// @notice Collects the fees associated with provided liquidity
/// @dev The contract must hold the erc721 token before it can collect fees
/// @param tokenId The id of the erc721 token
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collectAllFees(uint256 tokenId) external returns (uint256 amount0, uint256 amount1) {
// Caller must own the ERC721 position
// Call to safeTransfer will trigger `onERC721Received` which must return the selector else transfer will fail
nonfungiblePositionManager.safeTransferFrom(msg.sender, address(this), tokenId);
// set amount0Max and amount1Max to uint256.max to collect all fees
// alternatively can set recipient to msg.sender and avoid another transaction in `sendToOwner`
INonfungiblePositionManager.CollectParams memory params =
INonfungiblePositionManager.CollectParams({
tokenId: tokenId,
recipient: address(this),
amount0Max: type(uint128).max,
amount1Max: type(uint128).max
});
(amount0, amount1) = nonfungiblePositionManager.collect(params);
// send collected feed back to owner
_sendToOwner(tokenId, amount0, amount1);
}呼び出しアドレスに手数料送付
手数料またはポジション・トークンの形で、あらゆるトークンをNFTの所有者に送ります。
sendToOwnerでは、設定した手数料の額をsafeTransferの引数として渡し、手数料をオーナーに送金します。
/// @notice Transfers funds to owner of NFT
/// @param tokenId The id of the erc721
/// @param amount0 The amount of token0
/// @param amount1 The amount of token1
function _sendToOwner(
uint256 tokenId,
uint256 amount0,
uint256 amount1
) internal {
// get owner of contract
address owner = deposits[tokenId].owner;
address token0 = deposits[tokenId].token0;
address token1 = deposits[tokenId].token1;
// send collected fees to owner
TransferHelper.safeTransfer(token0, owner, amount0);
TransferHelper.safeTransfer(token1, owner, amount1);
}流動性の低下
ポジションを全て引き出さずにポジションの流動性を減少させます。
この例では、コントラクトがすでにポジションNFTを保有していることを前提とし、呼び出すアドレスはポジションNFTをコントラクトにdepositしたアドレスと同じである必要があります。
実運用では、amount0Minとamount1Minを調整して、スリッページを防止する必要があります。
流動性の低下
/// @notice A function that decreases the current liquidity by half. An example to show how to call the `decreaseLiquidity` function defined in periphery.
/// @param tokenId The id of the erc721 token
/// @return amount0 The amount received back in token0
/// @return amount1 The amount returned back in token1
function decreaseLiquidityInHalf(uint256 tokenId) external returns (uint256 amount0, uint256 amount1) {
// caller must be the owner of the NFT
require(msg.sender == deposits[tokenId].owner, 'Not the owner');
// get liquidity data for tokenId
uint128 liquidity = deposits[tokenId].liquidity;
uint128 halfLiquidity = liquidity / 2;
// amount0Min and amount1Min are price slippage checks
// if the amount received after burning is not greater than these minimums, transaction will fail
INonfungiblePositionManager.DecreaseLiquidityParams memory params =
INonfungiblePositionManager.DecreaseLiquidityParams({
tokenId: tokenId,
liquidity: halfLiquidity,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
});
(amount0, amount1) = nonfungiblePositionManager.decreaseLiquidity(params);
//send liquidity back to owner
_sendToOwner(tokenId, amount0, amount1);
}呼び出しアドレスに手数料送付
この関数は、手数料またはポジション・トークンの形で、あらゆるトークンをNFTの所有者に送ります。
sendToOwnerでは、設定した手数料の額をsafeTransferの引数として渡し、手数料をオーナーに送金します。
/// @notice Transfers funds to owner of NFT
/// @param tokenId The id of the erc721
/// @param amount0 The amount of token0
/// @param amount1 The amount of token1
function _sendToOwner(
uint256 tokenId,
uint256 amount0,
uint256 amount1
) internal {
// get owner of contract
address owner = deposits[tokenId].owner;
address token0 = deposits[tokenId].token0;
address token1 = deposits[tokenId].token1;
// send collected fees to owner
TransferHelper.safeTransfer(token0, owner, amount0);
TransferHelper.safeTransfer(token1, owner, amount1);
}流動性の増加
範囲内の流動性増加
この例では、コントラクトがすでにNFTを保管していることを想定しています。
Uniswap v3プロトコルを使用して、指定された流動性ポジションの境界を変更することはできません。
実運用では、amount0Minとamount1Minを調整して、スリッページを防止する必要があります。
/// @notice Increases liquidity in the current range
/// @dev Pool must be initialized already to add liquidity
/// @param tokenId The id of the erc721 token
/// @param amount0 The amount to add of token0
/// @param amount1 The amount to add of token1
function increaseLiquidityCurrentRange(
uint256 tokenId,
uint256 amountAdd0,
uint256 amountAdd1
)
external
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
{
INonfungiblePositionManager.IncreaseLiquidityParams memory params =
INonfungiblePositionManager.IncreaseLiquidityParams({
tokenId: tokenId,
amount0Desired: amountAdd0,
amount1Desired: amountAdd1,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
});
(liquidity, amount0, amount1) = nonfungiblePositionManager.increaseLiquidity(params);
}コントラクト全体
Uniswap V3のポジションNFTを保管し、手数料の徴収、流動性の増減、新規ポジションの作成によってポジションと流動性を操作できるコントラクトです。
LiquidityExamples.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '../libraries/TransferHelper.sol';
import '../interfaces/INonfungiblePositionManager.sol';
import '../base/LiquidityManagement.sol';
contract LiquidityExamples is IERC721Receiver {
address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
uint24 public constant poolFee = 3000;
INonfungiblePositionManager public immutable nonfungiblePositionManager;
/// @notice Represents the deposit of an NFT
struct Deposit {
address owner;
uint128 liquidity;
address token0;
address token1;
}
/// @dev deposits[tokenId] => Deposit
mapping(uint256 => Deposit) public deposits;
constructor(
INonfungiblePositionManager _nonfungiblePositionManager
) {
nonfungiblePositionManager = _nonfungiblePositionManager;
}
// Implementing `onERC721Received` so this contract can receive custody of erc721 tokens
function onERC721Received(
address operator,
address,
uint256 tokenId,
bytes calldata
) external override returns (bytes4) {
// get position information
_createDeposit(operator, tokenId);
return this.onERC721Received.selector;
}
function _createDeposit(address owner, uint256 tokenId) internal {
(, , address token0, address token1, , , , uint128 liquidity, , , , ) =
nonfungiblePositionManager.positions(tokenId);
// set the owner and data for position
// operator is msg.sender
deposits[tokenId] = Deposit({owner: owner, liquidity: liquidity, token0: token0, token1: token1});
}
/// @notice Calls the mint function defined in periphery, mints the same amount of each token.
/// For this example we are providing 1000 DAI and 1000 USDC in liquidity
/// @return tokenId The id of the newly minted ERC721
/// @return liquidity The amount of liquidity for the position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mintNewPosition()
external
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
{
// For this example, we will provide equal amounts of liquidity in both assets.
// Providing liquidity in both assets means liquidity will be earning fees and is considered in-range.
uint256 amount0ToMint = 1000;
uint256 amount1ToMint = 1000;
// transfer tokens to contract
TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amount0ToMint);
TransferHelper.safeTransferFrom(USDC, msg.sender, address(this), amount1ToMint);
// Approve the position manager
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), amount0ToMint);
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), amount1ToMint);
INonfungiblePositionManager.MintParams memory params =
INonfungiblePositionManager.MintParams({
token0: DAI,
token1: USDC,
fee: poolFee,
tickLower: TickMath.MIN_TICK,
tickUpper: TickMath.MAX_TICK,
amount0Desired: amount0ToMint,
amount1Desired: amount1ToMint,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
});
// Note that the pool defined by DAI/USDC and fee tier 0.3% must already be created and initialized in order to mint
(tokenId, liquidity, amount0, amount1) = nonfungiblePositionManager.mint(params);
// Create a deposit
_createDeposit(msg.sender, tokenId);
// Remove allowance and refund in both assets.
if (amount0 < amount0ToMint) {
TransferHelper.safeApprove(DAI, address(nonfungiblePositionManager), 0);
uint256 refund0 = amount0ToMint - amount0;
TransferHelper.safeTransfer(DAI, msg.sender, refund0);
}
if (amount1 < amount1ToMint) {
TransferHelper.safeApprove(USDC, address(nonfungiblePositionManager), 0);
uint256 refund1 = amount1ToMint - amount1;
TransferHelper.safeTransfer(USDC, msg.sender, refund1);
}
}
/// @notice Collects the fees associated with provided liquidity
/// @dev The contract must hold the erc721 token before it can collect fees
/// @param tokenId The id of the erc721 token
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collectAllFees(uint256 tokenId) external returns (uint256 amount0, uint256 amount1) {
// Caller must own the ERC721 position, meaning it must be a deposit
// set amount0Max and amount1Max to uint256.max to collect all fees
// alternatively can set recipient to msg.sender and avoid another transaction in `sendToOwner`
INonfungiblePositionManager.CollectParams memory params =
INonfungiblePositionManager.CollectParams({
tokenId: tokenId,
recipient: address(this),
amount0Max: type(uint128).max,
amount1Max: type(uint128).max
});
(amount0, amount1) = nonfungiblePositionManager.collect(params);
// send collected feed back to owner
_sendToOwner(tokenId, amount0, amount1);
}
/// @notice A function that decreases the current liquidity by half. An example to show how to call the `decreaseLiquidity` function defined in periphery.
/// @param tokenId The id of the erc721 token
/// @return amount0 The amount received back in token0
/// @return amount1 The amount returned back in token1
function decreaseLiquidityInHalf(uint256 tokenId) external returns (uint256 amount0, uint256 amount1) {
// caller must be the owner of the NFT
require(msg.sender == deposits[tokenId].owner, 'Not the owner');
// get liquidity data for tokenId
uint128 liquidity = deposits[tokenId].liquidity;
uint128 halfLiquidity = liquidity / 2;
// amount0Min and amount1Min are price slippage checks
// if the amount received after burning is not greater than these minimums, transaction will fail
INonfungiblePositionManager.DecreaseLiquidityParams memory params =
INonfungiblePositionManager.DecreaseLiquidityParams({
tokenId: tokenId,
liquidity: halfLiquidity,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
});
(amount0, amount1) = nonfungiblePositionManager.decreaseLiquidity(params);
//send liquidity back to owner
_sendToOwner(tokenId, amount0, amount1);
}
/// @notice Increases liquidity in the current range
/// @dev Pool must be initialized already to add liquidity
/// @param tokenId The id of the erc721 token
/// @param amount0 The amount to add of token0
/// @param amount1 The amount to add of token1
function increaseLiquidityCurrentRange(
uint256 tokenId,
uint256 amountAdd0,
uint256 amountAdd1
)
external
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
) {
TransferHelper.safeTransferFrom(deposits[tokenId].token0, msg.sender, address(this), amountAdd0);
TransferHelper.safeTransferFrom(deposits[tokenId].token1, msg.sender, address(this), amountAdd1);
TransferHelper.safeApprove(deposits[tokenId].token0, address(nonfungiblePositionManager), amountAdd0);
TransferHelper.safeApprove(deposits[tokenId].token1, address(nonfungiblePositionManager), amountAdd1);
INonfungiblePositionManager.IncreaseLiquidityParams memory params = INonfungiblePositionManager.IncreaseLiquidityParams({
tokenId: tokenId,
amount0Desired: amountAdd0,
amount1Desired: amountAdd1,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
});
(liquidity, amount0, amount1) = nonfungiblePositionManager.increaseLiquidity(params);
}
/// @notice Transfers funds to owner of NFT
/// @param tokenId The id of the erc721
/// @param amount0 The amount of token0
/// @param amount1 The amount of token1
function _sendToOwner(
uint256 tokenId,
uint256 amount0,
uint256 amount1
) internal {
// get owner of contract
address owner = deposits[tokenId].owner;
address token0 = deposits[tokenId].token0;
address token1 = deposits[tokenId].token1;
// send collected fees to owner
TransferHelper.safeTransfer(token0, owner, amount0);
TransferHelper.safeTransfer(token1, owner, amount1);
}
/// @notice Transfers the NFT to the owner
/// @param tokenId The id of the erc721
function retrieveNFT(uint256 tokenId) external {
// must be the owner of the NFT
require(msg.sender == deposits[tokenId].owner, 'Not the owner');
// transfer ownership to original owner
nonfungiblePositionManager.safeTransferFrom(address(this), msg.sender, tokenId);
//remove information related to tokenId
delete deposits[tokenId];
}
}