Skip to content

PerpsV2MarketBase

Description

Source: contracts/PerpsV2MarketBase.sol

Structs

TradeParams

Source

Field Type Description
sizeDelta int256 TBA
price uint256 TBA
takerFee uint256 TBA
makerFee uint256 TBA
trackingCode bytes32 TBA

Variables

baseAsset

Source

Type: bytes32

fundingLastRecomputed

Source

Type: uint32

fundingSequence

Source

Type: int128[]

marketKey

Source

Type: bytes32

marketSize

Source

Type: uint128

marketSkew

Source

Type: int128

positions

Source

Type: mapping(address => struct IPerpsV2BaseTypes.Position)

Constructor

constructor

Source

Details

Signature

constructor(address _resolver, bytes32 _baseAsset, bytes32 _marketKey)

Visibility

public

State Mutability

``

Views

assetPrice

Source

Details

Signature

assetPrice() view returns (uint256 price, bool invalid)

Visibility

public

State Mutability

view

resolverAddressesRequired

Source

Details

Signature

resolverAddressesRequired() view returns (bytes32[] addresses)

Visibility

public

State Mutability

view

Internal Functions

_abs

Source

Details

Signature

_abs(int256 x) pure returns (uint256)

Visibility

internal

State Mutability

pure

_accessibleMargin

Source

Details

Signature

_accessibleMargin(struct IPerpsV2BaseTypes.Position position, uint256 price) view returns (uint256)

Visibility

internal

State Mutability

view

_accruedFunding

Source

Details

Signature

_accruedFunding(struct IPerpsV2BaseTypes.Position position, uint256 price) view returns (int256 funding)

Visibility

internal

State Mutability

view

_applyDebtCorrection

Source

Details

Signature

_applyDebtCorrection(struct IPerpsV2BaseTypes.Position newPosition, struct IPerpsV2BaseTypes.Position oldPosition)

Visibility

internal

State Mutability

``

_assetPriceRequireSystemChecks

Source

Details

Signature

_assetPriceRequireSystemChecks() returns (uint256)

Visibility

internal

State Mutability

``

_canLiquidate

Source

Details

Signature

_canLiquidate(struct IPerpsV2BaseTypes.Position position, uint256 price) view returns (bool)

Visibility

internal

State Mutability

view

_closePosition

Source

Details

Signature

_closePosition(bytes32 trackingCode)

Visibility

internal

State Mutability

``

_currentFundingRate

Source

Details

Signature

_currentFundingRate(uint256 price) view returns (int256)

Visibility

internal

State Mutability

view

_currentLeverage

Source

Details

Signature

_currentLeverage(struct IPerpsV2BaseTypes.Position position, uint256 price, uint256 remainingMargin_) pure returns (int256 leverage)

Visibility

internal

State Mutability

pure

_dynamicFeeRate

Source

Details

Signature

_dynamicFeeRate() view returns (uint256 feeRate, bool tooVolatile)

Visibility

internal

State Mutability

view

_exchangeCircuitBreaker

Source

Details

Signature

_exchangeCircuitBreaker() view returns (contract IExchangeCircuitBreaker)

Visibility

internal

State Mutability

view

_exchanger

Source

Details

Signature

_exchanger() view returns (contract IExchanger)

Visibility

internal

State Mutability

view

_isError

Source

Details

Signature

_isError(enum IPerpsV2BaseTypes.Status status) pure returns (bool)

Visibility

internal

State Mutability

pure

_latestFundingIndex

Source

Details

Signature

_latestFundingIndex() view returns (uint256)

Visibility

internal

State Mutability

view

_liquidatePosition

Source

Details

Signature

_liquidatePosition(address account, address liquidator, uint256 price)

Visibility

internal

State Mutability

``

Emits

_liquidationFee

Source

Details

Signature

_liquidationFee(int256 positionSize, uint256 price) view returns (uint256 lFee)

Visibility

internal

State Mutability

view

_liquidationMargin

Source

Details

Signature

_liquidationMargin(int256 positionSize, uint256 price) view returns (uint256 lMargin)

Visibility

internal

State Mutability

view

_manager

Source

Details

Signature

_manager() view returns (contract IFuturesMarketManagerInternal)

Visibility

internal

State Mutability

view

_marginPlusProfitFunding

Source

Details

Signature

_marginPlusProfitFunding(struct IPerpsV2BaseTypes.Position position, uint256 price) view returns (int256)

Visibility

internal

State Mutability

view

_marketDebt

Source

Details

Signature

_marketDebt(uint256 price) view returns (uint256)

Visibility

internal

State Mutability

view

_max

Source

Details

Signature

_max(int256 x, int256 y) pure returns (int256)

Visibility

internal

State Mutability

pure

_min

Source

Details

Signature

_min(int256 x, int256 y) pure returns (int256)

Visibility

internal

State Mutability

pure

_modifyPosition

Source

Details

Signature

_modifyPosition(int256 sizeDelta, bytes32 trackingCode)

Visibility

internal

State Mutability

``

_netFundingPerUnit

Source

Details

Signature

_netFundingPerUnit(uint256 startIndex, uint256 price) view returns (int256)

Visibility

internal

State Mutability

view

_nextFundingEntry

Source

Details

Signature

_nextFundingEntry(uint256 price) view returns (int256 funding)

Visibility

internal

State Mutability

