Skip to main content

IDomFiPerp

IDomFiPerp

Addresses

ChainAddress

Functions

previewIncrease

Preview results of an increase

function previewIncrease(
address user,
PositionLabel positionLabel,
bytes32 productId,
uint256 margin,
bool isLong,
FPUnsigned leverage
) external returns (
struct IDomFiPerp.IncreasePreview increasePreview
)
Dev note

May revert if the increase would revert.

Parameters

NameTypeDescription
useraddressOwner of the position
positionLabelPositionLabelUser-defined label of the position
productIdbytes32Product 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.
leverageFPUnsignedLeverage at which margin will be added to the position

Return Values

NameTypeDescription
increasePreviewstruct IDomFiPerp.IncreasePreviewComputed IncreasePreview for the position

previewDecrease

Preview results of a decrease

function previewDecrease(
PositionId positionId,
uint256 decreaseMargin
) external returns (
struct IDomFiPerp.DecreasePreview decreasePreview
)

Parameters

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

Return Values

NameTypeDescription
decreasePreviewstruct IDomFiPerp.DecreasePreviewComputed DecreasePreview for the position

increasePosition

Increase (or create) a position.

function increasePosition(
address user,
PositionLabel positionLabel,
bytes32 productId,
uint256 margin,
bool isLong,
FPUnsigned leverage
) 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().
productIdbytes32Product 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.
leverageFPUnsignedLeverage of this increase's margin. 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 IDomFiPerp.DecreasePositionParams[] params) external

Parameters

NameTypeDescription
paramsstruct IDomFiPerp.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, address recipient) external
Dev note

If margin >= position.margin, close position.

Parameters

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

getProduct

Get product details. See Product.

function getProduct(bytes32 productId) external view returns (struct IDomFiPerp.Product product)

Parameters

NameTypeDescription
productIdbytes32ID of this product

Return Values

NameTypeDescription
productstruct IDomFiPerp.ProductSaved parameters for this product

getPosition

Get details of a position. See Position.

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

Parameters

NameTypeDescription
globalPositionIdPositionIdGlobal position ID

Return Values

NameTypeDescription
positionstruct IDomFiPerp.PositionSaved position

getPosition

Get details of a user position. See Position.

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

Parameters

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

Return Values

NameTypeDescription
positionstruct IDomFiPerp.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 DOMD

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(
bytes32 productId,
bool isLong,
FPUnsigned leverage,
FPUnsigned positionPrice,
uint256 margin,
FPSigned funding,
FPUnsigned price
) external returns (
FPSigned pnl,
FPSigned fundingDebt
)

Parameters

NameTypeDescription
productIdbytes32productId of position to evaluate
isLongboolisLong of position to evaluate
leverageFPUnsignedleverage 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)

fundingManager

function fundingManager() external view returns (contract IFundingManager)

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(bytes32 productId, FPUnsigned value, uint64 timestamp, address oracle) external
Dev note

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

Parameters

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

Events

ProductAdded

event ProductAdded(bytes32 productId, struct IDomFiPerp.Product product)

ProductUpdated

event ProductUpdated(bytes32 productId, struct IDomFiPerp.Product product)

OwnerUpdated

event OwnerUpdated(address newOwner)

GuardianUpdated

event GuardianUpdated(address newGuardian)

GovUpdated

event GovUpdated(address newGov)

IncreasePosition

An event emitted when a position is increased in size.

event IncreasePosition(
PositionId positionId,
address user,
bytes32 productId,
uint256 fee,
FPUnsigned executionPrice,
struct IDomFiPerp.Position position
)

Parameters

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

DecreasePosition

An event emitted when a position is decreased in size.

event DecreasePosition(
PositionId positionId,
address user,
bytes32 productId,
bool didClose,
bool didLiquidate,
uint256 fee,
int256 netPnl,
FPUnsigned exitPrice,
struct IDomFiPerp.Position position
)

Parameters

NameTypeDescription
positionIdPositionIdThe position ID.
useraddressThe position's owner.
productIdbytes32The 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 IDomFiPerp.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.

RemoveMargin

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

event RemoveMargin(
PositionId positionId,
address user,
uint256 oldMargin,
FPUnsigned oldLeverage,
struct IDomFiPerp.Position position
)

Parameters

NameTypeDescription
positionIdPositionIdThe position ID.
useraddressThe position's owner.
oldMarginuint256The previous margin amount.
oldLeverageFPUnsignedThe previous position leverage.
positionstruct IDomFiPerp.PositionThe position after margin removed.

PositionLiquidated

An event emitted when a position is liquidated.

event PositionLiquidated(
PositionId positionId,
address liquidator,
uint256 liquidatorReward,
uint256 remainingReward,
struct IDomFiPerp.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 IDomFiPerp.PositionThe position before liquidation.

Types

Position

Fields

NameTypeDescription
owneraddress
productIdbytes32
marginuint256collateral provided for this position
leverageFPUnsigned
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;
bytes32 productId;
uint256 margin;
FPUnsigned leverage;
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 {
bytes32 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
productIdbytes32Globally 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 {
bytes32 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()
productIdbytes32product of this position
marginuint256margin to increase this position by
isLongbooldirection of this position
leverageFPUnsignedleverage of this increase's margin. After increase, resulting position must have valid leverage.
struct IncreasePositionParams {
address user;
PositionLabel positionLabel;
bytes32 productId;
uint256 margin;
bool isLong;
FPUnsigned leverage;
}

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. Leverage remains the same
recipientaddressWhere to send margin and any accompanying PnL
struct DecreasePositionParams {
address user;
PositionLabel positionLabel;
uint256 margin;
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
leverageFPUnsignedLeverage of new position (total size / total margin)
marginuint256Margin of new position (prev + increase)
struct IncreasePreview {
FPSigned funding;
FPUnsigned price;
FPUnsigned executionPrice;
FPUnsigned leverage;
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
struct DecreasePreview {
FPUnsigned price;
uint256 totalFee;
uint256 margin;
int256 netPnl;
bool isFullClose;
bool isLiquidatable;
}

PositionId

bytes32 globally-unique ID of a position. See getPositionId.

PositionLabel

bytes16 arbitrary user label for a position.