ajna-finance / ajna-core

The Ajna protocol is a non-custodial, peer-to-peer, permissionless lending, borrowing and trading system that requires no governance or external price feeds to function.
https://www.ajna.finance/
Other
31 stars 11 forks source link

Calculate reserve auction price using kicked amount #1032

Closed EdNoepel closed 11 months ago

EdNoepel commented 11 months ago

Description

Contradicting the whitepaper, Claimable Reserve Auctions (CRAs) originally had a pricing mechanism with a start price of 1 quote token for 1bbn AJNA. This was done to simplify the auction mechanism, but the whitepaper was not updated to reflect the implementation. Kirill's audit brought this up with issue M-01. Upon initial review we favored the original implementation and chose to update the whitepaper. This decision was challenged during the fix review.

The original implementation naturally prevented 0-bids, as the pricing function would not reach 0 after 72 hours. Since the amount of claimable reserves is now part of the formula, we can no longer guarantee this. As such, an explicit check has been added to ensure at least 1 wei of AJNA is burned. This change necessitated improvement in logic handling bids for less than the quote token's trading increment.

To reduce cost of updating unit tests, RewardsManager tests are now skipped. Removal of RewardsManager may be covered by a separate PR.

Note that the author is not necessarily in agreement with this change.

Purpose

(versus updating whitepaper)

Pros

Cons

Impact

Pool contract sizes are similar. 2.3x gas cost for kicking, due to writing to an additional storage slot. Trivial increase in gas cost for taking.

Tasks

ith-harvey commented 11 months ago

LGTM

rayToWad seems like is no longer used, so can be removed, shouldn't affect the bytecode size though.

done -> https://github.com/ajna-finance/contracts/pull/1032/commits/f9c22d57c4725b3b2022eb9aca5254e55a475b47