# Overview

Pika Protocol is a decentralized perpetuals swap exchange on Ethereum layer 2 with:

* **High leverage**: support up to 200x leverage
* **Low slippage**: nearly zero slippage for all pairs
* **Support crypto and forex trading**: support over 25 trading pairs
* **Low fees:** built on Ethereum Layer 2 with low gas fee
* **Simple experience:** swap directly from your wallet without making any deposits

![](https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FoWS6Z97qwDaU48uGa7cl%2Fimage.png?alt=media\&token=aa1d589b-4647-4b36-b19a-d65dfd6eec80)

## **Links**

*Website:* [*https://pikaprotocol.com/*](https://pikaprotocol.com/)&#x20;

*Twitter:* [*https://twitter.com/PikaProtocol*](https://twitter.com/PikaProtocol)&#x20;

*Medium:* [*https://pikaprotocol.medium.com/*](https://pikaprotocol.medium.com/)&#x20;

*Data Dashboard:* [ ](https://dune.com/pika-protocol/pika-v4)[*https://dune.com/pika-protocol/pika-v4*](https://dune.com/pika-protocol/pika-v4)

*Historic Funding Rates:* [*https://dune.com/pika-protocol/pika-v4-funding-rates*](https://dune.com/pika-protocol/pika-v4-funding-rates)


# Features

## Low Slippage

Pika has its liquidity concentrated around the current oracle price, making it possible to achieve the same level of liquidity as top perpetual exchanges. This enables capital efficiency and minimum trade slippage without requiring too much exchange liquidity. Specifically, Pika has zero slippage for major pairs like ETH, BTC and forex.

## Pricing

Pika uses the [on-demand decentralized Pyth oracle](https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand) to decide the mark price. Whenever an order is submitted, the keepers will fetch the price from Pyth price feed and update the mark price onchain before executing the order. To safeguard the accuracy of the low latency oracle, Chainlink oracle is used for most of [the pairs](https://docs.chain.link/data-feeds/price-feeds/addresses?network=optimism) with a bid/ask spread whenever the low latency oracle is not updating or its price deviates too much(2%) from Chainlink prices. In addition, traders can set an allowed slippage for each order submission, to make sure the order is executed only if the mark price is within the allowed slippage range.&#x20;

Pika has zero slippage for ETH, BTC and forex pairs. The trading price for each is almost the same as the mark price.

For other pairs, the trade price is dynamically adjusted on top of mark price. The pricing is determined by these factors in real time:

#### $$Trade Price = Mark Price \* Slippage + Price Adjustment$$&#xD;

**Mark Price:** Pika gets the real-time fast oracle price as the base price.

**Slippage**: The trade slippage is calculated based on the virtual liquidity, trade amount and trade direction, using the xyk model.

**Price Adjustment:** To reduce the risks to the LPs, Pika has the mechanism to balance the open interest of longs and shorts. When there are more longs than shorts in the protocol, the bid price will increase slightly to incentivize fewer long positions, and vice versa.

## Trade Many Assets

Pika Protocol empowers users to trade both crypto and non-crypto assets with leverage. It can support any asset as long as there's a reliable price feed.&#x20;

## Simple Experience

Unlike many other derivatives exchanges, Pika allows traders to swap directly from their wallets without any depositing steps.

## Fees

Pika Protocol was launched on the Optimism network, providing users with low transaction costs relative to layer-1 Ethereum. Other than the user gas fee, there are two fee parts:

**Execution Fee**: A small execution fee(\~0.00025 ETH) is charged when an order is submitted, which is paid to keepers reponsible to execute the submitted orders with latest oracle update.

**Trade Fee**: A small trade fee (0.05% for ETH/BTC, 0.1% for other crypto pairs and 0.02% for forex) is charged for each trade. 50% of trade fees are distributed to the vault (liquidity providers) and 50% to the protocol.

## Funding Rate

Pika has a funding mechanism to balance the longs and shorts for each trading pair, reducing the risk for liquidity vault. When there are more longs than shorts, longs pay shorts, incentivizing more traders to short. When there are more shorts than longs, shorts pay longs, incentivizing more traders to long. Since the liquidity vault is always at the minority side, it always receives funding. The funding rate of each trading pair is updated every time a trade is made for that pair, and the funding is paid or received when positions are closed. Annual funding rate is calculated as follows:

$$
(openInterestLong - openInterestShort) \* fundingMultiplier / maxExposure
$$

`fundingMultiplier` is set to 2 for crypto and 0.2 for forex right now and `maxExposure` is the max long or short exposure allowed for each pair, which can be found at the `Detail` section of the trading page.

## Market, Limit and Stop Orders

Pika supports 3 types of orders: market, limit and stop. The market orders are sent to be executed immediately once it is submitted. For limit and stop orders, they are submitted to be stored in a smart contract instead of centralized servers, with the aim to be as trustless as possible, and are triggered by keeper bots once the price requirement is matched.

Take-profit and stop-loss orders are a special type of limit and stop orders, which can be created together to close positions within 1 transaction.

## Liquidation

If the Oracle price reaches the liquidation price, the position will be liquidated. The liquidation price of a position is calculated using this formula:

Long Position: $$entryPrice - (entryPrice \* (liquidationThreshold \* margin + funding) / positionSize$$

Short Position: $$entryPrice + (entryPrice \* (liquidationThreshold \* margin + funding) / positionSize$$

The liquidationThreshold is set to 80% as default. The remaining margin of the liquidated position are shared as reward among liquidators, liquidity providers, PIKA token stakers and Pika Protocol.

**Examples:**

For the 50x ETH long position with entry price at $4000, positon size as 8000 USDC with margin as 160 USDC, and current funding as 10 USDC, the liquidation price would be $3941((4000 - (4000 \* (0.8 \* 160 + 10) / 8000)). If a liquidator liquidates this position at $3941, $32(160 \* (1 - 0.8)) will be used to pay liquidators, protocol fees and liquidity providers.

For the 50x ETH short position with entry price at $4000, positon size as 8000 USDC with margin as 160 USDC, and current funding as -10 USDC, the liquidation price would be $4059(4000 + (4000 \* (0.8 \* 160 - 10) / 8000). If a liquidator liquidates this position at $4059, $32(160 \* (1 - 0.8)) will be used to pay liquidators, protocol fees and liquidity providers.

At the launch, Pika Protocol team will be the liquidator for all the positions.

## Liquidity Vault

The protocol is backed by the liquidity providers. By staking in the vault, liquidity providers take the opposite position of all traders on the platform. The vault pays for trader profits and receives trader losses. In addition, it also receives trading fees, funding payments and liquidation profit of trades.

To protect vault from big loss in highly volatile conditions, the vault has a `maxExposure` parameter for each trading pair. When the `maxExposure` is reached, traders cannot open the additional position that increases the vault's exposure, but can open the position in the direction that decreases the vault's exposure. This should rarely happen when the vault's liquidity is big enough.

The APY shown for the vault is calculated based on the fees distributed to vault in the last 7 days.


# Crypto, Forex and Commodity Trading

## Trading Fees

BTC and ETH have 0.05% trading fees and other crypto pairs have 0.1% trading fees. The forex and commodity pairs have 0.012% trading fees because of its lower volatility.

Traders are offered the opportunity to receive up to a 50% discount on these fees. The discount amount is determined based on the trading volume over the past 30 days, as well as the number of PIKA tokens staked by the trader. This is outlined in the following fee structure::<https://www.pikaprotocol.com/#/fees>

## Trading Hours

For crypto pairs, market is live 24/7.

For forex and commodity pairs, market is closed from Friday 4pm EDT to Sunday 5pm EDT, and closed on these holidays:&#x20;

* December 25th - 27th
* January 1st - 3rd

Traders cannot close positions using the UI when the market is closed and if they close it via smart contract, a big slippage will be involved.

## Stop Loss Orders

The stop loss orders for forex and commodity may not work if the market opens at a different price than the price it closed at last time it was open, which could results in unexpected liquidations or profit. Therefore, traders are recommended to be careful with keeping orders open when market is closed.


# User Guide


# Trading

## Getting USDC and ETH&#x20;

Traders need to have both USDC and ETH on Optimism network to open a trade. USDC is used as the margin token and ETH is used to pay for gas fee.

You can use any of these bridges to transfer tokens to Optimism network:

<https://www.pikaprotocol.com/#/bridge>

<https://hop.exchange/>

<https://gateway.optimism.io/>

[https://cbridge.celer.network/](https://cbridge.celer.network/#/transfer)

On Optimism network, you can use [Uniswap](https://uniswap.exchange/) to swap ETH to USDC or USDC to ETH.

## Opening Positions

Switch your Metamask wallet to the right blockchain and connect it to the trade page. Click the product list on the right and select the trading pair you want to trade.

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FrFEUTcz3VIj707Boh4gw%2Fimage.png?alt=media&amp;token=41c63a54-677e-4481-ae56-66f5f57b9aa5" alt=""></div>

### Place Market Order

After selecting the "Market" on the top right section, choose `LONG` or `SHORT` and input the `Size` of the trade you want to open. The value in blue is the maximum size you can open based on your available USDC balance and your selected leverage. The `Margin` amount is automatically calculated based on your size and selected leverage. The margin is the amount of USDC you will transfer as the margin for this trade.&#x20;

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2F7uR7guBoNX5KDkRvVnaO%2Fimage.png?alt=media&amp;token=a52996f8-1b1a-499e-89d8-283df168656b" alt=""></div>

After that, the summary of the trade is updated. `Mark Price` is the current oracle price. `Entry Price` is the estimated trade price if you open the trade. `Price Impact` is the estimated price impact of your trade. `Liquidation Price` is the estimated price of your position to get liquidated. `Trade Fee` is the trade fee to be charged. `Execution Fee` is the fee to cover the gas cost of Pika keeper. `Total Cost` is the sum of the margin, trade fee and execution fee.

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2F4k79WfIiTndbledHImYH%2Fimage.png?alt=media&amp;token=ce543df8-1abb-447a-9983-7e817fa43238" alt=""></div>

If it's your first time trading on Pika, you would need to approve Pika contract to transfer your USDC and enable Pika keepers to submit market orders for you by agreeing with the terms.

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FBxqbdMJWWkaxfQAVd92s%2Fimage.png?alt=media&amp;token=b59222ac-a101-41a4-b01f-162c520dd6dd" alt=""></div>

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2F3PhCFr7PkLhwqM2JPTSv%2Fimage.png?alt=media&amp;token=85e30a4b-0dec-4dc0-bc9b-14a6699ad07f" alt=""></div>

Then after clicking the `Submit` button, the confirmation will show up with the order details. Then you can check the details before you click `Confirm`. If `Allowed Slippage` is too low or the price is too volatile, your order may be cancelled. The slippage value can be set at the top right of the page.

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FmmonSLm6RgR2zOUCuZqm%2Fimage.png?alt=media&amp;token=d1a6efb5-a470-4989-b9df-55685587f44f" alt=""></div>

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FpQsUIMyYhLQe1sfkEU6R%2Fimage.png?alt=media&amp;token=2102093a-c61f-42ef-a781-3fc5c264df98" alt=""></div>

The submitted orders will be picked up within few seconds by keepers to be executed with the next oracle update. You will receive notifications when the order is executed successfully and then you can see the active positions. If the order fails to be executed, you will be notified of the reasons and the orders will be automatically cancelled.

### Place TP/SL Order

If you want to add take-profit and stop-loss orders for your position when creating the market order, you can select them and bundle them in one transaction.

<div align="left"><figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FzCVp9HbWe9gXNK16DUDH%2Fimage.png?alt=media&amp;token=d861324f-1e5f-4c03-847e-60ed26eb745e" alt=""><figcaption></figcaption></figure></div>

### Place Limit/Stop Order

Limit and stop order submissions work similarly as the market order. The only difference is you need to specify the trigger price for these orders.

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2Fo6VthxQfnhY5qEgvFrxa%2Fimage.png?alt=media&amp;token=177605d2-24d5-42f0-b84f-8c23f68fa1b3" alt=""></div>

The submitted limit and stop orders will show up in `Orders` tab, where you have the option to edit the price of each order or cancel it. If the order cannot be submitted by the keeper, it will have red error message and you need to cancel and resubmit the order.

![](https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2F82OHEkH2aqCWRGrqeJmW%2Fimage.png?alt=media\&token=633c5942-8c0a-4472-a406-758524383595)

## Managing Positions

After the order is successfully executed, the position appears in the `Active Position` list with the position details.

<figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FPJX4aYwJB2uNMZJYWpqG%2Fimage.png?alt=media&amp;token=460fd6a9-cf57-484d-a8d7-82c5d47de62e" alt=""><figcaption></figcaption></figure>

To add or remove margin for an existing position, click the `Edit` button and input the margin to add or withdraw. Click the `Submit` button to submit the transaction after confirming the new position details.

<figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FnSUgS0G6ptZsTsbH3E6q%2Fimage.png?alt=media&amp;token=ba88a679-6901-415a-85b5-69650cbb707b" alt=""><figcaption></figcaption></figure>

## Close a Position

To close a position, click the `Close` button of the position and then input the amount of the margin to close. Same as an open position, you have the option of `Market` and `TP/SL` order type. You can either close the whole position or close it partially.

<figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FKacUZNLtUmUSiP4Rn0Rj%2Fimage.png?alt=media&amp;token=5db02100-627a-48fe-86b3-1041e3428b26" alt=""><figcaption></figcaption></figure>

A trade record appears in the `Trade History` section after the position is closed, recording the position details.

![](https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FlAQvBpMsAQMjHrHqicbi%2Fimage.png?alt=media\&token=3ab8d528-09d5-43bc-b354-576dd6618e32)

## Trading Charts

The trading charts showcase real-time prices sourced from the Pyth oracle, allowing users to choose their desired chart granularity (1m, 5m, 15m, etc). Active positions' entry and liquidation prices are prominently displayed, along with trigger prices for both stop-loss and take-profit orders.

*Pika uses TradingView technology to display data on charts. TradingView is a charting platform for a global community of traders and investors, but it's especially valued by crypto enthusiasts: you can track detailed symbol charts, e.g.* [*BTC USD*](https://www.tradingview.com/symbols/BTCUSD/) *and* [*ETH USD*](https://www.tradingview.com/symbols/ETHUSD/) *to always stay on top of where the markets are moving and be prepared for a next trade.*


# Liquidity

By providing liquidity to the exchange, liquidity providers take the opposite position of all traders on the platform. The vault pays for trader profits and receives trader losses. In addition, it also receives trading fees, funding fee and liquidation profit of trades.

After clicking "Stake" button, users can input the amount of USDC to be staked. Note the liquidity is locked for 3 days before the withdraw is allowed.&#x20;

![](https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FFEVc35DYxpYdi3GKVSOF%2Fimage.png?alt=media\&token=16da7a85-cc95-4137-a33f-fbb76f9976a2)

After staking, the stake position will show up below. Your share balance is the USDC value of your position.&#x20;

$$
My Share Balance = Staked Value - Traders Pnl
$$

Your USDC Reward is the USDC fees you earned by staking.

$$
My USDC Reward = My Share Percent \*  (Trading Fee + Liquidation Reward) \* 0.5
$$

![](https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2F6oCRi8Ru76MxdRkO3sdZ%2Fimage.png?alt=media\&token=a3250158-c40c-4a1e-b684-27e49561945c)

You can click the "Unstake" button to withdraw your liquidity. If the utilization ratio is close to 100%, you might not be able to withdraw the liquidity until someone closes the trade position. This is to ensure the platform is always solvent. For the USDC reward, however, you can choose to "Claim" it or "Reinvest" back into the vault whenever you like.


# Handling Abnormal Scenarios

Pika is designed to protect users by preventing a central point of failure. It has a design in place to handle these three extremely rare scenarios: 1. orders are not being executed; 2. fast oracle is not providing accurate prices; 3. website is down.

## Orders are not being executed

If you notice your market orders are not executed a minute after submission and you do not see any error notification, it might be because the keepers are down. Your submitted orders will appear in the `Orders` tab with the type as `Market`. If you are opening new market orders, you can click the `Cancel` button to cancel the order 3 minutes after submission. If you are closing existing positions, you can choose either the execute the order with the latest price or cancel the order 3 minutes after submission. This allows the user to close positions or cancel orders even if rare cases when keepers stop working.

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FNA2Zrn60l9XWUlHbNDXy%2Fimage.png?alt=media&amp;token=b38a4a3f-e108-478f-8db0-5356aace01a6" alt=""></div>

## Website is down

Pika is a permissionless onchain protocol. In case the website is down for some unexpected reasons, you can still manage positions and liquidity via Etherscan. Please refer to the [Trading via Etherscan](/user-guide/trading-via-etherscan) on how to close positions or do other actions on Etherscan.

In around 10 seconds after submitting the close order, you can check your position on Etherscan. If your order is executed successfully, your active position will show up as 0s.

If the order is not executed, the position info will be shown as unchanged. This may happen because your `_acceptablePrice` value is too tight. If you think that is the reason, you can try to update `_acceptablePrice` to a lower value for close long and higher value for close short, and then calling `createClosePosition` function again.&#x20;

If that still does not close your position, it may be because the keepers stopped working. You can wait 3 minutes and then manually execute the order by calling `executeClosePosition` on <https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#code>.

<div align="left"><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FtatxBDKQpeueUjoJ2PrU%2Fimage.png?alt=media&amp;token=0656969e-a44f-470a-a952-d937646aed56" alt=""></div>

There are two steps to get the `_key` parameter:&#x20;

* Get index parameter by calling `closePositionIndex` function with your wallet address.

<figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2Fq5JJjEwxM66SWKcaaLb0%2Fimage.png?alt=media&amp;token=c2a97d82-8ed9-4c70-b628-94500f6ef63c" alt=""><figcaption></figcaption></figure>

* Use the `index` value from step 1 to call `getRequestKey` function with your wallet address.

<figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FlpcCDf1jRl2gS3zwt8hk%2Fimage.png?alt=media&amp;token=d9058d05-4bc2-41fc-8f6c-ee93db6360da" alt=""><figcaption></figcaption></figure>


# Trading via Etherscan

Pika Protocol is a fully decentralized and permission-less exchange, operated not by team, but by unstoppable code. In the rare case when the website server is down, you can always trade directly with the smart contract from block explorers like Etherscan.

## Preparation

If you have previously approved the contract in Pika UI, you can skip this step.

#### **Approve** Pika Contracts for USDC

To approve the contract, you first open the USDC contract on Etherscan: <https://optimistic.etherscan.io/token/0x7f5c764cbc14f9669b88837ca1490cca17c31607#writeContract>

Then clicks `Connect to Web` to connect to your Metamask wallet.

You need to click the Approve function 4 times to approve these 4 addresses:

1. PikaPerpV4 address: 0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB
2. PositionManager address: 0xb67c152e69217b5acb85a2e19df13423351b0e27
3. OrderBook address: 0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C
4. PositionRouter address: 0xa78Cd820b198A943199deb0506E77d655b5078cC

The `amount` is your intended trade amount. If you want to trade 100 USDC, the input amount should be 10000000000(100\*1e8).&#x20;

#### Enable Trading

You need to open the PikaPerpV4 contract: <https://optimistic.etherscan.io/address/0x9b86b2be8edb2958089e522fe0eb7dd5935975ab#code> and call `setAccountManager` twice to enable the trading for market, limit and stop orders:

1. Call `setAccountManager` function by setting `_manager` as the PositionManager contract address(0xb67c152e69217b5acb85a2e19df13423351b0e27) and `_isActive` is true.
2. Call the `setAccountManager` function by setting `_manager` as the OrderBook contract address(0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C) and `_isActive` is true.

To enable placing market orders together with take profit and stop loss orders, you need to send two additional transactions:

1. Open the positionManager contract: <https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27> and call `setAccountManager` function, `_manager` is the positionRouter contract: 0xa78Cd820b198A943199deb0506E77d655b5078cC
2. Open the orderbook contract: <https://optimistic.etherscan.io/address/0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C> and call `setAccountManager` function, `_manager` is the positionRouter contract: 0xa78Cd820b198A943199deb0506E77d655b5078cC

## Place a Market Order

#### Place an Open Market Order

Open the PositionManager contract at[ ](https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#writeContract)<https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#writeContract> and fill in the parameters for `createOpenPosition` function. The parameters are described below. Then you can click the `Write` button to confirm the transaction.

<table><thead><tr><th width="150">Parameters</th><th>Description</th></tr></thead><tbody><tr><td>createOpenPosition</td><td>The ether to pay for execution fee. The input should be 0.00025.</td></tr><tr><td>account</td><td>Your wallet address</td></tr><tr><td>productId</td><td>The number represents the intended trading pair. Please refer to <a data-mention href="/user-guide/trading-pairs">Trading Pairs</a> for the productId of each trading pair.</td></tr><tr><td>margin</td><td>It is the USDC margin for the position. <br>Note the intended margin amount needs to multiply 1e8 for the input. For example: 50 USDC margin's input is 5000000000.</td></tr><tr><td>leverage</td><td>It is the leverage of the position. The value needs to multiply 1e8 for the input (1000000000 represents 10x leverage).</td></tr><tr><td>isLong</td><td>It is the direction of the position.<br>If you want to close a long position, the input is "true".<br>If you want to close a short position, the input is "false"</td></tr><tr><td>acceptablePrice</td><td>It is the lowest acceptable price for open short or close long order, and highest acceptable price for open long or close short order. The order will be cancelled if the current price does not satisfy the acceptable price. Note the intended price needs to multiply 1e8 for the input.</td></tr><tr><td>executionFee</td><td>It is the execution fee paid to keepers to cover the gas fee of executing the order. The input amount should be 25000 (representing 0.00025ETH).</td></tr><tr><td>referralCode</td><td>It is the referral code of the trade. Put <code>0x0000000000000000000000000000000000000000000000000000000000000000</code> before the launch of referral program</td></tr></tbody></table>

#### Check the Position

In around 10 seconds after submitting the open order, you can check your position on Pika from PikaPerpV4 contract's `getPosition` function: <https://optimistic.etherscan.io/address/0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB#readContract>. Below is the description of each parameters.

<table><thead><tr><th width="150">Parameters</th><th>Description</th></tr></thead><tbody><tr><td>account</td><td>User wallet address</td></tr><tr><td>productId</td><td>The number represents the trading pair. Please refer to <a data-mention href="/user-guide/trading-pairs">Trading Pairs</a> for the productId of each trading pair.</td></tr><tr><td>isLong</td><td>It is the direction for the position.<br>If it is "true", your position is long.<br>If it is "false", your position is short.</td></tr></tbody></table>

The values in the return array represent: `productId`, `leverage`, `entryPrice`, `oraclePriceAtTheEntry` (can be ignored), `margin`, `ownerOfPosition`, `entryTimestamp`, `direction`, and `fundingAtTheEntry` (can be ignored).

For example, the position below is a 2x ETH Long with the margin of 30 USDC, with enty price at 1847.867, opened at the timestamp of 1691810315.

<figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FbHg95bzvr1kRZK4DFstr%2Fimage.png?alt=media&amp;token=79753924-9556-4b82-ba5d-fd9f21ea2da5" alt=""><figcaption></figcaption></figure>

If your open order is not executed successfully, your active position will show up as 0s.&#x20;

#### Place a Close Market Order

Open the PositionManager contract at <https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#writeContract> and fill in the parameters for `createClosePosition` function. The parameters are the same as those for `createOpenPosition` mentioned above. Then you can click the `Write` button to confirm the transaction.

## Place a Limit/Stop Order

#### Place an Open Limit/Stop Order

Open the OrderBook contract at <https://optimistic.etherscan.io/address/0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C#writeContract> and fill in the parameters for `createOpenOrder` function. Fill in the parameters using the description provided below. Once all the parameters are entered, click the `Write` button to confirm the transaction.

<table><thead><tr><th width="150">Parameters</th><th>Description</th></tr></thead><tbody><tr><td>createOpenOrder</td><td>The ether to pay for execution fee. The input should be 0.00025.</td></tr><tr><td>productId</td><td>The number represents the intended trading pair. Please refer to <a data-mention href="/user-guide/trading-pairs">Trading Pairs</a> for the productId of each trading pair.</td></tr><tr><td>margin</td><td>It is the USDC margin for the position. <br>Note the intended margin amount needs to multiply 1e8 for the input. For example: 50 USDC margin's input is 5000000000.</td></tr><tr><td>leverage</td><td>It is the leverage of the position. The value needs to multiply 1e8 for the input (1000000000 represents 10x leverage).</td></tr><tr><td>isLong</td><td>It is the direction of the position.<br>If you want to close a long position, the input is "true".<br>If you want to close a short position, the input is "false"</td></tr><tr><td>triggerPrice</td><td>It is the price at which the order will be triggerred. Note the trigger has high success rate but not 100% if the price moves cross the price and then goes back quickly before the keeper is able to trigger it. Note the intended price needs to multiply 1e8 for the input.</td></tr><tr><td>triggerAboveThreshold</td><td>If you want the order to be triggered when the price is above triggerPrice, the input is "true".<br>If you want the order to be triggered when the price is below triggerPrice, the input is "false".</td></tr><tr><td>executionFee</td><td>It is the execution fee paid to keepers to cover the gas fee of executing the order. The input amount should be 25000 (representing 0.00025ETH).</td></tr></tbody></table>

#### Place a Close Limit/Stop Order

Open the OrderBook contract at[ ](https://optimistic.etherscan.io/address/0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C#code)<https://optimistic.etherscan.io/address/0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C#writeContract> and fill in the parameters for `createCloseOrder` function. These parameters are the same as those for `createOpenOrder` mentioned above, except for the \`size, which refers to the position size you wish to close. The intended size needs to multiply 1e8 for the input. Then you can click the `Write` button to confirm the transaction.

## Place an Open Market Order with Take Profit and Stop Loss Orders

Open the PositionRouter contract at[ ](https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#writeContract)<https://optimistic.etherscan.io/address/0xa78Cd820b198A943199deb0506E77d655b5078cC#writeContract> and fill in the parameters for `createOpenMarketOrderWithCloseTriggerOrders` function. The parameters are described below. After entering all the necessary information, click the `Write` button to confirm the transaction.

<table><thead><tr><th width="150">Parameters</th><th>Description</th></tr></thead><tbody><tr><td>createOpenMarketOrderWithCloseTriggerOrders</td><td>The ether to pay for execution fee. The input should be 0.00075 if you are open a market order with both take profit and stop loss orders. The input is 0.0005 if you are open a market order with either take proft or stop loss order.</td></tr><tr><td>productId</td><td>The number represents the intended trading pair. Please refer to <a data-mention href="/user-guide/trading-pairs">Trading Pairs</a> for the productId of each trading pair.</td></tr><tr><td>margin</td><td>It is the USDC margin for the position. <br>Note the intended margin amount needs to multiply 1e8 for the input. For example: 50 USDC margin's input is 5000000000.</td></tr><tr><td>leverage</td><td>It is the leverage of the position. The value needs to multiply 1e8 for the input (1000000000 represents 10x leverage).</td></tr><tr><td>isLong</td><td>It is the direction of the position.<br>If you want to close a long position, the input is "true".<br>If you want to close a short position, the input is "false"</td></tr><tr><td>acceptablePrice</td><td>It is the lowest acceptable price for open short or close long order, and highest acceptable price for open long or close short order. The order will be cancelled if the current price does not satisfy the acceptable price. Note the intended price needs to multiply 1e8 for the input.</td></tr><tr><td>executionFee</td><td>It is the execution fee paid to keepers to cover the gas fee of executing the order. The input amount should be 75000 (representing 0.00075ETH) if you open a market order with both take profit and stop loss orders. The input is 50000 if you are open a market order with either take proft or stop loss order.</td></tr><tr><td>stopLossPrice</td><td>It is the price below which the close long order will get triggered, and above which the close short order will get triggerred.<br>Put 0 if do not want to place stop loss order.</td></tr><tr><td>takeProfitPrice</td><td>It is the price above which the close long order will get triggered, and below which the close short order will get triggerred.<br>Put 0 if do not want to place take profit order.</td></tr><tr><td>referralCode</td><td>Put <code>0x0000000000000000000000000000000000000000</code> before the referral program is launched.</td></tr></tbody></table>

## Place Take Profit and Stop Loss Orders for an Existing Position

Open the PositionRouter contract at[ ](https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#writeContract)<https://optimistic.etherscan.io/address/0xa78Cd820b198A943199deb0506E77d655b5078cC#writeContract> and fill in the parameters for `createCloseTriggerOrders` function. These parameters are the same as those for `createOpenMarketOrderWithCloseTriggerOrders` mentioned above. Then you can click the `Write` button to confirm the transaction.

## Add and Remove Margin

First, open the PikaPerpV4 contract at <https://optimistic.etherscan.io/address/0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB#readContract>. Call the `getPositionId` function to retrieve the `positionId` using your address, `productId`, and position direction.

Next, navigate to <https://optimistic.etherscan.io/address/0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB#writeContract>. Call the `modifyMargin` function, inputting the `positionId` from the previous step, the margin amount you wish to add or remove, and specify `true` for adding margin or `false` for removing margin in the `shouldIncrease` field.


# Trading Pairs

Pika support a large number of crypo and forex pairs as follows:

| Product ID | Pair     |
| ---------- | -------- |
| 1          | ETHUSD   |
| 2          | BTCUSD   |
| 3          | SOLUSD   |
| 4          | AVAXUSD  |
| 5          | MATICUSD |
| 6          | LINKUSD  |
| 7          | SNXUSD   |
| 8          | AAVEUSD  |
| 9          | APEUSD   |
| 10         | AXSUSD   |
| 11         | UNIUSD   |
| 12         | OPUSD    |
| 13         | DOGEUSD  |
| 14         | CRVUSD   |
| 15         | NEARUSD  |
| 16         | ATOMUSD  |
| 17         | EURUSD   |
| 18         | USDJPY   |
| 19         | GBPUSD   |
| 20         | AUDUSD   |
| 21         | USDCAD   |
| 22         | BNBUSD   |
| 23         | DYDXUSD  |
| 24         | FTMUSD   |
| 25         | SANDUSD  |
| 26         | ARBUSD   |
| 27         | PEPEUSD  |
| 28         | GMXUSD   |
| 29         | WLDUSD   |
| 31         | MKRUSD   |
| 32         | XRPUSD   |
| 33         | LTCUSD   |
| 34         | LDOUSD   |
| 35         | SEIUSD   |
| 36         | APTUSD   |
| 37         | RUNUSD   |
| 38         | BCHUSD   |
| 40         | XAUUSD   |
| 41         | XAGUSD   |
| 42         | DOTUSD   |
|            |          |


# PIKA Token

PIKA token has been retired. You can read more at [ ](< https://vxtwitter.com/PikaProtocol/status/1723377198571081894>)<https://pikaprotocol.medium.com/important-update-for-pika-token-0db98f47558a>


# Reward Program

## Token Reward Program <a href="#c22e" id="c22e"></a>

PIKA’s token distribution has allocated 30% of the total PIKA supply for future platform rewards. These rewards incentivize liquidity providers, traders, and PIKA stakers. The rewards will be distributed as esPIKA over the next three years, starting in August 1st. The Pika rewards program will be reviewed monthly and the allocations can be adjusted. Any changes will be communicated at least seven days prior to implementation.

**Base Reward**

Approximately 0.75 million (0.75% of PIKA supply) esPIKA base rewards are distributed every 30 days:

* 35% goes to liquidity providers, distributed in real-time.
* 55% is allocated to traders: 45% as trader rewards, dispensed every epoch (30 days), and 10% as trading competition rewards, distributed per competition schedule.
* The remaining 10% goes to PIKA stakers, also distributed in real-time.

**Boosting Reward**

The Pika treasury growth fund receives penalties from early esPIKA redemptions. Half of the 30-day PIKA acquired is repurposed as a boosting reward for the next epoch (30 days). For instance, if a 0.2 million PIKA penalty is collected in a given epoch, 0.1 million is stored in the treasury, and the other 0.1 million is reallocated as a boosting reward for the next epoch. This reward is then distributed according to the same allocation percentage (45% to LPs, 45% to traders, and 10% to PIKA stakers).

In the coming months we will introduce a new referral program in which roughly 5% of esPIKA (out of the 0.75 million per epoch) will be set aside for referral rewards. This will lead to a revised distribution: 45% to liquidity providers, 42% to traders(35% as trader rewards and 7% as trading competition rewards), 8% to PIKA stakers, and 5% to the referral program. Details of the updated distribution plan will be communicated in advance.

## Benefits of Staking PIKA <a href="#c22e" id="c22e"></a>

Staking PIKA brings a host of benefits:

* PIKA stakers receive 30% of trading fees in real-time.
* An additional 10% of monthly esPIKA rewards are also distributed to PIKA stakers in real-time.
* Monthly trader rewards for each trader are dependent on the previous month’s trading fees and the amount of PIKA staked:\
  *Each trader’s rewards = total epoch trader rewards \* trader score / (sum of all trader scores)*\
  *Trader score = epoch trading fees \* PIKA staked ^ 0.5*
* Trading discounts for PIKA stakers, see the schedule below for details

<figure><img src="https://754592214-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQqm3d5en6TYOTzV6C8wz%2Fuploads%2FOk0U1xpvYwWEVccIE2aP%2Fimage.png?alt=media&amp;token=632868cf-7b52-4cc0-bd8b-582d91b002a7" alt=""><figcaption></figcaption></figure>


# Contracts

The Pika's smart contracts are deployed on Optimism network.

<table><thead><tr><th width="273">      Name</th><th>Address</th></tr></thead><tbody><tr><td>PikaPerpV4</td><td>0x8c9b6a4a4e61F4635E8e375E05ff98Db5516d25E</td></tr><tr><td>FundingManager</td><td>0x8aF1508Bd289e7cb6D565ECAFd88A4eB4cC2636c</td></tr><tr><td>FeeCalculator</td><td>0xe3451b170806Aab3e24b5Cd03a331C1CCdb4d7C1</td></tr><tr><td>VaultFeeReward</td><td>0x0e431Ea7E58e15a18f3334E3A6D195917fe1011a</td></tr><tr><td>PositionManager</td><td>0xCabE9b7B554Ebe8045E6c5499D7d3dC5C2716DB1</td></tr><tr><td>OrderBook</td><td>0x6C420e4B95808Db2365f51e108b913059d4160b1</td></tr><tr><td>PikaPriceFeed</td><td>0xEaB7BDcF0661cEc01C72b46eE38Aad21f4f239f7</td></tr></tbody></table>


# Audit

The Pika v4's smart contracts have been audited by PeckShield, and the audit report can be found at: <https://github.com/peckshield/publications/blob/master/audit_reports/PeckShield-Audit-Report-PikaPerpV3Audit2-v1.0.pdf>


# Pika Protocol V3

The v3 documentation can be found at: [https://pikaprotocol.gitbook.io/pika-protocol-v3](https://pikaprotocol.gitbook.io/pika-protocol-v3/)


# Pika Protocol V2

The v2 documentation can be found at: [https://pikaprotocol.gitbook.io/pika-protocol-v2](https://pikaprotocol.gitbook.io/pika-protocol-v2/overview)


# Pika Protocol V1


# Overview

![](https://754592214-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MY2KLV548KIYe8apY9V%2F-MY2KNtct8oqyC4gPTZc%2F-MY2LSd6ErlURFM-LoEx%2FScreen%20Shot%202021-04-07%20at%205.27.02%20PM.png?alt=media\&token=4bafcf0d-791f-4fb2-b17d-68183e0900bc)

Pika Protocol is a stablecoin protocol backed by decentralized derivatives. It consists of two components: **Pika Exchange** and **PIKA stablecoin**.

Pika Exchange is a perpetual swap exchange that supports leverage trading. It supports token based inverse perpetual swaps. The underlying of the exchange is a virtual automated market maker(vAMM).

PIKA Stablecoin is a stable currency backed by Pika Exchange with these features:

* **Stable:** it uses perpetual swap positions to back its price stability around a 1 dollar target. PIKA is minted by opening a 1x short position of an inverse perpetual swap.
* **Capital Efficient:** a PIKA is minted by depositing one dollar value of supported tokens(e.g., ETH, WBTC), achieving better capital efficiency than overcollateralized stablecoins.
* **Yield-bearing:** yields are generated from trading fees of perpetual contract exchange.


# Pika Exchange

Pika Exchange is a decentralized non-linear inverse perpetual swap exchange.

[Perpetual swap](https://www.bitmex.com/app/perpetualContractsGuide) is the most popular way to trade cryptocurrencies with leverage in centralized exchanges like Binance and Bitmex. There are two popular types of perpetual contracts: linear and inverse.

| Type    | Description                                                                                                                                                                    | PNL Calculation                                                  | Exchanges                                                                                                               |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| Linear  | <p>Quoted and settled in the quoted currency. <br></p><p>For example, ETHUSD linear contracts are both quoted and settled in USD.</p>                                          | <p>Number of Contracts \* (Exit Price - Entry Price)<br></p>     | <p>Centralized:</p><p>Binance, Huobi, Okex<br></p><p>Decentralized: </p><p>Perpetual Protocol, Futureswap, dYdX<br></p> |
| Inverse | <p>Quoted in one currency, but always settled in the underlying or base currency. <br></p><p>For example, ETHUSD inverse contracts are quoted in USD while settled in ETH.</p> | <p>Number of Contracts \* (1/Entry Price - 1/Exit Price)<br></p> | <p>Centralized:</p><p>Bitmex, Deribit, Binance, Huobi, Okex<br></p><p>Decentralized:</p><p>MCDEX</p>                    |

While linear contracts have the benefit of low exposure to the volatility of the underlying assets, it is unfavorable to those long term holders of the underlying assets, especially in the bull market. Almost all the current decentralized perpetual exchanges are only supporting linear contracts. Pika Exchange is the one that supports inverse contracts.

Pika Exchange is providing these features:

1. **Funding rate baked into price**: funding payments are taken care of by the open and close price of perpetual contracts, so no explicit funding payments need to be made by longs and shorts, making it more friendly for DeFi folks.
2. **Tokenized leveraged positions**: leveraged positions are tokenized into NFTs via ERC1155 standards, which allows traders to transfer or use tokens in the whole DeFi system.
3. **Virtual AMM with dynamic k adjustments**: the “x \* y = k” formula is used to determine the price of the perpetual contract, with k being dynamically adjusted based on open interest. This allows the exchange to achieve low slippage with small liquidity.

We want to give credits to Alpha Finance and Perpetual Protocol for some of these ideas. Our major difference from them is that they are providing USDT based linear contracts while Pika Exchange's contracts are token based inverse contracts. Also, a key purpose of the Pika Exchange is used to back the PIKA stablecoins.


# Funding

For conventional perpetual swap exchange, funding payment is used to keep the perp price close to the external index price of the underlying asset. For example, if the mark price of the perp is higher than the index price, longs pays shorts periodically to incentivize more shorts to bring the mark price close to index price, and vice versa.

Since the funding mechanism is not user friendly for non-professional traders and it is hard to implement funding for tokenized positions, Pika Exchange incorporates the funding payment into the price of the perpetual contract to make it more intuitive. If the mark price deviates from index price by a threshold, the protocol will move its price towards the index price every second.

For example, if the mark price is higher than index price by a threshold, the protocol will start to move its price lower towards the index price. The movement is determined by the deviation amount and the movement happens every second. This allows the short positions to be closed at a price that is lower than without price adjustment, leading to higher profit for shorts and lower profit for longs. Also, since the price adjustment action can be detected before it starts, it is a good profit strategy for traders to open shorts before the adjustment and close shorts after the adjustment. In this way, more shorts positions are incentivized while long positions are disincentivized, moving the mark price even quicker to the index price.


# Liquidation

## How is liquidation price determined?

Each leverage position of Pika Exchange has a strike price, at which the value of the position is equal to 0. In any exchange that supports leverage positions, there is always a price buffer to liquidate the positions before the collateral is depleted, which is used to protect exchanges from insolvency. Pika Exchange has a buffer value of 93% for liquidation.&#x20;

Long position example:

* A user opens a 5x long position of ETH/USD at price $1000.
* Since Pika is an inverse perpetual exchange, this position is interpreted by protocol as 5x short position of USD/ETH at price 1/1000.
* The strike price of the inverse short position:  1/1000 - 1/1000 / leverage=0.0008.
* The strike price of the long position: 1/0.0008 = $1250.
* The liquidation price of the inverse short position:  0.0008/0.93 = 0.00086.
* The liquidation price of the long position: 1/0.00086 = $1163.

Short position example:

* A user opens a 5x short position of ETH/USD at price $1000.
* Since Pika is an inverse perpetual exchange, this position is interpreted by protocol as 5x long position of USD/ETH at price 1/1000.
* The strike price of the inverse long position:  1/1000 + 1/1000 / leverage = 0.0012.
* The strike price of the short position: 1/0.0012 = $833.
* The liquidation price of the inverse long position:  0.0012 \* 0.93 = 0.001116.
* The liquidation price of the short position: 1/0.001116 = $896.

Check out parameter page for more details.<br>

## How is liquidation triggered?

Liquidations are normally triggered by external bots for most decentralized derivatives exchanges, where bots consistently check each user’s margin position for liquidation opportunities. The liquidation is often triggered on a per user basis when the margin falls below a certain requirement. Bots are normally rewarded by part of the liquidated user’s balance as incentive.

During the big price movement, this type of liquidation mechanism often has problems. Since bots need to liquidate each user one by one, it is often the case that bots are not fast enough to take care of all the positions that need to be liquidated, resulting in loss of insurance funds for the protocol. Pika Exchange adopts the bot-less liquidation mechanism, where each trade execution automatically checks if there are positions to liquidate. Also, instead of checking each user’s account, Pika Exchange simply invalidates a set of strike prices that is to be liquidated. The leveraged tokens with invalidated strike prices can no longer be traded back to the protocol, meaning the value of which is 0.


# Dynamic Liquidity Adjustment

A big challenge for virtual AMM is to decide the liquidity value. If the liquidity value is high, it has the benefit of lower trade slippage, but the high value also means it takes a large trade amount to move the price. Also, it is not a good idea to use constant liquidity forever with the growth of the exchange. Is there a way to dynamically update the liquidity based on some parameters?

In practice, the liquidity of an exchange is highly correlated with open interest and trading volume. That’s why Pika Exchange is making use of these two parameters to dynamically update the liquidity based on the following logic:

1. If short term TWAP open interest is higher than long term TWAP open interest(indicating the growing trend of open interest), the liquidity will be adjusted higher, and vice versa.
2. If today’s trading volume is higher than the previous day’s trading volume beyond a certain threshold, the liquidity will be adjusted higher, and vice versa.

The daily limit is applied for liquidity change amounts to protect the exchange from potential manipulations.

Pika Exchange is the first project that implements this feature and we expect it may take some time to experiment before becoming perfect.


# Parameters

**coefficient**: the k value of the “x\*y” formula, set by the market creator

**reserve0**: the initial value of the USD virtual liquidity, set by the market creator

**reserve**: the latest value of the USD virtual liquidity

**decayPerSecond**: exponential TWAP decay for markPrice, with 99.8% as default value

**timeElapsed**: the seconds elapsed since the last time when poke function is triggered

**maxPokeElapsed**: the max time cap for the timeElapsed, with default value as 1 hour(3600 seconds)

**markPrice**: exponential TWAP of spot price. It is used to calculate unrealized PNL and determine liquidations on the position.

markPrice = previousMarkPrice \*  decay + spotPrice \* (1 - decay), where

decay = decayPerSecond ^ timeElapsed

**indexPrice**: price from external exchanges, provided by a Chainlink oracle

**spotPrice**: AMM price + shift, where AMM price = (coefficient / reserve) / reserve

**fundingAdjustThreshold**: if the difference of markPrice and indexPrice is above this threshold, funding will be adjusted. With default value as 0.5%.

**shift**: funding adjustment

markIndexDiff = abs(markPrice - indexPrice) / indexPrice

if markIndexDiff > fundingAdjustThreshold:

&#x20;   shift = previousShift + timeElapsed \* markIndexDiff / secondsInADay&#x20;

else:

&#x20;   shift = previousShift&#x20;

**strikePrice**: the price at which the leverage position is worth 0

strikePrice of long position = markPrice + markPrice / leverage

strikePrice of short position = markPrice - markPrice / leverage

**safeThreshold**: buffer for liquidation, with default value as 93%

Long positions get liquidated when strikePrice / markPrice <= safeThreshold

Short positions get liquidated when markPrice / strikePrice >= safeThreshold

**spotMarkThreshold**: (spotPrice / markPrice) or (markPrice / spotPrice) must not exceed this value for a trade to be executed. Default value is 105%. This is a protection against price manipulation.

**liquidationPerSec**: the maximum amount of opposite trade the protocol will do per second to offset the liquidations. This is useful to prevent the flash crash of the price during big liquidation events.

**liquidityChangePerSec**: the maximum liquidity change per second, with default value as 0.5% per day cap

**smallDecayTwapOI**：exponential TWAP open interest for a shorter period

**largeDecayTwapOI**：exponential TWAP open interest for a longer period

**smallOIDecayPerSecond**: a faster exponential TWAP decay value to calculate smallDecayTwapOI, with default value as 99.999%

**largeOIDecayPerSecond**: a slower exponential TWAP decay value to calculate largeDecayTwapOI, with default value as 99.9999%

**volumeChangeThreshold**: If the difference between dailyVolume and prevDailyVolume is larger than this value, liquidity will be dynamically updated. Default value is 120%.

**OIChangeThreshold**: if (smallDecayTwapOI / largeDecayTwapOI) or (smallDecayTwapOI / largeDecayTwapOI) exceeds this value, the liquidity will be dynamically adjusted

i**sLiquidityDynamicByOI**: boolean flag to turn on/off the liquidity adjustment based on open interest movement

**isLiquidityDynamicByVolume**: boolean flag to turn on/off the liquidity adjustment based on trading value trend


# PIKA Stablecoin

One of the easiest ways to transform any token into dollar exposure is perpetual swap contracts. For example, Bitmex offers a BTC/USD contract that is margined in BTC. This contract is structured like non-linear inverse future contracts, meaning the contract value is measured in one currency, USD, but the position is margined and settled in a different currency, BTC. If a user opens a 1x short position, this gives the user a dollar exposure with the ability to earn yields from funding payments. This way of hedging is in fact widely adopted by traders to get exposed to dollar exposure.

PIKA achieves its stability in a similar way. To mint a PIKA, a user can simply open a 1 dollar value of short position in any supported token swap markets(e.g., ETH or WBTC).


# How it Works

## Overview

Essentially, PIKA stablecoins are backed by long positions’ loss at the time of the underlying token depreciation. At the time of the underlying token appreciation, the long positions’ profit are generated from both short positions’ loss and PIKA stablecoins' collateral token appreciation.

## Example

Let’s assume the current price of ETH is $2000 and Bob deposits 1ETH to Pika Protocol to mint 2000 PIKA stablecoins. This effectively opens a 1x short position of ETHUSD in the inverse perpetual swap margined in ETH.&#x20;

Assume the total value of all the long and short positions in the exchange are both $10000 (5 ETH), meaning there are $10000(5 ETH) values of long position and other $8000(4 ETH) of short position in the exchange. When Bob uses the 2000 PIKA to claim back their ETH at a later point, there could be three scenarios:

**ETH price remains the same:**&#x20;

Since both the longs and shorts positions of the exchange have 0 profit or loss, Bob can deposit 2000 PIKA to claim back their 1 ETH, with $2000 worth.

**ETH price goes up:**&#x20;

* Assume the price goes up to $4000.
* Net profit of longs: 10000 \* (1/2000 - 1/4000) = 2.5 ETH
* Net loss of shorts: 2.5 ETH
* Net loss of Bob’s position: 0.5 ETH
* As a result, Bob’s current collateral is 0.5 ETH(1 - 0.5). If Bob burns the 2000 PIKA stablecoins to claim back ETH now, it is still worth $2000.&#x20;

**ETH price goes down:**&#x20;

* Assume the price goes down to $1600.
* Net loss of longs: 10000 \* (1/1600 - 1/2000) = 1.25 ETH
* Net profit of shorts: 1.25 ETH
* Net profit of Bob’s position: 0.25 ETH
* As a result, Bob’s current collateral is 1.25 ETH(1 + 0.25). If Bob burns the 2000 PIKA stablecoins to claim back ETH now, it is still worth $2000.

<br>


# Compare with other Stablecoins

PIKA’s unique derivatives backed design makes it a stablecoin that avoids the shortcomings of other protocol designs. PIKA avoids the centralized risk of USDT and USDC, requires less collateral compared to DAI, achieves a stronger peg than ESD and Basis Cash, has a more battle tested model than Frax and Fei. In addition, it has the benefits of yield bearing without the need to stake.

![](https://754592214-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MY2KLV548KIYe8apY9V%2F-MZumSa5hoFEYIc-dLTQ%2F-MZunJDfWpDnoO4KaswM%2Fimage.png?alt=media\&token=a93f2981-0e4d-4277-b7fc-cd2d6bad0373)

Among all the current stablecoins, fractional collateralized algorithmic stablecoins are the most interesting ones to compare and we believe it will have a promising future, but it needs time to iterate and to be proven. In comparison, the advantage of PIKA is that its design has been battle tested in crypto perpetual exchanges for many years.

Stablecoin market is huge. As of Feburary 2021, total market capitalization of stablecoins surpassed $50 billion. Since the currently market are dominated by fiat backed stablecoins such as USDT and USDC, there's a big opportunity for DeFi native stablecoins and this won't be a zero-sum game. We look forward to a future where multiple DeFi native stablecoins take off.<br>


# Pika Share

The Pika Share(PKS) token is primarily a **utility token** designed to facilitate and incentivize the decentralized governance of the protocol. As such, holders of PKS tokens accrue voting rights proportional to their holdings. The following could be examples which PKS holders have the opportunity to propose and decide on:

* The new perpetual market to launch.
* Trading parameters of a perpetual market such as trading fees, liquidation threshold and funding fee adjustment threshold.

PKS token also functions as the last resort to the protocol. It can be minted by governance to backstop the system in the extremely rare case when the insurance fund of Pika Exchange is exhausted.


# Participate in Pika Protocol

## Take leverage positions&#x20;

Any trader who likes to take leveraged positions can long or short with Pika Exchange.

## Earn fees from holding PIKA

Any person who likes to earn interests without exposing to the volatility can benefit from holding PIKA tokens to earn trading fees.

## Use PIKA as a stablecoin

PIKA can also be minted to use as a stablecoin to transact or hedge the volatility.

## Arbitrage

Arbitrageurs can profit from:

* arbitraging price difference among Pika Exchange and other exchanges.
* arbitraging across different markets within Pika Exchange. For example, the price of PIKA from ETHUSD market and BTCUSD market could be different, and people can profit from minting from one market and burning in another market.

## Earn fees from staking

Stakers can benefit by

* staking underlying tokens of each trading market to back the Pika Exchange. In return stakers earn part of the trading fees.&#x20;
* staking LP tokens of PIKA and PKS to earn part of trading fees and PKS tokens.


# Risks

Pika Protocol is an experiential product like all the other DeFi projects, and it needs time to iterate before becoming perfect. There are some potential risks of the protocol users need to be aware of.

## General Smart Contract Risks

Like any other DeFi protocols, Pika Protocol has smart contract risks: there is a potential for the funds to be lost due to code bugs. This will be mitigated by smart contract auditing, testnet testing and use over time.

## Pika Exchange Risks

The virtual automated market maker(vAMM) is a concept that has been battle tested by Perpetual Protocol in the last few months, and we have made improvements such as making liquidity adjustment dynamic, tokenizing the leverage positions and optimizing the liquidation by not relying on external bots.  However,  vMM is still a new concept and needs time to get matured. For example, how to dynamically adjustment of K is something that needs time to be proven.


