/
hooks.go
68 lines (56 loc) · 2.05 KB
/
hooks.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 keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/umee-network/umee/v6/x/metoken"
leveragetypes "github.com/umee-network/umee/v6/x/leverage/types"
"github.com/umee-network/umee/v6/x/oracle/types"
)
// Hooks defines a structure around the x/oracle Keeper that implements various
// Hooks interface defined by other modules such as x/leverage.
type Hooks struct {
k Keeper
}
var _ leveragetypes.TokenHooks = Hooks{}
// Hooks returns a new Hooks instance that wraps the x/oracle keeper.
func (k Keeper) Hooks() Hooks {
return Hooks{k}
}
// AfterTokenRegistered implements the x/leverage Hooks interface. Specifically,
// it checks if the provided Token should be added to the existing accepted list
// of assets for the x/oracle module.
func (h Hooks) AfterTokenRegistered(ctx sdk.Context, token leveragetypes.Token) {
if token.Blacklist {
// Blacklisted tokens should not trigger updates to the oracle accept list
return
}
// Metokens shouldn't be part of oracle accept list. Every index informs its price to oracle each endBlock.
if metoken.IsMeToken(token.BaseDenom) {
return
}
acceptList := h.k.AcceptList(ctx)
var tokenExists bool
for _, t := range acceptList {
if t.BaseDenom == token.BaseDenom {
tokenExists = true
break
}
}
if !tokenExists {
acceptList = append(acceptList, types.Denom{
BaseDenom: token.BaseDenom,
SymbolDenom: token.SymbolDenom,
Exponent: token.Exponent,
})
}
h.k.SetAcceptList(ctx, acceptList)
}
// AfterRegisteredTokenRemoved implements the x/leverage Hooks interface.
// Currently, it performs a no-op, however, we may want to remove tokens from
// the accept list in the future when they're removed from the x/leverage Token
// registry.
//
// We don't remove the token from the accept list because it might prove to be
// useful to still have price data for assets outside of the scope of the
// x/leverage registry. If assets need to be removed, they can always be purged
// via param change proposals.
func (h Hooks) AfterRegisteredTokenRemoved(sdk.Context, leveragetypes.Token) {}