Skip to main content

IDomFiPerp

IDomFiPerp

Addresses

ChainAddress

Functions

priceFeed

function priceFeed() external view returns (contract IPriceFeed)

feeCalculator

function feeCalculator() external view returns (contract IFeeCalculator)

fundingManager

function fundingManager() external view returns (contract IFundingManager)

previewIncrease

Preview results of an increase

function previewIncrease(
address user,
PositionLabel positionLabel,
ProductId productId,
uint256 margin,
bool isLong,
FPUnsigned size
) external returns (
struct IExchangeDomain.IncreasePreview increasePreview
)
Dev note

May revert if the increase would revert.

Parameters

NameTypeDescription
useraddressOwner of the position
positionLabelPositionLabelUser-defined label of the position
productIdProductIdProduct for this position. Required for new positions; ignored ONLY if modifying an existing position.
marginuint256Collateral added to the position by the increase
isLongboolWhether position is long. Required for new positions; ignored ONLY if modifying an existing position.
sizeFPUnsignedSize (margin * leverage) of the increase

Return Values

NameTypeDescription
increasePreviewstruct IExchangeDomain.IncreasePreviewComputed IncreasePreview for the position

previewDecrease

Preview results of a decrease

function previewDecrease(
PositionId positionId,
uint256 decreaseMargin,
FPUnsigned decreaseSize
) external returns (
struct IExchangeDomain.DecreasePreview decreasePreview
)

Parameters

NameTypeDescription
positionIdPositionIdGlobal ID of position to be decreased. Must exist.
decreaseMarginuint256Margin amount to decrease by. May be greater than position margin
decreaseSizeFPUnsignedSize to decrease by. May be greater than position size

Return Values

NameTypeDescription
decreasePreviewstruct IExchangeDomain.DecreasePreviewComputed DecreasePreview for the position

increasePosition

Increase (or create) a position.

function increasePosition(
address user,
PositionLabel positionLabel,
ProductId productId,
uint256 margin,
bool isLong,
FPUnsigned size
) external

Parameters

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. Ignored in favor of stored value if position already exists.
marginuint256Margin to increase this position by.
isLongboolDirection of this position. Ignored in favor of stored value if position already exists.
sizeFPUnsignedSize (margin * leverage) of this increase. After increase, resulting position must have valid leverage.

removeMargin

Remove margin from a position (increasing leverage). Caller must be the position's owner or their manager.

function removeMargin(PositionId positionId, uint256 marginToRemove, address recipient) external
Dev note

Reverts if

  • resulting position is liquidatable
  • resulting position has leverage < 1 or leverage > product.maxLeverage
  • resulting position has margin < minMargin
  • removeMargin > position.margin

Parameters

NameTypeDescription
positionIdPositionIdPosition to remove margin from
marginToRemoveuint256Collateral to remove from margin
recipientaddressSend removed collateral to this address

canRemove

Whether a position can have margin withdrawn without liquidation or overleverage, and if so how much. See removeMargin().

function canRemove(PositionId positionId) external returns (bool canRemove_, int256 removeableMargin)

Parameters

NameTypeDescription
positionIdPositionIdGlobal ID of Position to check

Return Values

NameTypeDescription
canRemove_boolWhether it has margin available to withdraw
removeableMarginint256Available removal. Negative if !canRemove_

decreasePositions

Decrease (or close) multiple positions simultaneously. Fails unless all succeed.

function decreasePositions(struct IExchangeDomain.DecreasePositionParams[] params) external

Parameters

NameTypeDescription
paramsstruct IExchangeDomain.DecreasePositionParams[]List of decreases. See DecreasePositionParams

decreasePositionWithId

Decrease (or close) a position, and claim proportional share of position margin + PnL. Unlike removing margin, leverage remains the same.

function decreasePositionWithId(
PositionId positionId,
uint256 margin,
FPUnsigned size,
address recipient
) external
Dev note

If margin >= position.margin or size >= position.size, close position.

Parameters

NameTypeDescription
positionIdPositionIdTarget position. msg.sender must be its owner or their manager.
marginuint256Margin units to decrease
sizeFPUnsigned
recipientaddressWhere to send reclaimed share of position value + PnL

getProduct

Get product details. See Product.

function getProduct(ProductId productId) external view returns (struct IExchangeDomain.Product product)

Parameters

NameTypeDescription
productIdProductIdID of this product

Return Values

NameTypeDescription
productstruct IExchangeDomain.ProductSaved parameters for this product

getPosition

Get details of a position. See Position.

