Skip to main content

DomFiPerp

DomFiPerp

Perpetual long/short levered instruments for Domination Finance

The heart of Domination Finance exchange. Tracks positions per user. Prevents positions from being changed in ways that would violate vault-level risk management constraints.

Addresses

ChainAddress
Arbitrum Sepolia0xAbeB453C5a7735E8F91228a812EB083aB45B8b44
Base Sepolia0x260b93E1c41b9de692aeBE4B5313125484e74f7C
Base Mainnet0x53E219e30CB0697E312902295f2aAb69cC06c744

Functions

initialize

function initialize(struct StorageInstance app_) external

asset

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

function asset() public view returns (contract IERC20 assetToken)

Return Values

NameTypeDescription
assetTokencontract IERC20assetToken Address of token

fundingManager

function fundingManager() external view returns (contract IFundingManager)

priceFeed

function priceFeed() external view returns (contract IPriceFeed)

feeCalculator

function feeCalculator() external view returns (contract IFeeCalculator)

feeDistributor

function feeDistributor() external view returns (contract IFeeDistributor)

feeReferral

function feeReferral() external view returns (contract IFeeReferral)

vault

function vault() external view returns (contract IDomFiVault)

totalWeight

function totalWeight() external view returns (FPUnsigned)

totalOpenInterest

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

function totalOpenInterest() external view returns (FPUnsigned)

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

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.

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
)
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
[0]struct IExchangeDomain.IncreasePreview

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) public 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

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

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
) public
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

liquidatePositions

Liquidate positionIds and send any bounty to feeReceiver

function liquidatePositions(PositionId[] positionIds, address feeReceiver) external
Dev note

Reverts if any positions are not liquidatable. Reverts if public liquidation is disabled but msg.sender is not a registered liquidator.

Parameters

NameTypeDescription
positionIdsPositionId[]Positions to liquidate
feeReceiveraddressRecipient of any liquidator rewards

canLiquidate

Liquidation information for each position in positionIds

function canLiquidate(
PositionId[] positionIds
) external returns (
FPSigned[] pnl,
FPSigned[] funding,
bool[] isLiquidatable
)

Parameters

NameTypeDescription
positionIdsPositionId[]Positions to compute liquidation info for

Return Values

NameTypeDescription
pnlFPSigned[]Position PnL. See getPositionPnlAndFunding
fundingFPSigned[]Position funding. See getPositionPnlAndFunding
isLiquidatablebool[]Whether this position is liquidatable

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
) public 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) public returns (FPSigned pnlRate)

Parameters

NameTypeDescription
positionIdPositionIdGlobally-unique ID of the position in question

Return Values

NameTypeDescription
pnlRateFPSignedPnL rate of this position. 100% = 1.0

isManagerFor

Whether manager is a registered manager approved by account .

function isManagerFor(address manager, address account) public view 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

getTotalPnl

Compute total trader PnL across all positions, ignoring maxPositionProfit

function getTotalPnl() external returns (FPSigned totalPnl)
Dev note

Used for withdraw delays. Computed with composite positions.

Return Values

NameTypeDescription
totalPnlFPSignedtotalPnl Sum of all position PnLs if there was no maxPositionProfit

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

getPositionId

Compute the global position ID of a user's position

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

Parameters

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

Return Values

NameTypeDescription
positionIdPositionIdGlobally unique position ID

getPosition

Get details of a position. See position

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

Parameters

NameTypeDescription
positionIdPositionId

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

getPositions

Get details for many positions. See position

function getPositions(
PositionId[] positionIds
) external view returns (
struct IExchangeDomain.Position[] _positions
)

Parameters

NameTypeDescription
positionIdsPositionId[]Globally-unique position IDs

Return Values

NameTypeDescription
_positionsstruct IExchangeDomain.Position[]Saved positions. May be uninitialized

addProduct

Add a new product

function addProduct(struct IExchangeDomain.ProductParams _product) external

Parameters

