yearn / yearn-vaults-v3

GNU Affero General Public License v3.0
104 stars 37 forks source link

feat: added smooth profit distribution mechanism #65

Closed bufander closed 2 years ago

bufander commented 2 years ago

Description

Implemented a smooth profit distribution mechanism.

Profits declared during process_report are locked and released linearly for a total length of seconds specified with profit_unlock_time (ie: for the full profit to be available for the users, profit_unlock_time has to pass since the profit declaration).

Losses declared in process_report are damped by existing profits in the buffer before affecting the price_per_share (reducing total_debt). This reduces the distribution_rate of the existing profits.

Important changes

See economic scenarios in : smooth profit distribution mechanism - 64

Fixes #64

Checklist

bufander commented 2 years ago

I think we should change the approach to something less gas intensive (for loops are expected to at least do around 10-20 iterations in this approach).

I will think through it and post alternatives

yes, I think you are right, we probably need to think of an alternative in which we can achieve a profit smoothing without needing so many operations

jmonteer commented 2 years ago

I think we should change the approach to something less gas intensive (for loops are expected to at least do around 10-20 iterations in this approach). I will think through it and post alternatives

yes, I think you are right, we probably need to think of an alternative in which we can achieve a profit smoothing without needing so many operations

analyzing a simpler way to update locking time, which I think makes sense.

bufander commented 2 years ago

After conversation with @jmonteer I've updated profit smoothing mechanism to a less gas intensive design.

We no longer store an array of profits, but only profit_end_date (timestamp in which all profits are unlocked) and profit_distribution_rate (a distribution rate computed with a proportional approach of new profits and time to unlock old profits. See link for full formula).

By using new design, updating the state is "cheap" but we are still smoothing the profit distribution through time to avoid front-running profits.

jmonteer commented 2 years ago

LGTM