IPOR Protocol
  • The IPOR Protocol Documentation
  • IPOR Protocol V2
  • Research / Whitepapers
    • Conceptual Whitepaper
  • Audits
  • Community Links
  • IPOR Protocol Roadmap
  • IPOR FAQ
    • About the IPOR Protocol
    • Using the IPOR Protocol
    • Liquidity Mining
    • Swaps VS Perps
    • $FUSN Snapshot
  • About IPOR
    • Who Uses IPOR and for What?
    • Why IPOR?
    • IPOR Manifesto
  • IPOR Fusion ⚛️
    • Fusion Introduction
      • Defragmenting DeFi Yield
    • Why Fusion?
    • Users
    • Use Cases
    • Architecture Overview
      • Atomists
      • Alphas
    • Vaults
      • Access Management
    • Fuses
    • Security
      • For Liquidity Providers
      • For Vault Owners
      • Testing
    • Open-source Repository
    • Aragon Integration
  • IPOR Index
    • What is the IPOR Index
    • Working with the IPOR Index
    • IPOR stETH Index
  • Interest Rate Derivatives
    • Interest Rate Derivative
    • Index Calculation
    • IPOR Publication
    • IBT
    • Indicative Term Sheet
  • Automated Market Maker
    • The Automated Market Maker
    • Liquidity Provisioning
    • IPOR Swaps
      • Hedging example with Morpho protocol
    • Spread
      • Math behind the demand spread
    • Risk oracle
    • SOAP
    • Liquidations
    • Asset Management
  • Tokenomics
    • IPOR Token
    • Token distribution model
    • Power IPOR
    • Liquidity mining
      • Math behind the rewards contract
    • Power Token Liquidity Mining for Developers
  • IPOR DAO
    • IPOR DAO Governance
      • Discord - All Channels
      • Discord - Open Governance Forum
      • Discord - Formal Governance
      • Snapshot - Formal Governance
      • Governing Multisig wallets
    • Decentralizing IPOR
      • Configuration Parameters
  • Developers Docs
    • Fusion
      • Developing а Fuse
      • Configuring Pre-hooks
    • Deployed Contracts
      • Ethereum
      • Arbitrum
      • Base
    • Working with IPOR Router
    • ABI
    • V2 changes
    • IPOR Oracle
    • Vault Wrapper
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Automated Market Maker
  2. Spread

Math behind the demand spread

PreviousSpreadNextRisk oracle

Last updated 1 year ago

Was this helpful?

Demand-driven component to spread as input takes several variables:

  • Liquidity depth in the liquidity pools

  • amount of collateral deposited by the swap takers

  • amount of notional exposure on each leg (pay-fixed or receive-fixed)

As well as configuration params from the:

  • Max Collateral Factor

  • Max Leverage

The demand part is calculated in a couple of steps:

  1. first, the depth of the pools is assessed by adding the liquidity available in the pools and the absolute value of the difference between collateral on both legs.

lpDepth=LPCollateral−∣CollateralpayFix−CollaterealrecFix∣lpDepth = LPCollateral - |Collateral_{payFix} - Collatereal_{recFix}|lpDepth=LPCollateral−∣CollateralpayFix​−CollaterealrecFix​∣
  1. Next, with help from the risk oracle the notional depth can be calculated. It is necessary later on to compile. MaxLeverage and MaxLPCollateralFactorPerLeg are fetched from the risk oracle

notionalDepth=lpDepth⋅MaxLeverage⋅MaxLPCollateralFactorPerLegnotionalDepth = lpDepth \cdot MaxLeverage \cdot MaxLPCollateralFactorPerLegnotionalDepth=lpDepth⋅MaxLeverage⋅MaxLPCollateralFactorPerLeg
  1. As the swaps get open their notional value is added and forms Time Weighted Notional (TWN) per leg. This value is kept separately per each asset and tenor.

