Contracts

KPerp.Exchange contracts
Kava EVM

Token contracts:

Trading pairs

KPE-USDC Elk Finance Pool: 0x9321922ae0e4Ad4642707cAc5bBaECF9C26f2B18

Core contracts:

Oracle contracts:

Peripheral contracts:

Referral contracts:

Reward contracts:

Trackers:

Staked + Bonus KPE (sbKPE): 0x9d1FBA576dcF223E89C065Ce8D081a4331397288
Staked + Bonus + Fee KPE (sbfKPE): 0xFB7FAB7F4B712eD3a45941F4611C846234165378
Fee + Staked KLP (fsKLP): 0xecEb9ac90B5D38a0D0Cd223245BDE2Dc67453690

Distributors:

Staking contracts:

Swap

To execute a swap:
  • Approve the Router contract for the token and amount you would like to swap
  • Call Router.swap with parameters:
    • _path: [tokenIn, tokenOut]
    • _amountIn: amount of tokenIn to swap
    • _minOut: minimum expected output amount
    • _receiver: address of the receiver of tokenOut
  • The function will revert if the amount of tokenOut sent to the receiver is less than _minOut
To get swap amounts before execution:
  • Call Reader.getMaxAmountIn with parameters:
    • _vault: address of the vault
    • _tokenIn: address of token that will be given
    • _tokenOut: address of token to be received
    • The max amount of tokenIn that can be swapped will be returned
  • Call Reader.getAmountOut with parameters:
    • _vault: address of the vault
    • _tokenIn: address of token that will be given
    • _tokenOut: address of token to be received
    • _amountIn: amount of tokenIn to swap
    • Two values will be returned, the first is the amount out after fees, and the second is the fee amount
    • The fee amount will be in terms of tokenOut

Query Available Amounts

The maximum sum of all position sizes is capped by the amount of tokens there are in the pool, for example, if the total sizes of all ETH long positions is 4,000,000 USD and the pool has 1000 ETH with 800 ETH reserved for the positions, then the maximum position size of a long position that can be opened would be 200 ETH worth.
Vault.poolAmounts(_token) can be used to retrieve the amount of tokens in the pool. Vault.reservedAmounts(_token) can be used to retrieve the reserved amount of tokens.
For shorts, the query would depend on the stablecoin token used to open the position.

Opening / Increasing a Position

To open or increase the size of an existing position:
  • Approve the Router contract for the token and amount you would deposit as collateral for the position
  • PositionManager.increasePosition can be called by partner contracts and will open the position in one transaction
  • Alternatively PositionRouter.createIncreasePosition can be used by any contract and will request the position to be opened, a keeper will then execute this request
  • PositionRouter.createIncreasePosition has the same input parameters but additionally has an executionFee value that can be set to PositionRouter.minExecutionFee. If the position cannot be opened at the specified "_price" value then the request will be cancelled and the funds sent back to the account that made the request
  • Call PositionManager.increasePosition with parameters:
    • _path: [tokenIn, collateralToken] or [tokenIn]
    • _indexToken: the address of the token you want to long or short
    • _amountIn: the amount of tokenIn you want to deposit as collateral
    • _minOut: the min amount of collateralToken to swap for
    • _sizeDelta: the USD value of the change in position size
    • _isLong: whether to long or short
    • _price: the USD value of the max (for longs) or min (for shorts) index price accepted when opening the position
  • _path allows swapping to the collateralToken if needed
  • For longs, the collateralToken must be the same as the indexToken
  • For shorts, the collateralToken can be any stablecoin token
  • _minOut can be zero if no swap is required
  • USD values for _sizeDelta and _price are multiplied by (10 ** 30), so for example to open a long position of size 1000 USD, the value 1000 * (10 ** 30) should be used

Closing / Decreasing a Position

To close or decrease an existing position:
  • PositionManager.decreasePosition can be called by partner contracts and will close or decrease the position in one transaction
  • Alternatively PositionRouter.createDecreasePosition can be used by any contract and will request the position to be closed / decreased, a keeper will then execute this request.
  • PositionRouter.createDecreasePosition has the same input parameters but additionally has an executionFee value that can be set to PositionRouter.minExecutionFee. If the position cannot be opened at the specified "_price" value then the request will be cancelled
  • Call Router.decreasePosition with parameters:
    • _collateralToken: the collateral token used
    • _indexToken: the index token of the position
    • _collateralDelta: the amount of collateral in USD value to withdraw
    • _sizeDelta: the USD value of the change in position size
    • _isLong: whether the position is a long or short
    • _receiver: the address to receive the withdrawn tokens
    • _price: the USD value of the min (for shorts) or max (for longs) index price accepted when decreasing the position
    • If _sizeDelta is the same size as the position, the collateral after adding profits or deducting losses will be sent to the receiver address

Positions List

A list of position details can be retrieved by calling Reader.getPositions
  • _vault: the vault contract address
  • _account: the account of the user
  • _collateralTokens: an array of collateralTokens
  • _indexTokens: an array of indexTokens
  • _isLong: an array of whether the position is a long position
The returned positions will be in the order of the query, for example, given the following inputs:
  • _collateralTokens: [WBTC.address, WETH.address, USDC.address]
  • _indexTokens: [WBTC.address, WETH.address, WBTC.address]
  • _isLong: [true, true, false]
The position details would be returned for
  • Long BTC position, positionIndex: 0
  • Long ETH position, positionIndex: 1
  • Short BTC position, positionIndex: 2
The returned array would be a list of values ordered by the positions:
  • size
    • position size in USD
    • value at: positionIndex * 9
  • collateral
    • position collateral in USD
    • value at: positionIndex * 9 + 1
  • averagePrice
    • average entry price of the position in USD
    • value at: positionIndex * 9 + 2
  • entryFundingRate
    • a snapshot of the cumulative funding rate at the time the position was entered
    • value at: positionIndex * 9 + 3
  • hasRealisedProfit
    • 1 if the position has a positive realised profit, 0 otherwise
    • value at: positionIndex * 9 + 4
  • realisedPnl
    • the realised PnL for the position in USD
    • value at: positionIndex * 9 + 5
  • lastIncreasedTime
    • timestamp of the last time the position was increased
    • value at: positionIndex * 9 + 6
  • hasProfit
    • 1 if the position is currently in profit, 0 otherwise
    • value at: positionIndex * 9 + 7
  • delta
    • amount of current profit or loss of the position in USD
    • value at: positionIndex * 9 + 8
Last modified 1yr ago