IExchange

  struct SwapParams(
    address trader
    address baseToken
    bool isBaseToQuote
    bool isExactInput
    bool isClose
    uint256 amount
    uint160 sqrtPriceLimitX96
  )

SwapResponsearrow-up-right

  struct SwapResponse(
    uint256 base
    uint256 quote
    int256 exchangedPositionSize
    int256 exchangedPositionNotional
    uint256 fee
    uint256 insuranceFundFee
    int256 pnlToBeRealized
    uint256 sqrtPriceAfterX96
    int24 tick
    bool isPartialClose
  )

SwapCallbackDataarrow-up-right

RealizePnlParamsarrow-up-right

The actual swap function

can only be called from ClearingHouse

Parameters:arrow-up-right

Name
Type
Description

params

struct IExchange.SwapParams

The parameters of the swap

Return Values:arrow-up-right

Name
Type
Description

swapResponse

struct IExchange.SwapResponse

The result of the swap

settleFundingarrow-up-right

Settle the funding payment for the time interval since the last settlement

This function should be called at the beginning of every high-level function, such as openPosition() while it doesn't matter who calls this function this function 1. settles personal funding payment 2. updates global funding growth personal funding payment is settled whenever there is pending funding payment the global funding growth update only happens once per unique timestamp (not blockNumber, due to Arbitrum)

Return Values:arrow-up-right

Name
Type
Description

fundingPayment

int256

the funding payment of a trader in one market should be settled into owned realized Pnl

fundingGrowthGlobal

struct Funding.Growth

the up-to-date globalFundingGrowth, usually used for later calculations

getMaxTickCrossedWithinBlockarrow-up-right

Get the max ticks allowed to be crossed within a block when reducing position

Parameters:arrow-up-right

Name
Type
Description

baseToken

address

Address of the base token

Return Values:arrow-up-right

Name
Type
Description

maxTickCrossedWithinBlock

uint24

The max ticks allowed to be crossed within a block when reducing position

getAllPendingFundingPaymentarrow-up-right

Get all the pending funding payment for a trader

Return Values:arrow-up-right

Name
Type
Description

pendingFundingPayment

int256

The pending funding payment of the trader.

Positive value means the trader pays funding, negative value means the trader receives funding.

isOverPriceSpreadarrow-up-right

Check if current price spread between market price and index twap is over maximum price spread.

Parameters:arrow-up-right

Name
Type
Description

baseToken

address

Address of the base token

Return Values:arrow-up-right

Name
Type
Description

true

bool

if over the maximum price spread

getPendingFundingPaymentarrow-up-right

Get the pending funding payment for a trader in a given market

this is the view version of _updateFundingGrowth()

Return Values:arrow-up-right

Name
Type
Description

pendingFundingPayment

int256

The pending funding payment of a trader in one market,

including liquidity & balance coefficients. Positive value means the trader pays funding, negative value means the trader receives funding.

getSqrtMarkTwapX96arrow-up-right

Deprecated function, will be removed in the next release, use getSqrtMarketTwapX96() instead Get the square root of the market twap price with the given time interval

The return value is a X96 number

Parameters:arrow-up-right

Name
Type
Description

baseToken

address

Address of the base token

twapInterval

uint32

The time interval in seconds

Return Values:arrow-up-right

Name
Type
Description

sqrtMarkTwapX96

uint160

The square root of the market twap price

getSqrtMarketTwapX96arrow-up-right

Get the square root of the market twap price with the given time interval

The return value is a X96 number

Parameters:arrow-up-right

Name
Type
Description

baseToken

address

Address of the base token

twapInterval

uint32

The time interval in seconds

Return Values:arrow-up-right

Name
Type
Description

sqrtMarketTwapX96

uint160

The square root of the market twap price

getPnlToBeRealizedarrow-up-right

Get the pnl that can be realized if trader reduce position

This function normally won't be needed by traders, but it might be useful for 3rd party

Parameters:arrow-up-right

Name
Type
Description

params

struct IExchange.RealizePnlParams

The params needed to do the query, encoded as RealizePnlParams in calldata

Return Values:arrow-up-right

Name
Type
Description

pnlToBeRealized

int256

The pnl that can be realized if trader reduce position

getOrderBookarrow-up-right

Get OrderBook contract address

Return Values:arrow-up-right

Name
Type
Description

orderBook

address

OrderBook contract address

getAccountBalancearrow-up-right

Get AccountBalance contract address

Return Values:arrow-up-right

Name
Type
Description

accountBalance

address

AccountBalance contract address

getClearingHouseConfigarrow-up-right

Get ClearingHouseConfig contract address

Return Values:arrow-up-right

Name
Type
Description

clearingHouse

address

ClearingHouseConfig contract address

FundingUpdatedarrow-up-right

Emitted when the global funding growth is updated

Parameters:arrow-up-right

Name
Type
Description

baseToken

address

Address of the base token

marketTwap

uint256

The market twap price when the funding growth is updated

indexTwap

uint256

The index twap price when the funding growth is updated

MaxTickCrossedWithinBlockChangedarrow-up-right

Emitted when maxTickCrossedWithinBlock is updated

Parameters:arrow-up-right

Name
Type
Description

baseToken

address

Address of the base token

maxTickCrossedWithinBlock

uint24

Max tick allowed to be crossed within block when reducing position

AccountBalanceChangedarrow-up-right

Emitted when accountBalance is updated

Parameters:arrow-up-right

Name
Type
Description

accountBalance

address

The address of accountBalance contract

Last updated