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
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.
Oracle
The Market Contract is connected to the 3party oracle that provides current asset
price denominated in USD.
Mechanics
There are two main components of the system:
The Market contract that manages the funds.
Two token contracts (Long and Short) that represents the long and short position.
When user deposits funds, all goes into the Market. User has to choose if he
wants to go long or short. The user receives the corresponding token that
represents the ownership of deposited funds. The Market keeps track of the total
amount of the asset for the long and short positions.
When the price changes the Market changes the amount of the asset for the long
and short positions.
$L_{Long}$ is the total amount of the asset for the long position,
$L_{Short}$ is the total amount of the asset for the short position,
$T_{Long}$ is the total supply for the long token,
$T_{Short}$ is the total supply for the short token.
In addition:
$D$ - liquidity deposit for the long or short position,
$W$ - tokens amount to be exchanges for the asset.
$L$ - the amount of the asset for the long or short position.
$S$ - the total supply of the long or short token.
Mechanics
Whenever new price $Price_{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, first the short position
is reduced and then the long position is increased with the same amount.
And vice versa for the price increase.
Then the system updates the total supply of the long or short token.
Price goes up
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.