---
tags: LitReview
---
# Balancer Withdrawal Mechanisms Review
## Summary
"Balancer turns the concept of an index fund on its head: instead of paying fees to portfolio managers to rebalance your portfolio, you collect fees from traders, who rebalance your portfolio by following arbitrage opportunities"
## Price Mechanisms
- "Balancer is based on a particular N-dimensional surface which defines a cost function for the exchange of any pair of tokens held in a Balancer Pool."
- Essentially the same rules as uniswap are applied where it is assumed that arbitrage can bring prices in line with the correct values.
- The exchange for withdrawals is determined based upon the invariant.
## The Vault
- This smart contract is implemented to manage all tokens in each balancer pool and take care of any swap/exit/join actions
- Accounting logic is taken care of here, pool logic is taken care of within the pool contract
- **Streamr Connection**: Should each pool be managing accounting + pool logic, or is it worthwhile to implement a similar vault contract for all accounting logic
- **Streamr Connection**: This vault contract could possibly be run off the shelf with modifications, per the balancer documents: "This architecture brings different pool designs under the same umbrella; the Vault is agnostic to pool math and can accommodate any system that satisfies a few requirements. Anyone who comes up with a novel idea for a trading system can make a custom pool plugged directly into Balancer's existing liquidity instead of needing to build their own Decentralized Exchange."
- **Streamr Connection**: We might be able to design a way to take care of asymmetric liquidity needs by having it be that redemptions can be taken care of with a pool of funds held out while the broker unwinds.
- Gas effeciency is one of the biggest benefits to using this. Below is the comparison of gas cost from the documents:

## Flash Loans (Enabled by the Vault)
- Flash loans take care of the risks to uncollateralized loans by making it such that the amount must be paid back in the same transaction (with interest).
- Essentially, this gets used for arbitrage because when a user identifies mispricing between pools they use the flash loan to swap and close the arbitrage without putting up capital and then get the profits.
- **Streamr Connection**: Maybe there is a way to ensure single transaction such as having the brokers put out requests for stake which mean when given collateral it automatically is put toward the specified contract?
- **Streamr Connection**: Is there a need for any type of arbitrage? Is arbitrage between pools something to be encouraged or is it not really possible because of the need for things such as timelocks?
## Weighted Pools and AAVE Safety Module
- Balancer uses weighted pools where an allocation can be set between different assets.
- AAVE safety module is built off this to take care of cases where there is a deficit.
- In this case part of the locked AAVE gets auctioned to cover the assets needed to solve the deficit.
- Rewards are given to those who put funds into the safety module to secure against possible events
- Rewards are subject to a waiting period before they are able to be claimed
- If the safety module can't cover the shortfall then new AAVE is issued and sold in the open market
- The safety module uses 80% AAVE/20% ETH
## Central Counterparty Clearing House Connection
- With the use of the vault, there is a possibility of replicating the CCP strategy of insurance for losses
- The way this insurance policy might interact would be to require all broker pools to put up insurance payments each period to fund the insurance policy
- Upon a slashing in pools, there could be payments from the insurance policy to cover some losses
## Liquidity Providers
- In balancer, as well as other projects, providing liquidity is incentivized by profits for providing liquidity
- **Streamr Connection**: If a delegator wants an instant redemption, they can possibly get the payout from a liquidity miner who then assumes both the risk of getting the payout from the broker as well as the interest accrued during a period of waiting.
## Merkle Orchard
- This contract implements a much more gas effecient check on balances for withdrawal
- "A Merkle tree is a data structure that makes it easy to check data validity, in this case token balances. On each level of a balanced binary tree, elements are hashed together so it’s possible to verify that data exists in the tree by submitting hashes from leaf to root, a “Merkle Proof”."
- **Streamr Connection**: Limiting the withdrawals to weekly periods could both save on gas while also helping to coordinate liquidity.
- Claims can go to custom callback contracts that send to a liquidity pool.
- **Streamr Connection**: Instead of withdrawal to an account, it could go to staking another contract right away.
## Key Conclusions
1. The vault smart contract might be worthwhile to look at for adapting into the streamr ecosystem
2. By utilizing the vault, a CCP style insurance policy could be enacted
3. Flash loans likely don't have a huge connection to the streamr project, however, in the case of wanting to have some sort of arbitrage ability it could be useful
4. A safety module kind of mechanism might be worthwhile to plug up any issues.
## Resources
1. https://docs.balancer.fi/
2. https://docs.aave.com/aavenomics/