keeper

package
v0.0.0-...-ff1fc56 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APYToSPY

func APYToSPY(apy sdk.Dec) (sdk.Dec, error)

APYToSPY converts the input annual interest rate. For example, 10% apy would be passed as 1.10. SPY = Per second compounded interest rate is how cosmos mathematically represents APY.

func CalculateBorrowInterestFactor

func CalculateBorrowInterestFactor(perSecondInterestRate sdk.Dec, secondsElapsed sdk.Int) sdk.Dec

CalculateBorrowInterestFactor calculates the simple interest scaling factor, which is equal to: (per-second interest rate * number of seconds elapsed) Will return 1.000x, multiply by principal to get new principal with added interest

func CalculateBorrowRate

func CalculateBorrowRate(model types.InterestRateModel, cash, borrows, reserves sdk.Dec) (sdk.Dec, error)

CalculateBorrowRate calculates the borrow rate, which is the current APY expressed as a decimal based on the current utilization.

func CalculateSupplyInterestFactor

func CalculateSupplyInterestFactor(newInterest, cash, borrows, reserves sdk.Dec) sdk.Dec

CalculateSupplyInterestFactor calculates the supply interest factor, which is the percentage of borrow interest that flows to each unit of supply, i.e. at 50% utilization and 0% reserve factor, a 5% borrow interest will correspond to a 2.5% supply interest.

func CalculateUtilizationRatio

func CalculateUtilizationRatio(cash, borrows, reserves sdk.Dec) sdk.Dec

CalculateUtilizationRatio calculates an asset's current utilization rate

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of the hard MsgServer interface for the provided Keeper.

func NewQuerier

func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier

NewQuerier is the module level router for state queries

func NewQueryServerImpl

func NewQueryServerImpl(keeper Keeper, ak types.AccountKeeper, bk types.BankKeeper) types.QueryServer

NewQueryServerImpl creates a new server for handling gRPC queries.

func SPYToEstimatedAPY

func SPYToEstimatedAPY(apy sdk.Dec) sdk.Dec

SPYToEstimatedAPY converts the internal per second compounded interest rate into an estimated annual interest rate. The returned value is an estimate and should not be used for financial calculations.

Types

type Keeper

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

Keeper keeper for the hard module

func NewKeeper

NewKeeper creates a new keeper

func (Keeper) AccrueInterest

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

AccrueInterest applies accrued interest to total borrows and reserves by calculating interest from the last checkpoint time and writing the updated values to the store.

func (Keeper) AfterBorrowCreated

func (k Keeper) AfterBorrowCreated(ctx sdk.Context, borrow types.Borrow)

AfterBorrowCreated - call hook if registered

func (Keeper) AfterBorrowModified

func (k Keeper) AfterBorrowModified(ctx sdk.Context, borrow types.Borrow)

AfterBorrowModified - call hook if registered

func (Keeper) AfterDepositCreated

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

AfterDepositCreated - call hook if registered

func (Keeper) AfterDepositModified

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

AfterDepositModified - call hook if registered

func (Keeper) ApplyInterestRateUpdates

func (k Keeper) ApplyInterestRateUpdates(ctx sdk.Context)

ApplyInterestRateUpdates translates the current interest rate models from the params to the store, with each money market accruing interest.

func (Keeper) AttemptKeeperLiquidation

func (k Keeper) AttemptKeeperLiquidation(ctx sdk.Context, keeper sdk.AccAddress, borrower sdk.AccAddress) error

AttemptKeeperLiquidation enables a keeper to liquidate an individual borrower's position

func (Keeper) BeforeBorrowModified

func (k Keeper) BeforeBorrowModified(ctx sdk.Context, borrow types.Borrow)

BeforeBorrowModified - call hook if registered

func (Keeper) BeforeDepositModified

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

BeforeDepositModified - call hook if registered

func (Keeper) Borrow

func (k Keeper) Borrow(ctx sdk.Context, borrower sdk.AccAddress, coins sdk.Coins) error

