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

Revert with `InvalidAmount` if unscaled amount to add / remove in `Deposit` library #1049

Closed prateek105 closed 10 months ago

prateek105 commented 11 months ago

Description

NOTE: default revert in Deposits library is still to be discussed, another approach would be to check amount and revert in LenderActions.moveQuoteToken and TakerActions._rewardBucketTake (but this will duplicate code)

Purpose

Impact

Tasks

grandizzy commented 11 months ago

please update comment of function with @dev calculated unscaled amount to move is 0 InvalidAmount()

prateek105 commented 10 months ago

Looks ok. I'm little bit worried though about the long-term behavior of the pool as the scale grows indefinitely, while inflator resets

@dmitriia I think we had this discussion in our meetings and it was concluded that for the scale to grow to a number that can affect a pool in a significant manner will take a very long amount of time. Hence we ignore this. @mattcushman would be the best person to confirm this.

mattcushman commented 10 months ago

Ajna has some practical limitations in terms of prices and timescales/cumulative interest accrued in which it can operate well. There is a practical way to reset the inflator, but no practical way to reset the bucket scales (I suppose it could have implemented a mechanism where someone would pay the gas to iterate through all 7388 buckets, setting the scales to 1.0 and the deposit values to their underlying value). OTOH I think that this will take centuries to become an issue for any reasonable pool: the scales always accrue more slowly than the interest rate if there is no kick-able loan, and even at a sustained APY of 50%, 100 years still doesn't exceed 1 WAD in scale.

dmitriia commented 10 months ago

I think that this will take centuries to become an issue for any reasonable pool

Agree, it's just something to have in mind. Given that most buckets are empty and can be skipped having a scale reset function with something like scale for a given index > 100 * inflator requirement (implying that there should have been an inflator reset in the past) might be helpful.