keeper

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const BaseDigitFactor = 1000000000000000000

BaseDigitFactor is 10**18, used during coin calculations

Variables

This section is empty.

Functions

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier returns a new querier function

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper keeper for the cdp module

func NewKeeper

NewKeeper creates a new keeper

func (Keeper) AddCdp

func (k Keeper) AddCdp(ctx sdk.Context, owner sdk.AccAddress, collateral sdk.Coins, principal sdk.Coins) sdk.Error

AddCdp adds a cdp for a specific owner and collateral type

func (Keeper) AddPrincipal

func (k Keeper) AddPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom string, principal sdk.Coins) sdk.Error

AddPrincipal adds debt to a cdp if the additional debt does not put the cdp below the liquidation ratio

func (Keeper) ApplyLiquidationPenalty

func (k Keeper) ApplyLiquidationPenalty(ctx sdk.Context, denom string, debt sdk.Int) sdk.Int

ApplyLiquidationPenalty multiplies the input debt amount by the liquidation penalty and mints the debt coins in the cdp module account

func (Keeper) AuctionCollateral

func (k Keeper) AuctionCollateral(ctx sdk.Context, deposits types.Deposits, debt sdk.Int, bidDenom string) sdk.Error

AuctionCollateral creates auctions from the input deposits which attempt to raise the corresponding amount of debt

func (Keeper) BurnDebtCoins

func (k Keeper) BurnDebtCoins(ctx sdk.Context, moduleAccount string, denom string, paymentCoins sdk.Coins) sdk.Error

BurnDebtCoins burns debt coins from the cdp module account

func (Keeper) CalculateCollateralToDebtRatio

func (k Keeper) CalculateCollateralToDebtRatio(ctx sdk.Context, collateral sdk.Coins, debt sdk.Coins) sdk.Dec

CalculateCollateralToDebtRatio returns the collateral to debt ratio of the input collateral and debt amounts

func (Keeper) CalculateCollateralizationRatio

func (k Keeper) CalculateCollateralizationRatio(ctx sdk.Context, collateral sdk.Coins, principal sdk.Coins, fees sdk.Coins) (sdk.Dec, sdk.Error)

CalculateCollateralizationRatio returns the collateralization ratio of the input collateral to the input debt plus fees

func (Keeper) CalculateCollateralizationRatioFromAbsoluteRatio

func (k Keeper) CalculateCollateralizationRatioFromAbsoluteRatio(ctx sdk.Context, collateralDenom string, absoluteRatio sdk.Dec) (sdk.Dec, sdk.Error)

CalculateCollateralizationRatioFromAbsoluteRatio takes a coin's denom and an absolute ratio and returns the respective collateralization ratio

func (Keeper) CalculateFees

func (k Keeper) CalculateFees(ctx sdk.Context, principal sdk.Coins, periods sdk.Int, denom string) sdk.Coins

CalculateFees returns the fees accumulated since fees were last calculated based on the input amount of outstanding debt (principal) and the number of periods (seconds) that have passed

func (Keeper) CdpCollateralRatioIndexIterator

func (k Keeper) CdpCollateralRatioIndexIterator(ctx sdk.Context, denom string, targetRatio sdk.Dec) sdk.Iterator

CdpCollateralRatioIndexIterator returns an sdk.Iterator for all cdps that have collateral denom matching denom and collateral:debt ratio LESS THAN targetRatio

func (Keeper) CdpDenomIndexIterator

func (k Keeper) CdpDenomIndexIterator(ctx sdk.Context, denom string) sdk.Iterator

CdpDenomIndexIterator returns an sdk.Iterator for all cdps with matching collateral denom

func (Keeper) CreateAuctionFromPartialDeposits

func (k Keeper) CreateAuctionFromPartialDeposits(ctx sdk.Context, partialDeps partialDeposits, debt sdk.Int, collateral sdk.Int, auctionSize sdk.Int, bidDenom string) (debtChange, collateralChange sdk.Int, err sdk.Error)

CreateAuctionFromPartialDeposits creates an auction from the input partial deposits

