-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitelist.go
85 lines (68 loc) · 2.96 KB
/
whitelist.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
79
80
81
82
83
84
85
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
swaptypes "github.com/fastock/fastock-chain/x/ammswap/types"
"github.com/fastock/fastock-chain/x/farm/types"
)
// GetWhitelist gets the whole whitelist currently
func (k Keeper) GetWhitelist(ctx sdk.Context) (whitelist types.PoolNameList) {
store := ctx.KVStore(k.StoreKey())
iterator := sdk.KVStorePrefixIterator(store, types.PoolsYieldNativeTokenPrefix)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
whitelist = append(whitelist, types.SplitPoolsYieldNativeTokenKey(iterator.Key()))
}
return
}
// GetWhitelist sets the pool name as a member into whitelist
func (k Keeper) SetWhitelist(ctx sdk.Context, poolName string) {
ctx.KVStore(k.storeKey).Set(types.GetWhitelistMemberKey(poolName), []byte(""))
}
// DeleteWhiteList removes the pool name from whitelist
func (k Keeper) DeleteWhiteList(ctx sdk.Context, poolName string) {
ctx.KVStore(k.storeKey).Delete(types.GetWhitelistMemberKey(poolName))
}
func (k Keeper) isPoolNameExistedInWhiteList(ctx sdk.Context, poolName string) bool {
return ctx.KVStore(k.storeKey).Has(types.GetWhitelistMemberKey(poolName))
}
func (k Keeper) satisfyWhiteListAdmittance(ctx sdk.Context, pool types.FarmPool) sdk.Error {
quoteTokenSymbol := k.GetParams(ctx).QuoteSymbol
// lock token is quote symbol
if pool.MinLockAmount.Denom == quoteTokenSymbol {
return nil
}
if !swaptypes.IsPoolToken(pool.MinLockAmount.Denom) {
// locked token is common token
// check the existence of locked token with default quoteTokenSymbol in Params
if !k.isSwapTokenPairExisted(ctx, pool.MinLockAmount.Denom, quoteTokenSymbol) {
return types.ErrSwapTokenPairNotExist(swaptypes.GetSwapTokenPairName(pool.MinLockAmount.Denom, quoteTokenSymbol))
}
return nil
}
// locked token is lpt
tokenSymbol0, tokenSymbol1 := swaptypes.SplitPoolToken(pool.MinLockAmount.Denom)
if tokenSymbol0 == quoteTokenSymbol || tokenSymbol1 == quoteTokenSymbol {
// base or quote token contains default quoteTokenSymbol in Params
// check the existence of locked token
if !k.isSwapTokenPairExisted(ctx, tokenSymbol0, tokenSymbol1) {
return types.ErrTokenNotExist(pool.MinLockAmount.Denom)
}
return nil
}
// base or quote token don't contain default quoteTokenSymbol in Params
// check the existence of locked token both with default quoteTokenSymbol in Params
if !k.isSwapTokenPairExisted(ctx, tokenSymbol0, quoteTokenSymbol) {
return types.ErrSwapTokenPairNotExist(swaptypes.GetSwapTokenPairName(tokenSymbol0, quoteTokenSymbol))
}
if !k.isSwapTokenPairExisted(ctx, tokenSymbol1, quoteTokenSymbol) {
return types.ErrSwapTokenPairNotExist(swaptypes.GetSwapTokenPairName(tokenSymbol1, quoteTokenSymbol))
}
return nil
}
func (k Keeper) isSwapTokenPairExisted(ctx sdk.Context, baseTokenSymbol, quoteTokenSymbol string) bool {
_, err := k.swapKeeper.GetSwapTokenPair(ctx, swaptypes.GetSwapTokenPairName(baseTokenSymbol, quoteTokenSymbol))
if err != nil {
return false
}
return true
}