-
Notifications
You must be signed in to change notification settings - Fork 36
/
cellarfees.go
40 lines (34 loc) · 1.6 KB
/
cellarfees.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package keeper
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/peggyjv/sommelier/v7/app/params"
"github.com/peggyjv/sommelier/v7/x/cellarfees/types"
)
// Getter for module account that holds the fee pool funds
func (k Keeper) GetFeesAccount(ctx sdk.Context) authtypes.ModuleAccountI {
return k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
}
func (k Keeper) GetEmission(ctx sdk.Context, remainingRewardsSupply math.Int) sdk.Coins {
previousSupplyPeak := k.GetLastRewardSupplyPeak(ctx)
cellarfeesParams := k.GetParams(ctx)
var emissionAmount math.Int
if remainingRewardsSupply.GT(previousSupplyPeak) {
k.SetLastRewardSupplyPeak(ctx, remainingRewardsSupply)
emissionAmount = remainingRewardsSupply.Quo(sdk.NewInt(int64(cellarfeesParams.RewardEmissionPeriod)))
} else {
emissionAmount = previousSupplyPeak.Quo(sdk.NewInt(int64(cellarfeesParams.RewardEmissionPeriod)))
}
// Emission should be at least 1usomm and at most the remaining reward supply
if emissionAmount.IsZero() {
emissionAmount = sdk.OneInt()
} else if emissionAmount.GTE(remainingRewardsSupply) {
// We zero out the previous peak value here to avoid doing it every block. We set the final emission
// to the remaining supply here even though it's potentially redundant because it's less code than
// having another check where we would also have to zero out the prevoius peak supply.
k.SetLastRewardSupplyPeak(ctx, sdk.ZeroInt())
emissionAmount = remainingRewardsSupply
}
return sdk.NewCoins(sdk.NewCoin(params.BaseCoinUnit, emissionAmount))
}