cdp

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Overview

nolint autogenerated code using github.com/rigelrozanski/multitool aliases generated for the following subdirectories: ALIASGEN: github.com/kava-labs/kava/x/cdp/keeper ALIASGEN: github.com/kava-labs/kava/x/cdp/types

Package CDP manages the storage of Collateralized Debt Positions. It handles their creation, modification, and stores the global state of all CDPs.

Notes

  • sdk.Int is used for all the number types to maintain compatibility with internal type of sdk.Coin - saves type conversion when doing maths. Also it allows for changes to a CDP to be expressed as a +ve or -ve number.
  • Only allowing one CDP per account-collateralDenom pair for now to keep things simple.
  • Genesis forces the global debt to start at zero, ie no stable coins in existence. This could be changed.
  • The cdp module fulfills the bank keeper interface and keeps track of the liquidator module's coins. This won't be needed with module accounts.
  • GetCDPs does not return an iterator, but instead reads out (potentially) all CDPs from the store. This isn't a huge performance concern as it is never used during a block, only for querying. An iterator could be created, following the queue style construct in gov and auction, where CDP IDs are stored under ordered keys. These keys could be a collateral-denom:collateral-ratio so that it is efficient to obtain the undercollateralized CDP for a given price and liquidation ratio. However creating a byte sortable representation of a collateral ratio wasn't very easy so the simpler approach was chosen.

TODO

  • A shorter name for an under-collateralized CDP would shorten a lot of function names
  • remove fake bank keeper and setup a proper liquidator module account
  • what happens if a collateral type is removed from the list of allowed ones?
  • Should the values used to generate a key for a stored struct be in the struct?
  • Add constants for the module and route names
  • Many more TODOs in the code
  • add more aggressive test cases
  • tags
  • custom error types, codespace

Index

Constants

View Source
const (
	BaseDigitFactor                 = keeper.BaseDigitFactor
	DefaultCodespace                = types.DefaultCodespace
	CodeCdpAlreadyExists            = types.CodeCdpAlreadyExists
	CodeCollateralLengthInvalid     = types.CodeCollateralLengthInvalid
	CodeCollateralNotSupported      = types.CodeCollateralNotSupported
	CodeDebtNotSupported            = types.CodeDebtNotSupported
	CodeExceedsDebtLimit            = types.CodeExceedsDebtLimit
	CodeInvalidCollateralRatio      = types.CodeInvalidCollateralRatio
	CodeCdpNotFound                 = types.CodeCdpNotFound
	CodeDepositNotFound             = types.CodeDepositNotFound
	CodeInvalidDepositDenom         = types.CodeInvalidDepositDenom
	CodeInvalidPaymentDenom         = types.CodeInvalidPaymentDenom
	CodeDepositNotAvailable         = types.CodeDepositNotAvailable
	CodeInvalidCollateralDenom      = types.CodeInvalidCollateralDenom
	CodeInvalidWithdrawAmount       = types.CodeInvalidWithdrawAmount
	CodeCdpNotAvailable             = types.CodeCdpNotAvailable
	CodeBelowDebtFloor              = types.CodeBelowDebtFloor
	CodePaymentExceedsDebt          = types.CodePaymentExceedsDebt
	CodeLoadingAugmentedCDP         = types.CodeLoadingAugmentedCDP
	EventTypeCreateCdp              = types.EventTypeCreateCdp
	EventTypeCdpDeposit             = types.EventTypeCdpDeposit
	EventTypeCdpDraw                = types.EventTypeCdpDraw
	EventTypeCdpRepay               = types.EventTypeCdpRepay
	EventTypeCdpClose               = types.EventTypeCdpClose
	EventTypeCdpWithdrawal          = types.EventTypeCdpWithdrawal
	EventTypeCdpLiquidation         = types.EventTypeCdpLiquidation
	EventTypeBeginBlockerFatal      = types.EventTypeBeginBlockerFatal
	AttributeKeyCdpID               = types.AttributeKeyCdpID
	AttributeKeyDepositor           = types.AttributeKeyDepositor
	AttributeValueCategory          = types.AttributeValueCategory
	AttributeKeyError               = types.AttributeKeyError
	ModuleName                      = types.ModuleName
	StoreKey                        = types.StoreKey
	RouterKey                       = types.RouterKey
	QuerierRoute                    = types.QuerierRoute
	DefaultParamspace               = types.DefaultParamspace
	LiquidatorMacc                  = types.LiquidatorMacc
	SavingsRateMacc                 = types.SavingsRateMacc
	QueryGetCdp                     = types.QueryGetCdp
	QueryGetCdpDeposits             = types.QueryGetCdpDeposits
	QueryGetCdps                    = types.QueryGetCdps
	QueryGetCdpsByCollateralization = types.QueryGetCdpsByCollateralization
	QueryGetParams                  = types.QueryGetParams
	RestOwner                       = types.RestOwner
	RestCollateralDenom             = types.RestCollateralDenom
	RestRatio                       = types.RestRatio
)

