Documentation ¶
Overview ¶
Package CSDT manages the storage of Collateralized Stable Debt Tokens. It handles their creation, modification, and stores the global state of all CSDTs.
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 CSDT to be expressed as a +ve or -ve number.
- Only allowing one CSDT 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 csdt module fulfills the bank keeper interface and keeps track of the liquidator module's coins. This won't be needed with module accounts.
- GetCSDTs does not return an iterator, but instead reads out (potentially) all CSDTs 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 CSDT IDs are stored under ordered keys. These keys could be a collateral-denom:collateral-ratio so that it is efficient to obtain the undercollateralized CSDT 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 CSDT 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
- Variables
- func ParamKeyTable() params.KeyTable
- func RegisterCodec(cdc *codec.Codec)
- func ValidateGenesis(data GenesisState) error
- type BankKeeper
- type ByCollateralRatio
- type CSDT
- type CSDTs
- type CollateralParam
- type CollateralParams
- type CollateralState
- type DebtParam
- type DebtParams
- type GenesisState
- type ModifyCsdtRequestBody
- type MsgAddCollateralParam
- type MsgCreateOrModifyCSDT
- type MsgDepositCollateral
- type MsgSetCollateralParam
- type MsgSettleDebt
- type MsgTransferCSDT
- type MsgWithdrawCollateral
- type MsgWithdrawDebt
- type OracleKeeper
- type Params
- type QueryCsdtsParams
- type SupplyKeeper
Constants ¶
const ( // ModuleKey is the name of the module ModuleName = "csdt" // StoreKey is the store key string for issue StoreKey = ModuleName // RouterKey is the message route for issue RouterKey = ModuleName // QuerierRoute is the querier route for issue QuerierRoute = ModuleName // Parameter store default namestore DefaultParamspace = ModuleName // StableDenom asset code of the dollar-denominated debt coin StableDenom = "ucsdt" // TODO allow to be changed // GovDenom asset code of the governance coin GovDenom = "uftm" )
const ( QueryGetCsdts = "cdts" QueryGetParams = "params" RestOwner = "owner" RestCollateralDenom = "collateralDenom" RestUnderCollateralizedAt = "underCollateralizedAt" )
Variables ¶
var ( // ParamStoreKeyAuctionParams Param store key for auction params KeyGlobalDebtLimit = []byte("GlobalDebtLimit") KeyCollateralParams = []byte("CollateralParams") KeyDebtParams = []byte("DebtParams") KeyCircuitBreaker = []byte("CircuitBreaker") KeyNominees = []byte("Nominees") DefaultGlobalDebt = sdk.NewCoins(sdk.NewCoin(StableDenom, sdk.NewInt(500000000000))) DefaultCircuitBreaker = false DefaultCollateralParams = CollateralParams{CollateralParam{ Denom: "uftm", LiquidationRatio: sdk.MustNewDecFromStr("1.5"), DebtLimit: sdk.NewCoins(sdk.NewCoin(StableDenom, sdk.NewInt(500000000000))), }} DefaultDebtParams = DebtParams{} )
Parameter keys
var ModuleCdc *codec.Codec
generic sealed codec to be used throughout module
Functions ¶
func ParamKeyTable ¶
ParamKeyTable Key declaration for parameters
func RegisterCodec ¶
RegisterCodec registers concrete types on the codec.
func ValidateGenesis ¶
func ValidateGenesis(data GenesisState) error
ValidateGenesis performs basic validation of genesis data returning an error for any failed validation criteria.
Types ¶
type BankKeeper ¶
type ByCollateralRatio ¶
type ByCollateralRatio CSDTs
byCollateralRatio is used to sort CSDTs
func (ByCollateralRatio) Len ¶
func (csdts ByCollateralRatio) Len() int
func (ByCollateralRatio) Less ¶
func (csdts ByCollateralRatio) Less(i, j int) bool
func (ByCollateralRatio) Swap ¶
func (csdts ByCollateralRatio) Swap(i, j int)
type CSDT ¶
type CSDT struct { //ID []byte // removing IDs for now to make things simpler Owner sdk.AccAddress `json:"owner" yaml:"owner"` // Account that authorizes changes to the CSDT CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` // Type of collateral stored in this CSDT CollateralAmount sdk.Coins `json:"collateral_amount" yaml:"collateral_amount"` // Amount of collateral stored in this CSDT Debt sdk.Coins `json:"debt" yaml:"debt"` AccumulatedFees sdk.Coins `json:"accumulated_fees" yaml:"accumulated_fees"` FeesUpdated time.Time `json:"fees_updated" yaml:"fees_updated"` // Amount of stable coin drawn from this CSDT }
CSDT is the state of a single account.
func (CSDT) IsUnderCollateralized ¶
type CollateralParam ¶
type CollateralParam struct { Denom string `json:"denom" yaml:"denom"` // Coin name of collateral type LiquidationRatio sdk.Dec `json:"liquidation_ratio" yaml:"liquidation_ratio"` // The ratio (Collateral (priced in stable coin) / Debt) under which a CSDT will be liquidated DebtLimit sdk.Coins `json:"debt_limit" yaml:"debt_limit"` // Maximum amount of debt allowed to be drawn from this collateral type }
func (CollateralParam) String ¶
func (cp CollateralParam) String() string
String implements fmt.Stringer
type CollateralParams ¶
type CollateralParams []CollateralParam
CollateralParams array of CollateralParam
func (CollateralParams) String ¶
func (cps CollateralParams) String() string
String implements fmt.Stringer
type CollateralState ¶
type CollateralState struct { Denom string // Type of collateral TotalDebt sdk.Int // total debt collateralized by a this coin type }
CollateralState stores global information tied to a particular collateral type.
type DebtParam ¶
type DebtParam struct { Denom string `json:"denom" yaml:"denom"` ReferenceAsset string `json:"reference_asset" yaml:"reference_asset"` DebtLimit sdk.Coins `json:"debt_limit" yaml:"debt_limit"` }
DebtParam governance params for debt assets
type GenesisState ¶
type GenesisState struct { Params Params `json:"params" yaml:"params"` CSDTs CSDTs `json:"csdts" yaml:"csdts"` }
func DefaultGenesisState ¶
func DefaultGenesisState() GenesisState
DefaultGenesisState returns a default genesis state TODO make this empty, load test values independent
type ModifyCsdtRequestBody ¶
type MsgAddCollateralParam ¶
type MsgAddCollateralParam struct { Nominee sdk.AccAddress `json:"nominee" yaml:"nominee"` CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` LiquidationRatio sdk.Dec `json:"liquidation_ratio" yaml:"liquidation_ratio"` DebtLimit sdk.Coins `json:"debt_limit" yaml:"debt_limit"` }
MsgAddCollateralParam adds collateral to CSDT management
func NewMsgAddCollateralParam ¶
func NewMsgAddCollateralParam( nominee sdk.AccAddress, collateralDenom string, liquidationRatio sdk.Dec, debtLimit sdk.Coins, ) MsgAddCollateralParam
NewMsgAddCollateralParam returns a new MsgAddCollateralParam.
func (MsgAddCollateralParam) GetSignBytes ¶
func (msg MsgAddCollateralParam) GetSignBytes() []byte
GetSignBytes gets the canonical byte representation of the Msg.
func (MsgAddCollateralParam) GetSigners ¶
func (msg MsgAddCollateralParam) GetSigners() []sdk.AccAddress
GetSigners returns the addresses of signers that must sign.
func (MsgAddCollateralParam) Route ¶
func (msg MsgAddCollateralParam) Route() string
Route return the message type used for routing the message.
func (MsgAddCollateralParam) Type ¶
func (msg MsgAddCollateralParam) Type() string
Type returns a human-readable string for the message, intended for utilization within tags.
func (MsgAddCollateralParam) ValidateBasic ¶
func (msg MsgAddCollateralParam) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type MsgCreateOrModifyCSDT ¶
type MsgCreateOrModifyCSDT struct { Sender sdk.AccAddress `json:"sender" yaml:"sender"` CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` CollateralChange sdk.Int `json:"collateral_change" yaml:"collateral_change"` DebtChange sdk.Int `json:"debt_change" yaml:"debt_change"` }
MsgCreateOrModifyCSDT creates, adds/removes collateral/stable coin from a csdt TODO Make this more user friendly - maybe split into four functions.
func NewMsgCreateOrModifyCSDT ¶
func NewMsgCreateOrModifyCSDT(sender sdk.AccAddress, collateralDenom string, collateralChange sdk.Int, debtChange sdk.Int) MsgCreateOrModifyCSDT
NewMsgCreateOrModifyCSDT returns a new MsgCreateOrModifyCSDT.
func (MsgCreateOrModifyCSDT) GetSignBytes ¶
func (msg MsgCreateOrModifyCSDT) GetSignBytes() []byte
GetSignBytes gets the canonical byte representation of the Msg.
func (MsgCreateOrModifyCSDT) GetSigners ¶
func (msg MsgCreateOrModifyCSDT) GetSigners() []sdk.AccAddress
GetSigners returns the addresses of signers that must sign.
func (MsgCreateOrModifyCSDT) Route ¶
func (msg MsgCreateOrModifyCSDT) Route() string
Route return the message type used for routing the message.
func (MsgCreateOrModifyCSDT) Type ¶
func (msg MsgCreateOrModifyCSDT) Type() string
Type returns a human-readable string for the message, intended for utilization within tags.
func (MsgCreateOrModifyCSDT) ValidateBasic ¶
func (msg MsgCreateOrModifyCSDT) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type MsgDepositCollateral ¶
type MsgDepositCollateral struct { Sender sdk.AccAddress `json:"sender" yaml:"sender"` CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` CollateralChange sdk.Int `json:"collateral_change" yaml:"collateral_change"` }
MsgDepositCollateral adds collateral to CSDT.
func NewMsgDepositCollateral ¶
func NewMsgDepositCollateral(sender sdk.AccAddress, collateralDenom string, collateralChange sdk.Int) MsgDepositCollateral
NewMsgDepositCollateral returns a new MsgDepositCollateral.
func (MsgDepositCollateral) GetSignBytes ¶
func (msg MsgDepositCollateral) GetSignBytes() []byte
GetSignBytes gets the canonical byte representation of the Msg.
func (MsgDepositCollateral) GetSigners ¶
func (msg MsgDepositCollateral) GetSigners() []sdk.AccAddress
GetSigners returns the addresses of signers that must sign.
func (MsgDepositCollateral) Route ¶
func (msg MsgDepositCollateral) Route() string
Route return the message type used for routing the message.
func (MsgDepositCollateral) Type ¶
func (msg MsgDepositCollateral) Type() string
Type returns a human-readable string for the message, intended for utilization within tags.
func (MsgDepositCollateral) ValidateBasic ¶
func (msg MsgDepositCollateral) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type MsgSetCollateralParam ¶
type MsgSetCollateralParam struct { Nominee sdk.AccAddress `json:"nominee" yaml:"nominee"` CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` LiquidationRatio sdk.Dec `json:"liquidation_ratio" yaml:"liquidation_ratio"` DebtLimit sdk.Coins `json:"debt_limit" yaml:"debt_limit"` }
MsgSetCollateralParam sets collateral in CSDT management
func NewMsgSetCollateralParam ¶
func NewMsgSetCollateralParam( nominee sdk.AccAddress, collateralDenom string, liquidationRatio sdk.Dec, debtLimit sdk.Coins, ) MsgSetCollateralParam
NewMsgSetCollateralParam returns a new MsgSetCollateralParam.
func (MsgSetCollateralParam) GetSignBytes ¶
func (msg MsgSetCollateralParam) GetSignBytes() []byte
GetSignBytes gets the canonical byte representation of the Msg.
func (MsgSetCollateralParam) GetSigners ¶
func (msg MsgSetCollateralParam) GetSigners() []sdk.AccAddress
GetSigners returns the addresses of signers that must sign.
func (MsgSetCollateralParam) Route ¶
func (msg MsgSetCollateralParam) Route() string
Route return the message type used for routing the message.
func (MsgSetCollateralParam) Type ¶
func (msg MsgSetCollateralParam) Type() string
Type returns a human-readable string for the message, intended for utilization within tags.
func (MsgSetCollateralParam) ValidateBasic ¶
func (msg MsgSetCollateralParam) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type MsgSettleDebt ¶
type MsgSettleDebt struct { Sender sdk.AccAddress `json:"sender" yaml:"sender"` CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` DebtDenom string `json:"debt_denom" yaml:"debt_denom"` DebtChange sdk.Int `json:"debt_change" yaml:"debt_change"` }
MsgSettleDebt returns debt to CSDT.
func NewMsgSettleDebt ¶
func NewMsgSettleDebt(sender sdk.AccAddress, collateralDenom, debtDenom string, debtChange sdk.Int) MsgSettleDebt
NewMsgSettleDebt returns a new MsgSettleDebt.
func (MsgSettleDebt) GetSignBytes ¶
func (msg MsgSettleDebt) GetSignBytes() []byte
GetSignBytes gets the canonical byte representation of the Msg.
func (MsgSettleDebt) GetSigners ¶
func (msg MsgSettleDebt) GetSigners() []sdk.AccAddress
GetSigners returns the addresses of signers that must sign.
func (MsgSettleDebt) Route ¶
func (msg MsgSettleDebt) Route() string
Route return the message type used for routing the message.
func (MsgSettleDebt) Type ¶
func (msg MsgSettleDebt) Type() string
Type returns a human-readable string for the message, intended for utilization within tags.
func (MsgSettleDebt) ValidateBasic ¶
func (msg MsgSettleDebt) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type MsgTransferCSDT ¶
type MsgTransferCSDT struct { }
MsgTransferCSDT changes the ownership of a csdt
type MsgWithdrawCollateral ¶
type MsgWithdrawCollateral struct { Sender sdk.AccAddress `json:"sender" yaml:"sender"` CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` CollateralChange sdk.Int `json:"collateral_change" yaml:"collateral_change"` }
MsgWithdrawCollateral removes collateral to CSDT.
func NewMsgWithdrawCollateral ¶
func NewMsgWithdrawCollateral(sender sdk.AccAddress, collateralDenom string, collateralChange sdk.Int) MsgWithdrawCollateral
NewMsgWithdrawCollateral returns a new MsgWithdrawCollateral.
func (MsgWithdrawCollateral) GetSignBytes ¶
func (msg MsgWithdrawCollateral) GetSignBytes() []byte
GetSignBytes gets the canonical byte representation of the Msg.
func (MsgWithdrawCollateral) GetSigners ¶
func (msg MsgWithdrawCollateral) GetSigners() []sdk.AccAddress
GetSigners returns the addresses of signers that must sign.
func (MsgWithdrawCollateral) Route ¶
func (msg MsgWithdrawCollateral) Route() string
Route return the message type used for routing the message.
func (MsgWithdrawCollateral) Type ¶
func (msg MsgWithdrawCollateral) Type() string
Type returns a human-readable string for the message, intended for utilization within tags.
func (MsgWithdrawCollateral) ValidateBasic ¶
func (msg MsgWithdrawCollateral) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type MsgWithdrawDebt ¶
type MsgWithdrawDebt struct { Sender sdk.AccAddress `json:"sender" yaml:"sender"` CollateralDenom string `json:"collateral_denom" yaml:"collateral_denom"` DebtDenom string `json:"debt_denom" yaml:"debt_denom"` DebtChange sdk.Int `json:"debt_change" yaml:"debt_change"` }
MsgWithdrawDebt withdraws debt from CSDT.
func NewMsgWithdrawDebt ¶
func NewMsgWithdrawDebt(sender sdk.AccAddress, collateralDenom, debtDenom string, debtChange sdk.Int) MsgWithdrawDebt
NewMsgWithdrawDebt returns a new MsgWithdrawDebt.
func (MsgWithdrawDebt) GetSignBytes ¶
func (msg MsgWithdrawDebt) GetSignBytes() []byte
GetSignBytes gets the canonical byte representation of the Msg.
func (MsgWithdrawDebt) GetSigners ¶
func (msg MsgWithdrawDebt) GetSigners() []sdk.AccAddress
GetSigners returns the addresses of signers that must sign.
func (MsgWithdrawDebt) Route ¶
func (msg MsgWithdrawDebt) Route() string
Route return the message type used for routing the message.
func (MsgWithdrawDebt) Type ¶
func (msg MsgWithdrawDebt) Type() string
Type returns a human-readable string for the message, intended for utilization within tags.
func (MsgWithdrawDebt) ValidateBasic ¶
func (msg MsgWithdrawDebt) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type OracleKeeper ¶
type OracleKeeper interface { GetCurrentPrice(sdk.Context, string) oracle.CurrentPrice // These are used for testing TODO replace mockApp with keeper in tests to remove these AddAsset(sdk.Context, string, string, oracle.Asset) error SetPrice(sdk.Context, sdk.AccAddress, string, sdk.Dec, time.Time) (oracle.PostedPrice, sdk.Error) SetCurrentPrices(sdk.Context) sdk.Error SetParams(ctx sdk.Context, params oracle.Params) }
type Params ¶
type Params struct { CollateralParams CollateralParams `json:"collateral_params" yaml:"collateral_params"` DebtParams DebtParams `json:"debt_params" yaml:"debt_params"` GlobalDebtLimit sdk.Coins `json:"global_debt_limit" yaml:"global_debt_limit"` CircuitBreaker bool `json:"circuit_breaker" yaml:"circuit_breaker"` Nominees []string `json:"nominees" yaml:"nominees"` }
Params governance parameters for cdp module
func DefaultParams ¶
func DefaultParams() Params
DefaultParams returns default params for cdp module
func NewParams ¶
func NewParams( debtLimit sdk.Coins, collateralParams CollateralParams, debtParams DebtParams, breaker bool, nominees []string, ) Params
NewParams returns a new params object
func (Params) GetCollateralParam ¶
func (cps Params) GetCollateralParam(collateralDenom string) CollateralParam
func (Params) IsCollateralPresent ¶
func (*Params) ParamSetPairs ¶
func (p *Params) ParamSetPairs() params.ParamSetPairs
ParamSetPairs implements the ParamSet interface and returns all the key/value pairs pairs of auth module's parameters. nolint
type QueryCsdtsParams ¶
type QueryCsdtsParams struct { CollateralDenom string // get CSDTs with this collateral denom Owner sdk.AccAddress // get CSDTs belonging to this owner UnderCollateralizedAt sdk.Dec // get CSDTs that will be below the liquidation ratio when the collateral is at this price. }
type SupplyKeeper ¶
type SupplyKeeper interface { GetSupply(ctx sdk.Context) (supply exported.SupplyI) SetSupply(ctx sdk.Context, supply exported.SupplyI) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) sdk.Error SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) sdk.Error BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) sdk.Error MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) sdk.Error }