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 to a pool. |
|
Decrease liquidity in an existing Uniswap V3 position. |
|
Deploy a new pool on Uniswap v3. |
|
Deploy v3 |
|
Deploy a Uniswap v3 factory contract. |
|
Construct Uniswap v3 deployment based on on-chain data. |
|
Increase liquidity in an existing Uniswap V3 position. |
|
Only need swap_router and PoolContract? |
Classes
Describe Uniswap v3 deployment. |
- class UniswapV3Deployment
Bases:
objectDescribe 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
- __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
web3 (web3.main.Web3) – Web3 instance
deployer (eth_typing.evm.HexAddress) – Deployer adresss
- 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
- deploy_pool(web3, deployer, *, deployment, token0, token1, fee)
Deploy a new pool on Uniswap v3.
See UniswapV3Factory.createPool() 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
token0 (web3.contract.contract.Contract) – Base token of the pool
token1 (web3.contract.contract.Contract) – Quote token of the pool
fee (int) – Fee of the pool
- 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
- 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
- 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
- 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
allow_different_weth_var – We assume Uniswap v3 ABI that has router.WETH() accessor. Some other DEXes might not have it. If set (default) ignore this error and just have None as the value for the wrapped token.
quoter_v2 –
Quoter is a QuoterV2, not V1.
V1 not deployed on Base.
web3 (web3.main.Web3) –
factory_address (Union[eth_typing.evm.HexAddress, str]) –
router_address (Union[eth_typing.evm.HexAddress, str]) –
position_manager_address (Union[eth_typing.evm.HexAddress, str]) –
quoter_address (Union[eth_typing.evm.HexAddress, str]) –
- Returns
Data class representing Uniswap v3 exchange deployment
- Return type