keeper

package
v0.21.11 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package keeper that mints Nibiru stablecoins, maintains their price stability, and ensures that the protocol remains collateralized enough for stablecoins to be redeemed.

Index

Constants

This section is empty.

Variables

View Source
var LiquidityRatioBands = sdk.MustNewDecFromStr("0.001")

Functions

func NeededCollAmtGivenGov

func NeededCollAmtGivenGov(
	govAmt sdkmath.Int, priceGov sdk.Dec, priceColl sdk.Dec,
	collRatio sdk.Dec) (neededCollAmt sdkmath.Int, mintableStableAmt sdkmath.Int)

NeededCollAmtGivenGov Computes the amount of COLL needed to mint NUSD given some NIBI amount. Args:

govAmt sdk.Int: Amount of  NIBI given.

Returns:

neededCollAmt sdk.Int: Amount of COLL needed.
mintableStableAmt sdk.Int: Amount of NUSD that can be minted.

func NeededGovAmtGivenColl

func NeededGovAmtGivenColl(
	collAmt sdkmath.Int, priceGov sdk.Dec, priceColl sdk.Dec,
	collRatio sdk.Dec) (neededGovAmt sdkmath.Int, mintableStableAmt sdkmath.Int)

NeededGovAmtGivenColl Computes the amount of NIBI needed to mint NUSD given some COLL amount. Args:

collAmt sdk.Int: Amount of COLL given.

Returns:

neededGovAmt sdk.Int: Amount of NIBI needed.
mintableStableAmt sdk.Int: Amount of NUSD that can be minted.

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

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

Types

type Hooks

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

Hooks wrapper struct for incentives keeper.

func (Hooks) AfterEpochEnd

func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber uint64)

AfterEpochEnd epochs hooks

func (Hooks) BeforeEpochStart

func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber uint64)

BeforeEpochStart epochs hooks.

type Keeper

type Keeper struct {
	ParamSubspace paramtypes.Subspace

	AccountKeeper types.AccountKeeper
	BankKeeper    types.BankKeeper
	OracleKeeper  types.OracleKeeper
	SpotKeeper    types.SpotKeeper
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey,
	memKey storetypes.StoreKey,
	paramSubspace paramtypes.Subspace,

	accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	priceKeeper types.OracleKeeper,
	spotKeeper types.SpotKeeper,
) Keeper

NewKeeper Creates a new x/stablecoin Keeper instance.

func (Keeper) AfterEpochEnd

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber uint64)

func (Keeper) BeforeEpochStart

func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber uint64)

func (Keeper) BurnStable

func (k Keeper) BurnStable(goCtx context.Context, msg *types.MsgBurnStable,
) (*types.MsgBurnStableResponse, error)

BurnStable burns stable coin (plus fees) and returns the equivalent of collateral and gov token. Fees are distributed between ecosystem fund and treasury based on feeRatio.

func (Keeper) Buyback

func (k Keeper) Buyback(
	goCtx context.Context, msg *types.MsgBuyback,
) (response *types.MsgBuybackResponse, err error)

Buyback buys governance tokens back from the user in order to release over collateralization.

func (*Keeper) BuybackGovAmtForTargetCollRatio

func (k *Keeper) BuybackGovAmtForTargetCollRatio(
	ctx sdk.Context,
) (neededGovAmt sdkmath.Int, err error)

BuybackGovAmtForTargetCollRatio returns the governance tokens that the protocol can buyback in order to have the optimal collateral ration.

Args:

ctx (sdk.Context): Carries information about the current state of the application.

Returns:

neededGovAmt (sdk.Int): The needed Governance amount that the protocol can buyback in order to
achieve the optimal collateral ratio.
err (error): The error containing information if something went wrong.

func (Keeper) CheckEnoughBalances

func (k Keeper) CheckEnoughBalances(ctx sdk.Context, coins sdk.Coins, account sdk.AccAddress) error

CheckEnoughBalances checks if account address has enough balance of coins.

func (Keeper) CirculatingSupplies added in v0.1.0

func (*Keeper) CollAmtFromBuyback

func (k *Keeper) CollAmtFromBuyback(
	ctx sdk.Context, valUSD sdk.Dec,
) (collAmt sdkmath.Int, err error)

CollAmtFromBuyback computes the COLL (collateral) given as a reward for calling buyback.

Args:

ctx (sdk.Context): Carries information about the current state of the application.
valUSD (sdk.Dec): Value in NUSD stablecoin to be used for buyback.

Returns:

collAmt (sdk.Int): Amount of COLL token rewarded for 'Buyback'.

func (*Keeper) CollAmtFromFullBuyback

func (k *Keeper) CollAmtFromFullBuyback(
	ctx sdk.Context,
) (collAmt sdkmath.Int, err error)

TODO hygiene: cover with test cases | https://github.com/NibiruChain/nibiru/issues/537

func (*Keeper) EvaluateCollRatio

func (k *Keeper) EvaluateCollRatio(ctx sdk.Context) (err error)

