cw_struct

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddMargin

type AddMargin struct {
	Pair   string   `json:"pair"`
	Margin sdk.Coin `json:"margin"`
}

type AllMarketsRequest

type AllMarketsRequest struct {
}

type AllMarketsResponse

type AllMarketsResponse struct {
	MarketMap map[string]Market `json:"market_map"`
}

type BasePriceRequest

type BasePriceRequest struct {
	Pair       string      `json:"pair"`
	IsLong     bool        `json:"is_long"`
	BaseAmount sdkmath.Int `json:"base_amount"`
}

type BasePriceResponse

type BasePriceResponse struct {
	Pair        string  `json:"pair"`
	BaseAmount  sdk.Dec `json:"base_amount"`
	QuoteAmount sdk.Dec `json:"quote_amount"`
	IsLong      bool    `json:"is_long"`
}

type BindingMsg

type BindingMsg struct {
	// bindings-perp ExecuteMsg enum types
	OpenPosition  *OpenPosition  `json:"open_position,omitempty"`
	ClosePosition *ClosePosition `json:"close_position,omitempty"`
	//MultiLiquidate        *MultiLiquidate        `json:"multi_liquidate,omitempty"` // TODO
	AddMargin             *AddMargin             `json:"add_margin,omitempty"`
	RemoveMargin          *RemoveMargin          `json:"remove_margin,omitempty"`
	DonateToInsuranceFund *DonateToInsuranceFund `json:"donate_to_insurance_fund,omitempty"` // TODO
	InsuranceFundWithdraw *InsuranceFundWithdraw `json:"insurance_fund_withdraw,omitempty"`
	PegShift              *PegShift              `json:"peg_shift,omitempty"`
	DepthShift            *DepthShift            `json:"depth_shift,omitempty"`
	SetMarketEnabled      *SetMarketEnabled      `json:"set_market_enabled,omitempty"`
	CreateMarket          *CreateMarket          `json:"create_market,omitempty"`

	EditOracleParams *EditOracleParams `json:"edit_oracle_params,omitempty"`
}

BindingMsg corresponds to the 'ExecuteMsg' enum in the CosmWasm binding contracts (Rust). It specifies which wasm execute messages can be called with Nibiru bindings and specifies the JSON schema that connects app ⇔ Wasm.

See: - https://github.com/NibiruChain/cw-nibiru/blob/90df123f8d32d47b5b280ec6ae7dde0f9dbf2787/contracts/bindings-perp/src/msg.rs

type BindingQuery

type BindingQuery struct {
	// bindings-perp NibiruQuery enum types
	Reserves        *ReservesRequest        `json:"reserves,omitempty"`
	AllMarkets      *AllMarketsRequest      `json:"all_markets,omitempty"`
	BasePrice       *BasePriceRequest       `json:"base_price,omitempty"`
	Positions       *PositionsRequest       `json:"positions,omitempty"`
	Position        *PositionRequest        `json:"position,omitempty"`
	PremiumFraction *PremiumFractionRequest `json:"premium_fraction,omitempty"`
	Metrics         *MetricsRequest         `json:"metrics,omitempty"`
	ModuleAccounts  *ModuleAccountsRequest  `json:"module_accounts,omitempty"`
	PerpParams      *PerpParamsRequest      `json:"module_params,omitempty"`
}

BindingQuery corresponds to the NibiruQuery enum in CosmWasm binding contracts (Rust). It specifies which queries can be called with Nibiru bindings and specifies the JSON schema that connects app ⇔ Wasm.

### Note

  1. The JSON field names must match the ones on the smart contract
  2. You use a pointer so that each field can be nil, which will be missing in the input or output json. What's actually sent from the contract will be an instance of the parent type, but the message body will be on one of these nullable fields. This is part of the reason we need the "omitempty" struct tags

See: - https://github.com/NibiruChain/cw-nibiru/blob/90df123f8d32d47b5b280ec6ae7dde0f9dbf2787/contracts/bindings-perp/src/query.rs

type ClosePosition

type ClosePosition struct {
	Pair string `json:"pair"`
}

type CreateMarket

type CreateMarket struct {
	Pair         string        `json:"pair"`
	PegMult      sdk.Dec       `json:"peg_mult,omitempty"`
	SqrtDepth    sdk.Dec       `json:"sqrt_depth,omitempty"`
	MarketParams *MarketParams `json:"market_params,omitempty"`
}

type DepthShift

type DepthShift struct {
	Pair      string  `json:"pair"`
	DepthMult sdk.Dec `json:"depth_mult"`
}

type DonateToInsuranceFund

type DonateToInsuranceFund struct {
	Sender   string   `json:"sender"`
	Donation sdk.Coin `json:"donation"`
}

