Skip to content

Calculate swap fee against cross price rather than par value#224

Merged
naddison36 merged 1 commit into
nicka/multi-base-lossfrom
nicka/swap-fee-cross-price
May 14, 2026
Merged

Calculate swap fee against cross price rather than par value#224
naddison36 merged 1 commit into
nicka/multi-base-lossfrom
nicka/swap-fee-cross-price

Conversation

@naddison36
Copy link
Copy Markdown
Collaborator

Summary

Fixes buy-side swap fee accrual so fees are bounded by the economic gain recognized in totalAssets().

Previously, _accrueSwapFee calculated fees from the discount to par:

PRICE_SCALE - buyPrice

but base inventory is valued in NAV at crossPrice. When crossPrice < PRICE_SCALE, this could allow accrued swap fees to exceed the actual NAV gain from buying base assets, causing LP value to be transferred to the feeCollector through buy/sell round trips.

This PR changes fee accrual to use the recognized NAV spread:

crossPrice - buyPrice

Changes

  • Pass crossPrice into _accrueSwapFee.
  • Calculate buy-side swap fees from crossPrice - buyPrice instead of PRICE_SCALE - buyPrice.
  • Keep existing swap pricing and liquidity behavior unchanged.
  • Update unit and fork test fee helpers to match the new fee semantics.
  • Add a regression test covering the case where:
    • crossPrice is slightly above buyPrice,
    • fee is high,
    • the old fee formula would exceed the NAV gain,
    • the new formula keeps accrued fees bounded by recognized economic gain.

Notes

For appreciating base assets such as sUSDe, the appreciation is still handled by the asset adapter’s convertToAssets() result. crossPrice, buyPrice, and sellPrice are then applied to that converted liquidity-asset value, so the fee remains bounded by the NAV spread after conversion.

Tests

forge fmt
forge build
forge test --match-path test/unit/OriginARM/CollectFees.sol
forge test --match-path test/unit/OriginARM/Setters.sol
forge test --match-path test/fork/EthenaARM/SwapExactTokensForTokens.t.sol
forge test --match-path 'test/unit/OriginARM/*.sol'
git diff --check

@naddison36 naddison36 merged commit 0e3ba17 into nicka/multi-base-loss May 14, 2026
8 checks passed
@naddison36 naddison36 deleted the nicka/swap-fee-cross-price branch May 14, 2026 08:11
naddison36 added a commit that referenced this pull request May 14, 2026
* Pro-rata losses to redeemers and remaining LPs

* Calculate swap fee against cross price rather than par value (#224)
naddison36 added a commit that referenced this pull request May 14, 2026
* WIP multi base assets

* - Move reusable multi-base asset config and swap accounting into AbstractARM
- Replace protocol-specific ARM redemption logic with generic asset adapters
- removed legacy max-cap sentinel handling
- Upgrade all ARMs to multi base assets
- Added wstETH to the Lido ARM
- Added weETH to EtherFi ARM

* Updated AI context

* Added wOETH to OETH ARM

* Updated ARM contract dependencies

* Updated Hardhat tasks

* Proxied the adapters

* Lido ARM upgrade checks

* Added Ethena upgrade guard

* Updated migration error

* More cleanup of legacy immutables

* fmt

* Update EtherFi ABI

* Update claimEthenaWithdrawals Hardhat task

* Fixed fork tests

* Fixed smoke tests

* Fix invariant tests

* Updated contract diagrams

* Renamed the ARM adapter-facing methods to requestBaseAssetRedeem and claimBaseAssetRedeem

* Used modifiers on adapters

* Pro-rata losses to redeemers and remaining LPs (#223)

* Pro-rata losses to redeemers and remaining LPs

* Calculate swap fee against cross price rather than par value (#224)
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.

1 participant