R Package to Interact and Trade with Uniswap Platform and Exploration of Uniswap data from GraphQL.
Install Using
devtools::install_github("Omni-Analytics-Group/uniswappeR")
The package has 3 Functionalities
- Trade : To query prices and make trades on Uniswap from R console
- Pull Data : To pull all types of data from Uniswap GraphQL to explore yourself
- Explore Data : To Analyse and explore the uniswap data
Our uniswappeR
R package includes the functionality to trade and query prices from the Uniswap Platform. To interact with the Uniswap Platform
we need to configure the environment and then we can use the functions to make trades on the uniswap platform and query prices.
View the video walkthrough on how to conduct trades through UniswappeR here.
- Install the reticulate package using
library(reticulate)
- Install python to use as backend using
install_python("3.8.7")
- Create a Virtual Environment to keep the backend sandboxed using
virtualenv_create("uniswappeR-env", version = "3.8.7")
- Install uniswap-python package using
virtualenv_install(envname="uniswappeR-env",packages=c("uniswap-python==0.4.6"))
- Use the Virtual Environment using
use_virtualenv("uniswappeR-env",required=TRUE)
- Extract checksum function from Web3 module
Web3_checksum <- import("web3",convert=FALSE)$Web3$toChecksumAddress
library(reticulate)
library(uniswappeR)
use_virtualenv("uniswappeR-env",required=TRUE)
set_infura_node("https://mainnet.infura.io/v3/XXXXXXXXXXXXXXXXXXX")
u_w <- uniswap_session(user_add = "**", pvt_key = "***")
-
We would use Uniswap(UNI)/ETH pair to query on
- UNI Token Address
t_a <- Web3_checksum("0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
- UNI Token Decimals
t_d <- 18
- UNI Token Address
-
We would use Uniswap(UNI)/ DAI Stablecoin pair to query for Token to Token swap
- UNI Token Address
t1_a <- Web3_checksum("0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
- UNI Token Decimals
t1_d <- 18
- DAI Token Address
t2_a <- Web3_checksum("0x6b175474e89094c44da98b954eedeac495271d0f")
- DAI Token Decimals
t2_d <- 18
- UNI Token Address
-
Check Your ETH Balance
check_eth_balance(u_w)
-
Check Your Uniswap (UNI) Token Balance
check_tok_balance(t_a,t_d,u_w)
-
How much UNI Token you would get for .5 ETH, When you Swap ETH for UNI
- Ethereum Quantity
e_q <- .5
check_eth.to.tok_eth.fix(t_a,t_d,e_q,u_w)
- Ethereum Quantity
-
How much ETH you need to get 2 UNI Tokens, When you Swap ETH for UNI
- UNI Tokens Quantity
t_q <- 2
check_eth.to.tok_tok.fix(t_a,t_d,t_q,u_w)
- UNI Tokens Quantity
-
How much ETH you would get for 2 UNI Tokens, When you Swap UNI for ETH
- Ethereum Quantity
t_q <- 2
check_tok.to.eth_tok.fix(t_a,t_d,t_q,u_w)
- Ethereum Quantity
-
How much UNI Token you need to get .5 ETH Tokens, When you Swap UNI for ETH
- Ethereum Quantity
e_q <- .5
check_tok.to.eth_eth.fix(t_a,t_d,e_q,u_w)
- Ethereum Quantity
-
How much DAI Token you would get for 2 UNI, When you Swap UNI for DAI (Uses UNI->ETH->DAI Route)
- UNI Quantity
t1_q <- 2
check_tok1.to.tok2_tok1.fix(t1_a,t1_d,t2_a,t2_d,t1_q,u_w)
- UNI Quantity
-
How much UNI Token you would need to get 50 DAI, When you Swap UNI for DAI (Uses UNI->ETH->DAI Route)
- UNI Quantity
t2_q <- 50
check_tok1.to.tok2_tok2.fix(t1_a,t1_d,t2_a,t2_d,t2_q,u_w)
- UNI Quantity
-
We would use Uniswap(UNI)/ETH pair to make swaps
- UNI Token Address
t_a <- Web3_checksum("0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
- UNI Token Decimals
t_d <- 18
- UNI Token Address
-
We would use Uniswap(UNI)/ DAI Stablecoin pair for Token to Token swap
- UNI Token Address
t1_a <- Web3_checksum("0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
- UNI Token Decimals
t1_d <- 18
- DAI Token Address
t2_a <- Web3_checksum("0x6b175474e89094c44da98b954eedeac495271d0f")
- DAI Token Decimals
t2_d <- 18
- UNI Token Address
-
Swap .5 ETH for UNI Tokens
- Ethereum Quantity
e_q <- .5
trade_eth.to.tok_eth.fix(t_a,t_d,e_q,u_w)
- Ethereum Quantity
-
Swap as much ETH required to get 2 UNI Tokens
- UNI Quantity
t_q <- .5
trade_eth.to.tok_tok.fix(t_a,t_d,t_q,u_w)
- UNI Quantity
-
Swap 2 UNI Tokens for ETH
- UNI Quantity
t_q <- 2
trade_tok.to.eth_tok.fix(t_a,t_d,t_q,u_w)
- UNI Quantity
-
Swap as much UNI Tokens required to get .5 ETH
- Ethereum Quantity
e_q <- .5
trade_tok.to.eth_eth.fix(t_a,t_d,e_q,u_w)
- Ethereum Quantity
-
Swap 2 UNI Tokens for DAI Tokens
- UNI Quantity
t1_q <- 2
trade_tok1.to.tok2_tok1.fix(t1_a,t1_d,t2_a,t2_d,t1_q,u_w)
- UNI Quantity
-
Swap as much UNI Tokens required to get 20 DAI Tokens
- DAI Quantity
t2_q <- 20
trade_tok1.to.tok2_tok2.fix(t1_a,t1_d,t2_a,t2_d,t2_q,u_w)
- DAI Quantity
Our uniswappeR
R package contains the codebase to abstracts away the GraphQL layer of querying for uniswap data into a user-friendly R package.
View the video walkthrough on how to pull data into R using UniswappeR.
library(uniswappeR)
factory_stats_v2()
uniswap_stats_hist_v2()
token_stats_v2(token_address = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
token_stats_hist_v2(token_address = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
token_pair_map_v2(token_address = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
pair_stats_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
pair_stats_hist_hourly_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
pair_stats_hist_daily_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
pair_liq_positions_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
pair_liq_positions_hist_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
pair_mint_txs_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
pair_burn_txs_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
pair_swap_txs_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
user_lps_v2(user_address = "0x2502f65d77ca13f183850b5f9272270454094a08")
user_hist_lps_v2(user_address = "0x2502f65d77ca13f183850b5f9272270454094a08")
user_swaps_v2(user_address = "0xcd8aa390e6eabbd2169b3580c1f7ce854675fd03")
user_mints_v2(user_address = "0xcd8aa390e6eabbd2169b3580c1f7ce854675fd03")
user_burns_v2(user_address = "0xcd8aa390e6eabbd2169b3580c1f7ce854675fd03")
data_to_export <- token_stats_hist_v2(token_address = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
path_to_export <- "~/Desktop/uniswappeR_export.csv"
export_data(data_to_export,path_to_export)
Our uniswappeR
R package includes a number of high level functions for interacting and visualise the data from uniswap:
vis_uniswap_stats_hist_v2()
vis_token_stats_hist_v2(token_address = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
vis_token_pair_map_v2(token_address = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984")
vis_pair_stats_hist_daily_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
vis_pair_liq_positions_v2(pair_address = "0xf00e80f0de9aea0b33aa229a4014572777e422ee")
addresses <- c("0x2e3381202988d535e8185e7089f633f7c9998e83", "0x4d9c274ADF71e4201B4aB1f28BF05D44eE4bA261")
swap_data <- swaps(addresses)
swap_visualizations(swap_data)
swap_performance(swap_data)
plot_to_export <- vis_uniswap_stats_hist_v2()
path_to_export <- "~/Desktop/uniswappeR_plot_export.png"
export_plot(plot_to_export,path_to_export)
Omni Analytics Group is an incorporated group of passionate technologists who help others use data science to change the world. Our practice of data science leads us into many exciting areas where we enthusiastically apply our machine learning, artificial intelligence and analysis skills. Our flavor for this month, the blockchain! To learn more about what we do or just to have fun, join us over on Twitter.