NameTypeDescription
_productstruct IExchangeDomain.ProductParamsSee IDomFiPerp.ProductParams

updateProductMaxLeverage

Update the max leverage of a product

function updateProductMaxLeverage(ProductId _productId, FPUnsigned _maxLeverage) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_maxLeverageFPUnsignedSee IDomFiPerp.Product.maxLeverage

updateProductFee

Update the base trade fee for a product

function updateProductFee(ProductId _productId, FPUnsigned _fee) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_feeFPUnsignedSee IDomFiPerp.Product.fee

updateProductActive

Enable or disable a product

function updateProductActive(ProductId _productId, bool _isActive) external

Parameters

NameTypeDescription
_productIdProductIdProduct to (de)activate
_isActiveboolIDomFiPerp.Product.isActive

updateProductMinPriceChange

Update the minimum price change for positions on a product.

function updateProductMinPriceChange(ProductId _productId, FPUnsigned _minPriceChange) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_minPriceChangeFPUnsignedSee IDomFiPerp.Product.minPriceChange

updateProductLiquidationBounty

Update the liquidation bounty for positions on a product

function updateProductLiquidationBounty(ProductId _productId, FPUnsigned _liquidationBounty) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_liquidationBountyFPUnsignedSee IDomFiPerp.Product.liquidationBounty

updateProductExposureMultiplier

Update a product's exposure multiplier

function updateProductExposureMultiplier(ProductId _productId, FPUnsigned _exposureMultiplier) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_exposureMultiplierFPUnsignedSee IDomFiPerp.Product.exposureMultiplier

updateProductReserveMultiplier

Update a product's reserve multiplier

function updateProductReserveMultiplier(ProductId _productId, FPUnsigned _reserveMultiplier) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_reserveMultiplierFPUnsignedSee IDomFiPerp.Product.reserveMultiplier

updateProductWeight

Update a product's weight for exposure calculations

function updateProductWeight(ProductId _productId, FPUnsigned _weight) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_weightFPUnsignedSee IDomFiPerp.Product.weight

updateProductLiquidationThreshold

Update the liquidation threshold for positions on a product

function updateProductLiquidationThreshold(ProductId _productId, FPUnsigned _liquidationThreshold) external

Parameters

NameTypeDescription
_productIdProductIdProduct to change
_liquidationThresholdFPUnsignedSee IDomFiPerp.Product.liquidationThreshold

updateProductFundingExponent

Set product funding exponent. Funding rate is (productExposure / maxExposure) ^ fundingExponent * fundingMultiplier

function updateProductFundingExponent(ProductId _productId, FPUnsigned _fundingExponent) external
Dev note

Set to 1 to "disable".

Parameters

NameTypeDescription
_productIdProductIdID of product to change funding exponent
_fundingExponentFPUnsignedNew funding exponent. Must be > 0

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

managers

function managers(address _manager) external view returns (bool)

setManager

(De)register an address as a manager. With permission, managers can change positions on behalf of other addresses.

function setManager(address _manager, bool _isActive) external

Parameters

NameTypeDescription
_manageraddressAddress to affect
_isActiveboolWhether this address should be a manager.

approvedManagers

function approvedManagers(address _account, address _manager) external view returns (bool)

setAccountManager

Permit or prohibit another address from changing the sender's positions

function setAccountManager(address _manager, bool _isActive) external

Parameters

NameTypeDescription
_manageraddressAddress to approve or remove, e.g. OrderBook
_isActiveboolWhether this address may change the sender's positions.

minMargin

function minMargin() external view returns (uint256)

setMinMargin

Set the minimum margin increment for all positions

function setMinMargin(uint256 _minMargin) external
Dev note

USD value of minMargin * liquidationThreshold * liquidationBounty should be greater than the typical USD value of gas to call liquidatePosition when the network is congested.

Parameters

NameTypeDescription
_minMarginuint256Prevent actions that would create a position with less than this much collateral

isTradeEnabled

function isTradeEnabled() external view returns (bool)

setTradeEnabled

