Uniswap V2

Examples

uniswap_v2

Reference

async ctc.protocols.uniswap_v2_utils.async_get_pool_burns(pool_address, start_block=None, end_block=None, replace_symbols=False, normalize=True, provider=None, verbose=False)
Parameters
  • pool_address (<class 'str'>) –

  • start_block (Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending'], NoneType]) –

  • end_block (Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending'], NoneType]) –

  • replace_symbols (<class 'bool'>) –

  • normalize (<class 'bool'>) –

  • provider (Union[str, PartialProvider, Provider, NoneType]) –

  • verbose (<class 'bool'>) –

Return type

Any

async ctc.protocols.uniswap_v2_utils.async_get_pool_decimals(pool=None, *, x_address=None, y_address=None, provider=None)
Parameters
  • pool (Address | None) –

  • x_address (Address | None) –

  • y_address (Address | None) –

  • provider (ProviderSpec) –

Return type

list[int]

async ctc.protocols.uniswap_v2_utils.async_get_pool_mints(pool_address, start_block=None, end_block=None, replace_symbols=False, normalize=True, provider=None, verbose=False)
Parameters
  • pool_address (<class 'str'>) –

  • start_block (Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending'], NoneType]) –

  • end_block (Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending'], NoneType]) –

  • replace_symbols (<class 'bool'>) –

  • normalize (<class 'bool'>) –

  • provider (Union[str, PartialProvider, Provider, NoneType]) –

  • verbose (<class 'bool'>) –

Return type

Any

async ctc.protocols.uniswap_v2_utils.async_get_pool_state(pool, *, block='latest', provider=None, normalize=True, fill_empty=True)
Parameters
  • pool (<class 'str'>) –

  • block (Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending']]) –

  • provider (Union[str, PartialProvider, Provider, NoneType]) –

  • normalize (<class 'bool'>) –

  • fill_empty (<class 'bool'>) –

Return type

<class ‘uniswap_v2uniswap_v2PoolState’>

async ctc.protocols.uniswap_v2_utils.async_get_pool_state_by_block(pool, *, blocks, provider=None, normalize=True)
Parameters
  • pool (<class 'str'>) –

  • blocks (Sequence[Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending']]]) –

  • provider (Union[str, PartialProvider, Provider, NoneType]) –

  • normalize (<class 'bool'>) –

Return type

<class ‘uniswap_v2uniswap_v2PoolStateByBlock’>

async ctc.protocols.uniswap_v2_utils.async_get_pool_swaps(pool_address, start_block=None, end_block=None, replace_symbols=False, normalize=True, provider=None, verbose=False)
Parameters
  • pool_address (<class 'str'>) –

  • start_block (Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending'], NoneType]) –

  • end_block (Union[SupportsRound, str, int, Literal['latest'], Literal['earliest'], Literal['pending'], NoneType]) –

  • replace_symbols (<class 'bool'>) –

  • normalize (<class 'bool'>) –

  • provider (Union[str, PartialProvider, Provider, NoneType]) –

  • verbose (<class 'bool'>) –

Return type

Any

async ctc.protocols.uniswap_v2_utils.async_get_pool_symbols(pool=None, *, x_address=None, y_address=None, provider=None)
Parameters
  • pool (Address | None) –

  • x_address (Address | None) –

  • y_address (Address | None) –

  • provider (ProviderSpec) –

Return type

list[str]

async ctc.protocols.uniswap_v2_utils.async_get_pool_tokens(pool, provider=None)
ctc.toolbox.amm_utils.cpmm.print_pool_summary(x_reserves, y_reserves, lp_total_supply=None, x_name=None, y_name=None, fee_rate=None, indent=None, depths=None)
Parameters
  • x_reserves (int | float) –

  • y_reserves (int | float) –

  • lp_total_supply (int | float | None) –

  • x_name (str | None) –

  • y_name (str | None) –

  • fee_rate (float | None) –

  • indent (int | str | None) –

  • depths (Sequence[float] | None) –

Return type

None

ctc.toolbox.amm_utils.cpmm.print_trade_summary(x_name=None, y_name=None, x_holdings_before=None, y_holdings_before=None, indent=None, **trade_kwargs)
Parameters
  • x_name (str | None) –

  • y_name (str | None) –

  • x_holdings_before (int | float | None) –

  • y_holdings_before (int | float | None) –

  • indent (int | str | None) –

  • trade_kwargs (Any) –

Return type

None

ctc.toolbox.amm_utils.cpmm.trade(x_reserves, y_reserves, x_sold=None, x_bought=None, y_sold=None, y_bought=None, new_x_reserves=None, new_y_reserves=None, fee_rate=None)

perform trade with AMM

## Input Requirements - all input values must be positive - must always specify both x_reserves and y_reserves - must specify exactly one of:

  • x_sold

  • x_bought

  • y_sold

  • y_bought

  • new_x_reserves

  • new_y_reserves

  • values in this list can be scalars or numpy arrays

Parameters
  • x_reserves (int | float) –

  • y_reserves (int | float) –

  • x_sold (int | float | None) –

  • x_bought (int | float | None) –

  • y_sold (int | float | None) –

  • y_bought (int | float | None) –

  • new_x_reserves (int | float | None) –

  • new_y_reserves (int | float | None) –

  • fee_rate (int | float | None) –

Return type

Trade