Borrow funds

func (Keeper) CalculateLtv

func (k Keeper) CalculateLtv(ctx sdk.Context, deposit types.Deposit, borrow types.Borrow) (sdk.Dec, error)

CalculateLtv calculates the potential LTV given a user's deposits and borrows. The boolean returned indicates if the LTV should be added to the store's LTV index.

func (Keeper) CalculatePaymentAmount

func (k Keeper) CalculatePaymentAmount(owed sdk.Coins, payment sdk.Coins) (sdk.Coins, error)

CalculatePaymentAmount prevents overpayment when repaying borrowed coins

func (Keeper) CalculateWithdrawAmount

func (k Keeper) CalculateWithdrawAmount(available sdk.Coins, request sdk.Coins) (sdk.Coins, error)

CalculateWithdrawAmount enables full withdraw of deposited coins by adjusting withdraw amount to equal total deposit amount if the requested withdraw amount > current deposit amount

func (Keeper) DecrementBorrowedCoins

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

DecrementBorrowedCoins decrements the total amount of borrowed coins by the coins parameter

func (Keeper) DecrementSuppliedCoins

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

DecrementSuppliedCoins decrements the total amount of supplied coins by the coins parameter

func (Keeper) DeleteBorrow

func (k Keeper) DeleteBorrow(ctx sdk.Context, borrow types.Borrow)

DeleteBorrow deletes a borrow from the store

func (Keeper) DeleteDeposit

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

DeleteDeposit deletes a deposit from the store

func (Keeper) DeleteMoneyMarket

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

DeleteMoneyMarket deletes a money market from the store

func (Keeper) Deposit

func (k Keeper) Deposit(ctx sdk.Context, depositor sdk.AccAddress, coins sdk.Coins) error

Deposit deposit

func (Keeper) GetAllMoneyMarkets

func (k Keeper) GetAllMoneyMarkets(ctx sdk.Context) (moneyMarkets types.MoneyMarkets)

GetAllMoneyMarkets returns all money markets from the store

func (Keeper) GetBorrow

func (k Keeper) GetBorrow(ctx sdk.Context, borrower sdk.AccAddress) (types.Borrow, bool)

GetBorrow returns a Borrow from the store for a particular borrower address and borrow denom

func (Keeper) GetBorrowInterestFactor

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

GetBorrowInterestFactor returns the current borrow interest factor for an individual market

func (Keeper) GetBorrowedCoins

func (k Keeper) GetBorrowedCoins(ctx sdk.Context) (sdk.Coins, bool)

GetBorrowedCoins returns an sdk.Coins object from the store representing all currently borrowed coins

func (Keeper) GetDeposit

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

GetDeposit returns a deposit from the store for a particular depositor address, deposit denom

func (Keeper) GetDepositsByUser

func (k Keeper) GetDepositsByUser(ctx sdk.Context, user sdk.AccAddress) []types.Deposit

GetDepositsByUser gets all deposits for an individual user

func (Keeper) GetMinimumBorrowUSDValue

func (k Keeper) GetMinimumBorrowUSDValue(ctx sdk.Context) sdk.Dec

GetMinimumBorrowUSDValue returns the minimum borrow USD value

func (Keeper) GetMoneyMarket

func (k Keeper) GetMoneyMarket(ctx sdk.Context, denom string) (types.MoneyMarket, bool)

GetMoneyMarket returns a money market from the store for a denom

func (Keeper) GetParams

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

GetParams returns the params from the store

func (Keeper) GetPreviousAccrualTime

func (k Keeper) GetPreviousAccrualTime(ctx sdk.Context, denom string) (time.Time, bool)

GetPreviousAccrualTime returns the last time an individual market accrued interest

func (Keeper) GetStoreLTV

func (k Keeper) GetStoreLTV(ctx sdk.Context, addr sdk.AccAddress) (sdk.Dec, error)

GetStoreLTV calculates the user's current LTV based on their deposits/borrows in the store and does not include any outsanding interest.

func (Keeper) GetSuppliedCoins

func (k Keeper) GetSuppliedCoins(ctx sdk.Context) (sdk.Coins, bool)

GetSuppliedCoins returns an sdk.Coins object from the store representing all currently supplied coins

func (Keeper) GetSupplyInterestFactor

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

GetSupplyInterestFactor returns the current supply interest factor for an individual market

func (Keeper) GetSyncedBorrow

func (k Keeper) GetSyncedBorrow(ctx sdk.Context, borrower sdk.AccAddress) (types.Borrow, bool)

GetSyncedBorrow returns a borrow object containing current balances and indexes

func (Keeper) GetSyncedDeposit

func (k Keeper) GetSyncedDeposit(ctx sdk.Context, depositor sdk.AccAddress) (types.Deposit, bool)

GetSyncedDeposit returns a deposit object containing current balances and indexes

func (Keeper) GetTotalDeposited

func (k Keeper) GetTotalDeposited(ctx sdk.Context, depositDenom string) (total sdk.Int)

GetTotalDeposited returns the total amount deposited for the input deposit type and deposit denom

func (Keeper) GetTotalReserves

func (k Keeper) GetTotalReserves(ctx sdk.Context) (sdk.Coins, bool)

GetTotalReserves returns the total reserves for an individual market

func (Keeper) IncrementBorrowedCoins

func (k Keeper) IncrementBorrowedCoins(ctx sdk.Context, newCoins sdk.Coins)

IncrementBorrowedCoins increments the total amount of borrowed coins by the newCoins parameter

func (Keeper) IncrementSuppliedCoins

func (k Keeper) IncrementSuppliedCoins(ctx sdk.Context, newCoins sdk.Coins)

IncrementSuppliedCoins increments the total amount of supplied coins by the newCoins parameter

func (Keeper) IsWithinValidLtvRange

func (k Keeper) IsWithinValidLtvRange(ctx sdk.Context, deposit types.Deposit, borrow types.Borrow) (bool, error)

IsWithinValidLtvRange compares a borrow and deposit to see if it's within a valid LTV range at current prices

func (Keeper) IterateBorrowInterestFactors

func (k Keeper) IterateBorrowInterestFactors(ctx sdk.Context, cb func(denom string, factor sdk.Dec) (stop bool))

IterateBorrowInterestFactors iterates over all borrow interest factors in the store and returns both the borrow interest factor and the key (denom) it's stored under

func (Keeper) IterateBorrows

func (k Keeper) IterateBorrows(ctx sdk.Context, cb func(borrow types.Borrow) (stop bool))

IterateBorrows iterates over all borrow objects in the store and performs a callback function

func (Keeper) IterateDeposits

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

IterateDeposits iterates over all deposit objects in the store and performs a callback function

func (Keeper) IterateMoneyMarkets

func (k Keeper) IterateMoneyMarkets(ctx sdk.Context, cb func(denom string, moneyMarket types.MoneyMarket) (stop bool))

IterateMoneyMarkets iterates over all money markets objects in the store and performs a callback function

that returns both the money market and the key (denom) it's stored under

func (Keeper) IterateSupplyInterestFactors

func (k Keeper) IterateSupplyInterestFactors(ctx sdk.Context, cb func(denom string, factor sdk.Dec) (stop bool))

IterateSupplyInterestFactors iterates over all supply interest factors in the store and returns both the supply interest factor and the key (denom) it's stored under

func (Keeper) LoadLiquidationData

func (k Keeper) LoadLiquidationData(ctx sdk.Context, deposit types.Deposit, borrow types.Borrow) (map[string]LiqData, error)

LoadLiquidationData returns liquidation data, deposit, borrow

func (Keeper) Repay

func (k Keeper) Repay(ctx sdk.Context, sender, owner sdk.AccAddress, coins sdk.Coins) error

Repay borrowed funds

func (Keeper) SeizeDeposits

