v4-core icon indicating copy to clipboard operation
v4-core copied to clipboard

Inquiry about the storage location and asset management of ERC20 tokens in Uniswap V4

Open CodexDao opened this issue 1 year ago • 1 comments

Component

Pool Actions (swap, modifyPosition, donate, take, settle, mint)

Describe the suggested feature and problem it solves.

I have been studying the code for Uniswap V4 and am trying to understand where exactly my ERC20 tokens are stored when I, as a liquidity provider (LP), add liquidity to Uniswap. Additionally, I am curious about where the asset management for ERC20 is implemented.

I have examined parts of the "v4-core-main" and "v4-periphery-main" codes but I am still uncertain about the storage location for ERC20 tokens and the implementation of asset management. I noticed that the "PoolManager.sol" contract seems to handle some interactions with the liquidity pools, but I did not find logic that directly handles ERC20 tokens or asset management within this contract.

I understand that in the complete Uniswap protocol, there is usually a specific contract, such as UniswapV3Pool, that manages liquidity pools, including the locking and unlocking of ERC20 tokens from LPs, as well as potential asset management. However, I did not find this or a similar contract in the code I examined.

I also noticed that there are some Hook contracts, such as "BaseHook.sol", in "v4-periphery-main". I am wondering if the asset management for ERC20 is implemented in these Hook contracts, or elsewhere?

My question is: In the "v4-core-main" and "v4-periphery-main" codes that I have provided, where exactly are ERC20 tokens stored? Where is the asset management logic implemented? If possible, could you indicate which file or segment of code I should look at for this logic?

Describe the desired implementation.

No response

Describe alternatives.

No response

Additional context.

No response

CodexDao avatar Jul 14 '23 03:07 CodexDao

Here's what I understand: Pool's ERC20 token balance is stored in reservesOf. User's liquidity is stored in pool.Position.Info When user swap ERC20 balance is stored in ERC1155.

boy-good avatar Jul 14 '23 08:07 boy-good

Your LP position is likely through our periphery contracts (i.e. https://github.com/Uniswap/v3-periphery/blob/main/contracts/NonfungiblePositionManager.sol). Otherwise if interacting directly with the pool your ERC20 balances sit directly in the PoolManager (and must be sent there during lockAcquired() usually via the settle() method and are tracked in PoolManager.pools(id).positions in the Position.Info struct as measured by liquidity, and feeGrowthInside params. If you update your position, feesOwed are given back to the caller as balanceDelta for them to take.

ewilz avatar Jul 19 '23 21:07 ewilz