Collecting Fees | Uniswap (2024)

To collect the fees of an owner position, transfer the NFT from the calling address, assign the relevant variables from the NFT to local variables within our function, and pass those variables to thenonfungiblePositionManager to call collect.

This function collects all fees, sending them to the original owner of the NFT, while maintaining custody of the position 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);
}

This internal helper function sends any tokens, in the form of fees or position tokens, to the owner of an NFT.

In _sendToOwner, we pass the amount of fees due, previously populated in the last function, as arguments to safeTransfer, which transfers the fees to owner.

 /// @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);
}
Collecting Fees | Uniswap (2024)
Top Articles
Anger can be exhausting
T2 Tax Return - Everything You Need To Know About Your T2
What Did Bimbo Airhead Reply When Asked
UPS Paketshop: Filialen & Standorte
Amc Near My Location
Craigslist Vans
Kaydengodly
Bucks County Job Requisitions
Pitt Authorized User
Premier Boating Center Conroe
Sport Clip Hours
Diablo 3 Metascore
2016 Ford Fusion Belt Diagram
Mineral Wells Independent School District
Colorado mayor, police respond to Trump's claims that Venezuelan gang is 'taking over'
What Happened To Anna Citron Lansky
Locate At&T Store Near Me
Niche Crime Rate
Wgu Academy Phone Number
Project, Time & Expense Tracking Software for Business
Www.publicsurplus.com Motor Pool
Craigslist Battle Ground Washington
Valic Eremit
Hctc Speed Test
Arrest Gif
Jesus Revolution Showtimes Near Regal Stonecrest
Speedstepper
Free T33N Leaks
2004 Honda Odyssey Firing Order
Frank Vascellaro
Korg Forums :: View topic
Robot or human?
Does Iherb Accept Ebt
Western Gold Gateway
Vanessa West Tripod Jeffrey Dahmer
Bimmerpost version for Porsche forum?
How To Get Soul Reaper Knife In Critical Legends
Wsbtv Fish And Game Report
NHL training camps open with Swayman's status with the Bruins among the many questions
Dr Adj Redist Cadv Prin Amex Charge
Anhedönia Last Name Origin
Gasoline Prices At Sam's Club
Promo Code Blackout Bingo 2023
Shell Gas Stations Prices
Rs3 Nature Spirit Quick Guide
4k Movie, Streaming, Blu-Ray Disc, and Home Theater Product Reviews & News
Oklahoma City Farm & Garden Craigslist
Matt Brickman Wikipedia
Suzanne Olsen Swift River
Affidea ExpressCare - Affidea Ireland
Ravenna Greataxe
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 6334

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.