Documentation ¶
Index ¶
- func NewMsgServerImpl(keeper Keeper) types.MsgServer
- func NewQuerier(k Keeper) queryServer
- type Keeper
- func (k Keeper) AddMargin(goCtx context.Context, msg *types.MsgAddMargin) (res *types.MsgAddMarginResponse, err error)
- func (k Keeper) CalcPerpTxFee(ctx sdk.Context, quoteAmt sdk.Dec) (toll sdk.Int, spread sdk.Int, err error)
- func (k Keeper) CalcRemainMarginWithFundingPayment(ctx sdk.Context, currentPosition types.Position, marginDelta sdk.Dec) (remaining RemainingMarginWithFundingPayment, err error)
- func (k Keeper) ClearPosition(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) error
- func (k Keeper) ExecuteFullLiquidation(ctx sdk.Context, liquidator sdk.AccAddress, position *types.Position) (liquidationResp types.LiquidateResp, err error)
- func (k Keeper) ExecutePartialLiquidation(ctx sdk.Context, liquidator sdk.AccAddress, currentPosition *types.Position) (types.LiquidateResp, error)
- func (k Keeper) GetMarginRatio(ctx sdk.Context, position types.Position, ...) (marginRatio sdk.Dec, err error)
- func (k Keeper) GetModuleAccountBalance(ctx sdk.Context, denom string) sdk.Coin
- func (k *Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetPosition(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) (*types.Position, error)
- func (k Keeper) Liquidate(goCtx context.Context, msg *types.MsgLiquidate) (res *types.MsgLiquidateResponse, err error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) OpenPosition(ctx sdk.Context, pair common.TokenPair, side types.Side, ...) (err error)
- func (k Keeper) PairMetadata() PairMetadata
- func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
- func (k Keeper) Positions() PositionsState
- func (k Keeper) PrepaidBadDebtState() PrepaidBadDebtState
- func (k Keeper) RemoveMargin(goCtx context.Context, msg *types.MsgRemoveMargin) (res *types.MsgRemoveMarginResponse, err error)
- func (k *Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) SetPosition(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress, ...)
- func (k Keeper) SettlePosition(ctx sdk.Context, currentPosition types.Position) (transferredCoins sdk.Coins, err error)
- func (k Keeper) Whitelist() Whitelist
- func (k Keeper) Withdraw(ctx sdk.Context, denom string, receiver sdk.AccAddress, ...) (err error)
- type PairMetadata
- type ParamsState
- type PositionsState
- func (p PositionsState) Create(ctx sdk.Context, position *types.Position) error
- func (p PositionsState) Get(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) (*types.Position, error)
- func (p PositionsState) Set(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress, ...)
- func (p PositionsState) Update(ctx sdk.Context, position *types.Position) error
- type PrepaidBadDebtState
- func (pbd PrepaidBadDebtState) Decrement(ctx sdk.Context, denom string, decrement sdk.Int) (amount sdk.Int)
- func (pbd PrepaidBadDebtState) Get(ctx sdk.Context, denom string) (amount sdk.Int)
- func (pbd PrepaidBadDebtState) Increment(ctx sdk.Context, denom string, increment sdk.Int) (amount sdk.Int)
- func (pbd PrepaidBadDebtState) Set(ctx sdk.Context, denom string, amount sdk.Int)
- type RemainingMarginWithFundingPayment
- type Whitelist
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMsgServerImpl ¶
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 (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 ¶
GetModuleAccountBalance gets the airdrop coin balance of module account.
func (Keeper) GetPosition ¶
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) 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 (k Keeper) Params( goCtx context.Context, req *types.QueryParamsRequest, ) (*types.QueryParamsResponse, error)
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) SetPosition ¶
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) 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 (p PairMetadata) Get(ctx sdk.Context, pair common.TokenPair) (*types.PairMetadata, error)
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
type PositionsState ¶
type PositionsState Keeper
func (PositionsState) Get ¶
func (p PositionsState) Get(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) (*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
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).
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 }