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
_0
bytes32
undefined
EMERGENCY_ADMIN
function EMERGENCY_ADMIN() external view returns (bytes32)
Returns
_0
bytes32
undefined
GOVERNANCE
function GOVERNANCE() external view returns (bytes32)
Returns
_0
bytes32
undefined
changePosition
function changePosition(address account, uint256 amount, uint256 minAmount, enum LibPerpetual.Side direction, bool isLiquidation) external nonpayable returns (int256 quoteProceeds, int256 baseProceeds, int256 profit, int256 tradingFeesPayed, bool isPositionIncreased, bool isPositionClosed)
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
function clearingHouse() external view returns (contract IClearingHouse)
Clearing House contract
Returns
_0
contract IClearingHouse
undefined
curveCryptoViews
function curveCryptoViews() external view returns (contract ICurveCryptoViews)
Curve Crypto Views
Returns
_0
contract ICurveCryptoViews
undefined
getGlobalPosition
function getGlobalPosition() external view returns (struct LibPerpetual.GlobalPosition)
Get global market position
Returns
_0
LibPerpetual.GlobalPosition
undefined
getLpLiquidity
function getLpLiquidity(address account) external view returns (uint256)
Get the lp tokens owned by a Liquidity Provider
Parameters
account
address
Liquidity Provider
Returns
_0
uint256
undefined
getLpOpenNotional
function getLpOpenNotional(address account) external view returns (int256)
Get the dollar value of the liquidity provided by a liquidity Provider
Parameters
account
address
Address of the LP
Returns
_0
int256
undefined
getLpPosition
function getLpPosition(address account) external view returns (struct LibPerpetual.LiquidityProviderPosition)
Get the position of a liquidity provider
Parameters
account
address
Address to get the LP position from
Returns
_0
LibPerpetual.LiquidityProviderPosition
undefined
getLpPositionAfterWithdrawal
function getLpPositionAfterWithdrawal(address account) external view returns (struct LibPerpetual.TraderPosition)
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
function getLpTradingFees(address account) external view returns (uint256 tradingFeesEarned)
Get the trading fees earned by a LP
Parameters
account
address
Address of the liquidity provider
Returns
tradingFeesEarned
uint256
undefined
getLpUnrealizedPnL
function getLpUnrealizedPnL(address account) external view returns (int256 pnl)
Get the unrealized profit and loss of a LP
Parameters
account
address
Address of the liquidity provider
Returns
pnl
int256
undefined
getPendingPnL
function getPendingPnL(address account) external view returns (int256 pnL)
Get the Profit and Loss of a user
Parameters
account
address
Address to get the pnL from
Returns
pnL
int256
undefined
getRoleAdmin
function getRoleAdmin(bytes32 role) external view returns (bytes32)
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
function getTotalLiquidityProvided() external view returns (uint256)
Get the market total liquidity provided to the Crypto Swap pool
Returns
_0
uint256
undefined
getTraderPosition
function getTraderPosition(address account) external view returns (struct LibPerpetual.TraderPosition)
Get the position of a trader
Parameters
account
address
Address to get the trading position from
Returns
_0
LibPerpetual.TraderPosition
undefined
getTraderUnrealizedPnL
function getTraderUnrealizedPnL(address account) external view returns (int256 pnl)
Get the unrealized profit and loss of a trader
Parameters
account
address
Trader
Returns
pnl
int256
undefined
getUserDebt
function getUserDebt(address account) external view returns (int256 debt)
Get the user debt of an user
Parameters
account
address
Address to get the pnL from
Returns
debt
int256
undefined
grantRole
function grantRole(bytes32 role, address account) external nonpayable
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
function hasRole(bytes32 role, address account) external view returns (bool)
Returns true
if account
has been granted role
.
Parameters
role
bytes32
undefined
account
address
undefined
Returns
_0
bool
undefined
indexPrice
function indexPrice() external view returns (int256)
Return the current off-chain exchange rate for vBase/vQuote
Returns
_0
int256
undefined
insuranceFee
function insuranceFee() external view returns (int256)
paid on dollar value of an opened position (used in ClearingHouse)
Returns
_0
int256
undefined
isEmergencyAdmin
function isEmergencyAdmin(address account) external view returns (bool)
Parameters
account
address
undefined
Returns
_0
bool
undefined
isGovernor
function isGovernor(address account) external view returns (bool)
Parameters
account
address
undefined
Returns
_0
bool
undefined
isLpPositionOpen
function isLpPositionOpen(address account) external view returns (bool)
Whether or not a LP position is opened
Parameters
account
address
Address of the LP
Returns
_0
bool
undefined
isTraderPositionOpen
function isTraderPositionOpen(address account) external view returns (bool)
Whether a trader position is opened or not
Parameters
account
address
Address of the trader
Returns
_0
bool
undefined
isTradingExpansionAllowed
function isTradingExpansionAllowed() external view returns (bool)
wether opening and extending trading positions is allowed
Returns
_0
bool
undefined
lockPeriod
function lockPeriod() external view returns (uint256)
time when the liquidity provision has to be locked
Returns
_0
uint256
undefined
lpDebtCoef
function lpDebtCoef() external view returns (int256)
lp debt coefficient
Returns
_0
int256
undefined
market
function market() external view returns (contract ICryptoSwap)
Curve CryptoSwap pool
Returns
_0
contract ICryptoSwap
undefined
marketCumulativeAmount
function marketCumulativeAmount() external view returns (int256)
Returns
_0
int256
undefined
marketCumulativeAmountAtBeginningOfPeriod
function marketCumulativeAmountAtBeginningOfPeriod() external view returns (int256)
Returns
_0
int256
undefined
marketPrice
function marketPrice() external view returns (uint256)
Return the last traded price (used for TWAP)
Returns
_0
uint256
undefined
marketTwap
function marketTwap() external view returns (int128)
Market Time-weighted average price of base
Returns
_0
int128
undefined
maxBlockTradeAmount
function maxBlockTradeAmount() external view returns (uint256)
max trade amount in one block
Returns
_0
uint256
undefined
maxLiquidityProvided
function maxLiquidityProvided() external view returns (uint256)
maximum liquidity which can be provided to the pool
Returns
_0
uint256
undefined
maxPosition
function maxPosition() external view returns (uint256)
max position size (1/10 of maxBlockTradeAmount)
Returns
_0
uint256
undefined
oracleCumulativeAmount
function oracleCumulativeAmount() external view returns (int256)
Returns
_0
int256
undefined
oracleCumulativeAmountAtBeginningOfPeriod
function oracleCumulativeAmountAtBeginningOfPeriod() external view returns (int256)
Returns
_0
int256
undefined
oracleTwap
function oracleTwap() external view returns (int128)
Oracle Time-weighted average price of base
Returns
_0
int128
undefined
pause
function pause() external nonpayable
Pause the contract
Can only be called by Emergency Admin
paused
function paused() external view returns (bool)
Returns true if the contract is paused, and false otherwise.
Returns
_0
bool
undefined
provideLiquidity
function provideLiquidity(address account, uint256[2] amounts, uint256 minLpAmount) external nonpayable returns (int256 tradingFees)
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
function removeLiquidity(address account, uint256 liquidityAmountToRemove, uint256[2] minVTokenAmounts, uint256 proposedAmount, uint256 minAmount, bool isLiquidation) external nonpayable returns (int256 profit, int256 tradingFeesPayed, uint256 reductionRatio, int256 quoteProceeds, bool isPositionClosed)
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
function removeLiquiditySwap(address account, uint256 liquidityAmountToRemove, uint256[2] minVTokenAmounts, bytes func) external nonpayable
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
function renounceRole(bytes32 role, address account) external nonpayable
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
function revokeRole(bytes32 role, address account) external nonpayable
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
function riskWeight() external view returns (uint256)
risk weight of the perpetual pair
Returns
_0
uint256
undefined
sensitivity
function sensitivity() external view returns (int256)
funding rate sensitivity to price deviations
Returns
_0
int256
undefined
setParameters
function setParameters(IPerpetual.PerpetualParams params) external nonpayable
Parameters
params
IPerpetual.PerpetualParams
undefined
settleLpFunding
function settleLpFunding(address account) external nonpayable returns (int256 fundingPayments)
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
function settleTraderFunding(address account) external nonpayable returns (int256 fundingPayments)
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
function supportsInterface(bytes4 interfaceId) external view returns (bool)
See {IERC165-supportsInterface}.
Parameters
interfaceId
bytes4
undefined
Returns
_0
bool
undefined
toggleTradingExpansionPause
function toggleTradingExpansionPause(bool toPause) external nonpayable
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
function twapFrequency() external view returns (uint256)
period over which twap is calculated
Returns
_0
uint256
undefined
unpause
function unpause() external nonpayable
Unpause the contract
Can only be called by Emergency Admin
updateGlobalState
function updateGlobalState() external nonpayable
Update the global state of the perpetual market
Can be called by offchain worker to update market conditions
vBase
function vBase() external view returns (contract IVBase)
vBase token (traded on CryptoSwap pool)
Returns
_0
contract IVBase
undefined
vQuote
function vQuote() external view returns (contract IVQuote)
vQuote token (traded on CryptoSwap pool)
Returns
_0
contract IVQuote
undefined
Events
DustGenerated
event DustGenerated(int256 vBaseAmount)
Emitted when (base) dust is generated
Parameters
vBaseAmount
int256
undefined
FundingPaid
event FundingPaid(address indexed account, int256 amount, int256 globalCumulativeFundingRate, int256 userCumulativeFundingRate, bool isTrader)
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
event FundingRateUpdated(int256 cumulativeFundingRate, int256 cumulativeFundingPerLpToken, int256 fundingRate)
Emitted when funding rate is updated
Parameters
cumulativeFundingRate
int256
undefined
cumulativeFundingPerLpToken
int256
undefined
fundingRate
int256
undefined
Log
event Log(string errorMessage)
Emitted when swap with cryptoswap pool fails
Parameters
errorMessage
string
undefined
Paused
event Paused(address account)
Parameters
account
address
undefined
PerpetualParametersChanged
event PerpetualParametersChanged(uint256 newRiskWeight, uint256 newMaxLiquidityProvided, uint256 newTwapFrequency, int256 newSensitivity, uint256 newMaxBlockTradeAmount, int256 newInsuranceFee, int256 newLpDebtCoef, uint256 lockPeriod)
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
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole)
Parameters
role indexed
bytes32
undefined
previousAdminRole indexed
bytes32
undefined
newAdminRole indexed
bytes32
undefined
RoleGranted
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender)
Parameters
role indexed
bytes32
undefined
account indexed
address
undefined
sender indexed
address
undefined
RoleRevoked
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender)
Parameters
role indexed
bytes32
undefined
account indexed
address
undefined
sender indexed
address
undefined
TradingExpansionPauseToggled
event TradingExpansionPauseToggled(address admin, bool toPause)
Emitted when an admin pauses or unpause trading expansion operations
Parameters
admin
address
undefined
toPause
bool
undefined
TwapUpdated
event TwapUpdated(int256 newOracleTwap, int256 newMarketTwap)
Emitted when TWAP is updated
Parameters
newOracleTwap
int256
undefined
newMarketTwap
int256
undefined
Unpaused
event Unpaused(address account)
Parameters
account
address
undefined
Errors
PRBMathSD59x18__AbsInputTooSmall
error PRBMathSD59x18__AbsInputTooSmall()
Emitted when the input is MIN_SD59x18.
PRBMathSD59x18__DivInputTooSmall
error PRBMathSD59x18__DivInputTooSmall()
Emitted when one of the inputs is MIN_SD59x18.
PRBMathSD59x18__DivOverflow
error PRBMathSD59x18__DivOverflow(uint256 rAbs)
Emitted when one of the intermediary unsigned results overflows SD59x18.
Parameters
rAbs
uint256
undefined
PRBMathSD59x18__MulInputTooSmall
error PRBMathSD59x18__MulInputTooSmall()
Emitted when one of the inputs is MIN_SD59x18.
PRBMathSD59x18__MulOverflow
error PRBMathSD59x18__MulOverflow(uint256 rAbs)
Emitted when the intermediary absolute result overflows SD59x18.
Parameters
rAbs
uint256
undefined
PRBMath__MulDivFixedPointOverflow
error PRBMath__MulDivFixedPointOverflow(uint256 prod1)
Emitted when the result overflows uint256.
Parameters
prod1
uint256
undefined
PRBMath__MulDivOverflow
error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator)
Emitted when the result overflows uint256.
Parameters
prod1
uint256
undefined
denominator
uint256
undefined
Perpetual_AttemptReducePosition
error Perpetual_AttemptReducePosition()
Emitted when the user attempts to reduce their position using extendPosition
Perpetual_AttemptReversePosition
error Perpetual_AttemptReversePosition()
Emitted when the user attempts to reverse their position using changePosition
Perpetual_ExcessiveBlockTradeAmount
error Perpetual_ExcessiveBlockTradeAmount()
Emitted when the price impact of a position is too high
Perpetual_InsuranceFeeInvalid
error Perpetual_InsuranceFeeInvalid(int256 fee)
Emitted when the proposed insurance fee is insufficient/excessive
Parameters
fee
int256
undefined
Perpetual_InvalidAdminFee
error Perpetual_InvalidAdminFee()
Emitted when the curve admin fee is invalid
Perpetual_LPOpenPosition
error Perpetual_LPOpenPosition()
Emitted when the liquidity provider has an open position
Perpetual_LPWithdrawExceedsBalance
error Perpetual_LPWithdrawExceedsBalance()
Emitted when the user attempts to withdraw more liquidity than they have deposited
Perpetual_LockPeriodInvalid
error Perpetual_LockPeriodInvalid(uint256 lockPeriod)
Emitted when the proposed lp lock period is insufficient/excessive
Parameters
lockPeriod
uint256
undefined
Perpetual_LockPeriodNotReached
error Perpetual_LockPeriodNotReached(uint256 withdrawTime)
Emitted when the user attempts remove liquidity too early
Parameters
withdrawTime
uint256
undefined
Perpetual_LpAmountDeviation
error Perpetual_LpAmountDeviation()
Emitted when the user attempts provide liquidity with skewed ratios
Perpetual_LpDebtCoefInvalid
error Perpetual_LpDebtCoefInvalid(int256 lpDebtCoef)
Emitted when the proposed lp debt coefficient is insufficient/excessive
Parameters
lpDebtCoef
int256
undefined
Perpetual_MarketBalanceTooLow
error Perpetual_MarketBalanceTooLow()
Emitted when a token balance of the market is lte 1
Perpetual_MaxBlockAmountInvalid
error Perpetual_MaxBlockAmountInvalid(uint256 maxBlockTradeAmount)
Emitted when the proposed maximum block trade amount is insufficient
Parameters
maxBlockTradeAmount
uint256
undefined
Perpetual_MaxLiquidityProvided
error Perpetual_MaxLiquidityProvided()
Emitted when the max tvl is reached
Perpetual_MaxPositionSize
error Perpetual_MaxPositionSize()
Emitted when the position exceeds the max position size
Perpetual_NoOpenPosition
error Perpetual_NoOpenPosition()
Emitted when the user does not have an open position
Perpetual_RiskWeightInvalid
error Perpetual_RiskWeightInvalid(uint256 riskWeight)
Emitted when the proposed market risk weight is insufficient/excessive
Parameters
riskWeight
uint256
undefined
Perpetual_SenderNotClearingHouse
error Perpetual_SenderNotClearingHouse()
Emitted when the sender is not the clearing house
Perpetual_SenderNotClearingHouseOwner
error Perpetual_SenderNotClearingHouseOwner()
Emitted when the sender is not the clearing house owner
Perpetual_SensitivityInvalid
error Perpetual_SensitivityInvalid(int256 sensitivity)
Emitted when the proposed funding rate sensitivity is insufficient/excessive
Parameters
sensitivity
int256
undefined
Perpetual_TooMuchExposure
error Perpetual_TooMuchExposure()
Emitted when the user attempts to open a too large short position
Perpetual_TradingExpansionPaused
error Perpetual_TradingExpansionPaused()
Emitted when trading expansion operations are paused
Perpetual_TwapFrequencyInvalid
error Perpetual_TwapFrequencyInvalid(uint256 twapFrequency)
Emitted when the proposed twap frequency is insufficient/excessive
Parameters
twapFrequency
uint256
undefined
Perpetual_VirtualTokenApprovalConstructor
error Perpetual_VirtualTokenApprovalConstructor(uint256 tokenIndex)
Emitted when the constructor fails to give approval of a virtual token to the market
Parameters
tokenIndex
uint256
undefined
Perpetual_ZeroAddressConstructor
error Perpetual_ZeroAddressConstructor(uint256 paramIndex)
Emitted when the zero address is provided as a parameter in the constructor
Parameters
paramIndex
uint256
undefined
Last updated