Module levana_perpswap_cosmos::leverage

source ·
Expand description

Data types to represent leverage

Within the perps platform, we have a few different varieties of leverage:

  • Does the leverage value include direction? Directioned leverage uses negative values to represent shorts and positive to represent longs. Undirectioned is the absolute leverage amount. We use the term “signed” represent leverage types that include the direction.

  • Notional or base: leverage is given in terms of exposure to the base asset. Within the protocol, for collateral-is-quote markets, the same applies, since base and notional are the same asset. However, for collateral-is-base, we have to convert the leverage in two ways: (1) flip the direction from long to short or short to long, and (2) apply the off-by-one factor to account for the exposure the trader experiences by using the base asset as collateral.

We end up with three different data types:

  • LeverageToBase is the the absolute leverage (without direction) from the trader point of view in terms of exposure to the base asset.

  • SignedLeverageToBase is the trader perspective of leverage, but uses negative values to represent shorts.

  • SignedLeverageToNotional is the protocol’s perspective of leverage including the sign.

It’s not necessary to provide a LeverageToNotional, since within the protocol we always use signed values. The unsigned version is only for trader/API convenience.

To provide a worked example: suppose a trader wants to open a 5x leveraged short. If the market is collateral-is-quote, the LeverageToBase value would be 5, SignedLeverageToBase would be -5, and SignedLeverageToNotional would also be -5.

By contrast, if the market is collateral-is-base, the external values would remain the same, but SignedLeverageToNotional would be 6 from the formula to_notional = 1 - to_base.

Structs§