Developer Docs
Search
K

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

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

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

function clearingHouse() external view returns (contract IClearingHouse)
Clearing House contract

Returns

Name
Type
Description
_0
contract IClearingHouse
undefined

curveCryptoViews

function curveCryptoViews() external view returns (contract ICurveCryptoViews)
Curve Crypto Views

Returns

Name
Type
Description
_0
contract ICurveCryptoViews
undefined

getGlobalPosition

function getGlobalPosition() external view returns (struct LibPerpetual.GlobalPosition)
Get global market position

Returns

Name
Type
Description
_0
LibPerpetual.GlobalPosition
undefined

getLpLiquidity

function getLpLiquidity(address account) external view returns (uint256)
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

function getLpOpenNotional(address account) external view returns (int256)
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

function getLpPosition(address account) external view returns (struct LibPerpetual.LiquidityProviderPosition)
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

function getLpPositionAfterWithdrawal(address account) external view returns (struct LibPerpetual.TraderPosition)
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

function getLpTradingFees(address account) external view returns (uint256 tradingFeesEarned)
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

function getLpUnrealizedPnL(address account) external view returns (int256 pnl)
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

function getPendingPnL(address account) external view returns (int256 pnL)
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

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

Name
Type
Description
role
bytes32
undefined

Returns

Name
Type
Description
_0
bytes32
undefined

getTotalLiquidityProvided

function getTotalLiquidityProvided() external view returns (uint256)
Get the market total liquidity provided to the Crypto Swap pool

Returns

Name
Type
Description
_0
uint256
undefined

getTraderPosition

function getTraderPosition(address account) external view returns (struct LibPerpetual.TraderPosition)
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

function getTraderUnrealizedPnL(address account) external view returns (int256 pnl)
Get the unrealized profit and loss of a trader

Parameters

Name
Type
Description
account
address
Trader

Returns

Name
Type
Description
pnl
int256
undefined

getUserDebt

function getUserDebt(address account) external view returns (int256 debt)
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

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

Name
Type
Description
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

Name
Type
Description
role
bytes32
undefined
account
address
undefined

Returns

Name
Type
Description
_0
bool
undefined

indexPrice

function indexPrice() external view returns (int256)
Return the current off-chain exchange rate for vBase/vQuote

Returns

Name
Type
Description
_0
int256
undefined

insuranceFee

function insuranceFee() external view returns (int256)
paid on dollar value of an opened position (used in ClearingHouse)

Returns

Name
Type
Description
_0
int256
undefined

isEmergencyAdmin

function isEmergencyAdmin(address account) external view returns (bool)

Parameters

Name
Type
Description
account
address
undefined

Returns

Name
Type
Description
_0
bool
undefined

isGovernor

function isGovernor(address account) external view returns (bool)

Parameters

Name
Type
Description
account
address
undefined

Returns

Name
Type
Description
_0
bool
undefined

isLpPositionOpen

function isLpPositionOpen(address account) external view returns (bool)
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

function isTraderPositionOpen(address account) external view returns (bool)
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

function isTradingExpansionAllowed() external view returns (bool)
wether opening and extending trading positions is allowed

Returns

Name
Type
Description
_0
bool
undefined

lockPeriod

function lockPeriod() external view returns (uint256)
time when the liquidity provision has to be locked

Returns

Name
Type
Description
_0
uint256
undefined

lpDebtCoef

function lpDebtCoef() external view returns (int256)
lp debt coefficient

Returns

Name
Type
Description
_0
int256
undefined

market

function market() external view returns (contract ICryptoSwap)
Curve CryptoSwap pool

Returns

Name
Type
Description
_0
contract ICryptoSwap
undefined

marketCumulativeAmount

function marketCumulativeAmount() external view returns (int256)

Returns

Name
Type
Description
_0
int256
undefined

marketCumulativeAmountAtBeginningOfPeriod

function marketCumulativeAmountAtBeginningOfPeriod() external view returns (int256)

Returns

Name
Type
Description
_0
int256
undefined

marketPrice

function marketPrice() external view returns (uint256)
Return the last traded price (used for TWAP)

Returns

Name
Type
Description
_0
uint256
undefined

marketTwap

function marketTwap() external view returns (int128)
Market Time-weighted average price of base

Returns

Name
Type
Description
_0
int128
undefined

maxBlockTradeAmount

function maxBlockTradeAmount() external view returns (uint256)
max trade amount in one block

Returns

Name
Type
Description
_0
uint256
undefined

maxLiquidityProvided

function maxLiquidityProvided() external view returns (uint256)
maximum liquidity which can be provided to the pool

Returns

<