Kperp.Exchange
  • KPerp.Exchange
  • Trading
  • Tokenomics
  • KLP
  • Contracts
  • Rewards
  • Referral Program
  • Team
  • API
Powered by GitBook
On this page
  • Token contracts:
  • Trading pairs
  • Core contracts:
  • Oracle contracts:
  • Peripheral contracts:
  • Referral contracts:
  • Reward contracts:
  • Staking contracts:
  • Swap
  • Query Available Amounts
  • Opening / Increasing a Position
  • Closing / Decreasing a Position
  • Positions List

Contracts

KPerp.Exchange contracts

PreviousKLPNextRewards

Last updated 2 years ago

Kava EVM

Token contracts:

KPE

esKPE

USDK

KLP

Trading pairs

KPE-USDC Elk Finance Pool:

Core contracts:

KLPManager OrderBook

OrderExecutor

PositionManager

PositionRouter

Router

Vault

Oracle contracts:

Peripheral contracts:

Referral contracts:

Reward contracts:

Trackers:

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

VaultErrorController

VaultUtils

FastPriceEvents

FastPriceFeed

BatchSender

esKPEBatchSender

Timelock

TokenManager

OrderBookReader

Reader

RewardReader

VaultReader

ReferralReader

ReferralStorage

RewardRouter

Staked KPE (sKPE):

Staked + Bonus KPE (sbKPE):

Staked + Bonus + Fee KPE (sbfKPE):

Fee KLP (fKLP):

Fee + Staked KLP (fsKLP):

Staked KPE Distributor:

Bonus KPE Distributor:

Fee KPE Distributor:

Fee KLP Distributor:

Staked KLP Distributor:

KLPBalance

KPEVester

KLPVester

StakeManager

0xD92B90BcA03818634089f13891Bed8f707f6f0c0
0x04d3FdC7Cbe159C4AB62e3EFd964973ffcbd0e8d
0x7Af0e20C39c0b1B7E4F5372e4DFFfC0fc88B606B
0xDCb0F74a2e26380a52728b3da5bb3031DE96cEFb
0x12Fe6b85a38eAf48Fd59Cd3ad5b441B85B35b3b7
0x403C94FF5C79efcaae46760C5e3402C80DeB42d6
0xe36076A122c4089AEAdf3c63b2fA40f7FccD6E74
0xc143DBb36e40df93138E621608928Cb51E13330D
0x6fd9cCCb64C8Be97DE7798eDeAD22e074aea430A
0xb46B48daB7eFebEE44728E770ad84FcAC7168D81
0xD870Beb69169f58F73ec4B8f343c63464fa94590
0xcA78c665a581CdD473e204ad6Cd0476Fbd776877
0xB1583Abdf7FD520eFDA92a9A4f1d443fa54A500a
0xf1846c8DC06C6227007932413018c0D40EB25f80
0xcc9d37bDaF874Fa07c8598A95407FDE4d9f67725
0x0ccf044c5fc03b2527F1f2BBaa588bCb27158522
0x9d1FBA576dcF223E89C065Ce8D081a4331397288
0xFB7FAB7F4B712eD3a45941F4611C846234165378
0xCF4a5eAfc8B08C3bE1c4Be2343d1FB762a0C768F
0xecEb9ac90B5D38a0D0Cd223245BDE2Dc67453690
0x76704F7596502641FAe4038e3637fB5537A3Dac6
0x703103751053272a0F1bc0dD24da47248B5CC559
0xBAcA4D520400B586BfcEbA25B1BFbe9C65457c1f
0xE7b9136606021720A9D6AE2712b2F4dc3945e382
0xDFfFBb896dd7994326E9f37DfF1a79C8Bfd5dDA9
0x56e6F78d69411E802AABf6535a7cA9900595626a
0x1c02a02496a09c8c2B9DDa021464db6C7E032095
0x580E7B6F201DfC10467Ff6C196A765F43a8a227f
0x60dD5C3c9F2eC7D2eA3b1b067f47b615f25eb44A
0x3817e3f374bABcB0CFa5A39EB59d97aDc6812098
0xbf1E247cc2B36b3f3caE91bEd258EDa9788d933f
0x8ac8F87Be61728249B0669146A9b868caa0AFE8A
0xEbA6FC17194125aD68e7f7c912475065c388c21D
0x9321922ae0e4Ad4642707cAc5bBaECF9C26f2B18
0x06aFA60dA872F95edE503Bd27543E3Eb2dc77695
0x038058327BE336Eb3dD8daD182B196752B648bB3
0x6fd9cCCb64C8Be97DE7798eDeAD22e074aea430A
0x20DbB1e71E98Cf0906E9eA7675911b937A1C68F8
0x91E4701186E1640121F3DC88e57D2E530ad427C0
0x546E383CCaBdcCf348e2239e202566e7b824DF97
0xA64227152CBF5f0F9d48E8a54a28D0DDBd8D5e38
Page cover image