func (Keeper) CreateAuctionsFromDeposit

func (k Keeper) CreateAuctionsFromDeposit(ctx sdk.Context, dep types.Deposit, debt sdk.Int, totalCollateral sdk.Int, auctionSize sdk.Int, principalDenom string) (debtChange sdk.Int, collateralChange sdk.Int, err sdk.Error)

CreateAuctionsFromDeposit creates auctions from the input deposit until there is less than auctionSize left on the deposit

func (Keeper) DecrementTotalPrincipal

func (k Keeper) DecrementTotalPrincipal(ctx sdk.Context, collateralDenom string, principal sdk.Coins)

DecrementTotalPrincipal decrements the total amount of debt that has been drawn for a particular collateral type

func (Keeper) DeleteCDP

func (k Keeper) DeleteCDP(ctx sdk.Context, cdp types.CDP)

DeleteCDP deletes a cdp from the store

func (Keeper) DeleteDeposit

func (k Keeper) DeleteDeposit(ctx sdk.Context, cdpID uint64, depositor sdk.AccAddress)

DeleteDeposit deletes a deposit from the store

func (Keeper) DepositCollateral

func (k Keeper) DepositCollateral(ctx sdk.Context, owner sdk.AccAddress, depositor sdk.AccAddress, collateral sdk.Coins) sdk.Error

DepositCollateral adds collateral to a cdp

func (Keeper) DistributeSavingsRate added in v0.5.0

func (k Keeper) DistributeSavingsRate(ctx sdk.Context, debtDenom string) sdk.Error

DistributeSavingsRate distributes surplus that has accumulated in the liquidator account to address holding stable coins according the the savings rate

func (Keeper) GetAllCdps

func (k Keeper) GetAllCdps(ctx sdk.Context) (cdps types.CDPs)

GetAllCdps returns all cdps from the store

func (Keeper) GetAllCdpsByDenom

func (k Keeper) GetAllCdpsByDenom(ctx sdk.Context, denom string) (cdps types.CDPs)

GetAllCdpsByDenom returns all cdps of a particular collateral type from the store

func (Keeper) GetAllCdpsByDenomAndRatio

func (k Keeper) GetAllCdpsByDenomAndRatio(ctx sdk.Context, denom string, targetRatio sdk.Dec) (cdps types.CDPs)

GetAllCdpsByDenomAndRatio returns all cdps of a particular collateral type and below a certain collateralization ratio

func (Keeper) GetCDP

func (k Keeper) GetCDP(ctx sdk.Context, collateralDenom string, cdpID uint64) (types.CDP, bool)

GetCDP returns the cdp associated with a particular collateral denom and id

func (Keeper) GetCdpByOwnerAndDenom

func (k Keeper) GetCdpByOwnerAndDenom(ctx sdk.Context, owner sdk.AccAddress, denom string) (types.CDP, bool)

GetCdpByOwnerAndDenom queries cdps owned by owner and returns the cdp with matching denom

func (Keeper) GetCdpID

func (k Keeper) GetCdpID(ctx sdk.Context, owner sdk.AccAddress, denom string) (uint64, bool)

GetCdpID returns the id of the cdp corresponding to a specific owner and collateral denom

func (Keeper) GetCdpIdsByOwner

func (k Keeper) GetCdpIdsByOwner(ctx sdk.Context, owner sdk.AccAddress) ([]uint64, bool)

GetCdpIdsByOwner returns all the ids of cdps corresponding to a particular owner

func (Keeper) GetCollateral

func (k Keeper) GetCollateral(ctx sdk.Context, denom string) (types.CollateralParam, bool)

GetCollateral returns the collateral param with corresponding denom

func (Keeper) GetDebtDenom

func (k Keeper) GetDebtDenom(ctx sdk.Context) (denom string)

GetDebtDenom returns the denom of debt in the system

func (Keeper) GetDebtParam

func (k Keeper) GetDebtParam(ctx sdk.Context, denom string) (types.DebtParam, bool)

GetDebtParam returns the debt param with matching denom

func (Keeper) GetDenomPrefix

