Balancer

Constant Weighted Product Trading

class manual_balancer.BalancerExchange(factory_struct: FactoryData, exchg_struct: BalancerExchangeData)

How Balancer calls liquidity pools and uses the constant weighted product automated market maker

self.factory_structFactoryData

Factory data

self.exchg_structBalancerExchangeData

Balancer exchange data

burn(shares, amt_tkn_out, tkn_out, _from)

Burn liquidity from token based on number of pool shares and amount of token

amt_tkn_outfloat

Amount of token requested for burn

tkn_outERC20

Output token

_fromstr

User name/address

exit_pool(amt_shares_out, _from)

Remove liquidity via withdrawing shares amount for all assets within pool

amt_shares_outfloat

Amount of pool shares requested for exit

_fromstr

User name/address

exit_swap_extern_amount_out(amt_tkn_out, tkn_out, to)

Remove liquidity via withdrawing shares amount for a single asset

amt_tkn_outfloat

Amount of token requested for withdrawal

tkn_outERC20

Output token

tostr

User name/address

exit_swap_pool_amount_in(amt_shares_out, tkn_out, to)

Remove liquidity via withdrawing shares amount for a single asset

amt_shares_outfloat

Amount of pool shares requested for withdrawal

tkn_outERC20

Output token

tostr

User name/address

get_amount_in(amt_tkn_out, tkn_out, tkn_in)

Given some amount of an asset, quotes an equivalent amount of the other asset

amt_tkn_outfloat

Amount of token requested for quote

tkn_outERC20

Input token

tkn_inERC20

Output token

get_amount_out(amt_tkn_in, tkn_in, tkn_out)

Given some amount of an asset, quotes an equivalent amount of the other asset

amt_tkn_infloat

Amount of token requested for quote

tkn_inERC20

Input token

tkn_outERC20

Output token

get_price(base_tkn, opp_tkn)

Get price of select token in the exchange pair

base_tknfloat

Base token request for price quote

opp_tknERC20

Denomination token of price quote

get_reserve(token)

Get reserve amount of select token in the pool

tokenERC20

ERC20 token

join_pool(vault: BalancerVault, amt_shares_in: float, to: str)

Initialize a Balancer pool, and add liquidity for all asset deposit

tkn_grvaultoupBalancerERC20Group

Group of ERC20 objects

amt_shares_infloat

Amount of pool shares in

tostr

User name/address

join_swap_extern_amount_in(amt_tkn_in, tkn_in, to)

Add liquidity via depositing token amount for single asset deposit

amt_tkn_infloat

Amount of token coming in

tkn_inERC20

Input token

tostr

User name/address

join_swap_pool_amount_out(amt_shares_in, tkn_in, to)

Add liquidity via depositing shares amount for single asset deposit

amt_shares_infloat

Amount of pool shares coming in

tkn_inERC20

Input token

tostr

User name/address

mint(new_shares, amt_tkn_in, tkn_in, to)

Update reserve amount for specific token in the pool

new_sharesfloat

Amount of new pool shares requested for minting

amt_tkn_infloat

Input token

tkn_inERC20

Output token

tostr

User name/address

summary()

Summarize current state of balancer liquidity pool

swap(amt_swap, amt_fee, tkn_out, tkn_in, to)

Swap output token given input token

amt_outfloat

Amount of input token requested for swaping

tkn_inERC20

Input token

tkn_outERC20

Output token

tostr

User name/address

swap_exact_amount_in(amt_tkn_in, tkn_in, tkn_out, to)

Swap output token given input token

amt_tkn_infloat

Amount of input token requested for swaping

tkn_inERC20

Input token

tkn_outERC20

Output token

tostr

User name/address

swap_exact_amount_out(amt_tkn_out, tkn_out, tkn_in, to)

Swap input token given output token

amt_tkn_infloat

Amount of input token requested for swaping

tkn_inERC20

Input token

tkn_outERC20

Output token

tostr

User name/address

class manual_balancer.BalancerFactory(name: str, address: str)

Create Balancer liquidity pools for given token sets

self.namestr

Token name

self.addressstr

Address name

deploy(exchg_data: BalancerExchangeData)

Deploy a Balancer liquidity pool (LP) exchange

exchg_dataBalancerExchangeData

Exchange initialization data

exchangeBalancerExchange

Newly created exchange that is also a LP token

get_exchange(token)

Get exchange from given token

tokenERC20

receiving user address

exchangeBalancerExchange

exchange from mapped token

get_token(exchange)

Get token set from exchange

exchangeBalancerExchange

receiving user address

tokenERC20

token from mapped exchange

Vault

class balancerpy.vault.BalancerVault

Create Balancer vault for pool token management

self.tknslist

List of ERC20 tokens within vault

self.tkn_dicdictionary

Dictionary of ERC20 tokens within vault referenced by token name

self.tkn_denorm_wtsdictionary

Dictionary of denormalization weights referenced by token name

self.tkn_boundsdictionary

Dictionary of booleans (indicating token bound) referenced by token name

add_token(tkn: ERC20, weight: float, bound: bool = True)

Deploy a Balancer liquidity pool (LP) exchange

tknERC20

ERC20 token

weightfloat

Denormalized weight in pool

boundboolean

Indicator of whether token is bound to pool

check_tkn(tkn)

Check if ERC20 token is in vault

tknERC20

ERC20 token

containsboolean

Indicator of whether token is contained in vault

get_balances()

Get dictionary of token balances referened by token name

tkn_balancesdict

Dictionary of token balances

get_bounds()

Get dictionary of token bounds referened by token name

norm_wts_dictdict

Dictionary of token bounds indicating whether token is bound to pool

get_denorm_weights()

get_norm_weights

Get dictionary of token denormalized weights referened by token name

norm_wts_dictdict

Dictionary of token denormalized weights

get_dict()

Get dictionary of tokens referened by token name

tkn_dictdict

Dictionary of tokens

get_name()

Get token names

tkn_nmsstr

Token names delimited by hyphen

get_names()

Get token string names

tkn_nmslist

Token string names

get_norm_weights()

Get dictionary of token normalized weights referened by token name

norm_wts_dictdict

Dictionary of token normalized weights

get_token(tkn_name)

Get token from vault given its name symbol

tkn_namestr

Token name symbol

tknERC20

Retrieved ERC20 token

get_tokens()

Get list of tokens

tknslist

List of tokens

Quoting

class manual_balancer.CWPQuote

Constant weighted product liquidity pool token quotes (ie, price, reserve and liquidity)

get_amount_from_shares(lp, tkn, amount_shares_in)

Get amount of token reserve, given an amount of input liquidity pool shares

lpUniswapExchange

Uniswap LP

tkn: ERC20

Token asset from CWPT set

amount_shares_in: float

Amount of input shares

amt_out: float

Amount of token reserve

get_shares_from_amount(lp, tkn, amount_in)

Get amount of liquidity pool shares, given an amount of input token

lpUniswapExchange

Uniswap LP

tkn: ERC20

Token asset from CWPT set

amount_in: float

Amount of input token

lp_amt: float

Amount of liquidity pool shares

Tokens

class balancerpy.erc.ERC20(name: str, addr: str)

ERC20 token

self.token_namestr

Token name

self.token_addrstr

Token address

self.token_totalfloat

Token holdings

deposit(_from, value)

Deposit token amount in

_fromstr

user address

valuestr

delta to add to total

transfer(_to, value)

Transfer token amount out

_tostr

user address

valuestr

delta to remove from total