function getPosition(
PositionId globalPositionId
) external view returns (
struct IExchangeDomain.Position position
)

Parameters

NameTypeDescription
globalPositionIdPositionIdGlobal position ID

Return Values

NameTypeDescription
positionstruct IExchangeDomain.PositionSaved position

getPosition

Get details of a user position. See Position.

function getPosition(
address account,
PositionLabel positionLabel
) external view returns (
struct IExchangeDomain.Position position
)

Parameters

NameTypeDescription
accountaddressOwner of the position
positionLabelPositionLabelUser-defined label for this position

Return Values

NameTypeDescription
positionstruct IExchangeDomain.PositionSaved position

getPositionId

Compute the global position ID of a user's position

function getPositionId(
address account,
PositionLabel positionLabel
) external view returns (
PositionId positionId
)

Parameters

NameTypeDescription
accountaddressowner of this position
positionLabelPositionLabelUser-defined label for this position

Return Values

NameTypeDescription
positionIdPositionIdGlobally unique position ID

getMaxExposure

Get max exposure for a product: the highest permitted value of |long open interest - short open interest|

function getMaxExposure(
FPUnsigned productWeight,
FPUnsigned productExposureMultiplier
) external view returns (
FPUnsigned maxExposure
)

Parameters

NameTypeDescription
productWeightFPUnsignedproduct.weight; determines vault balance allocated to this product
productExposureMultiplierFPUnsignedmultiple of product's vault share allowed for exposure

Return Values

NameTypeDescription
maxExposureFPUnsignedpermitted max exposure

isManagerFor

Whether manager is a registered manager approved by account .

function isManagerFor(address manager, address account) external returns (bool isManager)

Parameters

NameTypeDescription
manageraddressPossible manager (for instance, an OrderBook)
accountaddressUser that may have approved manager

Return Values

NameTypeDescription
isManagerboolWhether manager is a registered manager approved by account .

validateOI

Revert if balance times utilizationMultiplier is less than OI

function validateOI(uint256 balance) external view
Dev note

Triggers after each transfer of dfUSDC

Parameters

NameTypeDescription
balanceuint256Balance of DomFiVault

asset

Collateral token of this perp, e.g. USDC or wETH

function asset() external view returns (contract IERC20)

Return Values

NameTypeDescription
[0]contract IERC20assetToken Address of token

getPositionPnlAndFunding

Get the Pnl of a position, including funding

function getPositionPnlAndFunding(
ProductId productId,
bool isLong,
FPUnsigned size,
FPUnsigned positionPrice,
uint256 margin,
FPSigned funding,
FPUnsigned price
) external returns (
FPSigned pnl,
FPSigned fundingDebt
)

Parameters

NameTypeDescription
productIdProductIdproductId of position to evaluate
isLongboolisLong of position to evaluate
sizeFPUnsignedsize of position to evaluate
positionPriceFPUnsignedprice of position to evaluate
marginuint256margin of position to evaluate
fundingFPSignedfunding of position to evaluate
priceFPUnsignedCurrent price of the position's product

Return Values

NameTypeDescription
pnlFPSignedIncrease in position value since creation, minus funding
fundingDebtFPSignedAccrued funding (and interest) which was subtracted from this position's PnL. A positive value reduces position value.

getPositionPnlRate

Compute the current PnL rate (PnL / margin) of a position at the most recent price.

function getPositionPnlRate(PositionId positionId) external returns (FPSigned pnlRate)

Parameters

NameTypeDescription
positionIdPositionIdGlobally-unique ID of the position in question

Return Values

NameTypeDescription
pnlRateFPSignedPnL rate of this position. 100% = 1.0

totalOpenInterest

total size (margin * leverage) of all outstanding positions in token wei

function totalOpenInterest() external view returns (FPUnsigned)

getTotalPnl

Compute total trader PnL across all positions, ignoring maxPositionProfit

function getTotalPnl() external returns (FPSigned)
Dev note

Used for withdraw delays. Computed with composite positions.

Return Values

NameTypeDescription
[0]FPSignedtotalPnl Sum of all position PnLs if there was no maxPositionProfit

updatePrice

Emit a PriceUpdate event for easy off-chain data access

function updatePrice(ProductId productId, FPUnsigned value, uint64 timestamp, address oracle) external
Dev note

This allows order bots to get price events without tracking oracle changes.

Parameters

NameTypeDescription
productIdProductIdID of product with price update
valueFPUnsignedNew price
timestampuint64Timestamp at which price was generated
oracleaddressSource of price update