Variables

View Source
var (
	// functions aliases
	NewKeeper                   = keeper.NewKeeper
	NewQuerier                  = keeper.NewQuerier
	NewCDP                      = types.NewCDP
	NewAugmentedCDP             = types.NewAugmentedCDP
	RegisterCodec               = types.RegisterCodec
	NewDeposit                  = types.NewDeposit
	ErrCdpAlreadyExists         = types.ErrCdpAlreadyExists
	ErrInvalidCollateralLength  = types.ErrInvalidCollateralLength
	ErrCollateralNotSupported   = types.ErrCollateralNotSupported
	ErrDebtNotSupported         = types.ErrDebtNotSupported
	ErrExceedsDebtLimit         = types.ErrExceedsDebtLimit
	ErrInvalidCollateralRatio   = types.ErrInvalidCollateralRatio
	ErrCdpNotFound              = types.ErrCdpNotFound
	ErrDepositNotFound          = types.ErrDepositNotFound
	ErrInvalidDepositDenom      = types.ErrInvalidDepositDenom
	ErrInvalidPaymentDenom      = types.ErrInvalidPaymentDenom
	ErrDepositNotAvailable      = types.ErrDepositNotAvailable
	ErrInvalidCollateralDenom   = types.ErrInvalidCollateralDenom
	ErrInvalidWithdrawAmount    = types.ErrInvalidWithdrawAmount
	ErrCdpNotAvailable          = types.ErrCdpNotAvailable
	ErrBelowDebtFloor           = types.ErrBelowDebtFloor
	ErrPaymentExceedsDebt       = types.ErrPaymentExceedsDebt
	ErrLoadingAugmentedCDP      = types.ErrLoadingAugmentedCDP
	NewGenesisState             = types.NewGenesisState
	DefaultGenesisState         = types.DefaultGenesisState
	GetCdpIDBytes               = types.GetCdpIDBytes
	GetCdpIDFromBytes           = types.GetCdpIDFromBytes
	CdpKey                      = types.CdpKey
	SplitCdpKey                 = types.SplitCdpKey
	DenomIterKey                = types.DenomIterKey
	SplitDenomIterKey           = types.SplitDenomIterKey
	DepositKey                  = types.DepositKey
	SplitDepositKey             = types.SplitDepositKey
	DepositIterKey              = types.DepositIterKey
	SplitDepositIterKey         = types.SplitDepositIterKey
	CollateralRatioBytes        = types.CollateralRatioBytes
	CollateralRatioKey          = types.CollateralRatioKey
	SplitCollateralRatioKey     = types.SplitCollateralRatioKey
	CollateralRatioIterKey      = types.CollateralRatioIterKey
	SplitCollateralRatioIterKey = types.SplitCollateralRatioIterKey
	NewMsgCreateCDP             = types.NewMsgCreateCDP
	NewMsgDeposit               = types.NewMsgDeposit
	NewMsgWithdraw              = types.NewMsgWithdraw
	NewMsgDrawDebt              = types.NewMsgDrawDebt
	NewMsgRepayDebt             = types.NewMsgRepayDebt
	NewParams                   = types.NewParams
	DefaultParams               = types.DefaultParams
	ParamKeyTable               = types.ParamKeyTable
	NewQueryCdpsParams          = types.NewQueryCdpsParams
	NewQueryCdpParams           = types.NewQueryCdpParams
	NewQueryCdpDeposits         = types.NewQueryCdpDeposits
	NewQueryCdpsByRatioParams   = types.NewQueryCdpsByRatioParams
	ValidSortableDec            = types.ValidSortableDec
	SortableDecBytes            = types.SortableDecBytes
	ParseDecBytes               = types.ParseDecBytes
	RelativePow                 = types.RelativePow

	// variable aliases
	ModuleCdc                           = types.ModuleCdc
	CdpIDKeyPrefix                      = types.CdpIDKeyPrefix
	CdpKeyPrefix                        = types.CdpKeyPrefix
	CollateralRatioIndexPrefix          = types.CollateralRatioIndexPrefix
	CdpIDKey                            = types.CdpIDKey
	DebtDenomKey                        = types.DebtDenomKey
	GovDenomKey                         = types.GovDenomKey
	DepositKeyPrefix                    = types.DepositKeyPrefix
	PrincipalKeyPrefix                  = types.PrincipalKeyPrefix
	PreviousBlockTimeKey                = types.PreviousBlockTimeKey
	PreviousDistributionTimeKey         = types.PreviousDistributionTimeKey
	KeyGlobalDebtLimit                  = types.KeyGlobalDebtLimit
	KeyCollateralParams                 = types.KeyCollateralParams
	KeyDebtParams                       = types.KeyDebtParams
	KeyDistributionFrequency            = types.KeyDistributionFrequency
	KeyCircuitBreaker                   = types.KeyCircuitBreaker
	KeyDebtThreshold                    = types.KeyDebtThreshold
	KeySurplusThreshold                 = types.KeySurplusThreshold
	DefaultGlobalDebt                   = types.DefaultGlobalDebt
	DefaultCircuitBreaker               = types.DefaultCircuitBreaker
	DefaultCollateralParams             = types.DefaultCollateralParams
	DefaultDebtParams                   = types.DefaultDebtParams
	DefaultCdpStartingID                = types.DefaultCdpStartingID
	DefaultDebtDenom                    = types.DefaultDebtDenom
	DefaultGovDenom                     = types.DefaultGovDenom
	DefaultSurplusThreshold             = types.DefaultSurplusThreshold
	DefaultDebtThreshold                = types.DefaultDebtThreshold
	DefaultPreviousBlockTime            = types.DefaultPreviousBlockTime
	DefaultPreviousDistributionTime     = types.DefaultPreviousDistributionTime
	DefaultSavingsDistributionFrequency = types.DefaultSavingsDistributionFrequency
	MaxSortableDec                      = types.MaxSortableDec
)

