Perpetual

Handle all the logic involving the pool. Interact with the CryptoSwap pool

Methods

DEFAULT_ADMIN_ROLE

function DEFAULT_ADMIN_ROLE() external view returns (bytes32)

Returns

Name
Type
Description

_0

bytes32

undefined

EMERGENCY_ADMIN

function EMERGENCY_ADMIN() external view returns (bytes32)

Returns

Name
Type
Description

_0

bytes32

undefined

GOVERNANCE

function GOVERNANCE() external view returns (bytes32)

Returns

Name
Type
Description

_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

Name
Type
Description

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

Name
Type
Description

quoteProceeds

int256

undefined

baseProceeds

int256

undefined

profit

int256

undefined

tradingFeesPayed

int256

undefined

isPositionIncreased

bool

undefined

isPositionClosed

bool

undefined

clearingHouse

Clearing House contract

Returns

Name
Type
Description

_0

contract IClearingHouse

undefined

curveCryptoViews

Curve Crypto Views

Returns

Name
Type
Description

_0

contract ICurveCryptoViews

undefined

getGlobalPosition

Get global market position

Returns

Name
Type
Description

_0

LibPerpetual.GlobalPosition

undefined

getLpLiquidity

Get the lp tokens owned by a Liquidity Provider

Parameters

Name
Type
Description

account

address

Liquidity Provider

Returns

Name
Type
Description

_0

uint256

undefined

getLpOpenNotional

Get the dollar value of the liquidity provided by a liquidity Provider

Parameters

Name
Type
Description

account

address

Address of the LP

Returns

Name
Type
Description

_0

int256

undefined

getLpPosition

Get the position of a liquidity provider

Parameters

Name
Type
Description

account

address

Address to get the LP position from

Returns

Name
Type
Description

_0

LibPerpetual.LiquidityProviderPosition

undefined

getLpPositionAfterWithdrawal

Get the (active) position of a liquidity provider after withdrawing liquidity

Parameters

Name
Type
Description

account

address

Address to get the LP position from

Returns

Name
Type
Description

_0

LibPerpetual.TraderPosition

undefined

getLpTradingFees

Get the trading fees earned by a LP

Parameters

Name
Type
Description

account

address

Address of the liquidity provider

Returns

Name
Type
Description

tradingFeesEarned

uint256

undefined

getLpUnrealizedPnL

Get the unrealized profit and loss of a LP

Parameters

Name
Type
Description

account

address

Address of the liquidity provider

Returns

Name
Type
Description

pnl

int256

undefined

getPendingPnL

Get the Profit and Loss of a user

Parameters

Name
Type
Description

account

address

Address to get the pnL from

Returns

Name
Type
Description

pnL

int256

undefined

getRoleAdmin

Returns the admin role that controls role. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.

Parameters

Name
Type
Description

role

bytes32

undefined

Returns

Name
Type
Description

_0

bytes32

undefined

getTotalLiquidityProvided

Get the market total liquidity provided to the Crypto Swap pool

Returns

Name
Type
Description

_0

uint256

undefined

getTraderPosition

Get the position of a trader

Parameters

Name
Type
Description

account

address

Address to get the trading position from

Returns

Name
Type
Description

_0

LibPerpetual.TraderPosition

undefined

getTraderUnrealizedPnL

Get the unrealized profit and loss of a trader

Parameters

Name
Type
Description

account

address

Trader

Returns

Name
Type
Description

pnl

int256

undefined

getUserDebt

Get the user debt of an user

Parameters

Name
Type
Description

account

address

Address to get the pnL from

Returns

Name
Type
Description

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

Name
Type
Description

role

bytes32

undefined

account

address

undefined

hasRole

Returns true if account has been granted role.

Parameters

Name
Type
Description

role

bytes32

undefined

account

address

undefined

Returns

Name
Type
Description

_0

bool

undefined

indexPrice

Return the current off-chain exchange rate for vBase/vQuote

Returns

Name
Type
Description

_0

int256

undefined

insuranceFee

paid on dollar value of an opened position (used in ClearingHouse)

Returns

Name
Type
Description

_0

int256

undefined

isEmergencyAdmin

Parameters

Name
Type
Description

account

address

undefined

Returns

Name
Type
Description

_0

bool

undefined

isGovernor

Parameters

Name
Type
Description

account

address

undefined

Returns

Name
Type
Description

_0

bool

undefined

isLpPositionOpen

Whether or not a LP position is opened

Parameters

Name
Type
Description

account

address

Address of the LP

Returns

Name
Type
Description

_0

bool

undefined

isTraderPositionOpen

Whether a trader position is opened or not

Parameters

Name
Type
Description

account

address

Address of the trader

Returns

Name
Type
Description

_0

bool

undefined

isTradingExpansionAllowed

wether opening and extending trading positions is allowed

Returns

Name
Type
Description

_0

bool

undefined

lockPeriod

time when the liquidity provision has to be locked

Returns

Name
Type
Description

_0

uint256

undefined

lpDebtCoef

lp debt coefficient

Returns

Name
Type
Description

_0

int256

undefined

market

Curve CryptoSwap pool

