-
Notifications
You must be signed in to change notification settings - Fork 287
/
handler.go
68 lines (55 loc) · 2.07 KB
/
handler.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
package treasury
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/terra-project/core/x/treasury/internal/types"
)
// NewTreasuryPolicyUpdateHandler custom gov proposal handler
func NewTreasuryPolicyUpdateHandler(k Keeper) govtypes.Handler {
return func(ctx sdk.Context, content govtypes.Content) error {
switch c := content.(type) {
case TaxRateUpdateProposal:
return handleTaxRateUpdateProposal(ctx, k, c)
case RewardWeightUpdateProposal:
return handleRewardWeightUpdateProposal(ctx, k, c)
default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized treasury proposal content type: %T", c)
}
}
}
// handleTaxRateUpdateProposal is a handler for updating tax rate
func handleTaxRateUpdateProposal(ctx sdk.Context, k Keeper, p TaxRateUpdateProposal) error {
taxPolicy := k.TaxPolicy(ctx)
taxRate := k.GetTaxRate(ctx)
newTaxRate := taxPolicy.Clamp(taxRate, p.TaxRate)
// Set the new tax rate to the store
k.SetTaxRate(ctx, newTaxRate)
// Emit gov handler events
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeTaxRateUpdate,
sdk.NewAttribute(types.AttributeKeyTaxRate, newTaxRate.String()),
),
)
logger := k.Logger(ctx)
logger.Info(fmt.Sprintf("updated tax-rate to %s", newTaxRate))
return nil
}
// handleRewardWeightUpdateProposal is a handler for updating reward weight
func handleRewardWeightUpdateProposal(ctx sdk.Context, k Keeper, p RewardWeightUpdateProposal) error {
rewardPolicy := k.RewardPolicy(ctx)
rewardWeight := k.GetRewardWeight(ctx)
newRewardWeight := rewardPolicy.Clamp(rewardWeight, p.RewardWeight)
// Set the new reward rate to the store
k.SetRewardWeight(ctx, newRewardWeight)
// Emit gov handler events
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeRewardWeightUpdate,
sdk.NewAttribute(types.AttributeKeyRewardWeight, newRewardWeight.String()),
),
)
logger := k.Logger(ctx)
logger.Info(fmt.Sprintf("updated reward-weight to %s", newRewardWeight))
return nil
}