/
params.go
78 lines (67 loc) · 2.14 KB
/
params.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
76
77
78
package quota
import (
"errors"
"github.com/umee-network/umee/v6/x/uibc"
)
// SetParams sets the x/uibc module's parameters.
func (k Keeper) SetParams(params uibc.Params) error {
bz, err := k.cdc.Marshal(¶ms)
if err != nil {
return err
}
k.store.Set(keyParams, bz)
return nil
}
// GetParams gets the x/uibc module's parameters.
func (k Keeper) GetParams() (params uibc.Params) {
bz := k.store.Get(keyParams)
if bz == nil {
return params
}
k.cdc.MustUnmarshal(bz, ¶ms)
return params
}
// UpdateQuotaParams update the ibc-transfer quota params for ibc denoms
func (k Keeper) UpdateQuotaParams(msg *uibc.MsgGovUpdateQuota, byEmergencyGroup bool) error {
pOld := k.GetParams()
pNew := pOld
pNew.TotalQuota = msg.Total
pNew.QuotaDuration = msg.QuotaDuration
pNew.TokenQuota = msg.PerDenom
pNew.InflowOutflowQuotaBase = msg.InflowOutflowQuotaBase
pNew.InflowOutflowTokenQuotaBase = msg.InflowOutflowTokenQuotaBase
pNew.InflowOutflowQuotaRate = msg.InflowOutflowQuotaRate
if byEmergencyGroup {
if err := validateEmergencyQuotaParamsUpdate(pOld, pNew); err != nil {
return err
}
}
return k.SetParams(pNew)
}
func validateEmergencyQuotaParamsUpdate(pOld, pNew uibc.Params) error {
var errs []error
if pNew.TotalQuota.GT(pOld.TotalQuota) || pNew.TokenQuota.GT(pOld.TokenQuota) ||
pNew.InflowOutflowQuotaBase.GT(pOld.InflowOutflowQuotaBase) ||
pNew.InflowOutflowTokenQuotaBase.GT(pOld.InflowOutflowTokenQuotaBase) ||
pNew.InflowOutflowQuotaRate.GT(pOld.InflowOutflowQuotaRate) {
errs = append(errs, errors.New("emergency group can't increase any of the quota parameters"))
}
if pNew.QuotaDuration != pOld.QuotaDuration {
errs = append(errs, errors.New("emergency group can't change QuotaDuration"))
}
if len(errs) != 0 {
return errors.Join(errs...)
}
return nil
}
// SetIBCStatus update the ibc-transfer status in module params.
func (k Keeper) SetIBCStatus(ibcStatus uibc.IBCTransferStatus) error {
params := k.GetParams()
params.IbcStatus = ibcStatus
return k.SetParams(params)
}
func (k Keeper) SetICS20HooksStatus(enabled bool) error {
params := k.GetParams()
params.Ics20Hooks = enabled
return k.SetParams(params)
}