keeper

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 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 Hooks added in v0.5.1

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

Hooks wrapper struct for perps keeper.

func (Hooks) AfterEpochEnd added in v0.5.1

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

func (Hooks) BeforeEpochStart added in v0.5.1

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

epochs hooks.

type Keeper

type Keeper struct {
	ParamSubspace paramtypes.Subspace

	BankKeeper      types.BankKeeper
	AccountKeeper   types.AccountKeeper
	PricefeedKeeper types.PricefeedKeeper
	VpoolKeeper     types.VpoolKeeper
	EpochKeeper     types.EpochKeeper
	// 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,
	epochKeeper types.EpochKeeper,
) 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) AfterEpochEnd added in v0.5.1

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64)

func (Keeper) BeforeEpochStart added in v0.5.1

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

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.AssetPair, traderAddr sdk.AccAddress) error

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

func (Keeper) ClosePosition added in v0.4.20

func (k Keeper) ClosePosition(ctx sdk.Context, pair common.AssetPair, addr sdk.AccAddress) (*types.PositionResp, error)

ClosePosition gets the current position, and calls OpenPosition to open a reverse position with amount equal to the current open notional.

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.AssetPair, traderAddr sdk.AccAddress,
) (*types.Position, error)

func (Keeper) Hooks added in v0.5.1

func (k Keeper) Hooks() Hooks

Return the wrapper struct.

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.AssetPair,
	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) PairMetadataState added in v0.5.1

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

func (Keeper) Params

func (Keeper) PositionsState added in v0.5.1

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

func (Keeper) PrepaidBadDebtState added in v0.2.0

func (k Keeper) PrepaidBadDebtState(ctx sdk.Context) 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.AssetPair, 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) WhitelistState added in v0.5.1

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

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 PairMetadataState added in v0.5.1

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

func (PairMetadataState) Get added in v0.5.1

func (PairMetadataState) GetAll added in v0.5.1

func (p PairMetadataState) GetAll() []*types.PairMetadata

func (PairMetadataState) Set added in v0.5.1

func (p PairMetadataState) Set(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 struct {
	// contains filtered or unexported fields
}

func (PositionsState) Create

func (p PositionsState) Create(position *types.Position) error

func (PositionsState) Delete added in v0.5.1

func (p PositionsState) Delete(pair common.AssetPair, addr sdk.AccAddress) error

func (PositionsState) Get

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

func (PositionsState) Iterate added in v0.5.0

func (p PositionsState) Iterate(do func(position *types.Position) (stop bool))

func (PositionsState) Set

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

func (PositionsState) Update

func (p PositionsState) Update(position *types.Position) error

type PrepaidBadDebtState added in v0.2.0

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

func (PrepaidBadDebtState) Decrement added in v0.2.1

func (s PrepaidBadDebtState) Decrement(denom string, decrement sdk.Int) (amount sdk.Int)

Decrement 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 (s PrepaidBadDebtState) Get(denom string) (amount sdk.Int)

Get 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 (s PrepaidBadDebtState) Increment(denom string, increment sdk.Int) (amount sdk.Int)

Increment 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) Iterate added in v0.5.0

func (s PrepaidBadDebtState) Iterate(do func(denom string, amount sdk.Int) (stop bool))

Iterate iterates over known prepaid bad debt.

func (PrepaidBadDebtState) Set added in v0.2.0

func (s PrepaidBadDebtState) Set(denom string, amount sdk.Int)

Set 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
}

func (RemainingMarginWithFundingPayment) String added in v0.5.1

type WhitelistState added in v0.5.1

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

func (WhitelistState) Add added in v0.5.1

func (w WhitelistState) Add(address sdk.AccAddress)

func (WhitelistState) IsWhitelisted added in v0.5.1

func (w WhitelistState) IsWhitelisted(address sdk.AccAddress) bool

func (WhitelistState) Iterate added in v0.5.1

func (w WhitelistState) Iterate(do func(addr sdk.AccAddress) (stop bool))

Jump to

Keyboard shortcuts

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