type EditOracleParams

type EditOracleParams struct {
	VotePeriod         *sdkmath.Int `json:"vote_period,omitempty"`
	VoteThreshold      *sdk.Dec     `json:"vote_threshold,omitempty"`
	RewardBand         *sdk.Dec     `json:"reward_band,omitempty"`
	Whitelist          []string     `json:"whitelist,omitempty"`
	SlashFraction      *sdk.Dec     `json:"slash_fraction,omitempty"`
	SlashWindow        *sdkmath.Int `json:"slash_window,omitempty"`
	MinValidPerWindow  *sdk.Dec     `json:"min_valid_per_window,omitempty"`
	TwapLookbackWindow *sdkmath.Int `json:"twap_lookback_window,omitempty"`
	MinVoters          *sdkmath.Int `json:"min_voters,omitempty"`
	ValidatorFeeRatio  *sdk.Dec     `json:"validator_fee_ratio,omitempty"`
}

type InsuranceFundWithdraw

type InsuranceFundWithdraw struct {
	Amount sdkmath.Int `json:"amount"`
	To     string      `json:"to"`
}

type LiquidationArgs

type LiquidationArgs struct {
	Pair   string `json:"pair"`
	Trader string `json:"trader"`
}

type Market

type Market struct {
	Pair         string        `json:"pair"`
	BaseReserve  sdk.Dec       `json:"base_reserve"`
	QuoteReserve sdk.Dec       `json:"quote_reserve"`
	SqrtDepth    sdk.Dec       `json:"sqrt_depth"`
	Depth        sdkmath.Int   `json:"depth"`
	TotalLong    sdk.Dec       `json:"total_long"`
	TotalShort   sdk.Dec       `json:"total_short"`
	PegMult      sdk.Dec       `json:"peg_mult"`
	Config       *MarketConfig `json:"config,omitempty"`
	MarkPrice    sdk.Dec       `json:"mark_price"`
	IndexPrice   string        `json:"index_price"`
	TwapMark     string        `json:"twap_mark"`
	BlockNumber  sdkmath.Int   `json:"block_number"`
}

func NewMarket

func NewMarket(appMarket perpv2types.Market, appAmm perpv2types.AMM, indexPrice, twapMark string, blockNumber int64) Market

func (Market) ToAppMarket

func (m Market) ToAppMarket() (appMarket perpv2types.Market, err error)

Converts the JSON market, which comes in from Rust, to its corresponding protobuf (Golang) type in the app: perpv2types.Market.

type MarketConfig

type MarketConfig struct {
	MaintenanceMarginRatio sdk.Dec `json:"maintenance_margin_ratio"`
	MaxLeverage            sdk.Dec `json:"max_leverage"`
}

type MarketParams

type MarketParams struct {
	Pair    string
	Enabled bool `json:"enabled,omitempty"`
	// the minimum margin ratio which a user must maintain on this market
	MaintenanceMarginRatio sdk.Dec `json:"maintenance_margin_ratio"`
	// the maximum leverage a user is able to be taken on this market
	MaxLeverage sdk.Dec `json:"max_leverage"`
	// Latest cumulative premium fraction for a given pair.
	// Calculated once per funding rate interval.
	// A premium fraction is the difference between mark and index, divided by the
	// number of payments per day. (mark - index) / # payments in a day
	LatestCumulativePremiumFraction sdk.Dec `json:"latest_cumulative_premium_fraction"`
	// the percentage of the notional given to the exchange when trading
	ExchangeFeeRatio sdk.Dec `json:"exchange_fee_ratio"`
	// the percentage of the notional transferred to the ecosystem fund when
	// trading
	EcosystemFundFeeRatio sdk.Dec `json:"ecosystem_fund_fee_ratio"`
	// the percentage of liquidated position that will be
	// given to out as a reward. Half of the liquidation fee is given to the
	// liquidator, and the other half is given to the ecosystem fund.
	LiquidationFeeRatio sdk.Dec `json:"liquidation_fee_ratio"`
	// the portion of the position size we try to liquidate if the available
	// margin is higher than liquidation fee
	PartialLiquidationRatio sdk.Dec `json:"partial_liquidation_ratio"`
	// specifies the interval on which the funding rate is updated
	FundingRateEpochId string `json:"funding_rate_epoch_id,omitempty"`
	// amount of time to look back for TWAP calculations
	TwapLookbackWindow sdkmath.Int `json:"twap_lookback_window"`
}

type Metrics

type Metrics struct {
	Pair        string            `json:"pair"`
	NetSize     sdkmath.LegacyDec `json:"net_size"`
	VolumeQuote sdkmath.LegacyDec `json:"volume_quote"`
	VolumeBase  sdkmath.LegacyDec `json:"volume_base"`
	BlockNumber sdkmath.Int       `json:"block_number"`
}

