Skip to main content

Exchange

IExchangeDomain

Addresses

ChainAddress

Types

Position

Fields

NameTypeDescription
owneraddress
productIdProductId
sizeFPUnsigned
marginuint256collateral provided for this position
priceFPUnsignedprice when position was increased. weighted average by size
fundingFPSignedfunding + interest when position was last increased
positionLabelPositionLabel
timestampuint64last position increase
isLongbool
struct Position {
address owner;
ProductId productId;
FPUnsigned size;
uint256 margin;
FPUnsigned price;
FPSigned funding;
PositionLabel positionLabel;
uint64 timestamp;
bool isLong;
}

ProductParams

Parameters to create a new Product. Does not include OI state variables.

struct ProductParams {
ProductId productId;
FPUnsigned maxLeverage;
FPUnsigned fee;
bool isActive;
FPUnsigned minPriceChange;
FPUnsigned weight;
FPUnsigned reserveMultiplier;
FPUnsigned exposureMultiplier;
FPUnsigned liquidationThreshold;
FPUnsigned liquidationBounty;
FPUnsigned fundingExponent;
}

Product

A product against which positions can be opened, e.g. Bitcoin dominance

Fields

NameTypeDescription
productIdProductIdGlobally unique productID, e.g. formatBytes32String("BTCDOM")
maxLeverageFPUnsignedMax leverage for positions on this product, e.g. 3x
feeFPUnsignedFraction of (margin*leverage) taken as a fee for position size changes, e.g. 0.0001
isActiveboolWhether positions can be opened and increased on this product
openInterestLongFPUnsignedSum of (margin*leverage) for all open longs
openInterestShortFPUnsignedSum of (margin*leverage) for all open shorts
minPriceChangeFPUnsignedMin oracle increase % for trader to close with profit before minProfitTime
weightFPUnsignedWeight with which to allocate global max exposure between products
reserveMultiplierFPUnsignedVirtual reserve used to calculate slippage. See DomFiPerp.calculatePrice()
exposureMultiplierFPUnsignedProduct exposure is limited to exposureMultiplier * its share of global max exposure
liquidationThresholdFPUnsignedLiquidate positions if losses exceed liquidationThreshold * margin
liquidationBountyFPUnsignedReward liquidations with liquidationBounty * remaining margin
fundingExponentFPUnsignedAn exponential scaling factor for funding rate
struct Product {
ProductId productId;
FPUnsigned maxLeverage;
FPUnsigned fee;
bool isActive;
FPUnsigned openInterestLong;
FPUnsigned openInterestShort;
FPUnsigned minPriceChange;
FPUnsigned weight;
FPUnsigned reserveMultiplier;
FPUnsigned exposureMultiplier;
FPUnsigned liquidationThreshold;
FPUnsigned liquidationBounty;
FPUnsigned fundingExponent;
}

IncreasePositionParams

Parameters for a request to increase (or create) a position

Fields

NameTypeDescription
useraddressOwner of the position. msg.sender must be user or their manager
positionLabelPositionLabeluser-defined ID of position to increase or create. See getPositionId()
productIdProductIdproduct of this position
marginuint256margin to increase this position by
isLongbooldirection of this position
sizeFPUnsignedsize (margin * leverage) of this increase. After increase, resulting position must have valid leverage.
struct IncreasePositionParams {
address user;
PositionLabel positionLabel;
ProductId productId;
uint256 margin;
bool isLong;
FPUnsigned size;
}

DecreasePositionParams

Parameters for a request to decrease (or close) a position

Fields

NameTypeDescription
useraddressOwner of this position. msg.sender must be user or their manager
positionLabelPositionLabeluser-defined ID of position to decrease/close. See getPositionId()
marginuint256amount of margin to decrease size to decrease
sizeFPUnsigned
recipientaddressWhere to send margin and any accompanying PnL
struct DecreasePositionParams {
address user;
PositionLabel positionLabel;
uint256 margin;
FPUnsigned size;
address recipient;
}

IncreasePreview

Preview result of an increasePosition call

Fields

NameTypeDescription
fundingFPSignedFunding of new position (weighted mean) @custom:executionPrice Slippage-adjusted price at which the increase would execute
priceFPUnsignedTotal price of new position (weighted harmonic mean)
executionPriceFPUnsigned
sizeFPUnsignedSize (margin * leverage) of new position
marginuint256Margin of new position (prev + increase)
struct IncreasePreview {
FPSigned funding;
FPUnsigned price;
FPUnsigned executionPrice;
FPUnsigned size;
uint256 margin;
}

DecreasePreview

Preview result of a decreasePosition call

Fields

NameTypeDescription
priceFPUnsignedexecution price of this decrease
totalFeeuint256trade fee paid by this decrease
marginuint256actual decrease in margin
netPnlint256PnL realized by this decrease, minus fees
isFullCloseboolWhether this decrease completely closed the position
isLiquidatableboolWhether the position was liquidatable
sizeFPUnsignedDecrease in size
struct DecreasePreview {
FPUnsigned price;
uint256 totalFee;
uint256 margin;
int256 netPnl;
bool isFullClose;
bool isLiquidatable;
FPUnsigned size;
}

IncreaseState

struct IncreaseState {
bool store;
bool isLong;
PositionLabel positionLabel;
address user;
FPUnsigned size;
ProductId productId;
uint256 margin;
}

