Skip to content

Commit

Permalink
feat: add support for user-provided fee collector module account
Browse files Browse the repository at this point in the history
  • Loading branch information
madrezaz committed Jun 27, 2023
1 parent d08cd0c commit 27de5a5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func New(
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
authtypes.FeeCollectorName,
)

app.BankKeeper.RegisterKeepers(app.AllianceKeeper, app.StakingKeeper)
Expand Down
3 changes: 1 addition & 2 deletions x/alliance/keeper/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/terra-money/alliance/x/alliance/types"
Expand Down Expand Up @@ -321,7 +320,7 @@ func (k Keeper) DeductAssetsWithTakeRate(ctx sdk.Context, lastClaim time.Time, a
}

if !coins.Empty() && !coins.IsZero() {
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, authtypes.FeeCollectorName, coins)
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, coins)
if err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions x/alliance/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Keeper struct {
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper
distributionKeeper types.DistributionKeeper
feeCollectorName string // name of the FeeCollector ModuleAccount
}

func NewKeeper(
Expand All @@ -31,13 +32,19 @@ func NewKeeper(
bankKeeper types.BankKeeper,
stakingKeeper types.StakingKeeper,
distributionKeeper types.DistributionKeeper,
feeCollectorName string,
) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
kt := paramtypes.NewKeyTable().RegisterParamSet(&types.Params{})
ps = ps.WithKeyTable(kt)
}

// make sure the fee collector module account exists
if accountKeeper.GetModuleAddress(feeCollectorName) == nil {
panic(fmt.Sprintf("%s module account has not been set", feeCollectorName))
}

return Keeper{
storeKey: storeKey,
paramstore: ps,
Expand All @@ -46,6 +53,7 @@ func NewKeeper(
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
distributionKeeper: distributionKeeper,
feeCollectorName: feeCollectorName,
}
}

Expand Down
4 changes: 1 addition & 3 deletions x/alliance/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/terra-money/alliance/x/alliance/types"
)

Expand Down Expand Up @@ -133,7 +131,7 @@ func (k Keeper) slashUndelegations(ctx sdk.Context, valAddr sdk.ValAddress, frac
tokensToSlash := fraction.MulInt(entry.Balance.Amount).TruncateInt()
entry.Balance = sdk.NewCoin(entry.Balance.Denom, entry.Balance.Amount.Sub(tokensToSlash))
coinToSlash := sdk.NewCoin(entry.Balance.Denom, tokensToSlash)
err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, authtypes.FeeCollectorName, sdk.NewCoins(coinToSlash))
err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, sdk.NewCoins(coinToSlash))
if err != nil {
return err
}
Expand Down

0 comments on commit 27de5a5

Please sign in to comment.