Skip to content

Refactor deposit tracking#53

Merged
alexkeating merged 16 commits intomainfrom
feat/change-deposit-tracking
Feb 25, 2026
Merged

Refactor deposit tracking#53
alexkeating merged 16 commits intomainfrom
feat/change-deposit-tracking

Conversation

@garyghayrat
Copy link
Copy Markdown
Member

closes #46

@garyghayrat garyghayrat force-pushed the feat/change-deposit-tracking branch from 87ab860 to 0e729b0 Compare January 21, 2026 17:33
@garyghayrat garyghayrat marked this pull request as ready for review January 27, 2026 16:12
Comment thread src/LPVault.sol Outdated
/// @param _amount0Max The maximum amount of token0 to deposit across all positions.
/// @param _amount1Max The maximum amount of token1 to deposit across all positions.
/// @param _liquidity The liquidity to add to position0. Other positions calculated
/// proportionally. @dev Requires liquidity to be initialized first via initializeLiquidity().
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// proportionally. @dev Requires liquidity to be initialized first via initializeLiquidity().
/// proportionally.
/// @dev Requires liquidity to be initialized first via initializeLiquidity().

Comment thread src/LPVault.sol
/// @return _amount0Used The actual amount of token0 used.
/// @return _amount1Used The actual amount of token1 used.
function deposit(uint256 _amount0Max, uint256 _amount1Max)
function initializeLiquidity(uint256 _amount0Max, uint256 _amount1Max)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is called once, and we don't want the caller to put arbitrary values, maybe these are defined in the constructor and are immutable?

Comment thread src/LPVault.sol Outdated

uint256 _totalAmount0Ref;
uint256 _totalAmount1Ref;
uint256 _liquidityReference = 1e18;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this liquidity reference?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just an arbitrary scale reference to compute reference token amounts per position.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem here is that this is the liquidity specified for the amounts, so what if this greater than the max? Is the idea the user has to increase their amount max call?

Comment thread src/LPVault.sol Outdated

if (_totalAmount0Ref == 0 && _totalAmount1Ref == 0) revert LPVault__ZeroLiquidity();

uint256 _liquidity0Full = type(uint256).max;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default value here max uint?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if we start with zero, down the line, if (_liquidity0ByAmount1 < _liquidity0Full) would return false when _totalAmount1Ref > 0. But usually we want to assign _liquidity0ByAmount1 to it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one number where that statement is false, so it seems a little misleading to put to the max value. Like why not make the value 0? Seems safer and hardcode the max uint check

Comment thread src/LPVault.sol Outdated

uint256 _liquidity0Full = type(uint256).max;
if (_totalAmount0Ref > 0) {
_liquidity0Full =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is 0 full and the other one called amount1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_liquidity0Full is the liquidity for position 0. By amount1 I'm guessing you might be referring to _liquidity0ByAmount1? That is how much of position 0 liquidity you can create if token1 is the limiting factor. I agree it's a bit confusing, open to name suggestions.

Comment thread test/LPVault.t.sol Outdated
}

/// @dev Calculates expected deposit outputs (shares = first position's liquidity).
function _calculateExpectedDeposit(uint256 _amount0, uint256 _amount1)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't recreate the logic in the test. Then we aren't really testing anything. We should run the code and verify the invariants maintain correctness

Comment thread test/LPVault.t.sol Outdated
vm.startPrank(_depositor);
MockERC20(Currency.unwrap(currency0)).approve(address(vault), _amount0);
MockERC20(Currency.unwrap(currency1)).approve(address(vault), _amount1);
function _setupInitializer(address _addr) internal {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of this setup naming. To generic, and it doesn't describe what goes into the setup.

Comment thread src/LPVault.sol
LiquidityPosition[] public positions;

/// @notice Whether liquidity has been initialized.
bool public liquidityInitialized;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ Make this immutable ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think so because liquidity doesn't get initialized in the constructor.

@garyghayrat garyghayrat force-pushed the feat/change-deposit-tracking branch from 8dae55f to f7db966 Compare February 6, 2026 16:49
@github-actions
Copy link
Copy Markdown

Coverage after merging feat/change-deposit-tracking into main will be

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   FixedFeeSwap.sol99.23%96.67%100%100%393
   LPVault.sol97.91%84.62%100%100%385, 556, 571, 583, 624, 692
   PrincipalToken.sol100%100%100%100%
   VaultShareToken.sol100%100%100%100%
   YieldToken.sol100%100%100%100%
   Zapper.sol100%100%100%100%
src/lib
   FeeTracking.sol100%100%100%100%

@alexkeating alexkeating merged commit 3712f0a into main Feb 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LP Vault-06: Reassess deposit tracking

3 participants