IDomFiPerp
Addresses
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
)
May revert if the increase would revert.
Parameters
Name | Type | Description |
---|
user | address | Owner of the position |
positionLabel | PositionLabel | User-defined label of the position |
productId | ProductId | Product for this position. Required for new positions; ignored ONLY if modifying an existing position. |
margin | uint256 | Collateral added to the position by the increase |
isLong | bool | Whether position is long. Required for new positions; ignored ONLY if modifying an existing position. |
size | FPUnsigned | Size (margin * leverage) of the increase |
Return Values
Name | Type | Description |
---|
increasePreview | struct IExchangeDomain.IncreasePreview | Computed 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
Name | Type | Description |
---|
positionId | PositionId | Global ID of position to be decreased. Must exist. |
decreaseMargin | uint256 | Margin amount to decrease by. May be greater than position margin |
decreaseSize | FPUnsigned | Size to decrease by. May be greater than position size |
Return Values
Name | Type | Description |
---|
decreasePreview | struct IExchangeDomain.DecreasePreview | Computed 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
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. Ignored in favor of stored value if position already exists. |
margin | uint256 | Margin to increase this position by. |
isLong | bool | Direction of this position. Ignored in favor of stored value if position already exists. |
size | FPUnsigned | Size (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
Reverts if
- resulting position is liquidatable
- resulting position has
leverage < 1
or leverage > product.maxLeverage
- resulting position has margin < minMargin
- removeMargin > position.margin
Parameters
Name | Type | Description |
---|
positionId | PositionId | Position to remove margin from |
marginToRemove | uint256 | Collateral to remove from margin |
recipient | address | Send 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
Name | Type | Description |
---|
positionId | PositionId | Global ID of Position to check |
Return Values
Name | Type | Description |
---|
canRemove_ | bool | Whether it has margin available to withdraw |
removeableMargin | int256 | Available removal. Negative if !canRemove_ |
decreasePositions
Decrease (or close) multiple positions simultaneously. Fails unless all succeed.
function decreasePositions(struct IExchangeDomain.DecreasePositionParams[] params) external
Parameters
Name | Type | Description |
---|
params | struct 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
If margin >= position.margin
or size >= position.size
, close position.
Parameters
Name | Type | Description |
---|
positionId | PositionId | Target position. msg.sender must be its owner or their manager. |
margin | uint256 | Margin units to decrease |
size | FPUnsigned | |
recipient | address | Where 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
Name | Type | Description |
---|
productId | ProductId | ID of this product |
Return Values
Name | Type | Description |
---|
product | struct IExchangeDomain.Product | Saved parameters for this product |
getPosition
Get details of a position. See Position.
function getPosition(
PositionId globalPositionId
) external view returns (
struct IExchangeDomain.Position position
)
Parameters
Name | Type | Description |
---|
globalPositionId | PositionId | Global position ID |
Return Values
Name | Type | Description |
---|
position | struct IExchangeDomain.Position | Saved position |
getPosition
Get details of a user position. See Position.
function getPosition(
address account,
PositionLabel positionLabel
) external view returns (
struct IExchangeDomain.Position position
)
Parameters
Name | Type | Description |
---|
account | address | Owner of the position |
positionLabel | PositionLabel | User-defined label for this position |
Return Values
Name | Type | Description |
---|
position | struct IExchangeDomain.Position | Saved position |
getPositionId
Compute the global position ID of a user's position
function getPositionId(
address account,
PositionLabel positionLabel
) external view returns (
PositionId positionId
)
Parameters
Name | Type | Description |
---|
account | address | owner of this position |
positionLabel | PositionLabel | User-defined label for this position |
Return Values
Name | Type | Description |
---|
positionId | PositionId | Globally 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
Name | Type | Description |
---|
productWeight | FPUnsigned | product.weight ; determines vault balance allocated to this product |
productExposureMultiplier | FPUnsigned | multiple of product's vault share allowed for exposure |
Return Values
Name | Type | Description |
---|
maxExposure | FPUnsigned | permitted max exposure |
isManagerFor
Whether manager
is a registered manager approved by account
.
function isManagerFor(address manager, address account) external returns (bool isManager)
Parameters
Name | Type | Description |
---|
manager | address | Possible manager (for instance, an OrderBook) |
account | address | User that may have approved manager |
Return Values
Name | Type | Description |
---|
isManager | bool | Whether manager is a registered manager approved by account . |
validateOI
Revert if balance
times utilizationMultiplier is less than OI
function validateOI(uint256 balance) external view
Triggers after each transfer of dfUSDC
Parameters
Name | Type | Description |
---|
balance | uint256 | Balance of DomFiVault |
asset
Collateral token of this perp, e.g. USDC or wETH
function asset() external view returns (contract IERC20)
Return Values
Name | Type | Description |
---|
[0] | contract IERC20 | assetToken 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
Name | Type | Description |
---|
productId | ProductId | productId of position to evaluate |
isLong | bool | isLong of position to evaluate |
size | FPUnsigned | size of position to evaluate |
positionPrice | FPUnsigned | price of position to evaluate |
margin | uint256 | margin of position to evaluate |
funding | FPSigned | funding of position to evaluate |
price | FPUnsigned | Current price of the position's product |
Return Values
Name | Type | Description |
---|
pnl | FPSigned | Increase in position value since creation, minus funding |
fundingDebt | FPSigned | Accrued 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
Name | Type | Description |
---|
positionId | PositionId | Globally-unique ID of the position in question |
Return Values
Name | Type | Description |
---|
pnlRate | FPSigned | PnL 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)
Used for withdraw delays. Computed with composite positions.
Return Values
Name | Type | Description |
---|
[0] | FPSigned | totalPnl 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
This allows order bots to get price events without tracking oracle
changes.
Parameters
Name | Type | Description |
---|
productId | ProductId | ID of product with price update |
value | FPUnsigned | New price |
timestamp | uint64 | Timestamp at which price was generated |
oracle | address | Source of price update |