Weighted Maths
Overview
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.
A360's AMM's Weighted Math equation is derived from BalancerV2's generalization of the constant product formula, accounting for cases with n>2 tokens as well as uneven weightings.
Invariant
The A360 AMM Mathemathical Invariant is defined as follows:
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.
Spot Price
The Spot Price for an asset inside of the pool is defined by both the weights defined during pool creation and the token balances of the pool at a specific point in time.
is the balance of token , the token being sold by the swapper which is going into the pool
is the balance of token , the token being bought by the swapper which is going out of the pool
is the weight of token
is the weight of token
Spot Price With Swap Fees
Swap Fees must be accounted for to calculate effective Spot Price. To do so we perform the same calculations, but subtracting the swap fees. The formula looks as follows:
Swap Formulas
outGivenIn
In a swap equation the token balances impacted are the input and the output tokens. The formula which calculates output balance based on input balance is as follows:
inGivenOut
To calculate the required asset input to receive a specific target output balance of the desired asset is defined below:
Last updated