• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Detailed instructions on how to deploy Uniswap on an Ethereum compatible blockchain

//** Please note this is a draft and this code is under heavy development. Not to be used in production **

How to deploy Uniswap


Housekeeping

The code in this section is packaged up into a single ./utils/housekeeping.sh file for your convenience. Below are the details of all of the ./utils/housekeeping.sh commands for your understanding.

sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install npm
npm install fs
npm install web3
npm install truffle-hdwallet-provider
sudo apt-get install apache2
# install Yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn

Update version of node

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

Clone the Uniswap Interface code using Git.

cd ~
git clone https://github.com/Uniswap/uniswap-interface.git

Change into the Uniswap Interface directory.

cd ~
cd uniswap-interface

Now, whilst in the ~/uniswap-interface directory, clone the "How To Install Uniswap" code using Git.

git clone https://github.com/second-state/how_to_deploy_uniswap.git

Change into the how_to_deploy_uniswap/ directory.

cd how_to_deploy_uniswap/

Accounts

Create 3 Ethereum compatible addresses using any method that you are comfortable with i.e. web3js etc.

Now paste the private and public keys of those addresses into the installation_data.json file as shown below.

vi ~/uniswap-interface/how_to_deploy_uniswap/installation_data.json

Here is an example of the private_key and public_key sections of that file.

  "private_key": {
    "alice": "your_new_key_here",
    "bob": "your_new_key_here",
    "charlie": "your_new_key_here"
  },
  "public_key": {
    "alice": "your_new_key_here",
    "bob": "your_new_key_here",
    "charlie": "your_new_key_here"
  }

You will need to fund these accounts with network tokens. So depending on your network, please go ahead and send at least 20 network tokens (from a Faucet etc.) to all three of these accounts.

Now place the RPC URL to your Ethereum compatible network in that same installation_data.json file.

vi ~/uniswap-interface/how_to_deploy_uniswap/installation_data.json

Here is an example of the rpc_endpoint section of that file.

"provider": {
	"rpc_endpoint": "http://rpc_url:port"
}

V1

Now run the Uniswap V1 smart contract installer.

cd ~/uniswap-interface/how_to_deploy_uniswap/uniswap_v1
node deploy_uniswap_v1.js

If you open the ../installation_data.json file, you will see that the Uniswap V1 contract addresses and the Alice and Bob (ERC20 and ERC20 Exchange) addresses have been automatically filled in.

"contract_address": {
    "uniswap_factory": "0x2DF5e651be537bB564005340EA5D8f6fA763b530",
    "weth": "",
    "uniswap_exchange_template": "0x68Fc886B0ca3D65AE8Ad21Fde01d8C4E2AD9d86c",
    "alice_exchange": "0x4A8f21726434951f5C1baA0F067d50fdA2a297e2",
    "bob_exchange": "0x61d82A90455EC7cDEdF7cF7F5267c0aF6657c626",
    "alice_erc20_token": "0x240Fc9370709bad1F4402186701C76e36a20848b",
    "bob_erc20_token": "0x09cB0AE6dddF68Aaad81b8f6B83c30dfdaA65b48",
    "uniswap_v2": "",
    "multicall": "",
    "migrator": "",
    "router": "",
    "ens_registry": "",
    "unisocks": ""
}

V2

Now run the Uniswap V2 smart contract installation script.

cd ~/uniswap-interface/how_to_deploy_uniswap/uniswap_v2

Important Warning

The feeToSetter has been hard-coded to the Charlie account inside the deploy_uniswap_v2.js script (that you are about to run). The feeToSetter is the account that is responsible for future profit that result from trades. This account is set to Charlie for demonstration purposes only. If you are running this script, you are responsible for correctly setting the feeToSetter account up and managing its private keys.

node deploy_uniswap_v2.js

Congratulations, the smart contracts are all deployed. You will see that all of the contract addresses in the installation_data.json file have been filled out.

"contract_address": {
	"uniswap_factory": "0x2DF5e651be537bB564005340EA5D8f6fA763b530",
	"weth": "0x043c7D26e381CB1bb025b4CE0A6E0C63D7767866",
	"uniswap_exchange_template": "0x68Fc886B0ca3D65AE8Ad21Fde01d8C4E2AD9d86c",
	"alice_exchange": "0x4A8f21726434951f5C1baA0F067d50fdA2a297e2",
	"bob_exchange": "0x61d82A90455EC7cDEdF7cF7F5267c0aF6657c626",
	"alice_erc20_token": "0x240Fc9370709bad1F4402186701C76e36a20848b",
	"bob_erc20_token": "0x09cB0AE6dddF68Aaad81b8f6B83c30dfdaA65b48",
	"uniswap_v2": "0x0fA47ae2b7Dee29571678580BBe9A8A88436E393",
	"multicall": "0x50F0463B01119Aa954ce40a7f21ecf4573E7605a",
	"migrator": "0x3cBe562Fd434aF61601937895000A91D014a49e7",
	"router": "0x5c192a0155D504772F3bc2689aF69116E098ECAa",
	"ens_registry": "0xA07e2676495eEDEdb5A50b9ba020Ba3A98f87D4E"
}