func (k Keeper) GetDenomPrefix(ctx sdk.Context, denom string) (byte, bool)

GetDenomPrefix returns the prefix of the matching denom

func (Keeper) GetDeposit

func (k Keeper) GetDeposit(ctx sdk.Context, cdpID uint64, depositor sdk.AccAddress) (deposit types.Deposit, found bool)

GetDeposit returns the deposit of a depositor on a particular cdp from the store

func (Keeper) GetDeposits

func (k Keeper) GetDeposits(ctx sdk.Context, cdpID uint64) (deposits types.Deposits)

GetDeposits returns all the deposits to a cdp

func (Keeper) GetGovDenom

func (k Keeper) GetGovDenom(ctx sdk.Context) (denom string)

GetGovDenom returns the denom of debt in the system

func (Keeper) GetNextCdpID

func (k Keeper) GetNextCdpID(ctx sdk.Context) (id uint64)

GetNextCdpID returns the highest cdp id from the store

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) types.Params

GetParams returns the params from the store

func (Keeper) GetPreviousBlockTime

func (k Keeper) GetPreviousBlockTime(ctx sdk.Context) (blockTime time.Time, found bool)

GetPreviousBlockTime get the blocktime for the previous block

func (Keeper) GetPreviousSavingsDistribution added in v0.5.0

func (k Keeper) GetPreviousSavingsDistribution(ctx sdk.Context) (distTime time.Time, found bool)

GetPreviousSavingsDistribution get the time of the previous savings rate distribution

func (Keeper) GetTotalDebt

func (k Keeper) GetTotalDebt(ctx sdk.Context, accountName string) sdk.Int

GetTotalDebt returns the total amount of debt tokens held by the liquidator module account

func (Keeper) GetTotalPrincipal

func (k Keeper) GetTotalPrincipal(ctx sdk.Context, collateralDenom string, principalDenom string) (total sdk.Int)

GetTotalPrincipal returns the total amount of principal that has been drawn for a particular collateral

func (Keeper) GetTotalSurplus

func (k Keeper) GetTotalSurplus(ctx sdk.Context, accountName string) sdk.Int

GetTotalSurplus returns the total amount of surplus tokens held by the liquidator module account

func (Keeper) HandleNewDebt

func (k Keeper) HandleNewDebt(ctx sdk.Context, collateralDenom string, principalDenom string, periods sdk.Int)

HandleNewDebt compounds the accumulated fees for the input collateral and principal coins. the following operations are performed: 1. The fees accumulated since the last block are calculated 2. The fees are minted, split between the liquidator module account (surplus) and the savings rate module account (savings rate) according to the savings rate parameter. 2. An equal amount of debt coins are minted in the cdp module account 3. updates the total amount of principal for the input collateral type in the store,

func (Keeper) IncrementTotalPrincipal

func (k Keeper) IncrementTotalPrincipal(ctx sdk.Context, collateralDenom string, principal sdk.Coins)

IncrementTotalPrincipal increments the total amount of debt that has been drawn with that collateral type

func (Keeper) IndexCdpByCollateralRatio

func (k Keeper) IndexCdpByCollateralRatio(ctx sdk.Context, denom string, id uint64, collateralRatio sdk.Dec)

IndexCdpByCollateralRatio sets the cdp id in the store, indexed by the collateral type and collateral to debt ratio

func (Keeper) IndexCdpByOwner

func (k Keeper) IndexCdpByOwner(ctx sdk.Context, cdp types.CDP)

IndexCdpByOwner sets the cdp id in the store, indexed by the owner

func (Keeper) IterateAllCdps

func (k Keeper) IterateAllCdps(ctx sdk.Context, cb func(cdp types.CDP) (stop bool))

IterateAllCdps iterates over all cdps and performs a callback function

func (Keeper) IterateCdpsByCollateralRatio

func (k Keeper) IterateCdpsByCollateralRatio(ctx sdk.Context, denom string, targetRatio sdk.Dec, cb func(cdp types.CDP) (stop bool))

