Documentation ¶
Index ¶
- Variables
- func ApproxExponential(x sdk.Dec) sdk.Dec
- func BorrowAPYInvariant(k Keeper) sdk.Invariant
- func ComputeCloseFactor(borrowedValue sdk.Dec, collateralValue sdk.Dec, liquidationThreshold sdk.Dec, ...) (closeFactor sdk.Dec)
- func ComputeLiquidation(availableRepay, availableCollateral, availableReward sdkmath.Int, ...) (tokenRepay sdkmath.Int, collateralBurn sdkmath.Int, tokenReward sdkmath.Int)
- func ExchangeRatesInvariant(k Keeper) sdk.Invariant
- func InefficientBorrowAmountInvariant(k Keeper) sdk.Invariant
- func InefficientCollateralAmountInvariant(k Keeper) sdk.Invariant
- func InterestScalarsInvariant(k Keeper) sdk.Invariant
- func Interpolate(x, xMin, yMin, xMax, yMax sdk.Dec) sdk.Dec
- func NewMsgServerImpl(keeper Keeper) types.MsgServer
- func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper)
- func ReserveAmountInvariant(k Keeper) sdk.Invariant
- func SupplyAPYInvariant(k Keeper) sdk.Invariant
- type Keeper
- func (k Keeper) AccrueAllInterest(ctx sdk.Context) error
- func (k Keeper) AvailableLiquidity(ctx sdk.Context, denom string) sdkmath.Int
- func (k Keeper) Borrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, borrow sdk.Coin) error
- func (k Keeper) CalculateBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk.Dec, error)
- func (k Keeper) CalculateCollateralValue(ctx sdk.Context, collateral sdk.Coins) (sdk.Dec, error)
- func (k Keeper) CalculateLiquidationThreshold(ctx sdk.Context, collateral sdk.Coins) (sdk.Dec, error)
- func (k Keeper) CollateralLiquidity(ctx sdk.Context, denom string) sdk.Dec
- func (k *Keeper) CollateralShare(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) Collateralize(ctx sdk.Context, borrowerAddr sdk.AccAddress, uToken sdk.Coin) error
- func (k Keeper) Decollateralize(ctx sdk.Context, borrowerAddr sdk.AccAddress, uToken sdk.Coin) error
- func (k Keeper) DeriveBorrowAPY(ctx sdk.Context, denom string) sdk.Dec
- func (k Keeper) DeriveExchangeRate(ctx sdk.Context, denom string) sdk.Dec
- func (k Keeper) DeriveSupplyAPY(ctx sdk.Context, denom string) sdk.Dec
- func (k Keeper) ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error)
- func (k Keeper) ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error)
- func (k Keeper) ExchangeUTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error)
- func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState
- func (k Keeper) FundOracle(ctx sdk.Context, requested sdk.Coins) error
- func (k Keeper) GetAllRegisteredTokens(ctx sdk.Context) []types.Token
- func (k Keeper) GetAllReserves(ctx sdk.Context) sdk.Coins
- func (k Keeper) GetAllSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress) (sdk.Coins, error)
- func (k Keeper) GetAllTotalCollateral(ctx sdk.Context) sdk.Coins
- func (k Keeper) GetAllUTokenSupply(ctx sdk.Context) sdk.Coins
- func (k Keeper) GetBorrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) sdk.Coin
- func (k Keeper) GetBorrowerBorrows(ctx sdk.Context, borrowerAddr sdk.AccAddress) sdk.Coins
- func (k Keeper) GetBorrowerCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddress) sdk.Coins
- func (k Keeper) GetCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) sdk.Coin
- func (k Keeper) GetEligibleLiquidationTargets(ctx sdk.Context) ([]sdk.AccAddress, error)
- func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetReserves(ctx sdk.Context, denom string) sdk.Coin
- func (k Keeper) GetSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress, denom string) (sdk.Coin, error)
- func (k Keeper) GetTokenSettings(ctx sdk.Context, denom string) (types.Token, error)
- func (k Keeper) GetTotalBorrowed(ctx sdk.Context, denom string) sdk.Coin
- func (k Keeper) GetTotalCollateral(ctx sdk.Context, denom string) sdk.Coin
- func (k Keeper) GetTotalSupply(ctx sdk.Context, denom string) (sdk.Coin, error)
- func (k Keeper) GetUTokenSupply(ctx sdk.Context, denom string) sdk.Coin
- func (k Keeper) HasCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddress) bool
- func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState)
- func (k Keeper) Liquidate(ctx sdk.Context, liquidatorAddr, borrowerAddr sdk.AccAddress, ...) (repaid sdk.Coin, liquidated sdk.Coin, reward sdk.Coin, err error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) ModuleBalance(ctx sdk.Context, denom string) sdk.Coin
- func (k Keeper) PriceRatio(ctx sdk.Context, fromDenom, toDenom string) (sdk.Dec, error)
- func (k Keeper) Repay(ctx sdk.Context, borrowerAddr sdk.AccAddress, payment sdk.Coin) (sdk.Coin, error)
- func (k Keeper) RepayBadDebt(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) (bool, error)
- func (k *Keeper) SetHooks(h types.Hooks) *Keeper
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) SetTokenSettings(ctx sdk.Context, token types.Token) error
- func (k Keeper) Supply(ctx sdk.Context, supplierAddr sdk.AccAddress, coin sdk.Coin) (sdk.Coin, error)
- func (k Keeper) SupplyUtilization(ctx sdk.Context, denom string) sdk.Dec
- func (k Keeper) SweepBadDebts(ctx sdk.Context) error
- func (k Keeper) TokenPrice(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) TokenValue(ctx sdk.Context, coin sdk.Coin) (sdk.Dec, error)
- func (k Keeper) TotalTokenValue(ctx sdk.Context, coins sdk.Coins) (sdk.Dec, error)
- func (k Keeper) Withdraw(ctx sdk.Context, supplierAddr sdk.AccAddress, uToken sdk.Coin) (sdk.Coin, error)
- type Querier
- func (q Querier) AccountBalances(goCtx context.Context, req *types.QueryAccountBalances) (*types.QueryAccountBalancesResponse, error)
- func (q Querier) AccountSummary(goCtx context.Context, req *types.QueryAccountSummary) (*types.QueryAccountSummaryResponse, error)
- func (q Querier) BadDebts(goCtx context.Context, req *types.QueryBadDebts) (*types.QueryBadDebtsResponse, error)
- func (q Querier) LiquidationTargets(goCtx context.Context, req *types.QueryLiquidationTargets) (*types.QueryLiquidationTargetsResponse, error)
- func (q Querier) MarketSummary(goCtx context.Context, req *types.QueryMarketSummary) (*types.QueryMarketSummaryResponse, error)
- func (q Querier) Params(goCtx context.Context, req *types.QueryParams) (*types.QueryParamsResponse, error)
- func (q Querier) RegisteredTokens(goCtx context.Context, req *types.QueryRegisteredTokens) (*types.QueryRegisteredTokensResponse, error)
Constants ¶
This section is empty.
Variables ¶
var EnableLiquidator = ""
EnableLiquidator must be set to "true" at compile time to enable QueryLiquidationTargets
Functions ¶
func ApproxExponential ¶
ApproxExponential is the taylor series expansion of e^x centered around x=0, truncated to the cubic term. It can be used with great accuracy to determine e^x when x is very small. Note that e^x = 1 + x/1! + x^2/2! + x^3 / 3! + ...
func BorrowAPYInvariant ¶
BorrowAPYInvariant checks that Borrow APY have all positive values
func ComputeCloseFactor ¶
func ComputeCloseFactor( borrowedValue sdk.Dec, collateralValue sdk.Dec, liquidationThreshold sdk.Dec, smallLiquidationSize sdk.Dec, minimumCloseFactor sdk.Dec, completeLiquidationThreshold sdk.Dec, ) (closeFactor sdk.Dec)
ComputeCloseFactor derives the maximum portion of a borrower's current borrowedValue that can currently be repaid in a single liquidate transaction.
closeFactor scales linearly between minimumCloseFactor and 1.0, reaching its maximum when borrowedValue has reached a critical value between liquidationThreshold to collateralValue. This critical value is defined as:
B = critical borrowedValue C = collateralValue L = liquidationThreshold CLT = completeLiquidationThreshold B = L + (C-L) * CLT
closeFactor is zero for borrowers that are not eligible for liquidation, i.e. borrowedValue < liquidationThreshold
Finally, if borrowedValue is less than smallLiquidationSize, closeFactor will always be 1 as long as the borrower is eligible for liquidation.
func ComputeLiquidation ¶
func ComputeLiquidation( availableRepay, availableCollateral, availableReward sdkmath.Int, repayTokenPrice, rewardTokenPrice, uTokenExchangeRate, liquidationIncentive, closeFactor, borrowedValue sdk.Dec, ) (tokenRepay sdkmath.Int, collateralBurn sdkmath.Int, tokenReward sdkmath.Int)
ComputeLiquidation takes the conditions preceding a liquidation and outputs the amounts of base token that should be repaid, collateral uToken burned, and reward token allocated as a result of the transaction, after accounting for limiting factors with as little rounding as possible. Inputs are as follows: - availableRepay: The lowest (in repay denom) of either liquidator balance, max repayment, or borrowed amount. - availableCollateral: The amount of the reward uToken denom which borrower has as collateral - availableReward: The amount of unreserved reward tokens in the module balance - repayTokenPrice: The oracle price of the base repayment denom - rewardTokenPrice: The oracle price of the base reward denom - uTokenExchangeRate: The uToken exchange rate from collateral uToken denom to reward base denom - liquidationIncentive: The liquidation incentive of the token reward denomination - closeFactor: The dynamic close factor computed from the borrower's borrowed value and liquidation threshold - borrowedValue: The borrower's borrowed value in USD
func ExchangeRatesInvariant ¶
ExchangeRatesInvariant checks that all denoms have an uToken exchange rate >= 1
func InefficientBorrowAmountInvariant ¶
InefficientBorrowAmountInvariant checks that borrow amounts have all positive values This runs in O(N) time where N is the number of participating addresses, so it should not be enabled in production.
func InefficientCollateralAmountInvariant ¶
InefficientCollateralAmountInvariant checks that collateral amounts have all positive values. This runs in O(N) time where N is the number of participating addresses, so it should not be enabled in production.
func InterestScalarsInvariant ¶
InterestScalarsInvariant checks that all denoms have an interest scalar >= 1
func Interpolate ¶
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 ¶
NewMsgServerImpl returns an implementation of MsgServer for the x/leverage module.
func RegisterInvariants ¶
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper)
RegisterInvariants registers the leverage module invariants
func ReserveAmountInvariant ¶
ReserveAmountInvariant checks that reserve amounts have non-negative balances
func SupplyAPYInvariant ¶
SupplyAPYInvariant checks that Supply APY have all positive values
Types ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
func NewKeeper ¶
func NewKeeper( cdc codec.Codec, storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, bk types.BankKeeper, ok types.OracleKeeper, ) (Keeper, error)
func (Keeper) AccrueAllInterest ¶
AccrueAllInterest is called by EndBlock to update borrow positions. It accrues interest on all open borrows, increase reserves, funds oracle rewards, and sets LastInterestTime to BlockTime.
func (Keeper) AvailableLiquidity ¶
AvailableLiquidity gets the unreserved module balance of a given token.
func (Keeper) Borrow ¶
Borrow 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 ¶
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) CalculateCollateralValue ¶
CalculateCollateralValue uses the price oracle to determine the value (in USD) provided by collateral sdk.Coins, using each token's uToken exchange rate. An error is returned if any input coins are not uTokens or if value calculation fails.
func (Keeper) CalculateLiquidationThreshold ¶
func (k Keeper) CalculateLiquidationThreshold(ctx sdk.Context, collateral sdk.Coins) (sdk.Dec, error)
CalculateLiquidationThreshold determines the maximum borrowed value (in USD) that a borrower with given collateral could reach before being eligible for liquidation, using each token's oracle price, uToken exchange rate, and liquidation threshold. An error is returned if any input coins are not uTokens or if value calculation fails.
func (Keeper) CollateralLiquidity ¶
CollateralLiquidity calculates the current collateral liquidity of a token denom, which is defined as the token's liquidity, divided by the base token equivalent of associated uToken's total collateral. Ranges from 0 to 1.0
func (*Keeper) CollateralShare ¶
CollateralShare calculates the portion of overall collateral (measured in USD value) that a given uToken denom represents.
func (Keeper) Collateralize ¶
Collateralize enables selected uTokens for use as collateral by a single borrower.
func (Keeper) Decollateralize ¶
func (k Keeper) Decollateralize(ctx sdk.Context, borrowerAddr sdk.AccAddress, uToken sdk.Coin) error
Decollateralize disables selected uTokens for use as collateral by a single borrower.
func (Keeper) DeriveBorrowAPY ¶
DeriveBorrowAPY derives the current borrow interest rate on a token denom using its supply utilization and token-specific params. Returns zero on invalid asset.
func (Keeper) DeriveExchangeRate ¶
DeriveExchangeRate calculated the token:uToken exchange rate of a base token denom.
func (Keeper) DeriveSupplyAPY ¶
DeriveSupplyAPY derives the current supply interest rate on a token denom using its supply utilization and borrow APY. Returns zero on invalid asset.
func (Keeper) ExchangeToken ¶
ExchangeToken converts an sdk.Coin containing a base asset to its value as a uToken.
func (Keeper) ExchangeUToken ¶
ExchangeUToken converts an sdk.Coin containing a uToken to its value in a base token.
func (Keeper) ExchangeUTokens ¶
ExchangeUTokens converts an sdk.Coins containing uTokens to their values in base tokens.
func (Keeper) ExportGenesis ¶
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState
ExportGenesis returns the x/leverage module's exported genesis state.
func (Keeper) FundOracle ¶
FundOracle transfers requested coins to the oracle module account, as long as the leverage module account has sufficient unreserved assets.
func (Keeper) GetAllRegisteredTokens ¶
GetAllRegisteredTokens returns all the registered tokens from the x/leverage module's KVStore.
func (Keeper) GetAllReserves ¶
GetAllReserves returns all reserves.
func (Keeper) GetAllSupplied ¶
GetAllSupplied returns the total tokens supplied by a user, including any interest accrued.
func (Keeper) GetAllTotalCollateral ¶
GetAllTotalCollateral returns total collateral across all uTokens.
func (Keeper) GetAllUTokenSupply ¶
GetAllUTokenSupply returns total supply of all uToken denoms.
func (Keeper) GetBorrow ¶
GetBorrow returns an sdk.Coin representing how much of a given denom a borrower currently owes.
func (Keeper) GetBorrowerBorrows ¶
GetBorrowerBorrows returns an sdk.Coins object containing all open borrows associated with an address.
func (Keeper) GetBorrowerCollateral ¶
GetBorrowerCollateral returns an sdk.Coins containing all of a borrower's collateral.
func (Keeper) GetCollateral ¶
GetCollateral 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) GetEligibleLiquidationTargets ¶
GetEligibleLiquidationTargets returns a list of borrower addresses eligible for liquidation.
func (Keeper) GetReserves ¶
GetReserves gets the reserved amount of a specified token. On invalid asset, the reserved amount is zero.
func (Keeper) GetSupplied ¶
func (k Keeper) GetSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress, denom string) (sdk.Coin, error)
GetSupplied returns an sdk.Coin representing how much of a given denom a user has supplied, including interest accrued.
func (Keeper) GetTokenSettings ¶
GetTokenSettings gets a token from the x/leverage module's KVStore.
func (Keeper) GetTotalBorrowed ¶
GetTotalBorrowed returns the total borrowed in a given denom.
func (Keeper) GetTotalCollateral ¶
GetTotalCollateral returns an sdk.Coin representing how much of a given uToken the x/leverage module account currently holds as collateral. Non-uTokens return zero.
func (Keeper) GetTotalSupply ¶
GetTotalSupply returns the total supplied by all suppliers in a given denom, including any interest accrued.
func (Keeper) GetUTokenSupply ¶
GetUTokenSupply gets the total supply of a specified utoken, as tracked by module state. On invalid asset or non-uToken, the supply is zero.
func (Keeper) HasCollateral ¶
HasCollateral returns true if a borrower has any collateral.
func (Keeper) InitGenesis ¶
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState)
InitGenesis initializes the x/leverage module state from a provided genesis state.
func (Keeper) Liquidate ¶
func (k Keeper) Liquidate( ctx sdk.Context, liquidatorAddr, borrowerAddr sdk.AccAddress, maxRepay sdk.Coin, rewardDenom string, ) (repaid sdk.Coin, liquidated sdk.Coin, reward sdk.Coin, err error)
Liquidate attempts to repay one of an eligible borrower's borrows (in part or in full) in exchange for some of the borrower's uToken collateral or associated base tokens. If the borrower is not over their liquidation 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 or available balances, then a partial liquidation, equal to the maximum valid amount, is performed. Because partial liquidation is possible and exchange rates vary, Liquidate returns the actual amount of tokens repaid, collateral liquidated, and base tokens or uTokens rewarded.
func (Keeper) ModuleBalance ¶
ModuleBalance returns the amount of a given token held in the x/leverage module account
func (Keeper) PriceRatio ¶
PriceRatio computed the ratio of the USD prices of two tokens, as sdk.Dec(fromPrice/toPrice). Will return an error if either token price is not positive, and guarantees a positive output.
func (Keeper) Repay ¶
func (k Keeper) Repay(ctx sdk.Context, borrowerAddr sdk.AccAddress, payment sdk.Coin) (sdk.Coin, error)
Repay attempts to repay a borrow position. If asset type is invalid, account balance is insufficient, or borrower has no borrows in payment denom to repay, 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, Repay returns the actual amount repaid.
func (Keeper) RepayBadDebt ¶
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. This function assumes the borrower has already been verified to have no collateral remaining.
func (Keeper) SetTokenSettings ¶
SetTokenSettings stores a Token into the x/leverage module's KVStore.
func (Keeper) Supply ¶
func (k Keeper) Supply(ctx sdk.Context, supplierAddr sdk.AccAddress, coin sdk.Coin) (sdk.Coin, error)
Supply 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. Returns the amount of uTokens minted.
func (Keeper) SupplyUtilization ¶
SupplyUtilization calculates the current supply utilization of a token denom.
func (Keeper) SweepBadDebts ¶
SweepBadDebts attempts to repay all bad debts in the system.
func (Keeper) TokenPrice ¶
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. When error is nil, price is guaranteed to be positive.
func (Keeper) TokenValue ¶
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 ¶
TotalTokenValue returns the total value of all supplied tokens. It is equivalent to the sum of TokenValue on each coin individually, except it ignores unregistered and blacklisted tokens instead of returning an error.
func (Keeper) Withdraw ¶
func (k Keeper) Withdraw(ctx sdk.Context, supplierAddr sdk.AccAddress, uToken sdk.Coin) (sdk.Coin, error)
Withdraw attempts to redeem uTokens from the leverage module in exchange for base tokens. If there are not enough uTokens in balance, Withdraw will attempt to withdraw uToken collateral to make up the difference (as long as borrow limit allows). If the uToken denom is invalid or balances are insufficient to withdraw the full amount requested, returns an error. Returns the amount of base tokens received.
type Querier ¶
type Querier struct {
Keeper
}
Querier implements a QueryServer for the x/leverage module.
func NewQuerier ¶
func (Querier) AccountBalances ¶
func (q Querier) AccountBalances( goCtx context.Context, req *types.QueryAccountBalances, ) (*types.QueryAccountBalancesResponse, error)
func (Querier) AccountSummary ¶
func (q Querier) AccountSummary( goCtx context.Context, req *types.QueryAccountSummary, ) (*types.QueryAccountSummaryResponse, error)
func (Querier) BadDebts ¶
func (q Querier) BadDebts( goCtx context.Context, req *types.QueryBadDebts, ) (*types.QueryBadDebtsResponse, error)
func (Querier) LiquidationTargets ¶
func (q Querier) LiquidationTargets( goCtx context.Context, req *types.QueryLiquidationTargets, ) (*types.QueryLiquidationTargetsResponse, error)
func (Querier) MarketSummary ¶
func (q Querier) MarketSummary( goCtx context.Context, req *types.QueryMarketSummary, ) (*types.QueryMarketSummaryResponse, error)
func (Querier) Params ¶
func (q Querier) Params( goCtx context.Context, req *types.QueryParams, ) (*types.QueryParamsResponse, error)
func (Querier) RegisteredTokens ¶
func (q Querier) RegisteredTokens( goCtx context.Context, req *types.QueryRegisteredTokens, ) (*types.QueryRegisteredTokensResponse, error)