Interface

Now change into the uniswap_interface directory.

cd ~/uniswap-interface/how_to_deploy_uniswap/uniswap_interface

Now run the modify_addresses.py script

python3 modify_addresses.py

Change back to the Uniswap directory so we can build the application.

cd ~/uniswap-interface/

An ls should look like this (no build folder yet)

LICENSE  README.md  cypress  cypress.json  how_to_deploy_uniswap  node_modules  package.json  public  src  tsconfig.json  yarn.lock

Build the application's dependencies using the following command.

yarn

Chain id changes (optional)

ChainID Please note: the chainId for each network is actuall set inside the Uniswap SDK's code You may not need/want to change this but if you do i.e. you are using chainId 2 instead of 1 please perform the following tasks

Open the how_to_deploy_uniswap/uniswap_interface/change_chain_id.py file and edit the one_to_two and one_to_two_II and new_value and new_value_II variables to suite your situation i.e. changing from chainId 1 to 2 would look like this.

one_to_two = "MAINNET = 1"
one_to_two_II = "chainId\:\"1\""
one_to_two_III = "chainId:1"
one_to_two_IV ="1: 'mainnet'"

new_value = "MAINNET = 2"
new_value_II = "chainId\:\"2\""
new_value_III = "chainId:2"
new_value_IV = "2: 'mainnet'"

Be sure to escape / and . and : (as shown above) because these will break the command when executed.

Now run this file

python3.6 change_chain_id.py

In addition to the above change, if your chainId is not standard i.e. your mainnet is not 1, then you must also modify the export declare const WETH section of the node_modules/@uniswap/sdk/dist/entities/token.d.ts file. The first position in this enum 1: Token; represents the MAINNET so go ahead and change it to suit your needs. In our case 1: Token;

export declare const WETH: {
    1: Token;
    3: Token;
    4: Token;
    5: Token;
    42: Token;
};

In addition to the above change, again if your chainId is not standard then go ahead and also update the src/utils/index.ts file in the following two places i.e. 1: '', and ETHERSCAN_PREFIXES[1]

const ETHERSCAN_PREFIXES: { [chainId in ChainId]: string } = {
  1: '',
  3: 'ropsten.',
  4: 'rinkeby.',
  5: 'goerli.',
  42: 'kovan.'
}
const prefix = `https://${ETHERSCAN_PREFIXES[chainId] || ETHERSCAN_PREFIXES[1]}etherscan.io`

In addition to the above change, another file in the Uniswap Interface source code specifies supportedChainIds. If your chainId is not in the list then add it like this vi src/connectors/index.ts

export const injected = new InjectedConnector({
  supportedChainIds: [1, 2, 3, 4, 5, 42]
})

In that same file, also change the 1 to your chainId in line 14 i.e.

export const NETWORK_CHAIN_ID: number = parseInt(process.env.REACT_APP_CHAIN_ID ?? '1')

Hopefully you did not have to change the chainId. If you are all set then go ahead and build the Uniswap Interface application


Disable Unisocks (Optional)

This Unisocks contract, this other Uniswap contract and the hard-coded Unisocks metadata are deployed against real-world assets (socks) and therefore it makes no sense to include this in the build. In order to disable the Unisocks component of this build we need to do the following updates to the code.

useContract.ts

  • Comment out the import UNISOCKS_ABI from '../constants/abis/unisocks.json' line in the src/hooks/useContract.ts file

  • Comment out the useSocksController section of the ./src/hooks/useContract.ts file

export function useSocksController(): Contract | null {
  const { chainId } = useActiveWeb3React()
  return useContract(
    chainId === ChainId.MAINNET ? '0x65770b5283117639760beA3F867b69b3697a91dd' : undefined,
    UNISOCKS_ABI,
    false
  )
}

useSocksBalance.ts

  • mv src/hooks/useSocksBalance.ts src/hooks/useSocksBalance.ts.orig

src/components/Web3Status/index.tsx

  • Comment out import { useHasSocks } from '../../hooks/useSocksBalance' and const hasSocks = useHasSocks() which are in the src/components/Web3Status/index.tsx file
  • Also comment out this block of code
