Weighted Math
Last updated
Last updated
Weighted Math is designed to allow for swaps between any assets whether or not they have any price correlation. Prices are determined by the pool balances, pool weights, and amounts of the tokens that are being swapped.
Polaris's Weighted Math equation is a generalization of the constant product formula recommended for Automated Market Makers (AMMs) in a post by Vitalik Buterin. Polaris's generalization accounts for cases with tokens as well as weightings that are not an even 50/50 split.
As the price of each token changes, traders and arbitrageurs rebalance the pool by making swaps. This maintains the desired weighting of the value held by each token whilst collecting trading fees from the traders.
The value function is defined as:
Where >
ranges over the tokens in the pool
is the balance of the token in the pool
is the normalized weight of the tokens, such that the sum of all normalized weights is 1.
For more formulas and derivations of the below formulas, please refer to the Balancer Whitepaper.
Each pair of tokens in a pool has a spot price defined entirely by the weights and balances of just that pair of tokens. The spot price between any two tokens,, or in short , is the the ratio of the token balances normalized by their weights:
is the balance of token , the token being sold by the trader which is going into the pool
is the balance of token , the token being bought by the trader which is going out of the pool
is the weight of token
is the weight of token
When we consider swap fees, we do exactly the same calculations as without fees, but using instead of since fees are taken out of the input amount. The equation then becomes: