Skip to content

Commit

Permalink
Fee Revenue Decay Rate set to per topic's epoch rather than global fi…
Browse files Browse the repository at this point in the history
…xed constant (#529)

## Purpose of Changes and their Description

Currently, we use a global parameter to drip revenue to the same extent
across all topics, regardless of their epoch length. This is somewhat
unfair, as topics of larger epochs then get dripped comparatively less
than those with shorter epoch lengths.

@jmdkastro proposes a more appropriate way of updating effective
revenue, that actually takes the topic epoch length into consideration
(through calculation of "epochs per week"). Relevant text from the
whitepaper:

The quantity `C_{t,i}` decays _each epoch_ by subtracting an amount `∆
C_{t,i} = N_{epochs,w} * C_{t,i}` (where `N_{epochs,w}` is the number of
epochs per week) and thus captures recent revenue.

This PR modifies the keeper.go `DripTopicFeeRevenue` function to do the
following: identify if we have dripped yet this epoch. If we have not,
then calculate the number of blocksPerWeek based on the blocksPerMonth,
get the epochs per block from the topic, then do the math to calculate
how much to decay for this epoch. Then it overwrites the fee revenue for
this topic, and marks this epoch as having been decayed.

This change add a new data structure to the keeper called
`lastDripBlock`. This change also deletes the global emissions module
parameter `TopicFeeRevenueDecayRate`

## Link(s) to Ticket(s) or Issue(s) resolved by this PR

PROTO-2150
RES-302

## Are these changes tested and documented?

Our existing unit tests were adapted to fit this new change, as some of
them had broke from the different algorithms.
  • Loading branch information
relyt29 authored Aug 21, 2024
1 parent c49aeec commit d23be2d
Show file tree
Hide file tree
Showing 20 changed files with 2,924 additions and 1,809 deletions.
15 changes: 0 additions & 15 deletions math/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ func CalcEma(
return ret, nil
}

func CalcExpDecay(
currentRev,
decayFactor Dec,
) (Dec, error) {
oneMinusDecayFactor, err := OneDec().Sub(decayFactor)
if err != nil {
return ZeroDec(), err
}
newRev, err := oneMinusDecayFactor.Mul(currentRev)
if err != nil {
return ZeroDec(), err
}
return newRev, nil
}

// Generic function that sorts the keys of a map
// Used for deterministic ranging of maps
func GetSortedKeys[K cmp.Ordered, V any](m map[K]V) []K {
Expand Down
25 changes: 0 additions & 25 deletions math/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,6 @@ func TestCalcEmaWithNoPrior(t *testing.T) {
require.True(t, alloraMath.InDelta(expected, result, alloraMath.MustNewDecFromString("0.0001")))
}

func TestCalcExpDecaySimple(t *testing.T) {
decayFactor := alloraMath.MustNewDecFromString("0.1")
currentRev := alloraMath.MustNewDecFromString("300")

// (1 - 0.1) * 300
// 0.9 * 300 = 270
expected := alloraMath.MustNewDecFromString("270")
result, err := alloraMath.CalcExpDecay(currentRev, decayFactor)
require.NoError(t, err)
require.True(t, alloraMath.InDelta(expected, result, alloraMath.MustNewDecFromString("0.0001")))
}

func TestCalcExpDecayZeroDecayFactor(t *testing.T) {
decayFactor := alloraMath.MustNewDecFromString("0")
currentRev := alloraMath.MustNewDecFromString("300")

// (1 - 0) * 300
// 1 * 300 = 300
expected := alloraMath.MustNewDecFromString("300")

result, err := alloraMath.CalcExpDecay(currentRev, decayFactor)
require.NoError(t, err)
require.True(t, alloraMath.InDelta(expected, result, alloraMath.MustNewDecFromString("0.0001")))
}

func TestStdDev(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading

0 comments on commit d23be2d

Please sign in to comment.