Balancer V1
Discord
  • Home
  • Getting Started
    • Use Cases
    • FAQ
  • Core Concepts
    • Protocol
      • Background
      • Glossary
      • Pool Lifecycle
      • Limitations
      • Math
        • Exponentiation
    • BAL Governance Token
      • BAL for Gas
    • Liquidity Mining
      • Exchange and BAL Mining Listing
      • Liquidity Mining Estimates API
    • Security
      • Audits
      • Bug Bounty
  • Smart Contracts
    • Exchange Proxy
    • Smart Order Router
      • Development & Examples
    • Smart Pools
      • Overview
      • Configurable Rights Pool
      • Component Libraries
        • Rights Manager
      • Smart Pool Templates
      • Liquidity Bootstrapping FAQ
    • On Chain Registry
    • Interfaces
    • Addresses
  • API
    • Migration to Version 1.0
    • Events
    • API Index
    • UML Docs
  • Guides
    • Interact via Etherscan
    • Using the SOR
    • Creating a Shared Pool
    • Creating a Smart Pool
    • CRP Tutorial
      • Liquidity Bootstrapping Example
    • Smart Pool Use Cases
      • Liquidity Bootstrapping Pool
      • Swing Trading Pool
      • Smart Treasury
      • Perpetual Synthetic Pool
      • Investors' Club
      • Experimental
    • Testing on Kovan
    • Hackathons
      • Hacking & Testing
      • Judging
      • Ideas
Powered by GitBook
On this page
  • This page has been deprecated. V1 documentation is partially maintained here
  • Exponentiation
  1. Core Concepts
  2. Protocol
  3. Math

Exponentiation

PreviousMathNextBAL Governance Token

Last updated 3 years ago

This page has been deprecated. V1 documentation is partially maintained

Exponentiation

The main formulas used in Balancer protocol make use of a form of exponentiation where both the base and exponent are fixed-point (non-integer) values. Take for example the swap functions, where the weights in both the exponent and the base are fractions:

Ao=(1−(BiBi+Ai)WiWo).BoA_o = \left(1 - \left(\frac{B_i}{B_i+A_i}\right)^{\frac{W_i}{W_o}}\right).B_oAo​=​1−(Bi​+Ai​Bi​​)Wo​Wi​​​.Bo​
Ai=((BoBo−Ao)WoWi−1).Bi\begin{equation} \begin{gathered} A_i = \left(\left(\frac{B_o}{B_o-A_o}\right)^{\frac{W_o}{W_i}}-1\right).B_i \end{gathered} \end{equation}Ai​=((Bo​−Ao​Bo​​)Wi​Wo​​−1).Bi​​​​

Since solidity does not have fixed point algebra or more complex functions like fractional power we use the following binomial approximation:

(1+x)α=1+αx+(α)(α−1)2!x2+(α)(α−1)(α−2)3!x3+⋯=∑k=0∞(αk)xk\begin{equation} \begin{gathered} \left(1+x\right)^\alpha=1+\alpha x+\frac{(\alpha)(\alpha-1)}{2!}x^2+ \frac{(\alpha)(\alpha-1)(\alpha-2)}{3!}x^3+ \cdots = \sum_{k=0}^{\infty}{\alpha \choose k}x^k \end{gathered} \end{equation}(1+x)α=1+αx+2!(α)(α−1)​x2+3!(α)(α−1)(α−2)​x3+⋯=k=0∑∞​(kα​)xk​​​

which converges for ∣x∣<1{|x| < 1}∣x∣<1.

When α>1\alpha>1α>1 we split the calculation into two parts for increased accuracy, the first is the exponential with the integer part of α\alphaα (which we can calculate exactly) and the second is the exponential with the fractional part of α\alphaα:

Ai=(1−(BoBo−Ao)int(WoWi)(BoBo−Ao)WoWi%1).Bi\begin{equation} \begin{gathered} A_i = \left(1 - \left(\frac{B_o}{B_o-A_o}\right)^{int\left(\frac{W_o}{W_i}\right)}\left(\frac{B_o}{B_o-A_o}\right)^{\frac{W_o}{W_i}\%1}\right).B_i \end{gathered} \end{equation}Ai​=​1−(Bo​−Ao​Bo​​)int(Wi​Wo​​)(Bo​−Ao​Bo​​)Wi​Wo​​%1​.Bi​​​​
here