Exchange
IExchangeDomain
Addresses
Chain | Address |
---|
Types
Position
Fields
Name | Type | Description |
---|---|---|
owner | address | |
productId | ProductId | |
size | FPUnsigned | |
margin | uint256 | collateral provided for this position |
price | FPUnsigned | price when position was increased. weighted average by size |
funding | FPSigned | funding + interest when position was last increased |
positionLabel | PositionLabel | |
timestamp | uint64 | last position increase |
isLong | bool |
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
Name | Type | Description |
---|---|---|
productId | ProductId | Globally unique productID, e.g. formatBytes32String("BTCDOM") |
maxLeverage | FPUnsigned | Max leverage for positions on this product, e.g. 3x |
fee | FPUnsigned | Fraction of (margin *leverage ) taken as a fee for position size changes, e.g. 0.0001 |
isActive | bool | Whether positions can be opened and increased on this product |
openInterestLong | FPUnsigned | Sum of (margin *leverage ) for all open longs |
openInterestShort | FPUnsigned | Sum of (margin *leverage ) for all open shorts |
minPriceChange | FPUnsigned | Min oracle increase % for trader to close with profit before minProfitTime |
weight | FPUnsigned | Weight with which to allocate global max exposure between products |
reserveMultiplier | FPUnsigned | Virtual reserve used to calculate slippage. See DomFiPerp.calculatePrice() |
exposureMultiplier | FPUnsigned | Product exposure is limited to exposureMultiplier * its share of global max exposure |
liquidationThreshold | FPUnsigned | Liquidate positions if losses exceed liquidationThreshold * margin |
liquidationBounty | FPUnsigned | Reward liquidations with liquidationBounty * remaining margin |
fundingExponent | FPUnsigned | An 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
Name | Type | Description |
---|---|---|
user | address | Owner of the position. msg.sender must be user or their manager |
positionLabel | PositionLabel | user-defined ID of position to increase or create. See getPositionId() |
productId | ProductId | product of this position |
margin | uint256 | margin to increase this position by |
isLong | bool | direction of this position |
size | FPUnsigned | size (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
Name | Type | Description |
---|---|---|
user | address | Owner of this position. msg.sender must be user or their manager |
positionLabel | PositionLabel | user-defined ID of position to decrease/close. See getPositionId() |
margin | uint256 | amount of margin to decrease size to decrease |
size | FPUnsigned | |
recipient | address | Where 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
Name | Type | Description |
---|---|---|
funding | FPSigned | Funding of new position (weighted mean) @custom:executionPrice Slippage-adjusted price at which the increase would execute |
price | FPUnsigned | Total price of new position (weighted harmonic mean) |
executionPrice | FPUnsigned | |
size | FPUnsigned | Size (margin * leverage) of new position |
margin | uint256 | Margin 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
Name | Type | Description |
---|---|---|
price | FPUnsigned | execution price of this decrease |
totalFee | uint256 | trade fee paid by this decrease |
margin | uint256 | actual decrease in margin |
netPnl | int256 | PnL realized by this decrease, minus fees |
isFullClose | bool | Whether this decrease completely closed the position |
isLiquidatable | bool | Whether the position was liquidatable |
size | FPUnsigned | Decrease 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
Chain | Address |
---|
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
Name | Type | Description |
---|---|---|
positionId | PositionId | The position ID. |
user | address | The position's owner. |
productId | ProductId | The position's product ID. |
fee | uint256 | The fee incurred to increase the position. |
executionPrice | FPUnsigned | The price used, after slippage |
position | struct IExchangeDomain.Position | The position after the increase size. |
delta | struct 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
Name | Type | Description |
---|---|---|
positionId | PositionId | The position ID. |
user | address | The position's owner. |
productId | ProductId | The position's product ID. |
didClose | bool | true if the position was full closed. |
didLiquidate | bool | true if the position was liquidated. |
fee | uint256 | The fee incurred to decrease the position. |
netPnl | int256 | The net PnL of the position. |
exitPrice | FPUnsigned | The exit price of the partial or full position decrease. |
position | struct IExchangeDomain.Position | The 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. |
delta | struct 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
Name | Type | Description |
---|---|---|
positionId | PositionId | The position ID. |
user | address | The position's owner. |
position | struct IExchangeDomain.Position | The position after margin removed. |
delta | struct IExchangeDomain.PositionDelta | The 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
Name | Type | Description |
---|---|---|
positionId | PositionId | The position ID. |
liquidator | address | The address of the liquidator. |
liquidatorReward | uint256 | The reward given to the liquidator denominated in the position's collateral token. |
remainingReward | uint256 | The remaining reward from the liquidated position denominated in the position's collateral token. |
position | struct IExchangeDomain.Position | The position before liquidation. |
IExchangeErrors
Addresses
Chain | Address |
---|
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()