Exchange

InternalReplaySwapParams

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

InternalSwapResponse

  struct InternalSwapResponse(
    int256 base
    int256 quote
    int256 exchangedPositionSize
    int256 exchangedPositionNotional
    uint256 fee
    uint256 insuranceFundFee
    int24 tick
  )

InternalRealizePnlParams

  struct InternalRealizePnlParams(
    address trader
    address baseToken
    int256 takerPositionSize
    int256 takerOpenNotional
    int256 base
    int256 quote
  )

Functions

initialize

  function initialize(
  ) external

setAccountBalance

  function setAccountBalance(
    address AccountBalance
  ) external

Parameters:

NameTypeDescription

AccountBalance

address

contract address

setMaxTickCrossedWithinBlock

  function setMaxTickCrossedWithinBlock(
    address baseToken,
    uint24 maxTickCrossedWithinBlock
  ) external

Restrict the price impact by setting the ticks can be crossed within a block when trader reducing liquidity. It is used to prevent the malicious behavior of the malicious traders. The restriction is applied in _isOverPriceLimitWithTick()

Parameters:

NameTypeDescription

baseToken

address

The base token address

maxTickCrossedWithinBlock

uint24

The maximum ticks can be crossed within a block

uniswapV3SwapCallback

  function uniswapV3SwapCallback(
    int256 amount0Delta,
    int256 amount1Delta,
    bytes data
  ) external

Called to msg.sender after executing a swap via IUniswapV3Pool#swap.

This callback is forwarded to ClearingHouse.uniswapV3SwapCallback() because all the tokens are stored in there.

Parameters:

NameTypeDescription

amount0Delta

int256

The amount of token0 that was sent (negative) or must be received (positive) by the pool by

the end of the swap. If positive, the callback must send that amount of token0 to the pool. |amount1Delta | int256 | The amount of token1 that was sent (negative) or must be received (positive) by the pool by the end of the swap. If positive, the callback must send that amount of token1 to the pool. |data | bytes | Any data passed through by the caller via the IUniswapV3PoolActions#swap call

swap

  function swap(
    struct IExchange.SwapParams params
  ) external returns (struct IExchange.SwapResponse)

The actual swap function

can only be called from ClearingHouse

Parameters:

NameTypeDescription

params

struct IExchange.SwapParams

The parameters of the swap

Return Values:

NameTypeDescription

The

struct IExchange.SwapResponse

result of the swap

settleFunding

  function settleFunding(
  ) external returns (int256 fundingPayment, struct Funding.Growth fundingGrowthGlobal)

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:

NameTypeDescription

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

getOrderBook

  function getOrderBook(
  ) external returns (address)

Get OrderBook contract address

Return Values:

NameTypeDescription

orderBook

address

OrderBook contract address

getAccountBalance

  function getAccountBalance(
  ) external returns (address)

Get AccountBalance contract address

Return Values:

NameTypeDescription

accountBalance

address

AccountBalance contract address

getClearingHouseConfig

  function getClearingHouseConfig(
  ) external returns (address)

Get ClearingHouseConfig contract address

Return Values:

NameTypeDescription

clearingHouse

address

ClearingHouseConfig contract address

getMaxTickCrossedWithinBlock

  function getMaxTickCrossedWithinBlock(
    address baseToken
  ) external returns (uint24)

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

Parameters:

NameTypeDescription

baseToken

address

Address of the base token

Return Values:

NameTypeDescription

maxTickCrossedWithinBlock

uint24

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

getPnlToBeRealized

  function getPnlToBeRealized(
    struct IExchange.RealizePnlParams params
  ) external returns (int256)

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:

NameTypeDescription

params

struct IExchange.RealizePnlParams

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

Return Values:

NameTypeDescription

pnlToBeRealized

int256

The pnl that can be realized if trader reduce position

getAllPendingFundingPayment

  function getAllPendingFundingPayment(
  ) external returns (int256 pendingFundingPayment)

Get all the pending funding payment for a trader

Return Values:

NameTypeDescription

pendingFundingPayment

int256

The pending funding payment of the trader.

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

isOverPriceSpread

  function isOverPriceSpread(
    address baseToken
  ) external returns (bool)

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

Parameters:

NameTypeDescription

baseToken

address

Address of the base token

Return Values:

NameTypeDescription

true

bool

if over the maximum price spread

getSqrtMarkTwapX96

  function getSqrtMarkTwapX96(
    address baseToken,
    uint32 twapInterval
  ) external returns (uint160)

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:

NameTypeDescription

baseToken

address

Address of the base token

twapInterval

uint32

The time interval in seconds

Return Values:

NameTypeDescription

sqrtMarkTwapX96

uint160

The square root of the market twap price

getSqrtMarketTwapX96

  function getSqrtMarketTwapX96(
    address baseToken,
    uint32 twapInterval
  ) external returns (uint160)

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

The return value is a X96 number

Parameters:

NameTypeDescription

baseToken

address

Address of the base token

twapInterval

uint32

The time interval in seconds

Return Values:

NameTypeDescription

sqrtMarketTwapX96

uint160

The square root of the market twap price

getPendingFundingPayment

  function getPendingFundingPayment(
  ) public returns (int256)

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

this is the view version of _updateFundingGrowth()

Return Values:

NameTypeDescription

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.

Last updated