LogoLogo
  • Introduction
  • App
    • How to
      • Connect a wallet
      • Swap
      • Approve Spending
      • Open a Long Position
      • Open a Short Position
      • Withdraw Funds
      • Add Funds
      • Close Position
      • Increase Leverage
      • Pay Off Debt
      • Deposit Liquidity
      • Withdraw Liquidity
      • Add Liquidity
    • Smart contract addresses
      • Arbitrum
      • Blast
    • FAQ
  • Protocol mechanics
    • Providing Liquidity
    • Trading
    • Marginly MAX leverage specifics
  • Protocol architecture
    • Overview
    • Pools
      • Pool variables
      • Pool parameters
      • User positions
      • User actions
      • Pool Factory API
      • Pool API
    • TWAP oracle
    • Loan pricing
    • Errors
    • Marginly SDK
  • Router
    • Router architecture
    • Adapters
      • ApeSwapAdapter
      • BalancerAdapter
      • CamelotAdapter
      • KyberSwapClassicAdapter
      • KyberSwapElasticAdapter
      • UniswapV2Adapter
      • UniswapV3Adapter
      • WooFiAdapter
  • Risk Management
    • Risk Management Overview
    • Keeper service and smart contract description
    • Keeper contract architecture
    • Liquidations and Deleveraging
    • Volatility as risk proxy
    • Insurance pool
    • Shutdown mode
  • Economics
    • Marginly economics
  • Future plans
    • Beyond Marginly v1
    • Some ideas for Marginly v2
  • Trading Contest FAQ
  • Github
  • Audit
Powered by GitBook
On this page
  1. Protocol mechanics

Marginly MAX leverage specifics

PreviousTradingNextOverview

Last updated 1 year ago

In Marginly, we specifically invoke a margin call before every user action: If your position happens to be the riskiest in the system, it will liquidate automatically on ANY action of ANY user.

Unfortunately, this means that when you close your position, and it's the riskiest one, instead of closure, you will get liquidated. Why not add leverage checks, you ask? This additional “if” logic increases contract size and requires complete refactoring by splitting the smart contract into many parts.

We will eventually have to do that as we envision some changes/improvements for Marginly’s protocol, including this particular one related to the riskiest position management.

Additionally, I would like to talk about the we use to value user positions. Take a look at the following picture:

It is an ETH/USDC 1-minute chart. The red line is the average over 30 minutes - our 30-minute TWAP price. Now imagine that you went long 20x in the shaded area. Even though the price temporarily goes up, the TWAP price, at which Marginly values your position, continues to decline as the moving average is lagging current data. If you use max leverage, you will get liquidated. This behavior could be somewhat misleading when looking solely at the charts. The same happens to shorts, by the way, Imagine you shorted at 1880 with 20x, but the system will value your position at ~1882.5 (the TWAP price). This is an instant liquidation.

One of the things we’re currently working on within our UX is a warning on position openings, so people understand the implications when they use max leverage.

TWAP oracle