IncreaseResult

struct IncreaseResult {
bool store;
bool isLong;
PositionId positionId;
PositionLabel positionLabel;
address user;
FPUnsigned size;
ProductId productId;
uint256 margin;
struct ProductPtr product;
FPUnsigned price;
FPSigned funding;
struct PositionPtr dest;
struct IExchangeDomain.IncreasePreview next;
}

PositionDelta

struct PositionDelta {
FPSigned size;
int256 margin;
uint64 timestamp;
}

IExchangeEvents

Addresses

ChainAddress

Events

ProductAdded

event ProductAdded(ProductId productId, struct IExchangeDomain.Product product)

ProductUpdated

event ProductUpdated(ProductId productId, struct IExchangeDomain.Product product)

IncreasePosition

An event emitted when a position is increased in size.

event IncreasePosition(
PositionId positionId,
address user,
ProductId productId,
uint256 fee,
FPUnsigned executionPrice,
struct IExchangeDomain.Position position,
struct IExchangeDomain.PositionDelta delta
)

Parameters

NameTypeDescription
positionIdPositionIdThe position ID.
useraddressThe position's owner.
productIdProductIdThe position's product ID.
feeuint256The fee incurred to increase the position.
executionPriceFPUnsignedThe price used, after slippage
positionstruct IExchangeDomain.PositionThe position after the increase size.
deltastruct IExchangeDomain.PositionDelta

DecreasePosition

An event emitted when a position is decreased in size.

event DecreasePosition(
PositionId positionId,
address user,
ProductId productId,
bool didClose,
bool didLiquidate,
uint256 fee,
int256 netPnl,
FPUnsigned exitPrice,
struct IExchangeDomain.Position position,
struct IExchangeDomain.PositionDelta delta
)

Parameters

NameTypeDescription
positionIdPositionIdThe position ID.
useraddressThe position's owner.
productIdProductIdThe position's product ID.
didClosebooltrue if the position was full closed.
didLiquidatebooltrue if the position was liquidated.
feeuint256The fee incurred to decrease the position.
netPnlint256The net PnL of the position.
exitPriceFPUnsignedThe exit price of the partial or full position decrease.
positionstruct IExchangeDomain.PositionThe position after the partial decrease. In the case of a full decrease, the position will have the last margin amount for the sake of easily identifying the position size before it was fully closed.
deltastruct IExchangeDomain.PositionDelta

RemoveMargin

An event emitted when a position's margin is removed to increase leverage.

event RemoveMargin(
PositionId positionId,
address user,
struct IExchangeDomain.Position position,
struct IExchangeDomain.PositionDelta delta
)

Parameters

NameTypeDescription
positionIdPositionIdThe position ID.
useraddressThe position's owner.
positionstruct IExchangeDomain.PositionThe position after margin removed.
deltastruct IExchangeDomain.PositionDeltaThe change in the position's margin and size.

PositionLiquidated

An event emitted when a position is liquidated.

event PositionLiquidated(
PositionId positionId,
address liquidator,
uint256 liquidatorReward,
uint256 remainingReward,
struct IExchangeDomain.Position position
)

Parameters

NameTypeDescription
positionIdPositionIdThe position ID.
liquidatoraddressThe address of the liquidator.
liquidatorRewarduint256The reward given to the liquidator denominated in the position's collateral token.
remainingRewarduint256The remaining reward from the liquidated position denominated in the position's collateral token.
positionstruct IExchangeDomain.PositionThe position before liquidation.

IExchangeErrors

Addresses

ChainAddress

Errors

PositionNotFound

error PositionNotFound(PositionId positionId)

ProductNotFound

error ProductNotFound(ProductId productId)

InactiveProduct

error InactiveProduct(ProductId productId)

InvalidProductId

The supplied productId was 0x0.

error InvalidProductId()

ZeroRemainingMargin

Attempted to remove margin from a position, but no margin would be left.

error ZeroRemainingMargin()

MarginBelowMin

Attempted to remove margin from a position, but the position would be left with less than the minimum margin amount.

error MarginBelowMin()

InvalidPosition

error InvalidPosition()

RemoveCallerNotAllowed

Attempted to remove margin from a position, but the caller does not own the position and isn't a registered manager of the owner.

error RemoveCallerNotAllowed()

DecreaseCallerNotAllowed

Attempted to decrease a position, but the caller does not own the position and isn't a registered manager of the owner.

error DecreaseCallerNotAllowed()

LeverageBelowMin

error LeverageBelowMin()

LeverageAboveMax

error LeverageAboveMax()

PriceFeedOnly

error PriceFeedOnly()

LiquidatorOnly

error LiquidatorOnly()

NotLiquidatable

error NotLiquidatable()

Liquidatable

error Liquidatable()

MaxOpenInterestExceeded

error MaxOpenInterestExceeded()

MaxExposureExceeded

error MaxExposureExceeded()

MaxUtilizationExceeded

error MaxUtilizationExceeded()

ProductExposureExceeded

error ProductExposureExceeded(ProductId productId, bool isLong)

NoRemovableMargin

error NoRemovableMargin()

TradeDisabled

error TradeDisabled()

IncreaseCallerNotAllowed

error IncreaseCallerNotAllowed()