uniswap_v3.deployment

Documentation for eth_defi.uniswap_v3.deployment Python module.

Uniswap v3 and compatible DEX deployments.

Compatible exchanges include Uniswap v3 deployments on:

  • Ethereum mainnet

  • Avalanche

  • Polygon

  • Optimism

  • Arbitrum

  • Base

Functions

add_liquidity(web3, deployer, *, deployment, ...)

Add liquidity to a pool.

decrease_liquidity(web3, position_owner, ...)

Decrease liquidity in an existing Uniswap V3 position.

deploy_pool(web3, deployer, *, deployment, ...)

Deploy a new pool on Uniswap v3.

deploy_uniswap_v3(web3, deployer[, weth, ...])

Deploy v3

deploy_uniswap_v3_factory(web3, deployer)

Deploy a Uniswap v3 factory contract.

fetch_deployment(web3, factory_address, ...)

Construct Uniswap v3 deployment based on on-chain data.

increase_liquidity(web3, position_owner, ...)

Increase liquidity in an existing Uniswap V3 position.

mock_partial_deployment_for_analysis(web3, ...)

Only need swap_router and PoolContract?

Classes

UniswapV3Deployment

Describe Uniswap v3 deployment.

class UniswapV3Deployment

Bases: object

Describe Uniswap v3 deployment.

web3: web3.main.Web3

The Web3 instance for which all the contracts here are bound

factory: web3.contract.contract.Contract

Factory address. See the Solidity source code.

weth: web3.contract.contract.Contract

WETH9Mock address. See the Solidity source code.

swap_router: web3.contract.contract.Contract

Swap router address. See the Solidity source code.

position_manager: web3.contract.contract.Contract

Non-fungible position manager address. See the Solidity source code.

PoolContract: web3.contract.contract.Contract

See the Solidity source code.

quoter_v2: bool

Use QuoterV2 instead of classic V1

Base chain has only QuoterV2.

router_v2: bool

Router contract is SwapRouter02

__init__(web3, factory, weth, swap_router, position_manager, quoter, PoolContract, quoter_v2=False, router_v2=False)
Parameters
  • web3 (web3.main.Web3) –

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

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

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

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

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

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

  • quoter_v2 (bool) –

  • router_v2 (bool) –

Return type

None

deploy_uniswap_v3_factory(web3, deployer)

Deploy a Uniswap v3 factory contract.

Parameters
Returns

Factory contract instance

Return type

web3.contract.contract.Contract

deploy_uniswap_v3(web3, deployer, weth=None, give_weth=10000)

Deploy v3

Example:

deployment = deploy_uniswap_v3(web3, deployer)
factory = deployment.factory
print(f"Uniswap factory is {factory.address}")
swap_router = deployment.swap_router
print(f"Uniswap swap router is {swap_router.address}")
Parameters
  • web3 (web3.main.Web3) – Web3 instance

  • deployer (eth_typing.evm.HexAddress) – Deployer account

  • weth (web3.contract.contract.Contract | None) – WETH contract instance

  • give_weth (int | None) – Automatically give some Wrapped ETH to the deployer. Express as ETH units.

Returns

Deployment details

Return type

eth_defi.uniswap_v3.deployment.UniswapV3Deployment

deploy_pool(web3, deployer, *, deployment, token0, token1, fee)

Deploy a new pool on Uniswap v3.

See UniswapV3Factory.createPool() for details.

Parameters
Returns

Pool contract proxy

Return type

web3.contract.contract.Contract

add_liquidity(web3, deployer, *, deployment, pool, amount0, amount1, lower_tick, upper_tick)

Add liquidity to a pool.

See Uniswap V3 documentation for details.

Parameters
  • web3 (web3.main.Web3) – Web3 instance

  • deployer (eth_typing.evm.HexAddress) – Deployer account

  • deployment (eth_defi.uniswap_v3.deployment.UniswapV3Deployment) – Uniswap v3 deployment

  • pool (web3.contract.contract.Contract) – Pool contract proxy

  • amount0 (int) – Amount of token0 to be added

  • amount1 (int) – Amount of token1 to be added

  • lower_tick (int) – Lower tick of the position

  • upper_tick (int) – Upper tick of the position

Returns

  • tx_receipt: Transaction receipt of the mint transaction

  • lower_tick: Corrected lower tick of the position with correct tick spacing

  • upper_tick: Corrected upper tick of the position with correct tick spacing

Return type

tuple[dict, int, int]

increase_liquidity(web3, position_owner, position_id, deployment, amount0, amount1, amount0_min=0, amount1_min=0)

Increase liquidity in an existing Uniswap V3 position. See Uniswap V3 documentation for details.

Parameters
  • web3 (web3.main.Web3) – Web3 instance

  • position_owner (eth_typing.evm.HexAddress) – The address of the position_owner.

  • position_id (int) – The id of the position to be increased, should be a positive integer.

  • deployment (eth_defi.uniswap_v3.deployment.UniswapV3Deployment) – Uniswap v3 deployment

  • amount0 (int) – Amount of token0 to be added

  • amount1 (int) – Amount of token1 to be added

  • amount0_min (int) – min amount0 desired, this is used as slippage check

  • amount1_min (int) – min amount1 desired, this is used as slippage check

Returns

tx_receipt: Transaction receipt of the increaseLiquidity transaction

Return type

dict

decrease_liquidity(web3, position_owner, position_id, deployment, liquidity_decrease_amount, amount0_min=0, amount1_min=0)

Decrease liquidity in an existing Uniswap V3 position. See Uniswap V3 documentation for details.

Parameters
  • web3 (web3.main.Web3) – Web3 instance

  • position_owner (eth_typing.evm.HexAddress) – The address of the position_owner.

  • position_id (int) – The id of the position to be decreased, should be a positive integer.

  • deployment (eth_defi.uniswap_v3.deployment.UniswapV3Deployment) – Uniswap v3 deployment

  • liquidity_decrease_amount (int) – The amount of liquidity we want to reduce our position by.

  • amount0_min (int) – Optional min amount0 desired, this is used as slippage check. Default is 0.

  • amount1_min (int) – Optional min amount1 desired, this is used as slippage check. Default is 0.

Returns

tx_receipt: Transaction receipt of the decreaseLiquidity transaction

Return type

dict

fetch_deployment(web3, factory_address, router_address, position_manager_address, quoter_address, quoter_v2=False, router_v2=False)

Construct Uniswap v3 deployment based on on-chain data.

Parameters
Returns

Data class representing Uniswap v3 exchange deployment

Return type

eth_defi.uniswap_v3.deployment.UniswapV3Deployment

mock_partial_deployment_for_analysis(web3, router_address)

Only need swap_router and PoolContract?

Parameters
  • web3 (web3.main.Web3) –

  • router_address (str) –