Documentation ¶
Index ¶
- func Interpolate(x, xMin, yMin, xMax, yMax sdk.Dec) sdk.Dec
- func NewMsgServerImpl(keeper Keeper) types.MsgServer
- type Keeper
- func (k Keeper) AccrueAllInterest(ctx sdk.Context) error
- func (k Keeper) BorrowAsset(ctx sdk.Context, borrowerAddr sdk.AccAddress, borrow sdk.Coin) error
- func (k Keeper) DeleteRegisteredTokens(ctx sdk.Context)
- func (k Keeper) ExchangeTokens(ctx sdk.Context, tokens sdk.Coin) (sdk.Coin, error)
- func (k Keeper) ExchangeUTokens(ctx sdk.Context, utokens sdk.Coin) (sdk.Coin, error)
- func (k Keeper) FromTokenToUTokenDenom(ctx sdk.Context, tokenDenom string) string
- func (k Keeper) FromUTokenToTokenDenom(ctx sdk.Context, uTokenDenom string) string
- func (k Keeper) GetAllRegisteredTokens(ctx sdk.Context) ([]types.Token, error)
- func (k Keeper) GetBorrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) sdk.Coin
- func (k Keeper) GetBorrowUtilization(ctx sdk.Context, denom string, totalBorrowed sdk.Int) (sdk.Dec, error)
- func (k Keeper) GetBorrowerBorrows(ctx sdk.Context, borrowerAddr sdk.AccAddress) (sdk.Coins, error)
- func (k Keeper) GetCollateralSetting(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) bool
- func (k Keeper) GetCollateralWeight(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) GetDynamicBorrowInterest(ctx sdk.Context, denom string, utilization sdk.Dec) (sdk.Dec, error)
- func (k Keeper) GetExchangeRate(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) GetInterestAtKink(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) GetInterestBase(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) GetInterestKinkUtilization(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) GetInterestMax(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetRegisteredToken(ctx sdk.Context, denom string) (types.Token, error)
- func (k Keeper) GetReserveAmount(ctx sdk.Context, denom string) sdk.Int
- func (k Keeper) GetReserveFactor(ctx sdk.Context, denom string) (sdk.Dec, error)
- func (k Keeper) GetTotalBorrows(ctx sdk.Context) (sdk.Coins, error)
- func (k Keeper) IncreaseReserves(ctx sdk.Context, coin sdk.Coin) error
- func (k Keeper) InitializeExchangeRate(ctx sdk.Context, denom string) error
- func (k *Keeper) InitializeLastInterestTime(ctx sdk.Context)
- func (k Keeper) IsAcceptedToken(ctx sdk.Context, tokenDenom string) bool
- func (k Keeper) IsAcceptedUToken(ctx sdk.Context, uTokenDenom string) bool
- func (k Keeper) LendAsset(ctx sdk.Context, lenderAddr sdk.AccAddress, loan sdk.Coin) error
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) RepayAsset(ctx sdk.Context, borrowerAddr sdk.AccAddress, payment sdk.Coin) error
- func (k Keeper) SetBorrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string, amount sdk.Int) error
- func (k Keeper) SetCollateralSetting(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string, enable bool) error
- func (k Keeper) SetExchangeRate(ctx sdk.Context, denom string, rate sdk.Dec) error
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) SetRegisteredToken(ctx sdk.Context, token types.Token)
- func (k Keeper) SetTokenDenom(ctx sdk.Context, tokenDenom string)
- func (k Keeper) TotalUTokenSupply(ctx sdk.Context, uTokenDenom string) sdk.Coin
- func (k Keeper) UpdateExchangeRates(ctx sdk.Context) error
- func (k Keeper) WithdrawAsset(ctx sdk.Context, lenderAddr sdk.AccAddress, uToken sdk.Coin) error
- type Querier
- func (q Querier) Borrowed(goCtx context.Context, req *types.QueryBorrowedRequest) (*types.QueryBorrowedResponse, error)
- func (q Querier) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
- func (q Querier) RegisteredTokens(goCtx context.Context, req *types.QueryRegisteredTokens) (*types.QueryRegisteredTokensResponse, error)
- func (q Querier) ReserveAmount(goCtx context.Context, req *types.QueryReserveAmountRequest) (*types.QueryReserveAmountResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Interpolate ¶ added in v0.7.0
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.
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, ) Keeper
func (Keeper) AccrueAllInterest ¶ added in v0.7.0
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 ¶
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) DeleteRegisteredTokens ¶ added in v0.7.0
DeleteRegisteredTokens deletes all registered tokens from the x/leverage module's KVStore.
func (Keeper) ExchangeTokens ¶
ExchangeTokens converts an sdk.Coin containing base assets to its value in uTokens
func (Keeper) ExchangeUTokens ¶ added in v0.8.4
ExchangeUTokens converts an sdk.Coin containing uTokens to its value in base assets
func (Keeper) FromTokenToUTokenDenom ¶
FromTokenToUTokenDenom returns the associated uToken denom for the given token denom. If the token denom does not exist, we assume the association is invalid and we return an empty string.
func (Keeper) FromUTokenToTokenDenom ¶
FromUTokenToTokenDenom returns the associated token denom for the given uToken denom. If the uToken denom does not exist, we assume the association is invalid and we return an empty string.
func (Keeper) GetAllRegisteredTokens ¶ added in v0.7.0
GetAllRegisteredTokens returns all the registered tokens from the x/leverage module's KVStore.
func (Keeper) GetBorrow ¶ added in v0.7.0
GetBorrow returns an sdk.Coin representing how much of a given denom a borrower currently owes.
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
GetBorrowerBorrows returns an sdk.Coins object containing all open borrows associated with an address.
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
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) GetExchangeRate ¶ added in v0.7.0
GetExchangeRate gets the token:uTokenexchange rate for a given base token denom
func (Keeper) GetInterestAtKink ¶ added in v0.7.0
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
GetInterestBase gets the base interest rate for a given token.
func (Keeper) GetInterestKinkUtilization ¶ added in v0.7.0
GetInterestKinkUtilization gets the utilization at the "kink" in the utilization:interest graph for a given token.
func (Keeper) GetInterestMax ¶ added in v0.7.0
GetInterestMax gets the maximum interest rate for a given token.
func (Keeper) GetRegisteredToken ¶ added in v0.7.0
GetRegisteredToken gets a token from the x/leverage module's KVStore.
func (Keeper) GetReserveAmount ¶ added in v0.7.0
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
GetReserveFactor gets the reserve factor for a given token.
func (Keeper) GetTotalBorrows ¶ added in v0.7.0
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) IncreaseReserves ¶
IncreaseReserves adds an sdk.Coin (denom, amount) to the module's reserve requirements.
func (Keeper) InitializeExchangeRate ¶ added in v0.7.0
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 ¶
InitializeLastInterestTime sets LastInterestTime to present if it does not exist (used for genesis).
func (Keeper) IsAcceptedToken ¶
IsAcceptedToken returns true if a given (non-UToken) token denom is an accepted asset type.
func (Keeper) IsAcceptedUToken ¶
IsAcceptedUToken returns true if a given uToken denom is an accepted asset type.
func (Keeper) LendAsset ¶
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) RepayAsset ¶
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.
func (Keeper) SetBorrow ¶ added in v0.7.0
func (k Keeper) SetBorrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string, amount sdk.Int) error
SetBorrow sets the amount borrowed by an address in a given denom to an amount
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
SetExchangeRate sets the token:uTokenexchange rate for a given base token denom
func (Keeper) SetRegisteredToken ¶
SetRegisteredToken stores a token into the x/leverage module's KVStore.
func (Keeper) SetTokenDenom ¶
SetTokenDenom stores the token denom along with the uToken denom association.
func (Keeper) TotalUTokenSupply ¶
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
UpdateExchangeRates calculates sets the token:uToken exchange rates for all token denoms.
func (Keeper) WithdrawAsset ¶
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 (Querier) Borrowed ¶ added in v0.7.0
func (q Querier) Borrowed( goCtx context.Context, req *types.QueryBorrowedRequest, ) (*types.QueryBorrowedResponse, error)
func (Querier) Params ¶ added in v0.7.0
func (q Querier) Params( goCtx context.Context, req *types.QueryParamsRequest, ) (*types.QueryParamsResponse, error)
func (Querier) RegisteredTokens ¶ added in v0.7.0
func (q Querier) RegisteredTokens( goCtx context.Context, req *types.QueryRegisteredTokens, ) (*types.QueryRegisteredTokensResponse, error)
func (Querier) ReserveAmount ¶ added in v0.7.0
func (q Querier) ReserveAmount( goCtx context.Context, req *types.QueryReserveAmountRequest, ) (*types.QueryReserveAmountResponse, error)