func (k Keeper) SeizeDeposits(ctx sdk.Context, keeper sdk.AccAddress, deposit types.Deposit,
	borrow types.Borrow, dDenoms, bDenoms []string,
) error

SeizeDeposits seizes a list of deposits and sends them to auction

func (Keeper) SetBorrow

func (k Keeper) SetBorrow(ctx sdk.Context, borrow types.Borrow)

SetBorrow sets the input borrow in the store, prefixed by the borrower address and borrow denom

func (Keeper) SetBorrowInterestFactor

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

SetBorrowInterestFactor sets the current borrow interest factor for an individual market

func (Keeper) SetBorrowedCoins

func (k Keeper) SetBorrowedCoins(ctx sdk.Context, borrowedCoins sdk.Coins)

SetBorrowedCoins sets the total amount of coins currently borrowed in the store

func (Keeper) SetDeposit

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

SetDeposit sets the input deposit in the store, prefixed by the deposit type, deposit denom, and depositor address, in that order

func (*Keeper) SetHooks

func (k *Keeper) SetHooks(hooks types.HARDHooks) *Keeper

SetHooks adds hooks to the keeper.

func (Keeper) SetMoneyMarket

func (k Keeper) SetMoneyMarket(ctx sdk.Context, denom string, moneyMarket types.MoneyMarket)

SetMoneyMarket sets a money market in the store for a denom

func (Keeper) SetParams

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

SetParams sets params on the store

func (Keeper) SetPreviousAccrualTime

func (k Keeper) SetPreviousAccrualTime(ctx sdk.Context, denom string, previousAccrualTime time.Time)

SetPreviousAccrualTime sets the most recent accrual time for a particular market

func (Keeper) SetSuppliedCoins

func (k Keeper) SetSuppliedCoins(ctx sdk.Context, suppliedCoins sdk.Coins)

SetSuppliedCoins sets the total amount of coins currently supplied in the store

func (Keeper) SetSupplyInterestFactor

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

SetSupplyInterestFactor sets the current supply interest factor for an individual market

func (Keeper) SetTotalReserves

func (k Keeper) SetTotalReserves(ctx sdk.Context, coins sdk.Coins)

SetTotalReserves sets the total reserves for an individual market

func (Keeper) StartAuctions

func (k Keeper) StartAuctions(ctx sdk.Context, borrower sdk.AccAddress, borrows, deposits sdk.Coins,
	depositCoinValues, borrowCoinValues types.ValuationMap, ltv sdk.Dec, liqMap map[string]LiqData,
) (sdk.Coins, error)

StartAuctions attempts to start auctions for seized assets

func (Keeper) SyncBorrowInterest

func (k Keeper) SyncBorrowInterest(ctx sdk.Context, addr sdk.AccAddress)

SyncBorrowInterest updates the user's owed interest on newly borrowed coins to the latest global state

func (Keeper) SyncSupplyInterest

func (k Keeper) SyncSupplyInterest(ctx sdk.Context, addr sdk.AccAddress)

SyncSupplyInterest updates the user's earned interest on supplied coins based on the latest global state

func (Keeper) ValidateBorrow

func (k Keeper) ValidateBorrow(ctx sdk.Context, borrower sdk.AccAddress, amount sdk.Coins) error

ValidateBorrow validates a borrow request against borrower and protocol requirements

func (Keeper) ValidateDeposit

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

ValidateDeposit validates a deposit

func (Keeper) ValidateRepay

func (k Keeper) ValidateRepay(ctx sdk.Context, sender, owner sdk.AccAddress, coins sdk.Coins) error

ValidateRepay validates a requested loan repay

func (Keeper) Withdraw

func (k Keeper) Withdraw(ctx sdk.Context, depositor sdk.AccAddress, coins sdk.Coins) error

Withdraw returns some or all of a deposit back to original depositor

type LiqData

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

LiqData holds liquidation-related data

Jump to

Keyboard shortcuts

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