Functions

func BeginBlocker

func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper)

BeginBlocker compounds the debt in outstanding cdps and liquidates cdps that are below the required collateralization ratio

func InitGenesis

func InitGenesis(ctx sdk.Context, k Keeper, pk PricefeedKeeper, sk SupplyKeeper, gs GenesisState)

InitGenesis sets initial genesis state for cdp module

func NewHandler

func NewHandler(k Keeper) sdk.Handler

NewHandler creates an sdk.Handler for cdp messages

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	AppModuleSimulation
	// contains filtered or unexported fields
}

AppModule app module type

func NewAppModule

func NewAppModule(keeper Keeper, pricefeedKeeper PricefeedKeeper, supplyKeeper SupplyKeeper) AppModule

NewAppModule creates a new AppModule object

func (AppModule) BeginBlock

func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)

BeginBlock module begin-block

func (AppModule) EndBlock

EndBlock module end-block

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage

ExportGenesis module export genesis

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis module init-genesis

func (AppModule) Name

func (AppModule) Name() string

Name module name

func (AppModule) NewHandler

func (am AppModule) NewHandler() sdk.Handler

NewHandler module handler

func (AppModule) NewQuerierHandler

func (am AppModule) NewQuerierHandler() sdk.Querier

NewQuerierHandler module querier

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute module querier route name

