> For the complete documentation index, see [llms.txt](https://metavision-labs.gitbook.io/balancerv2cad/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://metavision-labs.gitbook.io/balancerv2cad/simulation-packages/pool-functions.md).

# Pool Functions

Instantiate a pool either from `StablePool` or `WeightedPool` depending on your use-case.

**Fees**

In both `Stable Pool` and `Weighted Pool,` you can set the transaction fee amount in `BalancerConstants.py,`&#x20;

**Stable Pool**

**a) Add Liquidity**

`join_pool(balances: dict)`Add up to 2 coins in a 50/50 pool. Populate dictionary with this key value pair (key=token: str, value=balance: number)

**b) Withdraw Liquidity**&#x20;

`exit_pool(balances: dict)` Specify which assets/amount to withdraw by populating dictionary with key value pair (key=token: str, value=balance: number)

**c) Swap**`swap(token_in: str, token_out: str, amount: Decimal, given_in: bool)` Performs token swap based on given policy

case `given_in = True:`The default swap out-given-in.

case `given_in = False:`in-given-out, known amount of tokens we want to retrieve from the pool, and we calculate the amount needed in.

**Weighted Pool**

**a) Add Liquidity**

`join_pool(balances: dict, weights: dict)`Add up to 8 coins in a weighted pool. Populate the balances dictionary with this key value pair (key=token: str, value=balance: number), and weights using the same keys as balances (key=token: str, value=weight: number)

**b) Withdraw Liquidity**&#x20;

`exit_pool(balances: dict)` Specify which assets/amount to withdraw by populating dictionary with key value pair (key=token: str, value=balance: number)

**c) Swap**`swap(token_in: str, token_out: str, amount: Decimal, given_in: bool)` Performs token swap based on given policy

case `given_in = True:`The default swap out-given-in.

case `given_in = False:`in-given-out, known amount of tokens we want to retrieve from the pool, and we calculate the amount needed in.
