Uniswap V3
Constant Product Trading
- class uniswappy.cpt.factory.UniswapFactory(name: str, address: str)
Create Uniswap liquidity pools for given token pairs
- namestr
Token name
- addressstr
Token 0 name
- exchange_from_tokendictionary
Map of tokens to exchanges
- tokens_from_exchangedictionary
Map of exchanges to pair tokens
- deploy(exchg_data: UniswapExchangeData)
Deploy a Uniswap liquidity pool (LP) exchange
- exchg_dataUniswapExchangeData
Uniswap exchange initialization data
- exchangeUniswapExchange
Newly created exchange that is also a LP token
- get_exchange(token)
Get exchange from given pair token
- tokenERC20
receiving user address
- exchangeUniswapExchange
exchange from mapped token
- get_token(exchange)
Get token from exchange
- exchangeUniswapExchange
receiving user address
- tokenERC20
token from mapped exchange
- class uniswappy.cpt.exchg.UniswapV3Exchange(factory_struct: FactoryData, exchg_struct: UniswapExchangeData)
Uniswap V3 Exchange
- factory_structFactoryInit
Factory initialization data
- exchg_structUniswapExchangeInit
Exchange initialization data
- burn(recipient, tickLower, tickUpper, amount)
Burn liquidity from the sender and account tokens owed for the liquidity to the position. Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0. Fees must be collected separately via a call to collect
- recipientstr
Address for which the liquidity will be created
- tickLowerint
Lower tick of the position in which to add liquidity
- tickUpperint
Lower tick of the position in which to add liquidity
- amountint
How much liquidity to burn
- recipientstr
Address for which the liquidity will be created
- amount0int
Delta of the balance of token0 of the pool, exact when negative, minimum when positive
- amount1int
Delta of the balance of token1 of the pool, exact when negative, minimum when positive
- amountint
How much liquidity to burn
- checkTicks(tickLower, tickUpper)
Common checks for valid tick inputs
- tickLowerint
Lower tick of the position in which to add liquidity
- tickUpperint
Lower tick of the position in which to add liquidity
- collect(recipient, tickLower, tickUpper, amount0Requested, amount1Requested)
Collects tokens owed to a position. Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
- recipientstr
Address for which the liquidity will be created
- tickLowerint
Lower tick of the position in which to add liquidity
- tickUpperint
Lower tick of the position in which to add liquidity
- amount0Requestedint
How much token0 should be withdrawn from the fees owed
- amount1Requestedint
How much token1 should be withdrawn from the fees owed
- amount0float
Amount of token0 that was paid to mint the given amount of liquidity.
- amount1float
Amount of token1 that was paid to mint the given amount of liquidity.
- get_liquidity()
Get liquidity of exchange pool
- get_price(token)
Get price of select token in the exchange pair
- tokenERC20
ERC20 token
- get_reserve(token)
Get reserve amount of select token in the exchange pair
- tokenERC20
ERC20 token
- get_virtual_reserve(token)
Get virtual reserve amount of select token in the exchange pair
- tokenERC20
ERC20 token
- initialize(sqrtPriceX96)
Sets the initial price for the pool
- sqrtPriceX96float
the initial sqrt price of the pool as a Q64.96
- mint(recipient, tickLower, tickUpper, amount)
Adds liquidity for the given recipient/tickLower/tickUpper position. The final amounts calculated are automatically transferred from the swapper to the pool and vice verse. The amount of token0/token1 due depends on tickLower, tickUpper, the amount of liquidity, and the current price.
- recipientstr
Address for which the liquidity will be created
- tickLowerint
Lower tick of the position in which to add liquidity
- tickUpperint
Upper tick of the position in which to add liquidity
- amountint
Amount of liquidity to mint
- amount0float
Amount of token0 that was paid to mint the given amount of liquidity.
- amount1float
Amount of token1 that was paid to mint the given amount of liquidity.
- nextTick(tick, lte)
It is assumed that the keys are within [MIN_TICK , MAX_TICK], which should always be the case. We don’t run the risk of overshooting tickNext (out of boundaries) as long as ticks (keys) have been initialized within the boundaries. However, if there is no initialized tick to the left or right we will return the next boundary. Then we need to return the initialized bool to indicate that we are at the boundary and it is not an initalized tick.
- tickint
The starting tick
- lteint
Whether to search for the next initialized tick to the left (less than or equal to the starting tick)
- nextTickint
Next tick with liquidity to be used in the swap function
- setFeeProtocol(feeProtocol0, feeProtocol1)
Set the denominator of the protocol’s % share of the fees
- feeProtocol0int
New protocol fee for token0 of the pool
- feeProtocol1int
New protocol fee for token1 of the pool
- summary()
Summary print-out of exchange, reserves and liquidity
- swap(recipient, zeroForOne, amountSpecified, sqrtPriceLimitX96)
Swap token0 for token1, or token1 for token0. The tokens are automatically transferred at the end of the swapping function.
- recipientstr
Address for which the liquidity will be created
- zeroForOneint
the direction of the swap, true for token0 to token1, false for token1 to token0
- amountSpecifiedint
The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
- sqrtPriceLimitX96int
The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
- recipientstr
Address for which the liquidity will be created
- amount0int
Delta of the balance of token0 of the pool, exact when negative, minimum when positive
- amount1int
Delta of the balance of token1 of the pool, exact when negative, minimum when positive
- swap0ForExact1(recipient, amount, sqrtPriceLimit)
swapExact0For1
Swap token0 for exact value of token1
- recipientstr
Address for which the liquidity will be created
- amountint
How much token to swap
- sqrtPriceLimitint
Used to determine the highest price in the swap, and needs to be set when swapping on the pool directly.
- recipientstr
Address for which the liquidity will be created
- amount0int
Delta of the balance of token0 of the pool, exact when negative, minimum when positive
- amount1int
Delta of the balance of token1 of the pool, exact when negative, minimum when positive
- swap1ForExact0(recipient, amount, sqrtPriceLimit)
swapExact0For1
Swap token1 for exact value of token0
- recipientstr
Address for which the liquidity will be created
- amountint
How much token to swap
- sqrtPriceLimitint
Used to determine the highest price in the swap, and needs to be set when swapping on the pool directly.
- recipientstr
Address for which the liquidity will be created
- amount0int
Delta of the balance of token0 of the pool, exact when negative, minimum when positive
- amount1int
Delta of the balance of token1 of the pool, exact when negative, minimum when positive
- swapExact0For1(recipient, amount, sqrtPriceLimit)
Swap exact value of token0 for token1
- recipientstr
Address for which the liquidity will be created
- amountint
How much token to swap
- sqrtPriceLimitint
Used to determine the highest price in the swap, and needs to be set when swapping on the pool directly.
- recipientstr
Address for which the liquidity will be created
- amount0int
Delta of the balance of token0 of the pool, exact when negative, minimum when positive
- amount1int
Delta of the balance of token1 of the pool, exact when negative, minimum when positive
- swapExact1For0(recipient, amount, sqrtPriceLimit)
swapExact0For1
Swap exact value of token1 for token0
- recipientstr
Address for which the liquidity will be created
- amountint
How much token to swap
- sqrtPriceLimitint
Used to determine the highest price in the swap, and needs to be set when swapping on the pool directly.
- recipientstr
Address for which the liquidity will be created
- amount0int
Delta of the balance of token0 of the pool, exact when negative, minimum when positive
- amount1int
Delta of the balance of token1 of the pool, exact when negative, minimum when positive
Tokens
- class uniswappy.erc.ERC20(name: str, addr: str, decimal: int = None)
ERC20 token
- token_namestr
Token name
- token_addrstr
Token address
- token_totalfloat
Token holdings
- deposit(_from, value)
Deposit token
- _fromstr
user address
- valuestr
delta to add to total
- transfer(_to, value)
Transfer token
- _tostr
user address
- valuestr
delta to remove from total
- class uniswappy.erc.LPERC20(name: str, addr: str)
DAOSYS ERC20 token
- token_namestr
Token name
- token_addrstr
Token address
- token_totalfloat
Token holdings
- typefloat
Token type
- add_token_lp(value)
Add token delta to token total
- valuefloat
token delta
- remove_token_lp(value)
Remove token delta to token total
- valuefloat
token delta
- set_token_lp(token_total)
Reset token LP
- token_totalfloat
token total