const SOCK = (
  <span role="img" aria-label="has socks emoji" style={{ marginTop: -4, marginBottom: -4 }}>
    🧦
  </span>
)

from the src/components/Web3Status/index.tsx file

  • Also delete the {hasSocks ? SOCK : null} line of code which is also in the src/components/Web3Status/index.tsx file

Environment variables

Open the .env and .env.production files and update the REACT_APP_CHAIN_ID and the REACT_APP_NETWORK_URL to suite your needs.

Change the hard-coded RPC

Open the how_to_deploy_uniswap/uniswap_interface/change_rpc.py file and edit the following variables to suite your needs.

infura = "https\:\/\/mainnet\.infura\.io\/v3\/faa4639b090f46499f29d894da0551a0"
new_rpc = "http\:\/\/oasis-ssvm-demo\.secondstate\.io\:8545"

Be sure to escape / and . and : (as shown above) because these will break the command when executed.

Now run this script

python3.6 change_rpc.py

Build

Modify any addresses which are lurking in dependencies etc.

cd how_to_deploy_uniswap/uniswap_interface/ && python3 modify_addresses.py
cd ../../
yarn run build

This will generate a new build directory as well as some new files, as shown below.

  450.29 KB  build/static/js/4.047da443.chunk.js
  276.48 KB  build/static/js/5.5c7ecd7f.chunk.js
  155.14 KB  build/static/js/9.1f17fe1e.chunk.js
  95.38 KB   build/static/js/main.38d70569.chunk.js
  67.14 KB   build/static/js/0.1e3e94eb.chunk.js
  66.33 KB   build/static/js/6.e890ef53.chunk.js
  6.56 KB    build/static/js/1.5f3a35e8.chunk.js
  1.24 KB    build/static/js/runtime-main.c8bb7174.js
  907 B      build/static/css/4.996ad921.chunk.css
  165 B      build/static/js/8.81f9e545.chunk.js
  164 B      build/static/js/7.494e051e.chunk.js

You will remember that we just ran the modify_addresses.py script. We are now going to run that again (but this time, over the build folder, which the above build command just created). This is just to make sure that there are no addresses which relate to the original Uniswap source code (but rather our newly created contract addresses).

cd how_to_deploy_uniswap/uniswap_interface/ && python3 modify_addresses.py

Now run the change_rpc.py again also.

python3.6 change_rpc.py

If you are modifying the chainId (if you did the work above), please run this again.

WARNING only run this if you are using a different chainId !

python3.6 change_chain_id.py

Now, we return to the Uniswap directory to copy the modified build files over to our Apache2 server, where they will be deployed for the end users.

