Skip to content

Instantly share code, notes, and snippets.

@buendiadas
Last active July 29, 2021 20:44
Show Gist options
  • Save buendiadas/a152a1e2b377f504e8c4a272663f4f1f to your computer and use it in GitHub Desktop.
Save buendiadas/a152a1e2b377f504e8c4a272663f4f1f to your computer and use it in GitHub Desktop.

UniswapV3ExternalPosition

Actions

All the actions we need to interact with are pretty well summarized here: https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/interfaces/INonfungiblePositionManager.sol

  1. constructor():

    • Calls mint and creates a new NFTPosition, with a NFT position id, all the bellow params will be included (most of them part of INonFungiblePositionManager.

    • Input params: (token0, token1,fee, tickLower, tickUpper, amount0 desired , amount1 desired, amount0 min, amount1 min)

    • As a result fills UNISWAP_NON_FUNGIBLE_POSITION_ID, which is unique per EP.

  2. addLiquidity(uint256 _amount) Adds liquidity to a specific positionId (previously created)

  3. redeem(uint256 _amount): Removes liquidity from a specific tokenID

  4. collect(): Collect the fees associated to the NFT

  5. burn¿?: It is included in INonfungiblePositionManager.sol, consider if it makes sense to include it

Pricing

Compared to UniswapV2 pricing the external position will be simpler, while it is still unknown to me if it'll be expensive.

The reason for this simplicity is that we will know the amount of assets owed to the contract, so we can just use primitives, and we don't need to calc the price.

Pseudocoding:

uint256 UNISWAP_NON_FUNGIBLE_POSITION_ID;
address TOKEN_0;
address TOKEN_1;

function getManagedAsset() external override returns (address[] memory assets_, uint256[] amounts_ ) {
    assets_ = new address[](2);
    amounts_ = new address[](2);

    assets_ = [TOKEN_0, TOKEN_1];
    for(uint256 i; i< nftIds; i++) {
        // To be checked if there is a better way to retrieve this data (more efficient)
        (, , ... , ..., ,.... , tokensOwed0, tokensOwed1) = INonfungiblePositionManager(UNISWAP_NON_FUNGIBLE_POSITION_ID).positions(`UNISWAP_NON_FUNGIBLE_POSITION_ID`);

        amounts_ = [tokensOwed0, tokensOwed1];
    }

}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment