Introducing Balancer Simulations

Vasily Sumanov
Balancer Simulations
8 min readMar 9, 2021

A Python-based simulation environment for Balancer Pools

by Vasily Sumanov, Andrew Chiw, Raul Martinez and Angela Kreitenweis

Introduction

Balancer is one of the biggest liquidity providers on the market with $1.4B TVL, ranked number 5 among all DEXes by TVL. But Balancer Pools are much more than DEXes, they open up a wide range of opportunities for programmable liquidity:

  1. A building block for DeFi applications
    Balancer Pools are a key building block in other protocols, building and maintaining decentralized indices and portfolios, such as PowerIndex, PieDAO, and others. At the time of writing, the total TVL in these protocols sums up to ~$100m. Aave is a prime implementation of the proof of liquidity concept, with over 300M in a pool whose shares can be used as a staking asset. Following their example, EthicHub added the staking of pool liquidity as a major component of their tokenized Compensation System.
  2. Initial DEX offerings and liquidity bootstrapping
    Liquidity bootstrapping via Balancer pools became trendy, and more and more projects use this option for building up a community with skin in the game. These Initial DEX Offerings turned out to be particularly interesting for fair token distribution and price discovery as Perp.fi, FURUCOMBO, and Nsure demonstrated last year.
  3. Community token distribution
    YFI’s famous yield farming program offered YFI rewards for staking stable coins in various Balancer Pools to distribute YFI tokens with governance voting rights.
  4. Asset-specific AMM implementations
    Ampleforth’s rebase cryptocurrency is a perfect example of how to make use of Balancer smart pools. Via adapting pool weights to AMPL rebases, the AMPL protocol provides elastic supply and thus, removes price volatility and avoids value being drained from the pool by arbitrageurs.

This wide array of use cases requires a rigorous engineering process to explore and specify requirements for pool design and continuously optimize against an ecosystem’s objectives.

Simulations, as applied in various stress test contexts and frameworks, have proven to be a valuable tool to detect challenges and sensitivities early on.

With this article, we introduce Balancer Simulations, an open-source cadCAD model and documentation to support the design, optimization, and validation of Balancer Pools across their entire life cycle.

TVL in bullish markets always goes north. In many cases, the Invariant V (measured by the absolute value of Value Function), is a more meaningful metric for the healthiness of your pool (Source: Balancer Simulations)
In growing pools, some token balances might still decline. Growth in stable tokens (here DAI) at the cost of losing tokens growing in value (here WETH) poses a risk to liquidity providers and leads to impermanent loss. (Source: Balancer Simulations)

Model Introduction

At its core, Balancer Simulations offers a Python version of the full set of transactions available in a V1 Balancer Pool.

For code examples, please visit the Balancer Simulations documentation [1].

Note that this action space applies to native Balancer Pool implementations, and DeFi solutions using Balancer Pool variants like PowerPool and PieDAO. All pool operations in our model are implemented as cadCAD state updates. On top of these state update functions, cadCAD supports different system modeling approaches and can be easily integrated with common empirical data science workflows, like Monte Carlo methods, A/B testing, and parameter sweeps for a wide range of applications:

  • Analyze existing Balancer Pools using on-chain transaction data, understand pool characteristics, strengths, and weaknesses
  • Gain intuition by exploring pool variants, observe system behavior over time, derive the most valuable monitoring metrics for your use case
  • Run experiments based on historical transactions, mix historical and synthetic transactions to model particular market scenarios
  • Develop and test adaptive Dynamic AMM solutions, like Dynamic Weights Changing, test and optimize controls and feedback loops
  • Model agent behavior and apply Reinforcement Learning to run stress tests for a proposed system design
How attractive is your pool for liquidity providers? What are the drivers for LP rewards? For pools focusing on fee returns, it is important to gain a detailed understanding of agent behavior, fee-generating events, and most valuable transactions. (Source: Balancer Simulations)

Balancer Simulations V1.0

With Balancer Simulations V1.0 we demonstrate how real-world transactions can be plugged into a Balancer Pool model. We add external price feeds to showcase how various data sources can be combined for a most realistic simulation scenario. At the same time, the prototyping effort for new Balancer Pool designs is minimized using a Python digital twin of the system.

We are following the cadCAD System Model standard, with

  • State Variables to describe the mathematical state of the pool
  • State Update Functions, changing the state variables in discrete events
  • Policy Functions, defining how the system should be updated, in our case mapping transactions to the right method in the model
  • Partial State Update Blocks, which are sets of state updates and policy functions

Balancer Simulations V1.0 combines the following components:

a) on-chain transaction data of a Balancer pool, parsed from BigQuery Ethereum-Balancer, enriched with archive node information

b) USD price data (API or .csv exports from analytical platforms)

c) the Balancer Simulations cadCAD model

d) Jupyter Notebooks as the main interface to work with the model, customize simulations, and gain insights

Balancer Simulations model architecture

For setting up your environment, defining your data sources, and shaping your simulation please visit

Arbitrage trades against external markets drain value from your pool. There are several options to limit arbitrage trading opportunities and capture value. Simulations allow verifying the effect of concepts like Dynamic Weights Changing. (Source: Balancer Simulations)

Balancer Simulations Research Roadmap

With Balancer Simulations, we aim to provide infrastructure for Balancer Pools R&D and pool management.

Today’s main challenges for AMMs are capital inefficiency, and arbitrage value drain as a side-effect of token price volatility (impermanent loss)[2][3]. Both pose a risk to liquidity providers, and there are several approaches for solving these issues.

Optimizing trading fees is a first option [4], with the challenge of finding an optimal balance of attracting liquidity without distorting the accuracy of prices reported from the pool.

As suggested in Dynamic Weights Changing [5], adapting AMM parameters dynamically according to market changes is a second approach. Most recent research confirms that AMMs with dynamically adjusted weights can reduce arbitrage value drain, and provide more stable LP value than AMMs with constant weights [6].

All dynamic AMMs (dAMMs) rely on internal or external controlling signals to adjust parameters of the invariant equation. We distinguish two types of feedback loops applied:

a) Open-loop control, relying on external controlling signals, such as price oracles.

b) Closed-loop control, processing internal controlling signals, like trading activity or virtual balances.

Examples of open-loop dAMMs include DODO Classic liquidity pools [7] and the PowerIndex v2 Dynamic AMM [8], both successfully operating in mainnet. DODO Classic pools adjust i — a price parameter in the AMM equation based on oracle data, decreasing impermanent loss of LPs [9]. PowerPool changes weights based on TWAP oracle price feeds for smart rebalancing strategies in multi-token portfolios. [10].

In August 2020, 1inch.exchange introduced a new variant of a closed-loop control dAMM, called Mooniswap [11]). Kyber Network’s Dynamic Market Making [12] optimizes the price definition with a similar concept, applying a virtual balance controlling signal. Another example of a closed-loop dAMM is Bancor v2.1. The core concept of any asset/BNT trading pair and impermanent loss insurance is based on repayments in BNT tokens. BNT tokens are issued according to an elastic supply algorithm and cover impermanent loss for LPs staying in the pool for 100 days at minimum [13].

Of course, both types of feedback loops for dAMMs have their pros and cons. The main advantage of open-loop control dAMMs is flexibility allowing for a wide variety of rebalancing strategies in pool capital management. However, relying on external services such as oracles complicates the implementation, can be costly and introduces a new attack vector. Closed-loop control dAMMs offer (potentially) lower implementation effort, independence from external data sources, and extrinsic incentives.

At the present moment, AMMs with dynamically adjusted parameters are early-stage research for a new generation of DEXes, decentralized indices, automatically traded portfolios, and novel financial primitives. We will pick up Dynamic AMMs in forthcoming steps on the Balancer Simulations research roadmap:

  1. Structured analysis of Dynamic Balancer Pool variants
  2. Generalized metrics for analyzing Dynamic Balancer Pools, such as arbitrage trades and volume, the value extracted, or fees acquired by LPs
  3. Optimal weights changing process according to predefined system goals, optimizing the frequency of weights changing, or speed of transitioning
  4. Optimal trading fees for Dynamic Balancer Pools
  5. Dynamically Adjusted Weights based on closed-loop control signals, such as virtual price, measured by token balance deviation

Finally, Balancer V2 is due for launch in Q1 2021. Its tech specification presents an additional abstraction level, splitting the AMM logic and custody functions into different parts of the system. Coupled with a Dynamic AMM approach, this will spark off another wave of DeFi products and open up exciting research questions for Token Engineers.

Open Research for the Balancer Ecosystem

Balancer Simulations is a project of TE-AMM and the Token Engineering Community, funded by grants from Balancer and PowerPool, and kicked off by EthicHub.

It aims to build infrastructure and knowledge for rigorous Balancer Token Engineering to leverage the power and maximize robustness of Balancer Pools, a core building block in DeFi.

All research and models are available through open source repositories, and will be further developed by TE-AMM. We invite any project using Balancer Pools, or building products on top of it, to check out Balancer Simulations, join our Discord Channel, and contribute to open Balancer research.

Acknowledgements

Thanks very much to the following people for reviews: Markus Buhatem Koch, Michael Zargham, Ryan Watkins, and Andrew Penland.

Notes

[1] Balancer Simulations, “Getting started.”
https://token-engineering-balancer.gitbook.io/balancer-simulations/, March 2021. Accessed: 2021–03–04.

[2] Guillermo Angeris, Hsien-Tang Kao, Rei Chiang, Charlie Noyes, Tarun Chitra, An analysis of Uniswap markets, 2019. Available at: https://arxiv.org/abs/1911.03380

[3] J. R. Jensen and O. Ross, “Managing Risk in DeFi” in CEUR Workshop Proceedings, Aachen 2020, Available at SSRN: https://ssrn.com/abstract=3745568

[4] Alex Evans, Guillermo Angeris, Tarun Chitra, “Optimal Fees for Geometric Mean Market Makers”, 2021. Available at: https://stanford.edu/~guillean/papers/g3m-optimal-fee.pdf

[5] Mohan, Vijay, Automated Market Makers and Decentralized Exchanges: a DeFi Primer (October 30, 2020). Available at SSRN: https://ssrn.com/abstract=3722714

[6] Bhaskar Krishnamachari, Qi Feng, Eugenio Grippo, “Dynamic Curves for Decentralized Autonomous Cryptocurrency Exchanges”. Available at: https://arxiv.org/abs/2101.02778

[7] DODO Docs, “Proactive Market Making Algorithm.”
https://dodoex.github.io/docs/docs/pmm/. Accessed: 2021–03–04.

[8] PowerPool Medium, “PowerIndex v2 Dynamic AMM is launched for ASSY”, https://medium.com/powerpool/powerindex-v2-dynamic-amm-is-launched-for-assy-22dc5a493dc7/. 17 February 2021. Accessed: 2021–03–04.

[9] DODO Docs, “PMM Core Concepts”
https://dodoex.github.io/docs/docs/pmmDetails/. Accessed: 2021–03–04.

[10] PowerPool Medium, “The road to DAMM: launch of PowerOracle v2”, https://medium.com/powerpool/the-road-to-damm-launch-of-poweroracle-v2-ee5dd54410b1/. 17 February 2021. Accessed: 2021–03–04.

[11] Anton Bukov, Mikhail Melnik, Mooniswap whitepaper (10 August 2021). https://mooniswap.exchange/docs/MooniswapWhitePaper-v1.0.pdf

[12] Andrew Nguyen, Loi Luu, Ming Ng, Dynamic Automated Market Making, https://files.kyber.network/DMM-Feb21.pdf

[13] Bancor Medium, “Proposing Bancor v2.1: Single-Sided AMM with Elastic BNT Supply”, https://blog.bancor.network/proposing-bancor-v2-1-single-sided-amm-with-elastic-bnt-supply-bcac9fe655b. 13 October 2020. Accessed: 2021–03–04.

--

--

Vasily Sumanov
Balancer Simulations

Postindustrial economy researcher. Interests: social and economic systems, cryptoassets design. Co-founder: technomads.wtf