cd ../../ && sudo cp -rp build/* /var/www/html/ && sudo /etc/init.d/apache2 restart

Uniswap

More

If code changes are made in the source files (i.e. a console.log statement etc.), the following command is a one-stop-shop for a restart

yarn run build && cd how_to_deploy_uniswap/uniswap_interface/ && python3 modify_addresses.py && cd ../../ && sudo cp -rp build/* /var/www/html/ && sudo /etc/init.d/apache2 restart

v1 For official information, please see the official documentation of Uniswap V1

V2 For official information, please see the official documentation of Uniswap V2

More Repositories

1

wasmedge-quickjs

A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.
JavaScript
487
star
2

wasm-learning

Building Rust functions for Node.js to take advantage of Rust's performance, WebAssembly's security and portability, and JavaScript's ease-of-use. Demo code and recipes.
Rust
430
star
3

SOLL

SOLL is a new compiler for generate Ewasm from solidity and yul. See a demo here: https://asciinema.org/a/ezJqNLicn5fya02zwu4VXIo8a
C++
376
star
4

buidl

A browser-based IDE for creating, deploying, and sharing blockchain apps (DApps, or decentralized apps). Publish your first blockchain DApps in 5 minutes! Here is how: https://docs.secondstate.io/buidl-developer-tool/getting-started
Vue
364
star
5

microservice-rust-mysql

A template project for building a database-driven microservice in Rust and run it in the WasmEdge sandbox.
Rust
346
star
6

dapr-wasm

A template project to demonstrate how to run WebAssembly functions as sidecar microservices in dapr
Rust
275
star
7

smart-contract-search-engine

Takes a link to a smart contract's raw ABI file and an RPC URL and then indexes all instances of that smart contract
JavaScript
267
star
8

WasmEdge-WASINN-examples

Rust
237
star
9

LlamaEdge

The easiest & fastest way to run customized and fine-tuned LLMs locally or on the edge
Rust
206
star
10

wasmedge-nodejs-starter

A template project to run Rust functions in Node.js through the Second State WebAssembly engine.
JavaScript
158
star
11

rustwasmc

Tool for building Rust functions for Node.js. Combine the performance of Rust, safety and portability of WebAssembly, and ease of use of JavaScript.
Rust
129
star
12

chat-with-chatgpt

Chat with ChatGPT via GitHub issue comments.
111
star
13

WasmEdge-go

The GO language SDK and API for WasmEdge
Go
107
star
14

vercel-wasm-runtime

A template project for building high-performance, portable, and safe serverless functions in Vercel.
JavaScript
81
star
15

wasmedge-containers-examples

Shell
71
star
16

wasmedge_wasi_socket

A Rust lib for socket on WasmEdge.
Rust
70
star
17

meetups

70
star
18

rust-by-example-ext

Rust by Example -- Extended Edition
Dockerfile
64
star
19

lity

A rule-based contract-oriented high-level language.
C++
56
star
20

wasm-joey

Serverless Wasm - A lightweight Node.js application for deploying and executing WebAssembly(Wasm) binary-code via HTTP
JavaScript
54
star
21

ssvm-deno-starter

A template project to run Rust functions in Deno through the Second State WebAssembly engine.
Dockerfile
53
star
22

SewUp

A library to help you sew up your Ethereum project with Rust and just like develop in a common backend
Rust
52
star
23

rust-wasm-ai-demo

Rust functions for Tensorflow inference in Node.js. Rust's performance, WebAssembly's security and portability, and Javascript's ease-of-use.
Dockerfile
49
star
24

WasmEdge-go-examples

Go
46
star
25

recrypt-as-a-service

An open key management service to support privacy-first and scalable file sharing.
Rust
46
star
26

learn-rust-with-github-actions

Getting started with the Rust programming language using this VSCode and GitHub Actions template.
Dockerfile
46
star
27

aws-lambda-wasm-runtime

A template project for building high-performance, portable, and safe serverless functions in AWS Lambda.
JavaScript
44
star
28

wasmedge-seL4

Integrate WasmEdge with seL4
Shell
42
star
29

dapr-sdk-wasmedge

An experimental Dapr SDK in Rust. It is designed to run in WasmEdge applications.
Rust
41
star
30

MEGA

Make ETLs Great Again!
Rust
40
star
31

tencent-tensorflow-scf

A template project for serverless functions for Tensorflow inference on Tencent Cloud.
HTML
38
star
32

simple-staking-smart-contract

A smart contract which allows users to stake and un-stake (after a set period of time) a specified ERC20 token.
Solidity
38
star
33

wasm32-wasi-benchmark

C++
35
star
34

WebAssembly-landscape

The current development of WebAssembly
34
star
35

rust-examples

Simple Rust applications that run in WasmEdge
Rust
32
star
36

wasmedge-rustsdk-examples

Rust
31
star
37

tencent-scf-wasm-runtime

基于 WebAssembly 容器镜像的高性能腾讯云函数开发模版。A template project for building high-performance, portable, and safe serverless functions in Tencent Serverless Cloud Functions.
JavaScript
29
star
38

crunw

Add WasmEdge support to crun so that Docker and k8s tools can manage WasmEdge runtimes side by side with Docker-like application containers.
C
29
star
39

wasmedge-bindgen

Let WebAssembly's exported function support more data types for its parameters and return values.
Rust
29
star
40

wasmedge_tensorflow_interface

Rust
20
star
41

kubecon-eu-2023

20
star
42

substrate-ewasm

A substrate runtime module library (SRML) for Etherem flavored WebAssembly (ewasm)
18
star
43

runw

C++
18
star
44

simple-timelock-smart-contract

A simple timelock smart contract which locks ERC20 tokens for a specific time period and then allows users to unlock when that time period has elapsed
Solidity
17
star
45

netlify-wasm-runtime

A template project for building high-performance, portable, and safe serverless functions in Netlify.
JavaScript
16
star
46

rust-ssvm

Use EVMC binding SSVM and host written in Rust
Rust
15
star
47

serverless-reactor-starter

Rust
15
star
48

hugo-website

A no-code, no-software and no-cost solution to publishing sophisticated web sites managed by non-technical people.
HTML
15
star
49

witc

wasm-interface-types supplement & compiler of wasmedge
Haskell
13
star
50

ssvm-napi

SSVM Node.js Addon
C++
12
star
51

WasmEdge-tensorflow

C++
12
star
52

AI-as-a-Service

Rust
12
star
53

OCR-tesseract-on-Centos7

How to install and use tesseract OCR on Centos7 - without root access
11
star
54

interest-earner-smart-contract

A Solidity smart contract which allows users to stake, earn and un-stake.
Solidity
10
star
55

linear-timelock-smart-contract

Solidity smart contract which disburses ERC20 tokens linearly, over a specific period of time (all values are dynamic and are set by the contract owner)
Solidity
10
star
56

substrate-wasmedge

Substrate on WasmEdge
Rust
10
star
57

ssvm-tencent-starter

Shell
9
star
58

nodejs-helper

Rust
9
star
59

WasmEdge-tensorflow-tools

C++
9
star
60

llm-web-api-server

Rust
8
star
61

wasm-llm

Python
6
star
62

WasmEdge-evmc

Second State WebAssembly VM for EVMC Extension
C++
6
star
63

wasmedge-core

WasmEdge Node.js Addon
C++
6
star
64

wasmedge_plugin_rust_sdk

Rust
5
star
65

tencent-meme-scf

HTML
5
star
66

chatbot-ui

TypeScript
5
star
67

WasmEdge-image

C
5
star
68

qdrant-rest-client

A lightweight Qdrant client library for Rust
Rust
4
star
69

llm_todo

Python
4
star
70

wasmedge-mysql

A repository which provides a MySQL persistent storage solution for the WasmEdge runtime
JavaScript
4
star
71

SSVMRPC

A Remote Procedure Call (RPC) implementation which facilitates both code-deployment and code-execution interactions with SecondState's stateless Virtual Machine (SSVM)
Rust
4
star
72

opendapps

HTML
4
star
73

ssvm-napi-extensions

C++
4
star
74

micro-slots

Storing and accessing multiple integer values in Ethereum, using only one single uint256 slot
Python
4
star
75

libeni

Official C++ implementation of libENI, which is part of the Lity project.
C++
4
star
76

serialize_deserialize_u8_i32

A Rust library that safely converts, back and forward, between u8 and i32
Rust
3
star
77

tencent-ocr-scf

Serverless functions for OCR on Tencent Cloud.
HTML
3
star
78

ssvm-tencent-tensorflow

HTML
3
star
79

wasmedge_hostfunctionexample_interface

This is an example to create a host function interface for calling the WasmEdge internal host functions.
Rust
3
star
80

wasmmark

JavaScript
3
star
81

wasmedge-extensions

WasmEdge for Node.js Addon with extensions
C++
3
star
82

server-side-wasm-video-editing

An example of how to build a third-party application that uses SecondState's Wasm VM to edit video on the server side. This prototype shows how video can undergo frame-by-frame, pixel-by-pixel processing using native Wasm data only i.e. pixel as i32
HTML
3
star
83

docai-hf-rs

Document AI for WasmEdge
2
star
84

linkerd-wasm

A template project to run WebAssembly functions as microservices in Linkerd
2
star
85

wasmedge_process_interface

Rust
2
star
86

rfq-marketplace

Rust
2
star
87

WASI-NN-GGML-PLUGIN-REGISTRY

This is a registry project for storing all released WasmEdge WASI-NN GGML plugin with different llama.cpp versions.
2
star
88

linear-timelock-user-interface

Interface for LinearTimelock.sol smart contract
JavaScript
2
star
89

rust-faas-showcases

HTML
2
star
90

rust_native_storage_library

A library which compiles to `.so` and `.dylib` and facilitates the native storage (and retrieval) of key:value pairs on the host system
Rust
2
star
91

WasmEdge-storage

Second State WebAssembly VM for Rust Storage Extension
C++
2
star
92

simple-timelock-user-interface

A user interface for the simple timelock smart contract
JavaScript
2
star
93

WasmEdge-paratime

An Oasis Paratime using WasmEdge
Rust
2
star
94

SSVMContainer

A Rust application that sits between incoming requests from the network and the SSVM. This application handles the deployment of Wasm applications and manages the execution of services (callable functions inside the Wasm application). The actual execution takes place inside the SSVM. The SSVM is a stack-based Virtual Machine which is stateless. This SSVMContainer application is responsible for fielding incoming deployments and service calls as well as storing application state.
HTML
2
star
95

wasmedge_rustls_api

Rust
1
star
96

libsql_wasi_nn

Rust
1
star
97

haiku-connector

Haiku Connector Runner
Rust
1
star
98

wasmedge_hyper_rustls

A crate similar to rustls-hyper for wasi.
Rust
1
star
99

wasmedge_asyncify

Rust
1
star
100

interest-earner-user-interface

A user interface for the interest earner smart contract
JavaScript
1
star