view

_notionalValue

Source

Details

Signature

_notionalValue(int256 positionSize, uint256 price) pure returns (int256 value)

Visibility

internal

State Mutability

pure

_orderFee

Source

Details

Signature

_orderFee(struct PerpsV2MarketBase.TradeParams params, uint256 dynamicFeeRate) view returns (uint256 fee)

Visibility

internal

State Mutability

view

_orderSizeTooLarge

Source

Details

Signature

_orderSizeTooLarge(uint256 maxSize, int256 oldSize, int256 newSize) view returns (bool)

Visibility

internal

State Mutability

view

_positionDebtCorrection

Source

Details

Signature

_positionDebtCorrection(struct IPerpsV2BaseTypes.Position position) view returns (int256)

Visibility

internal

State Mutability

view

_postTradeDetails

Source

Details

Signature

_postTradeDetails(struct IPerpsV2BaseTypes.Position oldPos, struct PerpsV2MarketBase.TradeParams params) view returns (struct IPerpsV2BaseTypes.Position newPosition, uint256 fee, enum IPerpsV2BaseTypes.Status tradeStatus)

Visibility

internal

State Mutability

view

_profitLoss

Source

Details

Signature

_profitLoss(struct IPerpsV2BaseTypes.Position position, uint256 price) pure returns (int256 pnl)

Visibility

internal

State Mutability

pure

_proportionalSkew

Source

Details

Signature

_proportionalSkew(uint256 price) view returns (int256)

Visibility

internal

State Mutability

view

Requires

_recomputeFunding

Source

Details

Signature

_recomputeFunding(uint256 price) returns (uint256 lastIndex)

Visibility

internal

State Mutability

``

Emits

_recomputeMarginWithDelta

Source

Details

Signature

_recomputeMarginWithDelta(struct IPerpsV2BaseTypes.Position position, uint256 price, int256 marginDelta) view returns (uint256 margin, enum IPerpsV2BaseTypes.Status statusCode)

Visibility

internal

State Mutability

view

_remainingMargin

Source

Details

Signature

_remainingMargin(struct IPerpsV2BaseTypes.Position position, uint256 price) view returns (uint256)

Visibility

internal

State Mutability

view

_revertIfError

Source

Details

Signature

_revertIfError(bool isError, enum IPerpsV2BaseTypes.Status status) view

Visibility

internal

State Mutability

view

_sameSide

Source

Details

Signature

_sameSide(int256 a, int256 b) pure returns (bool)

Visibility

internal

State Mutability

pure

_settings

Source

Details

Signature

_settings() view returns (address)

Visibility

internal

State Mutability

view

_signedAbs

Source

Details

Signature

_signedAbs(int256 x) pure returns (int256)

Visibility

internal

State Mutability

pure

_systemStatus

Source

Details

Signature

_systemStatus() view returns (contract ISystemStatus)

Visibility

internal

State Mutability

view

_trade

Source

Details

Signature

_trade(address sender, struct PerpsV2MarketBase.TradeParams params)

Visibility

internal

State Mutability

``

Emits

_transferMargin

Source

Details

Signature

_transferMargin(int256 marginDelta, uint256 price, address sender)

Visibility

internal

State Mutability

``

Emits

_unrecordedFunding

Source

Details

Signature

_unrecordedFunding(uint256 price) view returns (int256 funding)

Visibility

internal

State Mutability

view

_updatePositionMargin

Source

Details

Signature

_updatePositionMargin(struct IPerpsV2BaseTypes.Position position, uint256 price, int256 marginDelta)

Visibility

internal

State Mutability

``

External Functions

closePosition

Source

Details

Signature

closePosition()

Visibility

external

State Mutability

``

closePositionWithTracking

Source

Details

Signature

closePositionWithTracking(bytes32 trackingCode)

Visibility

external

State Mutability

``

liquidatePosition

Source

Details

Signature

liquidatePosition(address account)

Visibility

external

State Mutability

``

modifyPosition

Source

Details

Signature

modifyPosition(int256 sizeDelta)

Visibility

external

State Mutability

``

modifyPositionWithTracking

Source

Details

Signature

modifyPositionWithTracking(int256 sizeDelta, bytes32 trackingCode)

Visibility

external

State Mutability

``

recomputeFunding

Source

Details

Signature

recomputeFunding() returns (uint256 lastIndex)

Visibility

external

State Mutability

``

Requires

transferMargin

Source

Details

Signature

transferMargin(int256 marginDelta)

Visibility

external

State Mutability

``

withdrawAllMargin

Source

Details

Signature

withdrawAllMargin()

Visibility

external

State Mutability

``

Events

FundingRecomputed

Source

Signature: FundingRecomputed(int256 funding, uint256 index, uint256 timestamp)

MarginTransferred

Source

Signature: MarginTransferred(address account, int256 marginDelta)

PositionLiquidated

Source

Signature: PositionLiquidated(uint256 id, address account, address liquidator, int256 size, uint256 price, uint256 fee)

PositionModified

Source

Signature: PositionModified(uint256 id, address account, uint256 margin, int256 size, int256 tradeSize, uint256 lastPrice, uint256 fundingIndex, uint256 fee)

Tracking

Source

Signature: Tracking(bytes32 trackingCode, bytes32 baseAsset, bytes32 marketKey, int256 sizeDelta, uint256 fee)