Here we will solve two examples using the pool above, weights are 40%, 40%, and 20% respectively.
Pool traits at the time of writing:
Swap fee: 0.25%
WMATIC: 273,763
MTA: 1,023,625
WETH: 66.0812
Total BPT: 249494.507172
For this example, we will choose to deposit 1,000 WMATIC and 2 WETH without altering the total MTA within the pool. Our alternate example will use a deposit of 10,000 WMATIC and 2 WETH to solidify understanding in a slightly more complex scenario. These instances are referenced below.
Firstly, we will determine our spot prices of each token in terms of 1 BPT. This can be done using the reciprocal of the redemption function most conveniently, making our input 1 BPT. We will do this for WMATIC and for WETH.
WMATIC
WETH
Next, we can determine the amount of BPT our investments would be worth based upon the spot price, this assumes zero price impact is occurring and sets our base case.
From here we must determine what value of our BPT are disproportionate from the ratios of the pool for an evenly distributed deposit this can be done simply by multiplying the Total BPT by the weight of each token as follows.
Using these values, we can determine how much of the total swap fee will be paid for each single token deposited. If our Base Value deposit for any token in BPT exceeds the Proportionate BPT deposit value, a swap fee will be implemented on the excess portion.
For example, because we deposited a Base Value of 364.5419683 BPT in WMATIC and the proportional deposit is 749.9135826 no swap fee will be implemented on the 1,000 WMATIC which were deposited. These will be crucial in determining our invariant ratio after the swap.
In the case of WETH our Base Value is 1510.241988 BPT, and proportional deposit is only 374.9567913 BPT. This yields the following calculation for a taxable amount:
Lastly, we must calculate our initial and post deposit invariant with fees to determine our net BPT and price impact based on the base case.
Our invariant ratio, multiplied by the initial total pool tokens, will yield the total pool tokens and therefore the amount which we will receive during our deposit. This value in comparison with our Base Case will determine our price impact.
Multi-token deposits encompass the single sided deposit knowledge base and emphasize how Balancer Protocol's invariant and swap fees are incorporated in complex scenarios.
Balancer Protocol has several features which differentiate it from all other core AMM platforms such as Uniswap and Curve. The one of focus in this section is the multi-token pools and the layer of complexity they add to the calculation of price impact, and ultimately disproportionate asset deposits.
Withdrawals only support proportional or single sided options in the current state; therefore, a single sided example will be solved. The principles defined in the proportional and single sided sections will be building blocks for the examples solved here.
For both examples we will utilize the WMATIC MTA WETH 40/40/20 Pool on Polygon as it highlights uneven weightings of assets as well as the multi-token aspects, we are interested in.
This example shows an increase in WMATIC only which evens out the ratios of deposit compare to the previous Multi-token example. Notice the decrease in price impact as the ratio is better managed.
Pool traits at the time of writing:
Swap fee: 0.25%
WMATIC: 273,763
MTA: 1,023,625
WETH: 66.0812
Total BPT: 249494.507172\
The changes from the previous example will be notably base value of 10,000 WMATIC in BPT changing the calculations that follow.
The new Base Total BPT will change the proportional values as shown below.
In this case both of our Base Values for WMATIC and WETH are greater than the proportional values for an evenly distributed despot. This means that both deposits will be taxable in terms of the swap fee.
WMATIC
WETH
Finally, we can utilize these values to compare the invariant ratios between the initial and the after-swap fees are paid. This will determine the BPT we receive as opposed to what we would without any change in spot price.
Our invariant ratio, multiplied by the initial total pool tokens, will yield the total pool tokens and therefore the amount which we will receive during our deposit. This value in comparison with our Base Case will determine our price impact.