LogoLogo
  • Learn about Balancer
  • Background
    • Team Goal
  • Fundamentals
    • White Paper
      • The Value Function
        • USDC WETH WBTC 33/33/33
        • BAL WETH 80/20
        • Price Change Proof
      • Spot & Effective Price
        • Spot Price
        • Effective Price
        • Price Impact
        • Price Impact - With Swap Fees
      • Trading Formulas
        • Out-Given-In
          • Including Swap Fees
        • In-Given-Out
          • Including Swap Fees
        • In-Given-Price
          • In-Given-Price Proof
          • Arbitrage 80/20
          • Arbitrage 50/50
        • Summary
      • Deposits & Withdrawals
        • Deposits
          • Proportional Deposits
            • BAL / WETH 80/20
          • Single Sided Deposits
            • Price Impact; 10,000 BAL
            • Price Impact; 100,000 BAL
          • Multi-token Deposits
            • Price Impact WMATIC / MTA / WETH
            • Price Impact [2] WMATIC / MTA / WETH
        • Withdrawals
          • Proportional Withdrawals
            • BAL/WETH 80/20
          • Singled Sided Withdrawals
            • Withdrawal Price Impact
    • Impermanent Loss
      • 50/50 Pools
      • 80/20 Pools
      • Multi-token Pools
    • veBAL Tokenomics
      • TLDR
      • Vote-Escrowed Governance
      • Financial Implications
        • Boosting BAL Incentives
          • Minimum veBAL for Max Boost
          • Maximum Boost
          • Calculating my Boost
          • Boost Delegation for Contract Wallet
        • Protocol Revenue Distribution
        • Gauge Voting
      • Inflation Schedule
      • veBAL FAQ
  • More Information
    • For Developers
      • GitHub Integration
    • For Support
    • References & Related Content
  • Documented Questions
    • Coming soon
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Fundamentals
  2. White Paper
  3. Trading Formulas

In-Given-Out

PreviousIncluding Swap FeesNextIncluding Swap Fees

Last updated 3 years ago

Was this helpful?

In-Given-Out

The In-Given-Out equation will be the opposite thought process as the Out-Given-In formula. The idea is a trader, you, or I, wants to receive a specific number of tokens and this equation will solve how many tokens need to trade into a pool to receive that amount out. Note the variables defined in the introduction have not changed.

Ai=Bi ∗ ((BoBo−Ao)WoWi−1)A_{i} = B_{i} \ * \ \Bigg(\bigg({\frac {B_{o}}{B_{o}-A_{o}}}\bigg)^{{\frac {W_{o}}{W_{i}}}}-1\Bigg)Ai​=Bi​ ∗ ((Bo​−Ao​Bo​​)Wi​Wo​​−1)

For example, we will determine which of two pools is best to trade USDC for WMATIC on Balancer’s Polygon network pools. We will examine the two following pools TEL/WMATIC/USDC 60/20/20 (0.2%) and the WMATIC/USDC/WETH/BAL 25/25/25/25 (0.25%) pools.

Pool (Wo / Wi)
USDC Balance (Bi)
WMATIC Balance (Bo)

60/20/20

107,244

56,164

25/25/25/25

5,194,894

2,722,125

Firstly, let us see what it will cost us to receive 1000 WMATIC as the amount we know we want out of our trade.

TEL/USDC/WMATIC 60/20/20:

WMATIC/USDC/WETH/BAL 25/25/25/25:

In the case we will spend less using our second option to receive the same amount of WMATIC making it the more desirable pool for the SOR to route us through. Now let’s incorporate swap fees.