keeper

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

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

func NewQuerier added in v0.4.0

func NewQuerier(k Keeper) queryServer

Types

type Keeper

type Keeper struct {
	ParamSubspace paramtypes.Subspace

	BankKeeper      types.BankKeeper
	AccountKeeper   types.AccountKeeper
	PricefeedKeeper types.PricefeedKeeper
	VpoolKeeper     types.VpoolKeeper
	// contains filtered or unexported fields
}

func NewKeeper

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

	accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	priceKeeper types.PricefeedKeeper,
	vpoolKeeper types.VpoolKeeper,
) Keeper

NewKeeper Creates a new x/perp Keeper instance.

func (Keeper) AddMargin

func (k Keeper) AddMargin(
	goCtx context.Context, msg *types.MsgAddMargin,
) (res *types.MsgAddMarginResponse, err error)
AddMargin deleverages an existing position by adding margin (collateral)

to it. Adding margin increases the margin ratio of the corresponding position.

func (Keeper) CalcPerpTxFee

func (k Keeper) CalcPerpTxFee(ctx sdk.Context, quoteAmt sdk.Dec) (toll sdk.Int, spread sdk.Int, err error)
CalcPerpTxFee calculates the total tx fee for exchanging `quoteAmt` of tokens on

the exchange.

Args:

quoteAmt (sdk.Int):

Returns:

toll (sdk.Int): Amount of tokens transferred to the the fee pool.
spread (sdk.Int): Amount of tokens transferred to the PerpEF.

func (Keeper) CalcRemainMarginWithFundingPayment

func (k Keeper) CalcRemainMarginWithFundingPayment(
	ctx sdk.Context,
	currentPosition types.Position,
	marginDelta sdk.Dec,
) (remaining RemainingMarginWithFundingPayment, err error)

func (Keeper) ClearPosition

func (k Keeper) ClearPosition(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) error

TODO test: ClearPosition | https://github.com/NibiruChain/nibiru/issues/299

func (Keeper) ExecuteFullLiquidation added in v0.2.3

func (k Keeper) ExecuteFullLiquidation(
	ctx sdk.Context, liquidator sdk.AccAddress, position *types.Position,
) (liquidationResp types.LiquidateResp, err error)

Fully liquidates a position. It is assumed that the margin ratio has already been checked prior to calling this method.

args:

  • ctx: cosmos-sdk context
  • liquidator: the liquidator's address
  • position: the position to liquidate

ret:

  • liquidationResp: a response object containing the results of the liquidation
  • err: error

func (Keeper) ExecutePartialLiquidation added in v0.2.3

func (k Keeper) ExecutePartialLiquidation(
	ctx sdk.Context, liquidator sdk.AccAddress, currentPosition *types.Position,
) (types.LiquidateResp, error)

ExecutePartialLiquidation partially liquidates a position

func (Keeper) GetMarginRatio

func (k Keeper) GetMarginRatio(
	ctx sdk.Context, position types.Position, priceOption types.MarginCalculationPriceOption,
) (marginRatio sdk.Dec, err error)

GetMarginRatio calculates the MarginRatio from a Position

func (Keeper) GetModuleAccountBalance

func (k Keeper) GetModuleAccountBalance(ctx sdk.Context, denom string) 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) GetPosition

func (k Keeper) GetPosition(
	ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress,
) (*types.Position, error)

func (Keeper) Liquidate added in v0.2.3

func (k Keeper) Liquidate(
	goCtx context.Context, msg *types.MsgLiquidate,
) (res *types.MsgLiquidateResponse, err error)
Liquidate allows to liquidate the trader position if the margin is below the

required margin maintenance ratio.

func (Keeper) Logger

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

func (Keeper) OpenPosition

func (k Keeper) OpenPosition(
	ctx sdk.Context,
	pair common.TokenPair,
	side types.Side,
	traderAddr sdk.AccAddress,
	quoteAssetAmount sdk.Int,
	leverage sdk.Dec,
	baseAssetAmountLimit sdk.Dec,
) (err error)

TODO test: OpenPosition | https://github.com/NibiruChain/nibiru/issues/299

func (Keeper) PairMetadata

func (k Keeper) PairMetadata() PairMetadata

func (Keeper) Params

func (Keeper) Positions

func (k Keeper) Positions() PositionsState

func (Keeper) PrepaidBadDebtState added in v0.2.0

func (k Keeper) PrepaidBadDebtState() PrepaidBadDebtState

func (Keeper) RemoveMargin

func (k Keeper) RemoveMargin(
	goCtx context.Context, msg *types.MsgRemoveMargin,
) (res *types.MsgRemoveMarginResponse, err error)
RemoveMargin further leverages an existing position by directly removing

the margin (collateral) that backs it from the vault. This also decreases the margin ratio of the position.

func (*Keeper) SetParams

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