IterateCdpsByCollateralRatio iterate over cdps with collateral denom equal to denom and collateral:debt ratio LESS THAN targetRatio and performs a callback function.

func (Keeper) IterateCdpsByDenom

func (k Keeper) IterateCdpsByDenom(ctx sdk.Context, denom string, cb func(cdp types.CDP) (stop bool))

IterateCdpsByDenom iterates over cdps with matching denom and performs a callback function

func (Keeper) IterateDeposits

func (k Keeper) IterateDeposits(ctx sdk.Context, cdpID uint64, cb func(deposit types.Deposit) (stop bool))

IterateDeposits iterates over the all the deposits of a cdp and performs a callback function

func (Keeper) LiquidateCdps

func (k Keeper) LiquidateCdps(ctx sdk.Context, marketID string, denom string, liquidationRatio sdk.Dec) sdk.Error

LiquidateCdps seizes collateral from all CDPs below the input liquidation ratio

func (Keeper) LoadAugmentedCDP

func (k Keeper) LoadAugmentedCDP(ctx sdk.Context, cdp types.CDP) (types.AugmentedCDP, sdk.Error)

LoadAugmentedCDP creates a new augmented CDP from an existing CDP

func (Keeper) MintDebtCoins

func (k Keeper) MintDebtCoins(ctx sdk.Context, moduleAccount string, denom string, principalCoins sdk.Coins) sdk.Error

MintDebtCoins mints debt coins in the cdp module account

func (Keeper) NetSurplusAndDebt

func (k Keeper) NetSurplusAndDebt(ctx sdk.Context) sdk.Error

NetSurplusAndDebt burns surplus and debt coins equal to the minimum of surplus and debt balances held by the liquidator module account for example, if there is 1000 debt and 100 surplus, 100 surplus and 100 debt are burned, netting to 900 debt

func (Keeper) RemoveCdpCollateralRatioIndex

func (k Keeper) RemoveCdpCollateralRatioIndex(ctx sdk.Context, denom string, id uint64, collateralRatio sdk.Dec)

RemoveCdpCollateralRatioIndex deletes the cdp id from the store's index of cdps by collateral type and collateral to debt ratio

func (Keeper) RemoveCdpOwnerIndex

func (k Keeper) RemoveCdpOwnerIndex(ctx sdk.Context, cdp types.CDP)

RemoveCdpOwnerIndex deletes the cdp id from the store's index of cdps by owner

func (Keeper) RepayPrincipal

func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom string, payment sdk.Coins) sdk.Error

RepayPrincipal removes debt from the cdp If all debt is repaid, the collateral is returned to depositors and the cdp is removed from the store

func (Keeper) ReturnCollateral

func (k Keeper) ReturnCollateral(ctx sdk.Context, cdp types.CDP)

ReturnCollateral returns collateral to depositors on a cdp and removes deposits from the store

func (Keeper) RunSurplusAndDebtAuctions

func (k Keeper) RunSurplusAndDebtAuctions(ctx sdk.Context) sdk.Error

RunSurplusAndDebtAuctions nets the surplus and debt balances and then creates surplus or debt auctions if the remaining balance is above the auction threshold parameter

func (Keeper) SeizeCollateral

func (k Keeper) SeizeCollateral(ctx sdk.Context, cdp types.CDP) sdk.Error

SeizeCollateral liquidates the collateral in the input cdp. the following operations are performed: 1. updates the fees for the input cdp, 2. sends collateral for all deposits from the cdp module to the liquidator module account 3. Applies the liquidation penalty and mints the corresponding amount of debt coins in the cdp module 3. moves debt coins from the cdp module to the liquidator module account, 4. decrements the total amount of principal outstanding for that collateral type (this is the equivalent of saying that fees are no longer accumulated by a cdp once it gets liquidated)

func (Keeper) SetCDP

func (k Keeper) SetCDP(ctx sdk.Context, cdp types.CDP)

SetCDP sets a cdp in the store

func (Keeper) SetCdpAndCollateralRatioIndex

func (k Keeper) SetCdpAndCollateralRatioIndex(ctx sdk.Context, cdp types.CDP, ratio sdk.Dec)

