Polaris Finance DEX
  • πŸ“ƒAbout Polaris Finance
  • 1️Polaris Finance Phase 1 (Seigniorage)
    • Phase 1 FAQ
    • Token Genesis Pools & Launches + FAQs
      • POLAR Gen. & Launch
      • LUNAR Gen. & Launch
      • TRIPOLAR Gen. & Launch
      • ETHERNAL Gen. & Launch
      • ORBITAL Gen. & Launch
      • USP Gen. & Launch
      • BINARIS Gen. & Launch
    • SUNRISE and Earn
    • SUNRISE Expansions
    • BONDs Mechanism
    • Pegged Assets
    • BOND Assets
    • DAO Fund
    • Contracts & Wallets
  • 2️Polaris Finance Phase 2 (DEX)
    • Phase 2 FAQ
    • Overview
    • How it works
    • xPOLAR
    • veXPOLAR
      • Overview
      • veXPOLAR FAQ
    • Pools
      • Weighted Pools
      • Stable Pools
      • MetaStable Pools
    • Fees
    • Maths
      • Weighted Math
      • Stable Math
  • πŸ†˜GUIDES
    • Moving between Aurora and Telos
    • Moving Assets and Liquidity to the new PolarisDEX
    • Moving from Solana to Aurora
    • Moving from EVM to Aurora
    • How to provide liquidity
  • πŸ’‘References
    • Dictionary
    • Polaris Finance Audit
Powered by GitBook
On this page
  • Overview
  • Invariant
  • Spot Price
  • Spot Price with Swap Fees
  1. Polaris Finance Phase 2 (DEX)
  2. Maths

Weighted Math

PreviousMathsNextStable Math

Last updated 2 years ago

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.

Polaris's Weighted Math equation is a generalization of the xβˆ—y=kx*y=kxβˆ—y=k constant product formula recommended for Automated Market Makers (AMMs) in . Polaris's generalization accounts for cases with nβ‰₯2n \geq2nβ‰₯2 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.

Invariant

The value function VVVis defined as:

V=∏tBtWtV= \prod_t B_t^{W_t}V=tβˆβ€‹BtWt​​

Where >

  • ttt ranges over the tokens in the pool

  • BtB_t Bt​ is the balance of the token in the pool

  • WtW_tWt​​is the normalized weight of the tokens, such that the sum of all normalized weights is 1.

Spot Price

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,SpotPriceioSpotPrice^o_iSpotPriceio​, or in short SPioSP^o_iSPio​, is the the ratio of the token balances normalized by their weights:

SPio=BiWiBoWoSP^o_i = \frac{\frac{B_i}{W_i}}{\frac{B_o}{W_o}}SPio​=Wo​Bo​​Wi​Bi​​​
  • BiB_iBi​ is the balance of token iii, the token being sold by the trader which is going into the pool

  • BoB_oBo​ is the balance of token ooo, the token being bought by the trader which is going out of the pool

  • WiW_iWi​ is the weight of token iii

  • WoW_oWo​ is the weight of token ooo

Spot Price with Swap Fees

When we consider swap fees, we do exactly the same calculations as without fees, but using Aiβ‹…(1βˆ’swapFee)A_i \cdot (1-swapFee)Ai​⋅(1βˆ’swapFee) instead of AiA_iAi​ since fees are taken out of the input amount. The equation then becomes:

SPio=BiWiBoWoβ‹…11βˆ’swapFeeSP^o_i = \frac{\frac{B_i}{W_i}}{\frac{B_o}{W_o}} \cdot \frac{1}{1-swapFee}SPio​=Wo​Bo​​Wi​Bi​​​⋅1βˆ’swapFee1​

For more formulas and derivations of the below formulas, please refer to the .

2️
a post by Vitalik Buterin
Balancer Whitepaper