Evaluate Coll ratio updates the collateral ratio if the price is out of the bounds.

func (*Keeper) GetCollRatio

func (k *Keeper) GetCollRatio(ctx sdk.Context) (collRatio sdk.Dec)

GetCollRatio queries the 'collRatio'.

func (Keeper) GetGovMarketCap

func (k Keeper) GetGovMarketCap(ctx sdk.Context) (sdkmath.Int, error)

func (Keeper) GetLiquidityRatio

func (k Keeper) GetLiquidityRatio(ctx sdk.Context) (sdk.Dec, error)

GetLiquidityRatio returns the liquidity ratio defined as govMarketCap / stableMarketCap

func (Keeper) GetLiquidityRatioBands

func (k Keeper) GetLiquidityRatioBands(ctx sdk.Context) (
	lowBand sdk.Dec, upBand sdk.Dec, err error)

func (Keeper) GetModuleAccountBalance

func (k Keeper) GetModuleAccountBalance(ctx sdk.Context) sdk.Coin

GetModuleAccountBalance gets the airdrop coin balance of module account.

func (*Keeper) GetParams

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

GetParams get all parameters as types.Params

func (Keeper) GetStableMarketCap

func (k Keeper) GetStableMarketCap(ctx sdk.Context) sdkmath.Int

func (Keeper) GetSupplyNIBI

func (k Keeper) GetSupplyNIBI(
	ctx sdk.Context,
) sdk.Coin

func (Keeper) GetSupplyNUSD

func (k Keeper) GetSupplyNUSD(
	ctx sdk.Context,
) sdk.Coin

func (*Keeper) GovAmtFromFullRecollateralize

func (k *Keeper) GovAmtFromFullRecollateralize(
	ctx sdk.Context,
) (govOut sdkmath.Int, err error)

func (*Keeper) GovAmtFromRecollateralize

func (k *Keeper) GovAmtFromRecollateralize(
	ctx sdk.Context, inUSD sdk.Dec,
) (govOut sdkmath.Int, err error)

GovAmtFromRecollateralize computes the GOV token given as a reward for calling recollateralize.

Args:

ctx (sdk.Context): Carries information about the current state of the application.
inUSD (sdk.Dec): Value in NUSD stablecoin to be used for recollateralization.

Returns:

govOut (sdk.Int): Amount of GOV token rewarded for 'Recollateralize'.

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

Hooks Return the wrapper struct.

func (Keeper) LiquidityRatioInfo added in v0.1.0

func (k Keeper) LiquidityRatioInfo(
	goCtx context.Context, req *types.QueryLiquidityRatioInfoRequest,
) (res *types.QueryLiquidityRatioInfoResponse, err error)

func (Keeper) Logger

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

func (Keeper) MintStable

func (k Keeper) MintStable(
	goCtx context.Context, msg *types.MsgMintStable,
) (*types.MsgMintStableResponse, error)

MintStable mints stable coins given collateral (COLL) and governance (GOV)

func (Keeper) ModuleAccountBalances added in v0.1.0

func (Keeper) Params

func (Keeper) Recollateralize

func (k Keeper) Recollateralize(
	goCtx context.Context, msg *types.MsgRecollateralize,
) (response *types.MsgRecollateralizeResponse, err error)

Recollateralize is a function that incentivizes the caller to add up to the amount of collateral needed to reach some target collateral ratio (`collRatioTarget`). Recollateralize checks if the USD value of collateral in the protocol is below the required amount defined by the current collateral ratio. Nibiru's NUSD stablecoin is taken to be the dollar that determines USD value.

Args:

  msg (MsgRecollateralize) {
    Creator (string): Caller of 'Recollateralize'
	Coll (sdk.Coin): Input collateral that will be sold to the protocol.
  }

Returns:

response (MsgRecollateralizeResponse) {
  Gov (sdk.Coin): Governance received as a reward for recollateralizing Nibiru.
}
err: Error condition for if the function succeeds or fails.

func (*Keeper) RecollateralizeCollAmtForTargetCollRatio

func (k *Keeper) RecollateralizeCollAmtForTargetCollRatio(
	ctx sdk.Context,
) (neededCollAmount sdkmath.Int, err error)

func (*Keeper) SetCollRatio

func (k *Keeper) SetCollRatio(ctx sdk.Context, collRatio sdk.Dec) (err error)

SetCollRatio manually sets the 'collRatio'. This method is mainly used for testing. when the chain is live, the collateral ratio cannot be manually set, only adjusted by a fixed amount (e.g. 0.25%).

func (*Keeper) SetParams

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

SetParams set the params

func (*Keeper) StableRequiredForTargetCollRatio

func (k *Keeper) StableRequiredForTargetCollRatio(
	ctx sdk.Context,
) (neededStable sdk.Dec, err error)

StableRequiredForTargetCollRatio is the collateral value in USD needed to reach a target collateral ratio.

Jump to

Keyboard shortcuts

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