Skip to content

[V-PHX-VUL-006] Split deposit should target the new pool ratio #204

@ueco-jb

Description

@ueco-jb

https://veridise.notion.site/Split-deposit-should-target-the-new-pool-ratio-c04d2ccddf1c433abfe48bc2912f6a1a

file: pool/src/contract.rs
location: fn split_deposit_based_on_pool_ratio

The function split_deposit_based_on_pool_ratio tries to match the amount deposited to the ratio of balances held by the pool. However, the target ratio is based on the pool ratio before the swap occurs.

Impact After the swap occurs, the ratio changes, and so the user is rewarded fewer LP shares and ends up losing equity even on a fee-less pool.

Recommendation At a minimum, we recommend updating target_ratio during the computation of final_offer_amount and final_ask_amount so that target_ratio is the ratio of pool balances after the swap, not before (e.g., target_ratio = Decimal::from_ratio(b_pool - swapped_b, a_pool + swapped_a) if the swapped asset is tokenA.

However, we would prefer to see the use of a precise formula for computing split_deposit_based_on_pool_ratio rather than the current binary search method.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions