keeper

package
v0.6.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Interpolate added in v0.7.0

func Interpolate(x, xMin, yMin, xMax, yMax sdk.Dec) sdk.Dec

Interpolate takes a line defined by two points (xMin, yMin) and (xMax, yMax), then finds the y-value of the point on that line for an input x-value. It will return yMin if xMin = xMax (i.e. a vertical line). While this function is intended for interpolation (xMin < x < xMax), it works correctly even when x is outside that range or when xMin > xMax.

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of MsgServer for the x/leverage module.

Types

type Keeper

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

func NewKeeper

func NewKeeper(
	cdc codec.Codec,
	storeKey sdk.StoreKey,
	paramSpace paramtypes.Subspace,
	bk types.BankKeeper,
	ok types.OracleKeeper,
) Keeper

func (Keeper) AccrueAllInterest added in v0.7.0

func (k Keeper) AccrueAllInterest(ctx sdk.Context) error

AccrueAllInterest is called by EndBlock when BlockHeight % InterestEpoch == 0. It should accrue interest on all open borrows, increase reserves, and set LastInterestTime to BlockTime.

func (Keeper) BorrowAsset

func (k Keeper) BorrowAsset(ctx sdk.Context, borrowerAddr sdk.AccAddress, borrow sdk.Coin) error

BorrowAsset attempts to borrow tokens from the leverage module account using collateral uTokens. If asset type is invalid, collateral is insufficient, or module balance is insufficient, we return an error.

func (Keeper) CalculateBorrowLimit added in v0.7.0

func (k Keeper) CalculateBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk.Dec, error)

CalculateBorrowLimit uses the price oracle to determine the borrow limit (in USD) provided by collateral sdk.Coins, using each token's uToken exchange rate and collateral weight. An error is returned if any input coins are not uTokens or if value calculation fails.

func (Keeper) DeleteRegisteredToken added in v0.7.0

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

DeleteRegisteredToken deletes a registered Token by base denomination from the x/leverage KVStore.

func (Keeper) DeleteRegisteredTokens added in v0.7.0

func (k Keeper) DeleteRegisteredTokens(ctx sdk.Context) error

DeleteRegisteredTokens deletes all registered tokens from the x/leverage module's KVStore.

func (Keeper) EquivalentTokenValue added in v0.7.0

func (k Keeper) EquivalentTokenValue(ctx sdk.Context, fromCoin sdk.Coin, toDenom string) (sdk.Coin, error)

EquivalentValue returns the amount of a selected denom which would have equal USD value to a provided sdk.Coin

func (Keeper) ExchangeToken added in v0.7.0

func (k Keeper) ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error)

ExchangeToken converts an sdk.Coin containing a base asset to its value as a uToken.

func (Keeper) ExchangeUToken added in v0.7.0

func (k Keeper) ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error)

ExchangeUToken converts an sdk.Coin containing a uToken to its value in a base token.

func (Keeper) FromTokenToUTokenDenom

func (k Keeper) FromTokenToUTokenDenom(ctx sdk.Context, tokenDenom string) string

FromTokenToUTokenDenom adds the uToken prefix ("u/") to an input denom. An empty string is returned if the input token denom is not an accepted asset type.

func (Keeper) FromUTokenToTokenDenom

func (k Keeper) FromUTokenToTokenDenom(ctx sdk.Context, uTokenDenom string) string

FromUTokenToTokenDenom strips the uToken prefix ("u/") from an input denom. An empty string is returned if the prefix is not present or if the resulting token denom is not an accepted asset type.

func (Keeper) GetAllRegisteredTokens added in v0.7.0

func (k Keeper) GetAllRegisteredTokens(ctx sdk.Context) ([]types.Token, error)

GetAllRegisteredTokens returns all the registered tokens from the x/leverage module's KVStore.

func (Keeper) GetAvailableToBorrow added in v0.7.0

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

GetAvailableToBorrow gets the amount available to borrow of a given token.

func (Keeper) GetBorrow added in v0.7.0

func (k Keeper) GetBorrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) sdk.Coin

GetBorrow returns an sdk.Coin representing how much of a given denom a borrower currently owes.

func (Keeper) GetBorrowAPY added in v0.7.0

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

GetBorrowAPY returns an sdk.Dec of an borrow APY returns sdk.ZeroDec if not found

func (Keeper) GetBorrowUtilization added in v0.7.0

func (k Keeper) GetBorrowUtilization(ctx sdk.Context, denom string, totalBorrowed sdk.Int) (sdk.Dec, error)

GetBorrowUtilization derives the current borrow utilization of an asset type from the current total borrowed.

func (Keeper) GetBorrowerBorrows added in v0.7.0

func (k Keeper) GetBorrowerBorrows(ctx sdk.Context, borrowerAddr sdk.AccAddress) sdk.Coins

GetBorrowerBorrows returns an sdk.Coins object containing all open borrows associated with an address.

func (Keeper) GetBorrowerCollateral added in v0.7.0

func (k Keeper) GetBorrowerCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddress) sdk.Coins

GetBorrowerCollateral returns an sdk.Coins containing all of a borrower's collateral.

func (Keeper) GetCollateralAmount added in v0.7.0

func (k Keeper) GetCollateralAmount(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) sdk.Coin

GetCollateralAmount returns an sdk.Coin representing how much of a given denom the x/leverage module account currently holds as collateral for a given borrower.

func (Keeper) GetCollateralSetting

func (k Keeper) GetCollateralSetting(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) bool

GetCollateralSetting checks if a uToken denom is enabled for use as collateral by a single borrower.

func (Keeper) GetCollateralWeight added in v0.7.0

func (k Keeper) GetCollateralWeight(ctx sdk.Context, denom string) (sdk.Dec, error)

GetCollateralWeight gets collateral weight of a given token.

func (Keeper) GetDynamicBorrowInterest added in v0.7.0

func (k Keeper) GetDynamicBorrowInterest(ctx sdk.Context, denom string, utilization sdk.Dec) (sdk.Dec, error)

GetDynamicBorrowInterest derives the current borrow interest rate on an asset type, using utilization and params.

func (Keeper) GetEligibleLiquidationTargets added in v0.7.0

func (k Keeper) GetEligibleLiquidationTargets(ctx sdk.Context) ([]sdk.AccAddress, error)

GetEligibleLiquidationTargets returns a list of borrower addresses eligible for liquidation

func (Keeper) GetExchangeRate added in v0.7.0

func (k Keeper) GetExchangeRate(ctx sdk.Context, denom string) (sdk.Dec, error)

GetExchangeRate gets the token:uTokenexchange rate for a given base token denom.

func (Keeper) GetInterestAtKink added in v0.7.0

func (k Keeper) GetInterestAtKink(ctx sdk.Context, denom string) (sdk.Dec, error)

GetInterestAtKink gets the interest rate at the "kink" in the utilization:interest graph for a given token.

func (Keeper) GetInterestBase added in v0.7.0

func (k Keeper) GetInterestBase(ctx sdk.Context, denom string) (sdk.Dec, error)

GetInterestBase gets the base interest rate for a given token.

func (Keeper) GetInterestKinkUtilization added in v0.7.0

func (k Keeper) GetInterestKinkUtilization(ctx sdk.Context, denom string) (sdk.Dec, error)

GetInterestKinkUtilization gets the utilization at the "kink" in the utilization:interest graph for a given token.

func (Keeper) GetInterestMax added in v0.7.0

func (k Keeper) GetInterestMax(ctx sdk.Context, denom string) (sdk.Dec, error)

GetInterestMax gets the maximum interest rate for a given token.

func (Keeper) GetLendAPY added in v0.7.0

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

GetLendAPY returns an sdk.Dec of an lend APY returns sdk.ZeroDec if not found.

func (Keeper) GetLiquidationIncentive added in v0.7.0

func (k Keeper) GetLiquidationIncentive(ctx sdk.Context, denom string) (sdk.Dec, error)

GetLiquidationIncentive gets liquidation incentive of a given token.

func (Keeper) GetParams

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

GetParams gets the x/leverage module's parameters.

func (Keeper) GetRegisteredToken added in v0.7.0

func (k Keeper) GetRegisteredToken(ctx sdk.Context, denom string) (types.Token, error)

GetRegisteredToken gets a token from the x/leverage module's KVStore.

func (Keeper) GetReserveAmount added in v0.7.0

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

GetReserveAmount gets the amount reserved of a specified token. On invalid asset, the reserved amount is zero.

func (Keeper) GetReserveFactor added in v0.7.0

func (k Keeper) GetReserveFactor(ctx sdk.Context, denom string) (sdk.Dec, error)

GetReserveFactor gets the reserve factor for a given token.

func (Keeper) GetTotalBorrows added in v0.7.0

func (k Keeper) GetTotalBorrows(ctx sdk.Context) (sdk.Coins, error)

GetTotalBorrows returns total borrows across all borrowers and asset types as an sdk.Coins. It is done for all asset types at once, rather than one denom at a time, because either case would require iterating through all open borrows the way borrows are currently stored ( prefix | address | denom ).

func (Keeper) InitializeExchangeRate added in v0.7.0

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

InitializeExchangeRate checks the token:uTokenexchange rate for a given base token denom and sets it to 1.0 if no rate has been registered. No-op if a rate already exists.

func (*Keeper) InitializeLastInterestTime

func (k *Keeper) InitializeLastInterestTime(ctx sdk.Context)

InitializeLastInterestTime sets LastInterestTime to present if it does not exist (used for genesis).

func (Keeper) IsAcceptedToken

func (k Keeper) IsAcceptedToken(ctx sdk.Context, tokenDenom string) bool

IsAcceptedToken returns true if a given (non-UToken) token denom is an accepted asset type.

func (Keeper) IsAcceptedUToken

func (k Keeper) IsAcceptedUToken(ctx sdk.Context, uTokenDenom string) bool

IsAcceptedUToken returns true if a given uToken denom is associated with an accepted base asset type.

func (Keeper) LendAsset

func (k Keeper) LendAsset(ctx sdk.Context, lenderAddr sdk.AccAddress, loan sdk.Coin) error

LendAsset attempts to deposit assets into the leverage module account in exchange for uTokens. If asset type is invalid or account balance is insufficient, we return an error.

func (Keeper) LiquidateBorrow added in v0.7.0

func (k Keeper) LiquidateBorrow(
	ctx sdk.Context, liquidatorAddr, borrowerAddr sdk.AccAddress, desiredRepayment sdk.Coin, rewardDenom string,
) (sdk.Int, sdk.Int, error)

LiquidateBorrow attempts to repay one of an eligible borrower's borrows (in part or in full) in exchange for a selected denomination of uToken collateral. If the borrower is not over their borrow limit, or the repayment or reward denominations are invalid, an error is returned. If the attempted repayment is greater than the amount owed or the maximum that can be repaid due to parameters (close factor) then a partial liquidation, equal to the maximum valid amount, is performed. The same occurs if the value of collateral in the selected reward denomination cannot cover the proposed repayment. Because partial liquidation is possible and exchange rates vary, LiquidateBorrow returns the actual amount of tokens repaid and uTokens rewarded (in that order).

func (Keeper) LiquidationParams added in v0.7.0

func (k Keeper) LiquidationParams(ctx sdk.Context, reward string, borrowed, limit sdk.Dec) (sdk.Dec, sdk.Dec, error)

LiquidationParams computes dynamic liquidation parameters based on collateral denomination, borrowed value, and borrow limit. Returns liquidationIncentive (the ratio of bonus collateral awarded during Liquidate transactions, and closeFactor (the fraction of a borrower's total borrowed value that can be repaid by a liquidator in a single liquidation event.)

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) ModuleBalance added in v0.7.0

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

ModuleBalance returns the amount of a given token held in the x/leverage module account

func (Keeper) RepayAsset

func (k Keeper) RepayAsset(ctx sdk.Context, borrowerAddr sdk.AccAddress, payment sdk.Coin) (sdk.Int, error)

RepayAsset attempts to repay an open borrow position with base assets. If asset type is invalid, account balance is insufficient, or no open borrow position exists, we return an error. Additionally, if the amount provided is greater than the full repayment amount, only the necessary amount is transferred. Because amount repaid may be less than the repayment attempted, RepayAsset returns the actual amount repaid.

func (Keeper) RepayBadDebt added in v0.7.0

func (k Keeper) RepayBadDebt(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) (bool, error)

RepayBadDebt uses reserves to repay borrower's debts of a given denom. It returns a boolean representing whether full repayment was achieved.

func (Keeper) SetBadDebtAddress added in v0.7.0

func (k Keeper) SetBadDebtAddress(ctx sdk.Context, denom string, borrowerAddr sdk.AccAddress, hasDebt bool)

SetBadDebtAddress sets or deletes an address in a denom's list of addresses with unpaid bad debt.

func (Keeper) SetBorrow added in v0.7.0

func (k Keeper) SetBorrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, borrow sdk.Coin) error

SetBorrow sets the amount borrowed by an address in a given denom. If the amount is zero, any stored value is cleared.

func (Keeper) SetBorrowAPY added in v0.7.0

func (k Keeper) SetBorrowAPY(ctx sdk.Context, denom string, borrowAPY sdk.Dec) error

SetBorrowAPY sets the borrow APY of an specific denom

func (Keeper) SetCollateralAmount added in v0.7.0

func (k Keeper) SetCollateralAmount(ctx sdk.Context, borrowerAddr sdk.AccAddress, collateral sdk.Coin) error

SetCollateralAmount sets the amount of a given denom the x/leverage module account currently holds as collateral for a given borrower. If the amount is zero, any stored value is cleared. A negative amount or invalid coin causes an error. This function does not move coins to or from the module account.

func (Keeper) SetCollateralSetting

func (k Keeper) SetCollateralSetting(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string, enable bool) error

SetCollateralSetting enables or disables a uToken denom for use as collateral by a single borrower.

func (Keeper) SetExchangeRate added in v0.7.0

func (k Keeper) SetExchangeRate(ctx sdk.Context, denom string, rate sdk.Dec) error

SetExchangeRate sets the token:uTokenexchange rate for a given base token denom.

func (*Keeper) SetHooks added in v0.7.0

func (k *Keeper) SetHooks(h types.Hooks) *Keeper

SetHooks sets the module's hooks. Note, hooks can only be set once.

func (Keeper) SetLendAPY added in v0.7.0

func (k Keeper) SetLendAPY(ctx sdk.Context, denom string, lendAPY sdk.Dec) error

SetLendAPY sets the lend APY of an specific denom.

func (Keeper) SetParams

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

SetParams sets the x/leverage module's parameters.

func (Keeper) SetRegisteredToken

func (k Keeper) SetRegisteredToken(ctx sdk.Context, token types.Token)

SetRegisteredToken stores a Token into the x/leverage module's KVStore.

func (Keeper) SetReserveAmount added in v0.7.0

func (k Keeper) SetReserveAmount(ctx sdk.Context, coin sdk.Coin) error

SetReserveAmount sets the amount reserved of a specified token.

func (Keeper) SweepBadDebts added in v0.7.0

func (k Keeper) SweepBadDebts(ctx sdk.Context) error

SweepBadDebts attempts to repay all bad debts in the system, efficiently stopping for any denomination where reserves become exhausted. It should be called every Interest Epoch.

func (Keeper) TokenPrice added in v0.7.0

func (k Keeper) TokenPrice(ctx sdk.Context, denom string) (sdk.Dec, error)

TokenPrice returns the USD value of a base token. Note, the token's denomination must be the base denomination, e.g. uumee. The x/oracle module must know of the base and display/symbol denominations for each exchange pair. E.g. it must know about the UMEE/USD exchange rate along with the uumee base denomination and the exponent. This function will not return non-positive exchange rates, preferring to error instead.

func (Keeper) TokenValue added in v0.7.0

func (k Keeper) TokenValue(ctx sdk.Context, coin sdk.Coin) (sdk.Dec, error)

TokenValue returns the total token value given a Coin. An error is returned if we cannot get the token's price or if it's not an accepted token.

func (Keeper) TotalTokenValue added in v0.7.0

func (k Keeper) TotalTokenValue(ctx sdk.Context, coins sdk.Coins) (sdk.Dec, error)

TotalTokenValue returns the total value of all supplied tokens. It is equivalent to calling GetTokenValue on each coin individually.

func (Keeper) TotalUTokenSupply

func (k Keeper) TotalUTokenSupply(ctx sdk.Context, uTokenDenom string) sdk.Coin

TotalUTokenSupply returns an sdk.Coin representing the total balance of a given uToken type if valid. If the denom is not an accepted uToken type, we return a zero amount.

func (Keeper) UpdateExchangeRates added in v0.7.0

func (k Keeper) UpdateExchangeRates(ctx sdk.Context) error

UpdateExchangeRates calculates sets the token:uToken exchange rates for all token denoms.

func (Keeper) WithdrawAsset

func (k Keeper) WithdrawAsset(ctx sdk.Context, lenderAddr sdk.AccAddress, uToken sdk.Coin) error

WithdrawAsset attempts to deposit uTokens into the leverage module in exchange for the original tokens lent. If the uToken type is invalid or account balance insufficient on either side, we return an error.

type Querier added in v0.7.0

type Querier struct {
	Keeper
}

Querier implements a QueryServer for the x/leverage module.

func NewQuerier

func NewQuerier(k Keeper) Querier

func (Querier) AvailableBorrow added in v0.7.0

func (Querier) BorrowAPY added in v0.7.0

func (Querier) BorrowLimit added in v0.7.0

func (Querier) Borrowed added in v0.7.0

func (Querier) Collateral added in v0.7.0

func (Querier) CollateralSetting added in v0.7.0

func (Querier) ExchangeRate added in v0.7.0

func (Querier) LendAPY added in v0.7.0

func (Querier) LiquidationTargets added in v0.7.0

func (Querier) MarketSize added in v0.7.0

func (Querier) Params added in v0.7.0

func (Querier) RegisteredTokens added in v0.7.0

func (Querier) ReserveAmount added in v0.7.0

Jump to

Keyboard shortcuts

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