SetCdpAndCollateralRatioIndex sets the cdp and collateral ratio index in the store

func (Keeper) SetDebtDenom

func (k Keeper) SetDebtDenom(ctx sdk.Context, denom string)

SetDebtDenom set the denom of debt in the system

func (Keeper) SetDeposit

func (k Keeper) SetDeposit(ctx sdk.Context, deposit types.Deposit)

SetDeposit sets the deposit in the store

func (Keeper) SetGovDenom

func (k Keeper) SetGovDenom(ctx sdk.Context, denom string)

SetGovDenom set the denom of the governance token in the system

func (Keeper) SetNextCdpID

func (k Keeper) SetNextCdpID(ctx sdk.Context, id uint64)

SetNextCdpID sets the highest cdp id in the store

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams sets params on the store

func (Keeper) SetPreviousBlockTime

func (k Keeper) SetPreviousBlockTime(ctx sdk.Context, blockTime time.Time)

SetPreviousBlockTime set the time of the previous block

func (Keeper) SetPreviousSavingsDistribution added in v0.5.0

func (k Keeper) SetPreviousSavingsDistribution(ctx sdk.Context, distTime time.Time)

SetPreviousSavingsDistribution set the time of the previous block

func (Keeper) SetTotalPrincipal

func (k Keeper) SetTotalPrincipal(ctx sdk.Context, collateralDenom string, principalDenom string, total sdk.Int)

SetTotalPrincipal sets the total amount of principal that has been drawn for the input collateral

func (Keeper) UpdateFeesForRiskyCdps added in v0.5.0

func (k Keeper) UpdateFeesForRiskyCdps(ctx sdk.Context, collateralDenom string, marketID string) sdk.Error

UpdateFeesForRiskyCdps calculates fees for risky CDPs The overall logic is first select the CDPs with 10% of the liquidation ratio Then we call calculate fees on each of those CDPs Next we store the result of the fees in the cdp.AccumulatedFees field Finally we set the cdp.FeesUpdated time to the current block time (ctx.BlockTime()) since that is when we made the update

func (Keeper) ValidateCollateral

func (k Keeper) ValidateCollateral(ctx sdk.Context, collateral sdk.Coins) sdk.Error

ValidateCollateral validates that a collateral is valid for use in cdps

func (Keeper) ValidateCollateralizationRatio

func (k Keeper) ValidateCollateralizationRatio(ctx sdk.Context, collateral sdk.Coins, principal sdk.Coins, fees sdk.Coins) sdk.Error

ValidateCollateralizationRatio validate that adding the input principal doesn't put the cdp below the liquidation ratio

func (Keeper) ValidateDebtLimit

func (k Keeper) ValidateDebtLimit(ctx sdk.Context, collateralDenom string, principal sdk.Coins) sdk.Error

ValidateDebtLimit validates that the input debt amount does not exceed the global debt limit

func (Keeper) ValidatePaymentCoins

func (k Keeper) ValidatePaymentCoins(ctx sdk.Context, cdp types.CDP, payment sdk.Coins, debt sdk.Coins) sdk.Error

ValidatePaymentCoins validates that the input coins are valid for repaying debt

func (Keeper) ValidatePrincipalAdd

func (k Keeper) ValidatePrincipalAdd(ctx sdk.Context, principal sdk.Coins) sdk.Error

ValidatePrincipalAdd validates that an asset is valid for use as debt when creating a new cdp

func (Keeper) ValidatePrincipalDraw

func (k Keeper) ValidatePrincipalDraw(ctx sdk.Context, principal sdk.Coins) sdk.Error

ValidatePrincipalDraw validates that an asset is valid for use as debt when drawing debt off an existing cdp

func (Keeper) WithdrawCollateral

func (k Keeper) WithdrawCollateral(ctx sdk.Context, owner sdk.AccAddress, depositor sdk.AccAddress, collateral sdk.Coins) sdk.Error

WithdrawCollateral removes collateral from a cdp if it does not put the cdp below the liquidation ratio

Jump to

Keyboard shortcuts

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