Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Two examples of calculating price impact with the incorporation of swap fees in single asset deposit scenarios.
Now let’s assume we are depositing into the BAL/WETH 80/20 Pool with 10,000 BAL and no WETH. We will be charged swap fees on the portion of our investment which is “off-balance”. In this case 20% of our pool is not in the form of BAL, therefore that is the taxed portion. As referenced from the trading with swap fees section.
The calculation follows as:
The current pool traits are as follows:
Swap fee: 0.05%
BAL: 5,691,640
WETH: 6,194.1921
BPT: 2,891,789.44800306
Using the known amount for A(t) we can calculate the amount of pool tokens we will be issued for this deposit.\
We can see on the user interface completing this transaction will yield a price impact of 0.03% (0.18% for the larger interaction). What exactly does this mean for an investor? Well in short from price impact for trading we can note that the ratio between assets change as supply and demand shifts during an exchange. In this case we are essentially exchanging BAL for Pool tokens and in doing so Pool tokens are becoming more expensive in reference to BAL. This is a bit more complex than comparing prices of individual assets in a pool, but we will focus on the current example to start. The spot price of a pool token and effective price of a pool token are the variables we need to calculate to determine our price impact from an investment.
Pool token spot price (Assume A(t) = 1 BAL):
Next, we must calculate the ratio of the pool’s invariant before and after the exchange of 10,000 BAL.
Using the invariant ratio, we can determine the new total number of pool tokens and in the same stroke, calculate the amount of pool tokens which we received for the exchange.
Knowing the amount of BAL, we needed to invest and the pool tokens we received in exchange we can determine the effective price of a pool token to compare with our spot price:
An example of a proportional Deposit into the BAL/WETH 80/20 liquidity pool
At the time of writing the BAL / WETH 80/20 pools has the following traits:
Swap fee: 0.05%
BAL: 5,682,882
WETH: 6,232.9054
BPT: 2,891,832.103892
Let’s assume we want to invest 500 BAL, and proportionally this would prompt us to invest 0.548393 WETH to maintain the pool balance (see The Value Function section for reference). We know our amount in and balance in of each token. The ratio of Dk over Bk will be the same regardless of which token is chosen in proportional investments and withdrawals:
See the BAL/WETH 80/20 Withdrawal Section to see that this transaction is reversible.
This section will breakdown the three core cases of asset deposits on Balancer Protocol.
Balancer Protocol allows users to invest in pools in a variety of ways. Proportional deposits yield no price impact and follow the ratios the pool is already in.
Single Sided Deposits permit users to deposit into a pool with only one of the assets. A price impact due to shifting the internal relationship of the tokens will be accounted in this scenario.
Multi-token Deposits are when a user deposits the tokens they have in an unproportional way. Not a single asset but multiple in a non-proportionate way.
See examples of each deposit type in the following pages:
Proportional deposits will yield newly minted Balancer Pool Tokens (BPT) for an investor. This function essentially states that the if the proportional amounts of all tokens deposited (Dk) in relation to the Balance of that given token (Bk) will yield that amount of the new total supply of pool tokens. The example in the whitepaper states that depositing 10% of each of the existing tokens in the pool an investor will receive 10% of the current BPT supply.
Equation:
Sample calculation:
Arbitrarily we will assume we are depositing 15% of the total balance meaning Dk divided by Bk will be 0.15
We will assume our total supply to be 10,000 BPTs at this time for the sake of simplicity. From here can make the following calculations:
Substituting 0.15 for our deposit over balance ratio and 10,000 for the supply value we can solve for the issued amount of pool tokens.
This shows that using the formula, based upon the number of tokens we deposit into a pool based upon the balance already we present we will be awarded a proportional number of pool tokens. These pool tokens are a user’s way to redeem their assets when the pool is exited.
Overview of asset deposits and withdrawals on Balancer Protocol
What is the act of providing liquidity, and what does it mean for me as an investor? Providing liquidity is when a user or entity places their assets into a liquidity pool. A liquidity pool is its own ecosystem where the assets within it are priced in relation to one another. The relative pricing inside the pool is only altered when outside interactions such as trades or new “off-balance” investments occur. The expectation as a liquidity provider (LP) is that as market prices change, the liquidity pool will be interacted with, and the internal balances of tokens will most likely change over time.
What benefits does providing liquidity give me, why should I not just hold all my assets individually? There are several key benefits providing liquidity for users which holding them does not permit.
Firstly, are the swap fees which are charged to those who interact with your liquidity pool. The more interactions with your pool, the more swap fees you will earn, growing the size of your investment over time. The second benefit are the platform rewards. Multiple decentralized exchange platforms such as Balancer incentivize their liquidity pools with additional rewards for asset pairs which are chosen through the liquidity mining & governance systems. This makes a liquidity pool an easy way to gain access to and maintain exposure in a strategic way to multiple assets while receiving economic incentives.
When providing liquidity to a pool on Balancer users have a few options. Originally in Balancer V1 liquidity providers had one option; to provide liquidity in the portions of tokens designated by the pool. For example, if a pool was weighted at a 50 / 50 ratio the liquidity provider had to provide liquidity of both tokens proportionally. This can become cumbersome in cases of multiple tokens such as eight token index pools.
Balancer V2 now permits liquidity providers the option to invest in pools using only a single asset which will then be added to the pool shifting the ratios of all other assets. This can be done with as many tokens as a liquidity provider has applicable to a pool and in proportion creating an extreme amount of flexibility when user’s want to invest in more exotic asset pools.
When a user invests in a pool in an unproportioned manner a price impact will take place because the internal pool ratios are changing. This is indirectly a cost to a new liquidity provider due to their investment shifting asset prices. This occurrence is called price impact. Like price impact incurred by traders during large swaps, this happens to maintain the supply and demand markets for all tokens involved. In this document we will examine several examples for each of these different investment conditions to display the underlying math which determines price impact on investments.
How does a single sided deposit work?
The pool tokens issued to a depositor of a single asset can be determined by utilizing the change in the value function (invariant) of the pool. As seen in the whitepaper the ratio of the change in the value function will yield the number of tokens issued. This information will become even more important when discussing multi-asset deposits:
This can be simplified for our purpose of a single sided deposit where all other tokens in a pool maintain constant balances. The token which we are investing into a pool will be denoted with the letter “t”. Amount in (At), Balance-In (Bt), Weight-In (Wt) and the pool token supply will be the variables in concern. When simplified the equation is as follows:
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.
Pool token spot price (Assume A(t) = 1 BAL):
Then, we must calculate the ratio of the pool’s invariant before and after the exchange of 100,000 BAL.
Using the invariant ratio, we can determine the new total number of pool tokens and in the same stroke, calculate the amount of pool tokens which we received for the exchange.
Knowing the amount of BAL, we needed to invest and the pool tokens we received in exchange we can determine the effective price of a pool token to compare with our spot price:
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.
This section will breakdown the two core cases of asset withdrawals on Balancer Protocol.
Balancer Protocol allows users to redeem their investments from pools in a two possible ways. Proportional withdrawals yield no price impact and follow the ratios the pool is already in.
Single Sided withdrawals permit users to withdraw from a pool in the form of only one of the assets. A price impact due to shifting the internal relationship of the tokens will be accounted in this scenario.
See examples of each withdrawal type in the following pages:
The opposite operation is needed to calculate the amount of each token remove from a pool upon withdrawing. The value we calculate will correlate to the balances of the tokens within the pool. Given any pool an investor may have funds in, they can determine the tokens they will receive as a % of the token balances.
Equation:
The Balance term (Bk) will vary for every pool and each token within a pool however the portion of each balance an investor is entitled to is related to their share of the pool in reference to pool tokens always.
As the external market prices of assets change the balances of tokens will fluctuate due to trading. The portion of the pool owned by an investor can only be changed as investors enter and exit the pool. For example, you may own 10% of a pool and after a few months as more people invest you now own 4% due to total supply of tokens increasing.
Assuming our previous example where we hold 1,500 pool tokens let’s assume the pool, we invested in has attracted far more liquidity. Now the total supply is at 25,000 pool tokens. Let’s calculate the number of tokens we will receive when we redeem our BPTs.
Using the expression above we know that given the current balances of each asset in the pool (Bk) we will receive 6% of each token in our wallet upon redemption. These examples may be simple in nature but, coupled with swap fees, they are the first building block towards understanding the complexity of single of mixed asset deposits and withdrawals.
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.
At the time of writing the BAL / WETH 80/20 pools has the following traits:
Swap fee: 0.05%
BAL: 5,682,882
WETH: 6,232.9054
BPT: 2,891,832.103892
Under the same conditions shown in the deposit example we will determine the amount of each token we would receive if we redeemed the 254.433587 pool tokens we were issued. The amount we receive should be the same as we would invest for the issued amount because the pool traits are constant in this example.
This solidifies the premise of accounting for the pool issuing and redeeming pool tokens Given the pool traits the minting or burning (investment or withdrawal) of pool tokens will respect the ratios of the balances within the pool and the percentage of total pool tokens.
Single Sided Withdrawals will follow the same principles laid out in the single sided deposit section prior. The invariant is the core of these transactions and resulting equations are derived from there. As seen in the whitepaper the ratio of the change in the value function will yield the number of tokens redeemed.
This can be simplified for our purpose of a single sided withdrawal where all other tokens in a pool maintain constant balances. The token which we are removing from a pool will be denoted with the letter “t”. Amount Out (At), Balance-Out (Bt) before the transaction, Weight-Out (Wt) and the pool token supply will be the variables in concern. When simplified the equation is as follows:
Now let’s assume we are withdrawing from the BAL/WETH 80/20 Pool, we want to remove 5 WETH from the pool not knowing how many pool tokens we will need to redeem. We will be charged swap fees on the portion of our withdrawal which is “off-balance”. In this case 80% of our pool is not in the form of WETH, therefore that is the taxed portion. In this case we know we will receive the total of 5 WETH from the withdrawal, (At), this means our “sent” value will be unknown and slightly higher to compensate the swap fee we are charged.
The current pool traits are as follows:
Swap fee: 0.05%
BAL: 5,598,984
WETH: 5,798.4836
BPT: 2,816,401.77912812
This equation can be rearranged to solve for A (sent) in terms of our BPT (P_redeemed) as follows:
Using this equation, we can solve for A (sent):
For our Spot Price:
From here we can calculate the amount of pool tokens we redeemed to receive our 5 WETH:
Then, we must calculate the ratio of the pool’s invariant before and after the withdrawal.
Using the invariant ratio, we can determine the new total number of pool tokens and in the same stroke, calculate the amount of pool tokens needed to exchange for our WETH.
Knowing the amount of BPT we needed to redeem and the amount of WETH we received in the withdrawal we can determine the effective price of a pool token to compare with our spot price:
Please note the swap fee and pool traits change dynamically over time making calculations such as these valid for only a short period of time. The purpose of these examples is to deepen the understanding of our platform for those interested in are already utilizing Balancer Protocol.