TWNt,tenor,leg=TWNt,tenor,leg+NswapTWN_{t,tenor,leg} = TWN_{t, tenor,leg} + N_{swap}TWNt,tenor,leg​=TWNt,tenor,leg​+Nswap​
  1. As the time passes the effect of a swap on the TWN is decaying to 0 at maturity. This value is calculated on the fly and used to measure the dynamic exposure of the pool to a given leg.

TWNt,tenor,leg=TWNt−1,tenor,leg⋅(tenor[s]−ΔT)tenor[s]TWN_{t, tenor,leg} = \frac{TWN_{t-1, tenor, leg} \cdot (tenor[s] - \Delta T)}{tenor[s]}TWNt,tenor,leg​=tenor[s]TWNt−1,tenor,leg​⋅(tenor[s]−ΔT)​
  1. In the next step the values of each tenor-specific TWN are added

TWNt,leg=∑tenorTWNt,legTWN_{t, leg} = \sum_{tenor}TWN_{t,leg}TWNt,leg​=tenor∑​TWNt,leg​
  1. Next it has to be determined, which leg is overweight and which one is underweight. This can be done by subtracting the TWN on each leg

overweightpayFixed=TWNpayFixed−TWNreceiveFixedoverweight_{payFixed} = TWN_{payFixed} - TWN_{receiveFixed}overweightpayFixed​=TWNpayFixed​−TWNreceiveFixed​
overweightreceiveFixed=TWNreceiveFixed−TWNpayFixedoverweight_{receiveFixed} = TWN_{receiveFixed} - TWN_{payFixed}overweightreceiveFixed​=TWNreceiveFixed​−TWNpayFixed​
  1. Once it can be determined which leg is overweight, the spread can be applied to IT depending on the size of the difference. Formula for both legs is identical.

ratiopayFixed={overweightpayFixednotionalDepthoverweightpayFixed>00overweightpayFixced≤0ratio_{payFixed} = \begin{cases} \frac{overweight_{payFixed}}{notionalDepth} & overweight_payFixed > 0 \\ 0 & overweight_{payFixced} \le 0 \end{cases}ratiopayFixed​={notionalDepthoverweightpayFixed​​0​overweightp​ayFixed>0overweightpayFixced​≤0​
  1. Finaly the demand spread can be calculated with help of simple step function. Linear step function presented below is subject to configuration and the final values of slope and base are to be set by the DAO.

demandSpreadleg={0.005⋅ratioratio<0.10.01⋅ratio+0.005ratio<0.20.015⋅ratio+0.005ratio<0.30.02⋅ratio+0.015ratio<0.40.05⋅ratio+0.03ratio<0.50.33(3)⋅ratio+0.15ratio<0.80.5⋅ratio+0.2ratio<1demandSpread_{leg} = \begin{cases} 0.005 \cdot ratio & ratio < 0.1 \\ 0.01 \cdot ratio + 0.005 & ratio < 0.2 \\ 0.015 \cdot ratio + 0.005 & ratio < 0.3 \\ 0.02 \cdot ratio + 0.015 & ratio < 0.4 \\ 0.05 \cdot ratio + 0.03 & ratio < 0.5 \\ 0.33(3) \cdot ratio + 0.15 & ratio < 0.8 \\ 0.5 \cdot ratio + 0.2 & ratio < 1 \\ \end{cases}demandSpreadleg​=⎩⎨⎧​0.005⋅ratio0.01⋅ratio+0.0050.015⋅ratio+0.0050.02⋅ratio+0.0150.05⋅ratio+0.030.33(3)⋅ratio+0.150.5⋅ratio+0.2​ratio<0.1ratio<0.2ratio<0.3ratio<0.4ratio<0.5ratio<0.8ratio<1​
  1. Now that the demand spread for leg is calculated same operations is repeated only this time notional of the new position that is to be opened is added to the "overweight" value. Afterwards simple average is calculated and final spread is returned. The last step is necessary in order to account for the slippage caused by the position and it removes the incentive of splitting position into multiple smaller swaps to potentially get a better rate

risk oracle