You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Abstract.
The Casper Shorts is a variation of a perpetual swap contract that is fully
onchain. It uses a pool-based mechanism to manage the liquidity between long and
short positions in case of price changes. Its design is gas-efficient and allows
for a high number of transactions.
1. Introduction
Perpetual swap is a contract between two parties to bet on the price of an
asset. One party goes long and the other goes short. The core idea of the system
is that whenever the price of the underlying asset changes, the system
rebalances the liquidity between long and short positions. Deposits are
represented $LONG$ and $SHORT$ tokens. System requires an oracle to provide the
price of the underlying asset.
2. Definitions
Smart contracts used to repesent the system:
$csCSPR$ - Wrapped Casper CSPR token, used an underlying asset in the
perpetual swap. Later referred aa asset.
$LONG$ - Token that represents the long position,
$SHORT$ - Token that represents the short position,
$Market$ - Contract that manages deposits, withdrawals, price oracle and
rebalancing of the liquidity between long and short positions.
The $State$ of the system is defined as:
$$ State = (P, L_{Long}, L_{Short}, T_{Long}, T_{Short}) $$
where:
$P$ - the current price of the asset,
$L_{Long}$ - the total amount of the asset for the long position,
$L_{Short}$ - the total amount of the asset for the short position,
$T_{Long}$ - the total supply for the $LONG$ token,
$T_{Short}$ - the total supply for the $SHORT$ token.
In addition:
$D$ - the Deposit amount of $scCSPR$ added to the long or short position,
$W$ - the Withdrawal amount of $LONG$ or $SHORT$ removed from the position,
$L$ - the Liquidity amount of the long or short positions.
$S$ - the total _Supply of the $LONG$ or $SHORT$ token.
3. Rebalce Mechanism
Whenever new price $P_{i+1}$ is received, the system updates the $State$, by
rebalancing the liquidity between long and short positions. If the new price is
lower then the previous price $P_i$, first the short position is reduced and
then the long position is increased with the same amount. And vice versa for the
price increase.
The Rebalancing Algorithm has two steps:
Loss Phase: System calculates the loss amount of underlying asset, that
the losing side lost. It is poportional the the price change. The maximum value
of it can be the total amount of the losing side. It is substracted from the
losing side.
Gain Phase: System adds the loss amount of the asset to the winning
side.
It is can be defined it for both sides separately.
3.1 Price Increased
Short position is losing liquidity and it is transferred to the long position.
The formula is intended to cap the adjustment to the total available liquidity,
using the min function.
When user deposits funds $D$ into the short or long position, the system
calculates the new amount of the position and the new total supply of the long
or short token.