github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/staking/keeper/pool.go (about) 1 package keeper 2 3 import ( 4 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 5 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/supply/exported" 6 "github.com/fibonacci-chain/fbc/x/staking/types" 7 ) 8 9 // GetBondedPool returns the bonded tokens pool's module account 10 func (k Keeper) GetBondedPool(ctx sdk.Context) (bondedPool exported.ModuleAccountI) { 11 return k.supplyKeeper.GetModuleAccount(ctx, types.BondedPoolName) 12 } 13 14 // GetNotBondedPool returns the not bonded tokens pool's module account 15 func (k Keeper) GetNotBondedPool(ctx sdk.Context) (notBondedPool exported.ModuleAccountI) { 16 return k.supplyKeeper.GetModuleAccount(ctx, types.NotBondedPoolName) 17 } 18 19 // bondedTokensToNotBonded transfers coins from the bonded to the not bonded pool within staking 20 func (k Keeper) bondedTokensToNotBonded(ctx sdk.Context, tokens sdk.SysCoin) { 21 22 coins := tokens.ToCoins() 23 err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.BondedPoolName, types.NotBondedPoolName, coins) 24 if err != nil { 25 panic(err) 26 } 27 } 28 29 // TotalBondedTokens total staking tokens supply which is bonded 30 // TODO:No usages found in project files,remove it later 31 func (k Keeper) TotalBondedTokens(ctx sdk.Context) sdk.Dec { 32 bondedPool := k.GetBondedPool(ctx) 33 return bondedPool.GetCoins().AmountOf(k.BondDenom(ctx)) 34 } 35 36 // StakingTokenSupply staking tokens from the total supply 37 func (k Keeper) StakingTokenSupply(ctx sdk.Context) sdk.Dec { 38 return k.supplyKeeper.GetSupplyByDenom(ctx, k.BondDenom(ctx)) 39 } 40 41 // BondedRatio the fraction of the staking tokens which are currently bonded 42 func (k Keeper) BondedRatio(ctx sdk.Context) sdk.Dec { 43 bondedPool := k.GetBondedPool(ctx) 44 45 stakeSupply := k.StakingTokenSupply(ctx) 46 if stakeSupply.IsPositive() { 47 return bondedPool.GetCoins().AmountOf(k.BondDenom(ctx)).Quo(stakeSupply) 48 } 49 return sdk.ZeroDec() 50 }