Documentation ¶
Index ¶
- func NewMsgServerImpl(keeper Keeper) types.MsgServer
- func NewQuerier(k Keeper) queryServer
- type Hooks
- type Keeper
- func (k Keeper) AddMargin(goCtx context.Context, msg *types.MsgAddMargin) (res *types.MsgAddMarginResponse, err error)
- func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64)
- func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64)
- 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.AssetPair, traderAddr sdk.AccAddress) error
- func (k Keeper) ClosePosition(ctx sdk.Context, pair common.AssetPair, addr sdk.AccAddress) (*types.PositionResp, 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.AssetPair, traderAddr sdk.AccAddress) (*types.Position, error)
- func (k Keeper) Hooks() Hooks
- func (k Keeper) Liquidate(ctx sdk.Context, liquidatorAddr sdk.AccAddress, pair common.AssetPair, ...) (feeToLiquidator sdk.Coin, feeToFund sdk.Coin, err error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) OpenPosition(ctx sdk.Context, pair common.AssetPair, side types.Side, ...) (err error)
- func (k Keeper) PairMetadataState(ctx sdk.Context) PairMetadataState
- func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
- func (k Keeper) PositionsState(ctx sdk.Context) PositionsState
- func (k Keeper) PrepaidBadDebtState(ctx sdk.Context) 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.AssetPair, traderAddr sdk.AccAddress, ...)
- func (k Keeper) SettlePosition(ctx sdk.Context, currentPosition types.Position) (transferredCoins sdk.Coins, err error)
- func (k Keeper) WhitelistState(ctx sdk.Context) WhitelistState
- func (k Keeper) Withdraw(ctx sdk.Context, denom string, receiver sdk.AccAddress, ...) (err error)
- type PairMetadataState
- type ParamsState
- type PositionsState
- func (p PositionsState) Create(position *types.Position) error
- func (p PositionsState) Delete(pair common.AssetPair, addr sdk.AccAddress) error
- func (p PositionsState) Get(pair common.AssetPair, traderAddr sdk.AccAddress) (*types.Position, error)
- func (p PositionsState) Iterate(do func(position *types.Position) (stop bool))
- func (p PositionsState) Set(pair common.AssetPair, traderAddr sdk.AccAddress, position *types.Position)
- func (p PositionsState) Update(position *types.Position) error
- type PrepaidBadDebtState
- func (s PrepaidBadDebtState) Decrement(denom string, decrement sdk.Int) (amount sdk.Int)
- func (s PrepaidBadDebtState) Get(denom string) (amount sdk.Int)
- func (s PrepaidBadDebtState) Increment(denom string, increment sdk.Int) (amount sdk.Int)
- func (s PrepaidBadDebtState) Iterate(do func(denom string, amount sdk.Int) (stop bool))
- func (s PrepaidBadDebtState) Set(denom string, amount sdk.Int)
- type RemainingMarginWithFundingPayment
- type WhitelistState
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 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
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 (Keeper) BeforeEpochStart ¶ added in v0.5.1
func (Keeper) CalcRemainMarginWithFundingPayment ¶
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 ¶
GetModuleAccountBalance gets the airdrop coin balance of module account.
func (Keeper) GetPosition ¶
func (Keeper) Liquidate ¶ added in v0.2.3
func (k Keeper) Liquidate( ctx sdk.Context, liquidatorAddr sdk.AccAddress, pair common.AssetPair, traderAddr sdk.AccAddress, ) (feeToLiquidator sdk.Coin, feeToFund sdk.Coin, err error)
Liquidate allows to liquidate the trader position if the margin is below the
required margin maintenance ratio.
args:
- liquidatorAddr: the liquidator who is executing the liquidation
- pair: the asset pair
- traderAddr: the trader who owns the position being liquidated
ret:
- feeToLiquidator: the amount of coins given to the liquidator
- feeToFund: the amount of coins given to the ecosystem fund
- err: error
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, baseAmtLimit 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 (k Keeper) Params( goCtx context.Context, req *types.QueryParamsRequest, ) (*types.QueryParamsResponse, error)
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) 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) 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 (p PairMetadataState) Get(pair common.AssetPair) (*types.PairMetadata, error)
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
type PositionsState ¶
type PositionsState struct {
// contains filtered or unexported fields
}
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)
type PrepaidBadDebtState ¶ added in v0.2.0
type PrepaidBadDebtState struct {
// contains filtered or unexported fields
}
func (PrepaidBadDebtState) Decrement ¶ added in v0.2.1
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
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).
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
func (r RemainingMarginWithFundingPayment) String() string
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))