Pods Options
app.pods.financeGithubBlogDiscord
  • Getting Started
  • Understand Options
    • What are options?
    • How do options work?
    • Pricing Options
  • The Protocol
    • Overview
    • Safety Measures
    • Ecosystem Participants
    • Use Cases
  • Options
    • Overview
    • Options Instrument
      • Variables
      • Functions
        • Mint
        • Unmint
        • Withdraw
        • Exercise
    • Smart Contracts
      • OptionFactory
      • PodPut
      • WPodPut
      • PodCall
      • WPodCall
    • Applied Use Cases
    • Understanding Returns
  • Options AMM
    • Overview
    • Options AMM
      • Variables
      • Components
      • Functions
        • Add Liquidity
        • Re-add Liquidity
        • Trade
        • Remove Liquidity
      • Pricing
      • Find The Next IV
      • Fees
      • Scenarios
        • LP Simulations
    • Smart Contracts
      • OptionAMMPool
      • OptionAMMFactory
      • OptionPoolRegistry
    • Applied Math
  • Developers
    • System Overview
    • Deployed Contracts
    • Dev Environment
  • Interfacing with Pods
    • Brand Assets
  • Code Integration Guides
    • Integrating with Pods (video)
    • How To Create Your Own Option
    • How To Create Your Own Pool
    • How To Trade (Buy/Sell)
    • How To Exercise
    • How To Remove Liquidity
  • User Guides
    • Videos
  • Security
    • Audits
  • APPENDIX
    • FAQ
    • Glossary of Terms
  • Additional Resources
  • app.pods.finance
  • Github
  • Blog
  • Discord
  • Twitter
  • Pods v0 Docs
Powered by GitBook
On this page
  • Add Liquidity
  • 1. Calculate factors
  • 1.1 Calculate Option Price
  • 1.2 Calculate the Pool's Value Factor ()
  • 2. Updates
  • 2.1 Update Deamortized Balance of the pool for each token
  • 2.2 Update the User Balances for each token and the Pool Factor previously calculated
  • 2.3 Update Total Balance of the pool for each token

Was this helpful?

  1. Options AMM
  2. Options AMM
  3. Functions

Add Liquidity

Understanding the add liquidity event step-by-step.

PreviousFunctionsNextRe-add Liquidity

Last updated 3 years ago

Was this helpful?

Add Liquidity

The event of adding liquidity requires the following information from the user: 1. AduA_{du}Adu​ Amount of token A to be added 2. BduB_{du}Bdu​ Amount of token B to be added 3. Owner

After the information was supplied, the add liquidity function will perform the following activities:

1. Calculate factors

1.1 Calculate Option Price

This happens if i≠0i≠0i=0. If i=0i=0i=0 , it is not required to calculate the option price in the very first liquidity provision in a pool.

For simplicity, let's acknowledge that the option price is a function that required a MarketData{MarketData}MarketData and an internal vector (IVIVIV) as input.

Pi=fp(IVi−1,MarketDatai)P_i=f_p({IV_{i-1}},{MarketData_i})Pi​=fp​(IVi−1​,MarketDatai​)

For more details about the pricing formula or its contract implementation for pricing the options, check .

1.2 Calculate the Pool's Value Factor (FviF_{v_{i}}Fvi​​)

If i=0i=0i=0 , Fvi=1F_{v_{i}}=1Fvi​​=1

If i≠0i≠0i=0 , Fvi=TBAi−1⋅Pi+TBBi−1DBAi−1⋅Pi+DBBi−1\displaystyle F_{v_{i}}= \frac{TB_{A_{i-1}}\cdot P_i+TB_{B_{i-1}}}{DB_{A_{i-1}} \cdot P_i+DB_{B_{i-1}}}Fvi​​=DBAi−1​​⋅Pi​+DBBi−1​​TBAi−1​​⋅Pi​+TBBi−1​​​

Since this is the first liquidity provision of the pool, this is i=0i=0i=0 and therefore, Fvi=1F_{v_{i}}=1Fvi​​=1.

2. Updates

2.1 Update Deamortized Balance of the pool for each token

By the time the pool is created (i=0i=0i=0) , the DBAiDB_{A_i}DBAi​​and DBBiDB_{B_i}DBBi​​ will be equal to the AduA_{du}Adu​ and BduB_{du}Bdu​ since:

Fvi=1F_{v_{i}} = 1Fvi​​=1 DBAi−1=0\displaystyle DB_{A_{i-1}}=0DBAi−1​​=0 DBBi−1=0\displaystyle DB_{B_{i-1}}=0DBBi−1​​=0

DBAi=DBAi−1+AduFvi\displaystyle DB_{A_{i}}=DB_{A_{i-1}} +\frac{A_{du}}{F_{v_{i}}}DBAi​​=DBAi−1​​+Fvi​​Adu​​

DBBi=DBBi−1+BduFvi\displaystyle DB_{B_{i}}=DB_{B_{i-1}} +\frac{B_{du}}{F_{v_{i}}}DBBi​​=DBBi−1​​+Fvi​​Bdu​​

2.2 Update the User Balances for each token and the Pool Factor previously calculated

Updating this factor is essential, especially when there is a re-add liquidity event.

UBAu=AduUB_{A_{u}}=A_{du}UBAu​​=Adu​

UBBu=BduUB_{B_{u}}=B_{du}UBBu​​=Bdu​

The UBfuUB_{f_{u}}UBfu​​ works as if it was a snapshot of the pool's factor at the moment of this user's deposit. This factor will be updated in the case of re-add liquidity by the user.

UBFu=FvduUB_{F_{u}}=F{v_{du}}UBFu​​=Fvdu​

2.3 Update Total Balance of the pool for each token

TBAi=TBAi−1+AduTB_{A_{i}}=TB_{A_{i-1}} +A_{du}TBAi​​=TBAi−1​​+Adu​

TBBi=TBBi−1+BduTB_{B_{i}}=TB_{B_{i-1}} +B_{du}TBBi​​=TBBi−1​​+Bdu​

At the contract level, an ERC20 transfer is happening. Total balance (TB) is just a mathematical representation. The Total balance is checked by consulting the balanceOf() of the pool contract of the respective token (tokenA or tokenB)

Add liquidity ✅

this section
ABPrice variable on _addLiquidity at AMM.sol
PoolValue factor variable on _addLiquidity at AMM.sol
FImp function at AMM.sol
deamortizedBalance on _addLiquidity at AMM.sol
Updating User Balance (userDepositSnapshot) at _addLiquidity on AMM.sol