Returns

Name
Type
Description

_0

contract ICryptoSwap

undefined

marketCumulativeAmount

Returns

Name
Type
Description

_0

int256

undefined

marketCumulativeAmountAtBeginningOfPeriod

Returns

Name
Type
Description

_0

int256

undefined

marketPrice

Return the last traded price (used for TWAP)

Returns

Name
Type
Description

_0

uint256

undefined

marketTwap

Market Time-weighted average price of base

Returns

Name
Type
Description

_0

int128

undefined

maxBlockTradeAmount

max trade amount in one block

Returns

Name
Type
Description

_0

uint256

undefined

maxLiquidityProvided

maximum liquidity which can be provided to the pool

Returns

Name
Type
Description

_0

uint256

undefined

maxPosition

max position size (1/10 of maxBlockTradeAmount)

Returns

Name
Type
Description

_0

uint256

undefined

oracleCumulativeAmount

Returns

Name
Type
Description

_0

int256

undefined

oracleCumulativeAmountAtBeginningOfPeriod

Returns

Name
Type
Description

_0

int256

undefined

oracleTwap

Oracle Time-weighted average price of base

Returns

Name
Type
Description

_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

Name
Type
Description

_0

bool

undefined

provideLiquidity

Provide liquidity to the pool

Parameters

Name
Type
Description

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

Name
Type
Description

tradingFees

int256

Generated profit generated from trading fees

removeLiquidity

Remove liquidity from the pool

Parameters

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

role

bytes32

undefined

account

address

undefined

riskWeight

risk weight of the perpetual pair

Returns

Name
Type
Description

_0

uint256

undefined

sensitivity

funding rate sensitivity to price deviations

Returns

Name
Type
Description

_0

int256

undefined

setParameters

Parameters

Name
Type
Description

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

Name
Type
Description

account

address

Liquidity Provider

Returns

Name
Type
Description

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

Name
Type
Description

account

address

Trader

Returns

Name
Type
Description

fundingPayments

int256

Pending funding payments

supportsInterface

See {IERC165-supportsInterface}.

Parameters

Name
Type
Description

interfaceId

bytes4

undefined

Returns

Name
Type
Description

_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

Name
Type
Description

toPause

bool

Whether to pause or not trading expansion operations

twapFrequency

period over which twap is calculated

Returns

Name
Type
Description

_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

Name
Type
Description

_0

contract IVBase

undefined

vQuote

vQuote token (traded on CryptoSwap pool)

Returns

Name
Type
Description

_0

contract IVQuote

undefined

Events

DustGenerated

Emitted when (base) dust is generated

Parameters

Name
Type
Description

vBaseAmount

int256

undefined

FundingPaid

Emitted when funding payments are exchanged for a trader / lp

Parameters

Name
Type
Description

account indexed

address

undefined

amount

int256

undefined

globalCumulativeFundingRate

int256

undefined

userCumulativeFundingRate

int256

undefined

isTrader

bool

undefined

FundingRateUpdated

Emitted when funding rate is updated

Parameters

Name
Type
Description

cumulativeFundingRate

int256

undefined

cumulativeFundingPerLpToken

int256

undefined

fundingRate

int256

undefined

Log

Emitted when swap with cryptoswap pool fails

Parameters

Name
Type
Description

errorMessage

string

undefined

Paused

Parameters

Name
Type
Description

account

address

undefined

PerpetualParametersChanged

Emitted when parameters are updated

Parameters

Name
Type
Description

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

Name
Type
Description

role indexed

bytes32

undefined

previousAdminRole indexed

bytes32

undefined

newAdminRole indexed

bytes32

undefined

RoleGranted

Parameters

Name
Type
Description

role indexed

bytes32

undefined

account indexed

address

undefined

sender indexed

address

undefined

RoleRevoked

Parameters

Name
Type
Description

role indexed

bytes32

undefined

account indexed

address

undefined

sender indexed

address

undefined

TradingExpansionPauseToggled

Emitted when an admin pauses or unpause trading expansion operations

Parameters

Name
Type
Description

admin

address

undefined

toPause

bool

undefined

TwapUpdated

Emitted when TWAP is updated

Parameters

Name
Type
Description

newOracleTwap

int256

undefined

newMarketTwap

int256

undefined

Unpaused

Parameters

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

rAbs

uint256

undefined

PRBMath__MulDivFixedPointOverflow

Emitted when the result overflows uint256.

Parameters

Name
Type
Description

prod1

uint256

undefined

PRBMath__MulDivOverflow

Emitted when the result overflows uint256.

Parameters

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

lockPeriod

uint256

undefined

Perpetual_LockPeriodNotReached

Emitted when the user attempts remove liquidity too early

Parameters

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

twapFrequency

uint256

undefined

Perpetual_VirtualTokenApprovalConstructor

Emitted when the constructor fails to give approval of a virtual token to the market

Parameters

Name
Type
Description

tokenIndex

uint256

undefined

Perpetual_ZeroAddressConstructor

Emitted when the zero address is provided as a parameter in the constructor

Parameters

Name
Type
Description

paramIndex

uint256

undefined

Last updated