Uniswap V2

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.UniswapExchange(factory_struct: FactoryData, exchg_struct: UniswapExchangeData)

Uniswap V2 Exchange

factory_structFactoryInit

Factory initialization data

exchg_structUniswapExchangeInit

Exchange initialization data

add_liquidity(_from_addr, amountADesired, amountBDesired, amountAMin, amountBMin)

Add liquidity to both tokens in the pair

_from_addrstr

receiving user address

amountADesiredfloat

desired amount of A

amountBDesiredfloat

desired amount of B

amountAMinfloat

Minimum amount of A

amountBMinfloat

Minimum amount of B

burn(to_addr, liquidity, amountA, amountB)

Burn liquidity from both coins in the pair based on lp amount

to_addrstr

receiving user address

liquidityfloat

amount of liquidity to be burned

amountAfloat

est. amount from reserve0 to be burned

amountBfloat

est. amount from reserve1 to be burned

get_amount_out(amount_in, token_in)

Get maximum output of opposing asset given input amount of token

amount_infloat

input amount of an asset

token_inERC20

asset token

amount outfloat

amount of opposing asset

get_amount_out0(amount_in)

Get maximum amount of other asset given input amount of an asset

amount_infloat

input amount of an asset

amount_out outfloat

reserve1 * reserve0

get_amount_out1(amount_in)

Get maximum amount of other asset given input amount of an asset

amount_infloat

input amount of an asset

amount_out outfloat

reserve1 * reserve0

get_amounts(to_addr, liquidity)

Remove liquidity from both coins in the pair based on lp amount

to_addrstr

receiving user address

liquidityfloat

lp amount

amountAfloat

liquidity portion of reserve0

amountBfloat

liquidity portion of reserve1

get_fee(token)

Get last fee amount of select token in the exchange pair

tokenERC20

ERC20 token

get_last_liquidity_deposit()

Get the last liquidity deposit that went into pool

get_liquidity()

Get liquidity of exchange pool

get_liquidity_from_provider(provider_account)

Get liquidity from provider

provider_accountstr

Provider account name

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

mint(to_addr, _amountA, _amountB)

Mint new liquidity based on amounts on each coin in the pair

to_addrstr

receiving user address

_amountAfloat

desired amount of A

_amountBfloat

desired amount of B

quote(amountA, reserveA, reserveB)

Given amount asset and reserves, return equivalent amount of other asset

amountAfloat

amount of a given asset token

reserveAfloat

total amount of asset A in LP

reserveBfloat

total amount of asset B in LP

remove_liquidity(to_addr, liquidity, amountAMin, amountBMin)

Remove liquidity from both coins in the pair based on lp amount

to_addrstr

receiving user address

liquidityfloat

lp amount to removed

amountAMinfloat

Minimum amount of A

amountBMinfloat

Minimum amount of B

amountAfloat

removed liquidity from reserve0

amountBfloat

removed liquidity from reserve1

summary()

Summary print-out of exchange, reserves and liquidity

swap(amountA_out, amountB_out, to_addr)

Remove liquidity from both coins in the pair based on lp amount

amountA_outfloat

swap amountA out

amountB_outfloat

swap amountB out

to_addrstr

receiving user address

swap_exact_tokens_for_tokens(amountIn, amountOutMin, token_in, to_addr)

Swap amt of token for min opposing token out

amountInfloat

swap amount in

amountOutMinfloat

min swap amount in

token_inERC20

Token to be swapped

to_addrstr

receiving user address

amount_out_expectedfloat

amount expected from the swap

update_reserves(user_nm, amountA_update=None, amountB_update=None)

Update reserve assets of either or both assets in the pair

user_nmstr

acccount holder

amountA_updatefloat

update amount of asset A

amountB_updatefloat

update amount of asset B

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