UniswapV2Deployment

Documentation for eth_defi.uniswap_v2.deployment.UniswapV2Deployment Python class.

class UniswapV2Deployment[source]

Uniswap v2 deployment description.

Attributes summary

web3

The Web3 instance for which the instances of this class are bound

factory

Factory address.

weth

WETH/WBNB etc.

router

Router address.

init_code_hash

The hash of deployed pair contract code.

PairContract

Pair contract.

Methods summary

__init__(web3, factory, weth, router, ...)

get_pair_contract(token_a, token_b)

Get a contract for a trading pair.

pair_for(token_a, token_b)

Calculate CREATE2 contract address for a trading pair.

web3: web3.main.Web3

The Web3 instance for which the instances of this class are bound

factory: web3.contract.contract.Contract

Factory address. Factory deploys new pair contracts and defines the exchange instance on a blockchain. See the Solidity source code.

weth: Optional[web3.contract.contract.Contract]

WETH/WBNB etc. wrapper contract address. See the Solidity source code.

If the router contract ABI has renamed this variable from WETH to something else, e.g. Trader Joe, this is left empty.

TDOO: Allow to provision the exchange with different router ABI files.

router: web3.contract.contract.Contract

Router address. New routers can be deployed to optimise trade routing and price impact. See the Solidity source code.

init_code_hash: eth_typing.encoding.HexStr

The hash of deployed pair contract code. Needed to derive new pair contract addresses. See here for more details.

PairContract: Type[web3.contract.contract.Contract]

Pair contract. Holds the token0 and token1 side of the liquidity pool. Executes actual trades. Mints/burns new liquidity provider (LP) tokens. See UniswapV2Pair smartc contract for details.

pair_for(token_a, token_b)[source]

Calculate CREATE2 contract address for a trading pair.

Parameters
  • token_a (str) –

  • token_b (str) –

Return type

Tuple[eth_typing.evm.ChecksumAddress, eth_typing.evm.HexAddress, eth_typing.evm.HexAddress]

get_pair_contract(token_a, token_b)[source]

Get a contract for a trading pair.

Parameters
  • token_a (str) –

  • token_b (str) –

Return type

web3.contract.contract.Contract

__init__(web3, factory, weth, router, init_code_hash, PairContract)
Parameters
  • web3 (web3.main.Web3) –

  • factory (web3.contract.contract.Contract) –

  • weth (Optional[web3.contract.contract.Contract]) –

  • router (web3.contract.contract.Contract) –

  • init_code_hash (eth_typing.encoding.HexStr) –

  • PairContract (Type[web3.contract.contract.Contract]) –

Return type

None