github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/farm/types/key.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/binary"
     5  
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  )
     8  
     9  const (
    10  	// ModuleName is the name of the module
    11  	ModuleName = "farm"
    12  
    13  	// StoreKey to be used when creating the KVStore
    14  	StoreKey = ModuleName
    15  
    16  	// TStoreKey is the string transient store representation
    17  	TStoreKey = "transient_" + ModuleName
    18  
    19  	// RouterKey to be used for routing msgs
    20  	RouterKey = ModuleName
    21  
    22  	// MintFarmingAccount as module account to be used for saving all mint farming tokens
    23  	MintFarmingAccount = "mint_farming_account"
    24  
    25  	// YieldFarmingAccount as module account to be used for saving all yield farming tokens
    26  	YieldFarmingAccount = "yield_farming_account"
    27  
    28  	// QuerierRoute to be used for querier msgs
    29  	QuerierRoute = ModuleName
    30  
    31  	// Byte length of period occupied
    32  	PeriodByteArrayLength = 8
    33  )
    34  
    35  var (
    36  	FarmPoolPrefix              = []byte{0x01}
    37  	Pool2AddressPrefix          = []byte{0x02}
    38  	Address2PoolPrefix          = []byte{0x03}
    39  	PoolsYieldNativeTokenPrefix = []byte{0x04}
    40  	PoolHistoricalRewardsPrefix = []byte{0x05}
    41  	PoolCurrentRewardsPrefix    = []byte{0x06}
    42  )
    43  
    44  const (
    45  	poolNameFromLockInfoKeyIndex = sdk.AddrLen + 1
    46  )
    47  
    48  func GetFarmPoolKey(poolName string) []byte {
    49  	return append(FarmPoolPrefix, []byte(poolName)...)
    50  }
    51  
    52  func GetAddressInFarmPoolKey(poolName string, addr sdk.AccAddress) []byte {
    53  	return append(Pool2AddressPrefix, append([]byte(poolName), addr.Bytes()...)...)
    54  }
    55  
    56  func GetLockInfoKey(addr sdk.AccAddress, poolName string) []byte {
    57  	return append(Address2PoolPrefix, append(addr.Bytes(), []byte(poolName)...)...)
    58  }
    59  
    60  func SplitPoolsYieldNativeTokenKey(keyWithPrefix []byte) (poolName string) {
    61  	return string(keyWithPrefix[1:])
    62  }
    63  
    64  // GetWhitelistMemberKey builds the key for a available pool name
    65  func GetWhitelistMemberKey(poolName string) []byte {
    66  	return append(PoolsYieldNativeTokenPrefix, []byte(poolName)...)
    67  }
    68  
    69  // SplitPoolNameFromLockInfoKey splits the pool name out from a LockInfoKey
    70  func SplitPoolNameFromLockInfoKey(lockInfoKey []byte) string {
    71  	return string(lockInfoKey[poolNameFromLockInfoKeyIndex:])
    72  }
    73  
    74  // GetPoolHistoricalRewardsKey gets the key for a pool's historical reward
    75  func GetPoolHistoricalRewardsKey(poolName string, period uint64) []byte {
    76  	b := make([]byte, PeriodByteArrayLength)
    77  	binary.LittleEndian.PutUint64(b, period)
    78  	return append(PoolHistoricalRewardsPrefix, append([]byte(poolName), b...)...)
    79  }
    80  
    81  // GetPoolHistoricalRewardsPrefix gets the prefix key with pool name for a pool's historical rewards
    82  func GetPoolHistoricalRewardsPrefix(poolName string) []byte {
    83  	return append(PoolHistoricalRewardsPrefix, []byte(poolName)...)
    84  }
    85  
    86  // GetPoolCurrentRewardsKey gets the key for a pool's current period reward
    87  func GetPoolCurrentRewardsKey(poolName string) []byte {
    88  	return append(PoolCurrentRewardsPrefix, []byte(poolName)...)
    89  }