/
abci.go
75 lines (66 loc) · 2.39 KB
/
abci.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 (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gitopia/gitopia/v2/app/params"
"github.com/gitopia/gitopia/v2/x/gitopia/types"
"github.com/pkg/errors"
)
func (k Keeper) TransferProportion(
ctx sdk.Context,
totalCoin sdk.Coin,
from string,
to string,
proportion sdk.Dec) (sdk.Coins, error) {
dec := sdk.NewDec(totalCoin.Amount.Int64())
amount := dec.Mul(proportion).Quo(sdk.NewDec(100)).TruncateInt()
if amount.IsZero() {
return nil, nil
}
coin := sdk.NewCoin(params.BaseCoinUnit, amount)
coins := sdk.Coins{coin}
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, from, to, coins)
if err != nil {
return nil, errors.Wrapf(err, "error distributing to %v", to)
}
return coins, nil
}
func (k Keeper) TokenDistribution(ctx sdk.Context) {
gitopiaParams := k.GetParams(ctx)
minterAddress := k.accountKeeper.GetModuleAddress(k.minterAccountName)
mintedCoin := k.bankKeeper.GetBalance(ctx, minterAddress, params.BaseCoinUnit)
remainingMintedCoins := sdk.Coins{mintedCoin}
if gitopiaParams.PoolProportions.Ecosystem != nil {
if gitopiaParams.PoolProportions.Ecosystem.Address != "" {
err := errors.New("ecosystem incentives address not empty")
ctx.Logger().Error(err.Error())
panic(err)
}
coins, err := k.TransferProportion(ctx, mintedCoin, k.minterAccountName, types.EcosystemIncentivesAccountName,
gitopiaParams.PoolProportions.Ecosystem.Proportion)
if err != nil {
ctx.Logger().Error(err.Error())
panic(err)
}
remainingMintedCoins = remainingMintedCoins.Sub(coins...)
}
if gitopiaParams.PoolProportions.Team != nil {
if gitopiaParams.PoolProportions.Team.Address != "" {
err := errors.New("team address not empty")
ctx.Logger().Error(err.Error())
panic(err)
}
coins, err := k.TransferProportion(ctx, mintedCoin, k.minterAccountName, types.TeamAccountName, gitopiaParams.PoolProportions.Team.Proportion)
if err != nil {
ctx.Logger().Error(err.Error())
panic(err)
}
remainingMintedCoins = remainingMintedCoins.Sub(coins...)
}
// move community, validator and delegator incentives into fee collector account,
// to be distributed by cosmos-sdk distribution module.
if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, k.minterAccountName, k.feeCollectorAccount, remainingMintedCoins); err != nil {
ctx.Logger().Error(fmt.Sprintf("error distributing community and staking proportion %v", err))
panic(err)
}
}