# User can sandwich their own position close to get back all of their position fees

Borrowing fees accrue to the pool only on position close, so a user flash-loans liquidity, closes their position, and reclaims most fees as an LP.

- Payout: Audit contest
- Severity: high
- Program: Velar Artha
- Found by: 0x37
- Disclosed: 2024-08-22
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-velar-artha-judging/issues/94
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-velar-artha%3AH-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:chained vuln:fee-bypass vuln:flash-loan

**Target:** Perpetuals/AMM pool position close and LP fee distribution (positions.vy)
**Root cause:** Borrowing fees are only distributed to LPs when a position closes, and are split pro-rata by current pool share rather than by LP longevity, so a temporary large LP captures most of the fee.
**Steps:**
1. Open a position that accrues borrowing fees.
2. Flash-loan a large sum and add it as liquidity to the pool, becoming majority LP.
3. Close the position so accrued fees are distributed to the pool reserves.
4. Withdraw LP tokens, receiving most of the distributed fees back.
5. Repay the flash loan, netting near-zero borrowing fees.
**How found:** Reviewer noticed fees are only distributed to LPs at position close and split evenly by current share, ignoring LP longevity, enabling a temporary majority-LP sandwich.
**Exploitation:** Attacker flash-loans capital, deposits as LP to dominate pool share, closes their own position to trigger fee distribution to reserves, then withdraws LP to reclaim the fees, repaying the loan.
**Insight:** When fees are settled lazily at a state-changing event and split by instantaneous pool share, a flash-loan-funded LP deposit right before the settlement event captures the accrued fees; check any 'distribute on close/claim' accounting for this sandwich.

