UniswapV2Deployment

Documentation for eth_defi.uniswap_v2.deployment.UniswapV2Deployment 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, ...)

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

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]

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

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: web3.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]

__init__(web3, factory, weth, router, init_code_hash, PairContract)
Parameters
Return type

None