SetParams set the params

func (Keeper) SetPosition

func (k Keeper) SetPosition(
	ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress,
	position *types.Position)

func (Keeper) SettlePosition

func (k Keeper) SettlePosition(
	ctx sdk.Context,
	currentPosition types.Position,
) (transferredCoins sdk.Coins, err error)

SettlePosition settles a trader position

func (Keeper) Whitelist

func (k Keeper) Whitelist() Whitelist

func (Keeper) Withdraw added in v0.2.0

func (k Keeper) Withdraw(
	ctx sdk.Context,
	denom string,
	receiver sdk.AccAddress,
	amountToWithdraw sdk.Int,
) (err error)

Withdraws coins from the vault to the receiver. If the total amount of coins to withdraw is greater than the vault's amount, then withdraw the shortage from the PerpEF and mark it as prepaid bad debt.

Prepaid bad debt will count towards realized bad debt from negative PnL positions when those are closed/liquidated.

An example of this happening is when a long position has really high PnL and closes their position, realizing their profits. There is a counter party short position with really negative PnL, but their position hasn't been closed/liquidated yet. We must pay the long trader first, which results in funds being taken from the EF. When the short position is closed, it also realizes some bad debt but because we have already withdrawn from the EF, we don't need to withdraw more from the EF.

type PairMetadata

type PairMetadata Keeper

func (PairMetadata) Get

func (PairMetadata) GetAll added in v0.4.2

func (p PairMetadata) GetAll(ctx sdk.Context) []*types.PairMetadata

func (PairMetadata) Set

func (p PairMetadata) Set(ctx sdk.Context, metadata *types.PairMetadata)

type ParamsState

type ParamsState Keeper

func (ParamsState) Get

func (p ParamsState) Get(ctx sdk.Context) (*types.Params, error)

func (ParamsState) Set

func (p ParamsState) Set(ctx sdk.Context, params *types.Params)

type PositionsState

type PositionsState Keeper

func (PositionsState) Create

func (p PositionsState) Create(ctx sdk.Context, position *types.Position) error

func (PositionsState) Get

func (p PositionsState) Get(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) (*types.Position, error)

func (PositionsState) Set

func (p PositionsState) Set(
	ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress, position *types.Position,
)

func (PositionsState) Update

func (p PositionsState) Update(ctx sdk.Context, position *types.Position) error

type PrepaidBadDebtState added in v0.2.0

type PrepaidBadDebtState Keeper

func (PrepaidBadDebtState) Decrement added in v0.2.1

func (pbd PrepaidBadDebtState) Decrement(ctx sdk.Context, denom string, decrement sdk.Int) (
	amount sdk.Int,
)

Decrements the amount of bad debt prepaid by denom.

The lowest it can be decremented to is zero. Trying to decrement a prepaid bad debt balance to below zero will clip it at zero.

func (PrepaidBadDebtState) Get added in v0.2.0

func (pbd PrepaidBadDebtState) Get(ctx sdk.Context, denom string) (amount sdk.Int)

Fetches the amount of bad debt prepaid by denom. Returns zero if the denom is not found.

func (PrepaidBadDebtState) Increment added in v0.2.0

func (pbd PrepaidBadDebtState) Increment(ctx sdk.Context, denom string, increment sdk.Int) (
	amount sdk.Int,
)

Increments the amount of bad debt prepaid by denom. Calling this method on a denom that doesn't exist is effectively the same as setting the amount (0 + increment).

func (PrepaidBadDebtState) Set added in v0.2.0

func (pbd PrepaidBadDebtState) Set(ctx sdk.Context, denom string, amount sdk.Int)

Sets the amount of bad debt prepaid by denom.

type RemainingMarginWithFundingPayment

type RemainingMarginWithFundingPayment struct {
	// Margin: amount of quote token (y) backing the position.
	Margin sdk.Dec

	/* BadDebt: Bad debt (margin units) cleared by the PerpEF during the tx.
	   Bad debt is negative net margin past the liquidation point of a position. */
	BadDebt sdk.Dec

	/* FundingPayment: A funding payment (margin units) made or received by the trader on
	    the current position. 'fundingPayment' is positive if 'owner' is the sender
		and negative if 'owner' is the receiver of the payment. Its magnitude is
		abs(vSize * fundingRate). Funding payments act to converge the mark price
		(vPrice) and index price (average price on major exchanges).
	*/
	FundingPayment sdk.Dec

	/* LatestCumulativePremiumFraction: latest cumulative premium fraction. Units are (margin units)/position size. */
	LatestCumulativePremiumFraction sdk.Dec
}

type Whitelist

type Whitelist Keeper

func (Whitelist) IsWhitelisted

func (w Whitelist) IsWhitelisted(ctx sdk.Context, address string) bool

Jump to

Keyboard shortcuts

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