Enable or disable trading

function setTradeEnabled(bool _isTradeEnabled) external

Parameters

NameTypeDescription
_isTradeEnabledboolWhether positions can be created/increased or not

maxShift

function maxShift() external view returns (FPUnsigned)

setMaxShift

Set max exposure-balancing slippage. See maxShift

function setMaxShift(FPUnsigned _maxShift) external

Parameters

NameTypeDescription
_maxShiftFPUnsignedNew value for maxShift. 0-1%

minProfitTime

function minProfitTime() external view returns (uint256)

setMinProfitTime

Set delay before positions with < minProfit can be cashed out

function setMinProfitTime(uint256 _minProfitTime) external

Parameters

NameTypeDescription
_minProfitTimeuint256New value for minProfitTime

allowPublicLiquidator

function allowPublicLiquidator() external view returns (bool)

setAllowPublicLiquidator

Allow anybody to liquidate positions, or restrict it to approved addresses only

function setAllowPublicLiquidator(bool _allowPublicLiquidator) external

Parameters

NameTypeDescription
_allowPublicLiquidatorboolNew value for allowPublicLiquidator

isManagerOnlyForOpen

function isManagerOnlyForOpen() external view returns (bool)

setIsManagerOnlyForOpen

Restrict position increases to approved addresses, or open to all

function setIsManagerOnlyForOpen(bool _isManagerOnlyForOpen) external

Parameters

NameTypeDescription
_isManagerOnlyForOpenboolNew value for isManagerOnlyForOpen

isManagerOnlyForClose

function isManagerOnlyForClose() external view returns (bool)

setIsManagerOnlyForClose

Restrict position decreases to approved addresses, or open to all

function setIsManagerOnlyForClose(bool _isManagerOnlyForClose) external

Parameters

NameTypeDescription
_isManagerOnlyForCloseboolNew value for isManagerOnlyForClose

utilizationMultiplier

function utilizationMultiplier() external view returns (FPUnsigned)

setUtilizationMultiplier

Set the utilization multiplier. Open interest is restricted to utilizationMultiplier times the vault balance

function setUtilizationMultiplier(FPUnsigned _utilizationMultiplier) external

Parameters

NameTypeDescription
_utilizationMultiplierFPUnsignedNew value for utilizationMultiplier

maxExposureMultiplier

function maxExposureMultiplier() external view returns (FPUnsigned)

setMaxExposureMultiplier

Set the max exposure multiplier. Exposure in any product is limited to maxExposureMultiplier times its share of the vault-level max exposure.

function setMaxExposureMultiplier(FPUnsigned _maxExposureMultiplier) external

Parameters

NameTypeDescription
_maxExposureMultiplierFPUnsignedNew value, > 0, for maxExposureMultiplier.

helpfulShiftScaler

function helpfulShiftScaler() external view returns (FPUnsigned)

setHelpfulShiftScaler

Set helpfulShiftScaler. Prices are shifted in proportion to exposure. For "helpful" orders that reduce exposure, scale price shift.

function setHelpfulShiftScaler(FPUnsigned _helpfulShiftScaler) external
Dev note

This should be < 1. Set to 1 to disable.

Parameters

NameTypeDescription
_helpfulShiftScalerFPUnsignedNew value, >0, for helpfulShiftScaler.

maxPositionProfit

function maxPositionProfit() external view returns (FPUnsigned)

setMaxPositionProfit

function setMaxPositionProfit(FPUnsigned _maxPositionProfit) external

liquidators

function liquidators(address _liquidator) external view returns (bool)

setLiquidator

Register or deregister an address as an active liquidator

function setLiquidator(address _liquidator, bool _isActive) external

Parameters

NameTypeDescription
_liquidatoraddressAddress to (de)activate as a liquidator
_isActiveboolWhether it can liquidate when !allowPublicLiquidators

pauseTrading

Pause trading, preventing anyone from opening new positions or increasing existing ones. Guardian only.

function pauseTrading() external