type MetricsRequest

type MetricsRequest struct {
	Pair string `json:"pair"`
}

type MetricsResponse

type MetricsResponse struct {
	Metrics Metrics `json:"metrics"`
}

type ModuleAccountWithBalance

type ModuleAccountWithBalance struct {
	Name    string         `json:"name"`
	Addr    sdk.AccAddress `json:"addr"`
	Balance []sdk.Coin     `json:"balance"`
}

type ModuleAccountsRequest

type ModuleAccountsRequest struct {
}

type ModuleAccountsResponse

type ModuleAccountsResponse struct {
	ModuleAccounts map[string]ModuleAccountWithBalance `json:"module_accounts"`
}

type MultiLiquidate

type MultiLiquidate struct {
	Liquidations []LiquidationArgs `json:"liquidations"`
}

type OpenPosition

type OpenPosition struct {
	Pair            string      `json:"pair"`
	IsLong          bool        `json:"is_long"`
	QuoteAmount     sdkmath.Int `json:"quote_amount"`
	Leverage        sdk.Dec     `json:"leverage"`
	BaseAmountLimit sdkmath.Int `json:"base_amount_limit"`
}

type PegShift

type PegShift struct {
	Pair    string  `json:"pair"`
	PegMult sdk.Dec `json:"peg_mult"`
}

type PerpParams

type PerpParams struct {
	Stopped                 bool              `json:"stopped"`
	FeePoolFeeRatio         sdkmath.LegacyDec `json:"fee_pool_fee_ratio"`
	EcosystemFundFeeRatio   sdkmath.LegacyDec `json:"ecosystem_fund_fee_ratio"`
	LiquidationFeeRatio     sdkmath.LegacyDec `json:"liquidation_fee_ratio"`
	PartialLiquidationRatio sdkmath.LegacyDec `json:"partial_liquidation_ratio"`
	FundingRateInterval     string            `json:"funding_rate_interval"`
	TwapLookbackWindow      sdkmath.Int       `json:"twap_lookback_window"`
	WhitelistedLiquidators  []string          `json:"whitelisted_liquidators"`
}

type PerpParamsRequest

type PerpParamsRequest struct {
}

type PerpParamsResponse

type PerpParamsResponse struct {
	ModuleParams PerpParams `json:"module_params"`
}

type Position

type Position struct {
	TraderAddr   string      `json:"trader_addr"`
	Pair         string      `json:"pair"`
	Size         sdk.Dec     `json:"size"`
	Margin       sdk.Dec     `json:"margin"`
	OpenNotional sdk.Dec     `json:"open_notional"`
	LatestCPF    sdk.Dec     `json:"latest_cpf"`
	BlockNumber  sdkmath.Int `json:"block_number"`
}

type PositionRequest

type PositionRequest struct {
	Trader string `json:"trader"`
	Pair   string `json:"pair"`
}

type PositionResponse

type PositionResponse struct {
	Position           Position    `json:"position"`
	Notional           sdk.Dec     `json:"notional"`
	Upnl               sdk.Dec     `json:"upnl"`
	Margin_ratio_mark  sdk.Dec     `json:"margin_ratio_mark"`
	Margin_ratio_index sdk.Dec     `json:"margin_ratio_index"`
	Block_number       sdkmath.Int `json:"block_number"`
}

type PositionsRequest

type PositionsRequest struct {
	Trader string `json:"trader"`
}

type PositionsResponse

type PositionsResponse struct {
	Positions map[string]Position `json:"positions"`
}

type PremiumFractionRequest

type PremiumFractionRequest struct {
	Pair string `json:"pair"`
}

type PremiumFractionResponse

type PremiumFractionResponse struct {
	Pair             string  `json:"pair"`
	CPF              sdk.Dec `json:"cpf"`
	EstimatedNextCPF sdk.Dec `json:"estimated_next_cpf"`
}

type RemoveMargin

type RemoveMargin struct {
	Pair   string   `json:"pair"`
	Margin sdk.Coin `json:"margin"`
}

type ReservesRequest

type ReservesRequest struct {
	Pair string `json:"pair"`
}

type ReservesResponse

type ReservesResponse struct {
	Pair         string  `json:"pair"`
	BaseReserve  sdk.Dec `json:"base_reserve"`
	QuoteReserve sdk.Dec `json:"quote_reserve"`
}

type SetMarketEnabled

type SetMarketEnabled struct {
	Pair    string `json:"pair"`
	Enabled bool   `json:"enabled"`
}

Jump to

Keyboard shortcuts

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