func (AppModule) RegisterInvariants

func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry)

RegisterInvariants register module invariants

func (AppModule) Route

func (AppModule) Route() string

Route module message route name

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic app module basics object

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis() json.RawMessage

DefaultGenesis default genesis state

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command

GetQueryCmd returns the root query command for the auction module.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command

GetTxCmd returns the root tx command for the cdp module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name get module name

func (AppModuleBasic) RegisterCodec

func (AppModuleBasic) RegisterCodec(cdc *codec.Codec)

RegisterCodec register module codec

func (AppModuleBasic) RegisterRESTRoutes

func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router)

RegisterRESTRoutes registers the REST routes for the cdp module.

func (AppModuleBasic) ValidateGenesis

func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error

ValidateGenesis module validate genesis

type AppModuleSimulation added in v0.5.0

type AppModuleSimulation struct{}

AppModuleSimulation defines the module simulation functions used by the cdp module.

func (AppModuleSimulation) GenerateGenesisState added in v0.5.0

func (AppModuleSimulation) GenerateGenesisState(simState *module.SimulationState)

GenerateGenesisState creates a randomized GenState of the cdp module

func (AppModuleSimulation) RandomizedParams added in v0.5.0

func (AppModuleSimulation) RandomizedParams(r *rand.Rand) []sim.ParamChange

RandomizedParams creates randomized cdp param changes for the simulator.

func (AppModuleSimulation) RegisterStoreDecoder added in v0.5.0

func (AppModuleSimulation) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry)

RegisterStoreDecoder registers a decoder for cdp module's types

type AugmentedCDP

type AugmentedCDP = types.AugmentedCDP

type AugmentedCDPs

type AugmentedCDPs = types.AugmentedCDPs

type CDP

type CDP = types.CDP

type CDPs

type CDPs = types.CDPs

type CollateralParam

type CollateralParam = types.CollateralParam

type CollateralParams

type CollateralParams = types.CollateralParams

type DebtParam

type DebtParam = types.DebtParam

type DebtParams

type DebtParams = types.DebtParams

type Deposit

type Deposit = types.Deposit

type Deposits

type Deposits = types.Deposits

type GenesisState

type GenesisState = types.GenesisState

func ExportGenesis

func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState

ExportGenesis export genesis state for cdp module

type Keeper

type Keeper = keeper.Keeper

type MsgCreateCDP

type MsgCreateCDP = types.MsgCreateCDP

type MsgDeposit

type MsgDeposit = types.MsgDeposit

type MsgDrawDebt

type MsgDrawDebt = types.MsgDrawDebt

type MsgRepayDebt

type MsgRepayDebt = types.MsgRepayDebt

type MsgWithdraw

type MsgWithdraw = types.MsgWithdraw

type Params

type Params = types.Params

type PricefeedKeeper

type PricefeedKeeper = types.PricefeedKeeper

type QueryCdpDeposits added in v0.5.0

type QueryCdpDeposits = types.QueryCdpDeposits

type QueryCdpParams

type QueryCdpParams = types.QueryCdpParams

type QueryCdpsByRatioParams

type QueryCdpsByRatioParams = types.QueryCdpsByRatioParams

type QueryCdpsParams

type QueryCdpsParams = types.QueryCdpsParams

type SupplyKeeper

type SupplyKeeper = types.SupplyKeeper

Directories

Path Synopsis
client
cli
DONTCOVER
DONTCOVER

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL