balancer_pool.py

This page explains the python code of Balancer core

NOTE: this file was used as the initial porting of BPool code and the basis for system_policies. Not used in the model.

Path: balancer_pool.py file discussed in this article. The file starts with importing balancer constants, and BalancerMath

from model.balancer_constants import MAX_TOTAL_WEIGHT, MAX_WEIGHT, MIN_BALANCE, MIN_FEE, MAX_BOUND_TOKENS, INIT_POOL_SUPPLY, EXIT_FEE, MAX_IN_RATIO, MAX_OUT_RATIO, MIN_WEIGHT
from model.balancer_math import BalancerMath
from dataclasses import dataclass

Data classes for storing information about the pool itself and swaps

@dataclass
class TokenRecord:
    bound: bool
    name: str
    denorm: Decimal
    balance: Decimal

@dataclass
class SwapInResult:
    token_amount_out: Decimal
    spot_price_after: Decimal

@dataclass
class SwapOutResult:
    token_amount_in: Decimal
    spot_price_after: Decimal

The BalancerMath class and related functions

Balancer Pool functions

Pool initialization with initial balances and Pool Shares

Functions for requesting tokens weights

Functions related to balances of tokens and Pool Shares

Functions for minting and burning Pool Shares (related to join and exit the pool)

Set swap fee function

Functions for receiving spot price (with and without fee)

Join and exit pool functions (liquidity provision and liquidity withdrawal)

Token swaps functions (two of them - for exact amount in and for exact amount out)

Join pool functions (liquidity provision)

Exit pool functions (liquidity withdrawal)

Last updated

Was this helpful?