Perpetual
Handle all the logic involving the pool. Interact with the CryptoSwap pool
Methods
DEFAULT_ADMIN_ROLE
Returns
_0
bytes32
undefined
EMERGENCY_ADMIN
Returns
_0
bytes32
undefined
GOVERNANCE
Returns
_0
bytes32
undefined
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
account
address
Trader
amount
uint256
Amount in vQuote (if LONG) or vBase (if SHORT) to sell. 18 decimals
minAmount
uint256
Minimum amount that the user is willing to accept. 18 decimals
direction
enum LibPerpetual.Side
Whether the trader wants to go in the LONG or SHORT direction overall
isLiquidation
bool
Transaction is a liquidation (true) or a regular transaction (false)
Returns
quoteProceeds
int256
undefined
baseProceeds
int256
undefined
profit
int256
undefined
tradingFeesPayed
int256
undefined
isPositionIncreased
bool
undefined
isPositionClosed
bool
undefined
clearingHouse
Clearing House contract
Returns
_0
contract IClearingHouse
undefined
curveCryptoViews
Curve Crypto Views
Returns
_0
contract ICurveCryptoViews
undefined
getGlobalPosition
Get global market position
Returns
_0
LibPerpetual.GlobalPosition
undefined
getLpLiquidity
Get the lp tokens owned by a Liquidity Provider
Parameters
account
address
Liquidity Provider
Returns
_0
uint256
undefined
getLpOpenNotional
Get the dollar value of the liquidity provided by a liquidity Provider
Parameters
account
address
Address of the LP
Returns
_0
int256
undefined
getLpPosition
Get the position of a liquidity provider
Parameters
account
address
Address to get the LP position from
Returns
_0
LibPerpetual.LiquidityProviderPosition
undefined
getLpPositionAfterWithdrawal
Get the (active) position of a liquidity provider after withdrawing liquidity
Parameters
account
address
Address to get the LP position from
Returns
_0
LibPerpetual.TraderPosition
undefined
getLpTradingFees
Get the trading fees earned by a LP
Parameters
account
address
Address of the liquidity provider
Returns
tradingFeesEarned
uint256
undefined
getLpUnrealizedPnL
Get the unrealized profit and loss of a LP
Parameters
account
address
Address of the liquidity provider
Returns
pnl
int256
undefined
getPendingPnL
Get the Profit and Loss of a user
Parameters
account
address
Address to get the pnL from
Returns
pnL
int256
undefined
getRoleAdmin
Returns the admin role that controls role
. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.
Parameters
role
bytes32
undefined
Returns
_0
bytes32
undefined
getTotalLiquidityProvided
Get the market total liquidity provided to the Crypto Swap pool
Returns
_0
uint256
undefined
getTraderPosition
Get the position of a trader
Parameters
account
address
Address to get the trading position from
Returns
_0
LibPerpetual.TraderPosition
undefined
getTraderUnrealizedPnL
Get the unrealized profit and loss of a trader
Parameters
account
address
Trader
Returns
pnl
int256
undefined
getUserDebt
Get the user debt of an user
Parameters
account
address
Address to get the pnL from
Returns
debt
int256
undefined
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
role
bytes32
undefined
account
address
undefined
hasRole
Returns true
if account
has been granted role
.
Parameters
role
bytes32
undefined
account
address
undefined
Returns
_0
bool
undefined
indexPrice
Return the current off-chain exchange rate for vBase/vQuote
Returns
_0
int256
undefined
insuranceFee
paid on dollar value of an opened position (used in ClearingHouse)
Returns
_0
int256
undefined
isEmergencyAdmin
Parameters
account
address
undefined
Returns
_0
bool
undefined
isGovernor
Parameters
account
address
undefined
Returns
_0
bool
undefined
isLpPositionOpen
Whether or not a LP position is opened
Parameters
account
address
Address of the LP
Returns
_0
bool
undefined
isTraderPositionOpen
Whether a trader position is opened or not
Parameters
account
address
Address of the trader
Returns
_0
bool
undefined
isTradingExpansionAllowed
wether opening and extending trading positions is allowed
Returns
_0
bool
undefined
lockPeriod
time when the liquidity provision has to be locked
Returns
_0
uint256
undefined
lpDebtCoef
lp debt coefficient
Returns
_0
int256
undefined
market
Curve CryptoSwap pool
Returns
_0
contract ICryptoSwap
undefined
marketCumulativeAmount
Returns
_0
int256
undefined
marketCumulativeAmountAtBeginningOfPeriod
Returns
_0
int256
undefined
marketPrice
Return the last traded price (used for TWAP)
Returns
_0
uint256
undefined
marketTwap
Market Time-weighted average price of base
Returns
_0
int128
undefined
maxBlockTradeAmount
max trade amount in one block
Returns
_0
uint256
undefined
maxLiquidityProvided
maximum liquidity which can be provided to the pool
Returns
_0
uint256
undefined
maxPosition
max position size (1/10 of maxBlockTradeAmount)
Returns
_0
uint256
undefined
oracleCumulativeAmount
Returns
_0
int256
undefined
oracleCumulativeAmountAtBeginningOfPeriod
Returns
_0
int256
undefined
oracleTwap
Oracle Time-weighted average price of base
Returns
_0
int128
undefined
pause
Pause the contract
Can only be called by Emergency Admin
paused
Returns true if the contract is paused, and false otherwise.
Returns
_0
bool
undefined
provideLiquidity
Provide liquidity to the pool
Parameters
account
address
Liquidity provider
amounts
uint256[2]
Amount of virtual tokens ([vQuote, vBase]) provided. 18 decimals
minLpAmount
uint256
Minimum amount of Lp tokens minted. 18 decimals
Returns
tradingFees
int256
Generated profit generated from trading fees
removeLiquidity
Remove liquidity from the pool
Parameters
account
address
Account of the LP to remove liquidity from
liquidityAmountToRemove
uint256
Amount of liquidity to be removed from the pool. 18 decimals
minVTokenAmounts
uint256[2]
Minimum amount of virtual tokens [vQuote, vBase] to withdraw from the curve pool. 18 decimals
proposedAmount
uint256
Amount of tokens to be sold, in vBase if LONG, in vQuote if SHORT. 18 decimals
minAmount
uint256
Minimum amount that the user is willing to accept, in vQuote if LONG, in vBase if SHORT. 18 decimals
isLiquidation
bool
Transaction is a liquidation (true) or a regular transaction (false)
Returns
profit
int256
Profit realized
tradingFeesPayed
int256
undefined
reductionRatio
uint256
undefined
quoteProceeds
int256
undefined
isPositionClosed
bool
undefined
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
account
address
Liquidity Provider
liquidityAmountToRemove
uint256
Amount of liquidity to be removed from the pool. 18 decimals
minVTokenAmounts
uint256[2]
Minimum amount of virtual tokens [vQuote, vBase] to withdraw from the curve pool. 18 decimals
func
bytes
Encoded function call to call on the curve viewer contract
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
role
bytes32
undefined
account
address
undefined
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
role
bytes32
undefined
account
address
undefined
riskWeight
risk weight of the perpetual pair
Returns
_0
uint256
undefined
sensitivity
funding rate sensitivity to price deviations
Returns
_0
int256
undefined
setParameters
Parameters
params
IPerpetual.PerpetualParams
undefined
settleLpFunding
Settle funding payments for a liquidity providerUpdate the cumulative funding rate for the LP and return pending funding payments
Parameters
account
address
Liquidity Provider
Returns
fundingPayments
int256
Pending funding payments
settleTraderFunding
Settle funding payments for a traderUpdate the cumulative funding rate for the trader and return pending funding payments
Parameters
account
address
Trader
Returns
fundingPayments
int256
Pending funding payments
supportsInterface
See {IERC165-supportsInterface}.
Parameters
interfaceId
bytes4
undefined
Returns
_0
bool
undefined
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
toPause
bool
Whether to pause or not trading expansion operations
twapFrequency
period over which twap is calculated
Returns
_0
uint256
undefined
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
_0
contract IVBase
undefined
vQuote
vQuote token (traded on CryptoSwap pool)
Returns
_0
contract IVQuote
undefined
Events
DustGenerated
Emitted when (base) dust is generated
Parameters
vBaseAmount
int256
undefined
FundingPaid
Emitted when funding payments are exchanged for a trader / lp
Parameters
account indexed
address
undefined
amount
int256
undefined
globalCumulativeFundingRate
int256
undefined
userCumulativeFundingRate
int256
undefined
isTrader
bool
undefined
FundingRateUpdated
Emitted when funding rate is updated
Parameters
cumulativeFundingRate
int256
undefined
cumulativeFundingPerLpToken
int256
undefined
fundingRate
int256
undefined
Log
Emitted when swap with cryptoswap pool fails
Parameters
errorMessage
string
undefined
Paused
Parameters
account
address
undefined
PerpetualParametersChanged
Emitted when parameters are updated
Parameters
newRiskWeight
uint256
undefined
newMaxLiquidityProvided
uint256
undefined
newTwapFrequency
uint256
undefined
newSensitivity
int256
undefined
newMaxBlockTradeAmount
uint256
undefined
newInsuranceFee
int256
undefined
newLpDebtCoef
int256
undefined
lockPeriod
uint256
undefined
RoleAdminChanged
Parameters
role indexed
bytes32
undefined
previousAdminRole indexed
bytes32
undefined
newAdminRole indexed
bytes32
undefined
RoleGranted
Parameters
role indexed
bytes32
undefined
account indexed
address
undefined
sender indexed
address
undefined
RoleRevoked
Parameters
role indexed
bytes32
undefined
account indexed
address
undefined
sender indexed
address
undefined
TradingExpansionPauseToggled
Emitted when an admin pauses or unpause trading expansion operations
Parameters
admin
address
undefined
toPause
bool
undefined
TwapUpdated
Emitted when TWAP is updated
Parameters
newOracleTwap
int256
undefined
newMarketTwap
int256
undefined
Unpaused
Parameters
account
address
undefined
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
rAbs
uint256
undefined
PRBMathSD59x18__MulInputTooSmall
Emitted when one of the inputs is MIN_SD59x18.
PRBMathSD59x18__MulOverflow
Emitted when the intermediary absolute result overflows SD59x18.
Parameters
rAbs
uint256
undefined
PRBMath__MulDivFixedPointOverflow
Emitted when the result overflows uint256.
Parameters
prod1
uint256
undefined
PRBMath__MulDivOverflow
Emitted when the result overflows uint256.
Parameters
prod1
uint256
undefined
denominator
uint256
undefined
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
fee
int256
undefined
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
lockPeriod
uint256
undefined
Perpetual_LockPeriodNotReached
Emitted when the user attempts remove liquidity too early
Parameters
withdrawTime
uint256
undefined
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
lpDebtCoef
int256
undefined
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
maxBlockTradeAmount
uint256
undefined
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
riskWeight
uint256
undefined
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
sensitivity
int256
undefined
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
twapFrequency
uint256
undefined
Perpetual_VirtualTokenApprovalConstructor
Emitted when the constructor fails to give approval of a virtual token to the market
Parameters
tokenIndex
uint256
undefined
Perpetual_ZeroAddressConstructor
Emitted when the zero address is provided as a parameter in the constructor
Parameters
paramIndex
uint256
undefined
Last updated