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 architecture

Loan pricing

This page describes how Marginly prices loans.

PreviousTWAP oracleNextErrors

Last updated 1 year ago

A collateralized loan model for the pool we consider has the following specifications:

  • The loan has an infinite lifetime (no maturity)

  • At time 0, the user borrows amount Q (Q > 0) USD from the pool using 1 unit of an asset (e.g., ETH) as collateral.

  • The continuously compounding loan interest rate is r. The client may regain the asset by repaying the Q*exp(rt) amount to the pool at any time t ≥ 0.

  • User may default (not obliged to return the loan)

The task may be regarded as a user buying an American option at the price of (asset price - Q) with the following payoff function:

Yt=max(0;PtETH−Qert);t≥0Y_t = max (0; P^{ETH}_t - Qe^{rt}); t \geq0Yt​=max(0;PtETH​−Qert);t≥0

This time-dependent strike price option is evaluated, for example, in . Since in our setup, we know the exact position user wants to take (the leverage), and thus the effective option value, we can rearrange final equations to solve for the interest rate r: Marginly calculates interest rate as proportional to the asset volatility and the leverage of the pool’s position:

r∼Lσ22r {\sim L\frac{\sigma^{2}}{2}}r∼L2σ2​

Marginly keeps track of the total long leverage and the total short leverage in the pool and scales interest rates proportionally for each side. This way, every time any user performs any action in the system, it recalculates how much interest has accrued since the last time and updates collateral and debt coefficients accordingly.

Xia and Zhou