Perpetual
Handle all the logic involving the pool. Interact with the CryptoSwap pool
Methods
DEFAULT_ADMIN_ROLE
Returns
EMERGENCY_ADMIN
Returns
GOVERNANCE
Returns
changePosition
Open or increase or reduce a position, either LONG or SHORT
Function can be used to extend or reduce a position. Reversing a position is prohibited.
Parameters
Returns
clearingHouse
Clearing House contract
Returns
curveCryptoViews
Curve Crypto Views
Returns
getGlobalPosition
Get global market position
Returns
getLpLiquidity
Get the lp tokens owned by a Liquidity Provider
Parameters
Returns
getLpOpenNotional
Get the dollar value of the liquidity provided by a liquidity Provider
Parameters
Returns
getLpPosition
Get the position of a liquidity provider
Parameters
Returns
getLpPositionAfterWithdrawal
Get the (active) position of a liquidity provider after withdrawing liquidity
Parameters
Returns
getLpTradingFees
Get the trading fees earned by a LP
Parameters
Returns
getLpUnrealizedPnL
Get the unrealized profit and loss of a LP
Parameters
Returns
getPendingPnL
Get the Profit and Loss of a user
Parameters
Returns
getRoleAdmin
Returns the admin role that controls role
. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.
Parameters
Returns
getTotalLiquidityProvided
Get the market total liquidity provided to the Crypto Swap pool
Returns
getTraderPosition
Get the position of a trader
Parameters
Returns
getTraderUnrealizedPnL
Get the unrealized profit and loss of a trader
Parameters
Returns
getUserDebt
Get the user debt of an user
Parameters
Returns
grantRole
Grants role
to account
. If account
had not been already granted role
, emits a {RoleGranted} event. Requirements: - the caller must have role
's admin role. May emit a {RoleGranted} event.
Parameters
hasRole
Returns true
if account
has been granted role
.
Parameters
Returns
indexPrice
Return the current off-chain exchange rate for vBase/vQuote
Returns
insuranceFee
paid on dollar value of an opened position (used in ClearingHouse)
Returns
isEmergencyAdmin
Parameters
Returns
isGovernor
Parameters
Returns
isLpPositionOpen
Whether or not a LP position is opened
Parameters
Returns
isTraderPositionOpen
Whether a trader position is opened or not
Parameters
Returns
isTradingExpansionAllowed
wether opening and extending trading positions is allowed
Returns
lockPeriod
time when the liquidity provision has to be locked
Returns
lpDebtCoef
lp debt coefficient
Returns
market
Curve CryptoSwap pool
Returns
marketCumulativeAmount
Returns
marketCumulativeAmountAtBeginningOfPeriod
Returns
marketPrice
Return the last traded price (used for TWAP)
Returns
marketTwap
Market Time-weighted average price of base
Returns
maxBlockTradeAmount
max trade amount in one block
Returns
maxLiquidityProvided
maximum liquidity which can be provided to the pool
Returns
maxPosition
max position size (1/10 of maxBlockTradeAmount)
Returns
oracleCumulativeAmount
Returns
oracleCumulativeAmountAtBeginningOfPeriod
Returns
oracleTwap
Oracle Time-weighted average price of base
Returns
pause
Pause the contract
Can only be called by Emergency Admin
paused
Returns true if the contract is paused, and false otherwise.
Returns
provideLiquidity
Provide liquidity to the pool
Parameters
Returns
removeLiquidity
Remove liquidity from the pool
Parameters
Returns
removeLiquiditySwap
Simulate removing liquidity from the curve pool to increase the slippage and then performs a single swap on the curve pool. Returns the proceeds from the trade with revert message
Used to compute the proposedAmount parameter needed for removing liquidityTo be statically called from ClearingHouseViewer.removeLiquiditySwap
Parameters
renounceRole
Revokes role
from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked role
, emits a {RoleRevoked} event. Requirements: - the caller must be account
. May emit a {RoleRevoked} event.
Parameters
revokeRole
Revokes role
from account
. If account
had been granted role
, emits a {RoleRevoked} event. Requirements: - the caller must have role
's admin role. May emit a {RoleRevoked} event.
Parameters
riskWeight
risk weight of the perpetual pair
Returns
sensitivity
funding rate sensitivity to price deviations
Returns
setParameters
Parameters
settleLpFunding
Settle funding payments for a liquidity providerUpdate the cumulative funding rate for the LP and return pending funding payments
Parameters
Returns
settleTraderFunding
Settle funding payments for a traderUpdate the cumulative funding rate for the trader and return pending funding payments
Parameters
Returns
supportsInterface
See {IERC165-supportsInterface}.
Parameters
Returns
toggleTradingExpansionPause
Allow/block trading operations tapping into the liquidity (i.e. opening and extending positions)Meant to be called once an agreed uppon minimum liquidity level is reached (or dropped back to)
Can only be called by Emergency Admin
Parameters
twapFrequency
period over which twap is calculated
Returns
unpause
Unpause the contract
Can only be called by Emergency Admin
updateGlobalState
Update the global state of the perpetual market
Can be called by offchain worker to update market conditions
vBase
vBase token (traded on CryptoSwap pool)
Returns
vQuote
vQuote token (traded on CryptoSwap pool)
Returns
Events
DustGenerated
Emitted when (base) dust is generated
Parameters
FundingPaid
Emitted when funding payments are exchanged for a trader / lp
Parameters
FundingRateUpdated
Emitted when funding rate is updated
Parameters
Log
Emitted when swap with cryptoswap pool fails
Parameters
Paused
Parameters
PerpetualParametersChanged
Emitted when parameters are updated
Parameters
RoleAdminChanged
Parameters
RoleGranted
Parameters
RoleRevoked
Parameters
TradingExpansionPauseToggled
Emitted when an admin pauses or unpause trading expansion operations
Parameters
TwapUpdated
Emitted when TWAP is updated
Parameters
Unpaused
Parameters
Errors
PRBMathSD59x18__AbsInputTooSmall
Emitted when the input is MIN_SD59x18.
PRBMathSD59x18__DivInputTooSmall
Emitted when one of the inputs is MIN_SD59x18.
PRBMathSD59x18__DivOverflow
Emitted when one of the intermediary unsigned results overflows SD59x18.
Parameters
PRBMathSD59x18__MulInputTooSmall
Emitted when one of the inputs is MIN_SD59x18.
PRBMathSD59x18__MulOverflow
Emitted when the intermediary absolute result overflows SD59x18.
Parameters
PRBMath__MulDivFixedPointOverflow
Emitted when the result overflows uint256.
Parameters
PRBMath__MulDivOverflow
Emitted when the result overflows uint256.
Parameters
Perpetual_AttemptReducePosition
Emitted when the user attempts to reduce their position using extendPosition
Perpetual_AttemptReversePosition
Emitted when the user attempts to reverse their position using changePosition
Perpetual_ExcessiveBlockTradeAmount
Emitted when the price impact of a position is too high
Perpetual_InsuranceFeeInvalid
Emitted when the proposed insurance fee is insufficient/excessive
Parameters
Perpetual_InvalidAdminFee
Emitted when the curve admin fee is invalid
Perpetual_LPOpenPosition
Emitted when the liquidity provider has an open position
Perpetual_LPWithdrawExceedsBalance
Emitted when the user attempts to withdraw more liquidity than they have deposited
Perpetual_LockPeriodInvalid
Emitted when the proposed lp lock period is insufficient/excessive
Parameters
Perpetual_LockPeriodNotReached
Emitted when the user attempts remove liquidity too early
Parameters
Perpetual_LpAmountDeviation
Emitted when the user attempts provide liquidity with skewed ratios
Perpetual_LpDebtCoefInvalid
Emitted when the proposed lp debt coefficient is insufficient/excessive
Parameters
Perpetual_MarketBalanceTooLow
Emitted when a token balance of the market is lte 1
Perpetual_MaxBlockAmountInvalid
Emitted when the proposed maximum block trade amount is insufficient
Parameters
Perpetual_MaxLiquidityProvided
Emitted when the max tvl is reached
Perpetual_MaxPositionSize
Emitted when the position exceeds the max position size
Perpetual_NoOpenPosition
Emitted when the user does not have an open position
Perpetual_RiskWeightInvalid
Emitted when the proposed market risk weight is insufficient/excessive
Parameters
Perpetual_SenderNotClearingHouse
Emitted when the sender is not the clearing house
Perpetual_SenderNotClearingHouseOwner
Emitted when the sender is not the clearing house owner
Perpetual_SensitivityInvalid
Emitted when the proposed funding rate sensitivity is insufficient/excessive
Parameters
Perpetual_TooMuchExposure
Emitted when the user attempts to open a too large short position
Perpetual_TradingExpansionPaused
Emitted when trading expansion operations are paused
Perpetual_TwapFrequencyInvalid
Emitted when the proposed twap frequency is insufficient/excessive
Parameters
Perpetual_VirtualTokenApprovalConstructor
Emitted when the constructor fails to give approval of a virtual token to the market
Parameters
Perpetual_ZeroAddressConstructor
Emitted when the zero address is provided as a parameter in the constructor
Parameters
Last updated