-
Notifications
You must be signed in to change notification settings - Fork 590
/
developer_fees.go
75 lines (63 loc) · 2.24 KB
/
developer_fees.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/v24/x/protorev/types"
)
// DistributeProfit sends the developer fee from the module account to the developer account
// and burns the remaining profit if denominated in osmo.
func (k Keeper) DistributeProfit(ctx sdk.Context, arbProfits sdk.Coins) error {
// Developer account must be set in order to be able to withdraw developer fees
developerAccount, err := k.GetDeveloperAccount(ctx)
if err != nil {
return err
}
// Get the days since genesis
daysSinceGenesis, err := k.GetDaysSinceModuleGenesis(ctx)
if err != nil {
return err
}
var (
devProfit sdk.Coins
remainingProfit sdk.Coins
profitSplit int64
)
if daysSinceGenesis < types.Phase1Length {
profitSplit = types.ProfitSplitPhase1
} else if daysSinceGenesis < types.Phase2Length {
profitSplit = types.ProfitSplitPhase2
} else {
profitSplit = types.ProfitSplitPhase3
}
// Calculate the developer fee from all arb profits
for _, arbProfit := range arbProfits {
devProfitAmount := arbProfit.Amount.MulRaw(profitSplit).QuoRaw(100)
devProfit = append(devProfit, sdk.NewCoin(arbProfit.Denom, devProfitAmount))
}
// Send the developer profit to the developer account
if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, developerAccount, devProfit); err != nil {
return err
}
// Remove the developer profit from the remaining arb profits
remainingProfit = arbProfits.Sub(devProfit...)
// If the remaining arb profits has the OSMO denom for one of the coins, burn the OSMO by sending to the null address
arbProfitsOsmoCoin := sdk.NewCoin(types.OsmosisDenomination, remainingProfit.AmountOf(types.OsmosisDenomination))
if arbProfitsOsmoCoin.IsPositive() {
err := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx,
types.ModuleName,
types.DefaultNullAddress,
sdk.NewCoins(arbProfitsOsmoCoin),
)
if err != nil {
return err
}
}
// Remove the burned OSMO from the remaining arb profits
remainingProfit = remainingProfit.Sub(arbProfitsOsmoCoin)
// Send all remaining arb profits to the community pool
return k.distributionKeeper.FundCommunityPool(
ctx,
remainingProfit,
k.accountKeeper.GetModuleAddress(types.ModuleName),
)
}