274 lines
9.0 KiB
Makefile
274 lines
9.0 KiB
Makefile
export NVM_ROOT := /home/ubuntu/.nvm
|
|
# export NODE_VERSION := v20.8.1 # required by web if v21.0.0 being used otherwise
|
|
export NODE_VERSION := v16.19.1
|
|
export PYTHON_VERSION := python3.11
|
|
export PATH := $(NVM_ROOT)/versions/node/$(NODE_VERSION)/bin:$(PATH)
|
|
|
|
# default:
|
|
# @echo run targets: startall, web, mock, backend, server
|
|
# @echo \n\nNote: you might need to reboot between some installation/setup steps
|
|
|
|
# Target to start all processes
|
|
|
|
default startall : FORCE
|
|
# startall runs mock.sh that does a force rebuild
|
|
bin/startall.sh
|
|
|
|
# Target to start processes
|
|
|
|
versions :
|
|
node --version
|
|
npm --version
|
|
yarn --version
|
|
cd backend && . venv/bin/activate && python3 --version
|
|
anvil --version
|
|
forge --version
|
|
@echo "\nPATH=$(PATH)"
|
|
|
|
version.json :
|
|
./bin/build_version.json.sh
|
|
|
|
web : FORCE version.json
|
|
cd web && node --version && npm --version
|
|
cd web && npm run build && npm run preview # static build for production experience
|
|
# cd web && npm run dev # hot reload for dev experience
|
|
|
|
mock : init_postgres
|
|
@echo "\n*** wait until script prints \"ONCHAIN EXECUTION COMPLETE & SUCCESSFUL\" ***\n"
|
|
TAG=mock ./bin/mock.sh # Anvil
|
|
# DEXORDER_USE_HARDHAT=1 TAG=mock ./bin/mock.sh # HardHat
|
|
|
|
mirrorprice : FORCE
|
|
MIRROR_POLLING=15 bin/mirrorprice
|
|
|
|
backend : FORCE
|
|
cd backend \
|
|
&& . venv/bin/activate \
|
|
&& python3 --version \
|
|
&& PYTHONPATH=src python3 -u src/dexorder/bin/main.py
|
|
|
|
server : FORCE
|
|
cd server \
|
|
&& node --version \
|
|
&& DEXORDER_PORT=3001 node main.js
|
|
|
|
# Install targets
|
|
|
|
install_postgres :
|
|
sudo apt install postgresql
|
|
|
|
install_docker_snap : # full docker desktop
|
|
snap install docker
|
|
sudo groupadd docker
|
|
sudo usermod -aG docker $(USER)
|
|
|
|
install_docker :
|
|
# https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
|
|
sudo apt update
|
|
sudo apt install apt-transport-https ca-certificates curl software-properties-common
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
echo "deb [arch=$$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
sudo apt update
|
|
apt-cache policy docker-ce
|
|
sudo apt install docker-ce
|
|
-sudo systemctl status docker --lines 0
|
|
-sudo groupadd docker
|
|
sudo usermod -aG docker $(USER)
|
|
|
|
install_node :
|
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
|
|
# . ~/.nvm/nvm.sh && nvm install v20.8.1 && npm install --global yarn
|
|
. ~/.nvm/nvm.sh && nvm install $(NODE_VERSION) && npm install --global yarn
|
|
|
|
install_python :
|
|
sudo apt install python3-virtualenv
|
|
sudo add-apt-repository ppa:deadsnakes/ppa -y
|
|
sudo add-apt-repository ppa:deadsnakes/nightly -y
|
|
sudo apt update
|
|
sudo apt install $(PYTHON_VERSION) -y
|
|
sudo apt install $(PYTHON_VERSION)-dev -y
|
|
$(PYTHON_VERSION) --version
|
|
|
|
install_foundry :
|
|
curl -L https://foundry.paradigm.xyz | bash
|
|
~/.foundry/bin/foundryup
|
|
sudo apt install jq
|
|
|
|
install_submodules :
|
|
git submodule init && git submodule update
|
|
cd contract && git submodule init && git submodule update
|
|
|
|
# Init targets
|
|
|
|
init_all : init_postgres init_yarns init_venv init_configs init_foundry
|
|
|
|
init_postgres :
|
|
cd /tmp; \
|
|
echo "\
|
|
drop database dexorder ; \
|
|
drop user dexorder; \
|
|
create database dexorder; \
|
|
create user dexorder with password 'redroxed'; \
|
|
grant all on database dexorder to dexorder; \
|
|
" | \
|
|
sudo -u postgres psql
|
|
|
|
init_yarns :
|
|
# cd web \
|
|
# && . ~/.nvm/nvm.sh \
|
|
# && nvm use v20.8.1
|
|
cd web \
|
|
&& node --version \
|
|
&& yarn install
|
|
cd server && node --version && yarn install
|
|
|
|
init_venv :
|
|
cd backend \
|
|
&& virtualenv -p /usr/bin/$(PYTHON_VERSION) venv \
|
|
&& . venv/bin/activate \
|
|
&& pip install --upgrade pip \
|
|
&& pip install -r requirements-lock.txt
|
|
|
|
init_configs :
|
|
cp backend/dexorder-mock.toml backend/dexorder.toml
|
|
cp backend/.secret-mock.toml backend/.secret.toml
|
|
cp server/.env-mock server/.env
|
|
cp web/.env-mock web/.env
|
|
cp contract/src/VaultAddress-default.sol contract/src/VaultAddress.sol
|
|
cp contract/foundry-default.toml contract/foundry.toml
|
|
@echo "\nMake sure to set vault address in contract/src/VaultAddress.sol file\n"
|
|
@echo "Make sure to set the arbitrum_mock and arbitrum_test aliases at the bottom of foundry.toml file\n"
|
|
|
|
diff_configs :
|
|
-diff backend/dexorder-mock.toml backend/dexorder.toml
|
|
-diff backend/.secret-mock.toml backend/.secret.toml
|
|
-diff server/.env-mock server/.env
|
|
-diff web/.env-mock web/.env
|
|
-diff contract/src/VaultAddress-default.sol contract/src/VaultAddress.sol
|
|
-diff contract/foundry-default.toml contract/foundry.toml
|
|
|
|
init_foundry :
|
|
cd contract/lib/forge-std && git submodule init && git submodule update
|
|
|
|
# deploy
|
|
|
|
deploy-contract :
|
|
cd contract; make build
|
|
cd contract; RPCURL=https://rpc.alpha.dexorder.trade ./bin/deploy.sh alpha mock
|
|
|
|
deploy-backend :
|
|
bin/deploy.sh backend
|
|
|
|
deploy-server :
|
|
bin/deploy.sh server
|
|
|
|
deploy-web :
|
|
bin/deploy.sh web
|
|
|
|
# GIT
|
|
|
|
dev-f21f278: # Working before 27d5d5294b break
|
|
git checkout f21f278
|
|
make submodule-update
|
|
rm -rf contract/out/
|
|
|
|
dev-27d5d5294b: # Diagonal line
|
|
git checkout 27d5d5294b
|
|
make submodule-update
|
|
rm -rf contract/out/
|
|
|
|
dev-contract: # checkout f21f28, but master on ./contract
|
|
git checkout f21f278
|
|
git submodule update
|
|
cd contract && git checkout master && git submodule update && rm -rf out
|
|
|
|
dev-master :
|
|
git checkout master
|
|
make submodule-master
|
|
|
|
submodule-update: # update all submodules
|
|
git submodule update
|
|
git submodule foreach 'git submodule update'
|
|
|
|
submodule-check :
|
|
@echo "origin/master vs HEAD for web:"
|
|
@cd web && git rev-parse origin/master && git rev-parse HEAD
|
|
@echo "origin/master vs HEAD for contract:"
|
|
@cd contract && git rev-parse origin/master && git rev-parse HEAD
|
|
@echo "origin/master vs HEAD for backend:"
|
|
@cd backend && git rev-parse origin/master && git rev-parse HEAD
|
|
@echo "origin/master vs HEAD for server:"
|
|
@cd server && git rev-parse origin/master && git rev-parse HEAD
|
|
|
|
submodule-master: # checkout master for all submodules
|
|
git submodule foreach 'git checkout master; git pull origin master'
|
|
|
|
# Debugging
|
|
|
|
MEH := $(shell grep 'MEH 0x' tmp/mock.log | awk '{print $$2}')
|
|
USXD := $(shell grep 'USXD 0x' tmp/mock.log | awk '{print $$2}')
|
|
DEX := $(shell grep -A 1 Dexorder tmp/mock.log | tail -1 | xargs)
|
|
VAULT := $(shell grep 'created vault' tmp/server.log | awk '{print $$3}')
|
|
|
|
addresses :
|
|
@echo
|
|
@echo "MEH: $(MEH):"
|
|
@echo "USXD: $(USXD):"
|
|
@echo "Dexorder: $(DEX):"
|
|
@echo "Vault: $(VAULT):"
|
|
|
|
balances : addresses fees balances_mock balances_dev
|
|
|
|
balances_mock :
|
|
@echo
|
|
@echo dexorder balances:
|
|
@HEX=$$(cast call $(MEH) "balanceOf(address)" $(DEX)); python3 -c "print('MEH ',$$HEX)"
|
|
@HEX=$$(cast call $(USXD) "balanceOf(address)" $(DEX)); python3 -c "print('USXD ',$$HEX)"
|
|
@echo native $$(cast balance $(DEX)) # native
|
|
|
|
@if [ -z "$(VAULT)" ]; then \
|
|
echo "\nVault not yet created\n"; \
|
|
else \
|
|
make --no-print-directory balances_vault; \
|
|
fi
|
|
|
|
balances_vault :
|
|
@echo
|
|
@echo vault balances:
|
|
@HEX=$$(cast call $(MEH) "balanceOf(address)" $(VAULT)); python3 -c "print('MEH ',$$HEX)"
|
|
@HEX=$$(cast call $(USXD) "balanceOf(address)" $(VAULT)); python3 -c "print('USXD ',$$HEX)"
|
|
@echo native $$(cast balance $(VAULT)) # native
|
|
|
|
fees :
|
|
@echo
|
|
@HEX=$$(cast call $(DEX) "feeSched()returns(uint8,uint8,uint8,uint8,uint8)" | head -1 ); python3 -c "print('fillFee: ', $$HEX/200, '%' )"
|
|
@HEX=$$(cast call $(DEX) "orderFee()returns(uint256)" | awk '{print $$1}'); python3 -c "print('orderFee: ', $$HEX/10**9 , 'Gwei', f'({$$HEX} Wei)' )"
|
|
@HEX=$$(cast call $(DEX) "trancheFee(uint256)returns(uint256)" 1 | awk '{print $$1}'); python3 -c "print('trancheFee:', $$HEX/10**9, 'Gwei', f'({$$HEX} Wei)' )"
|
|
|
|
balances_dev :
|
|
@echo
|
|
@echo "Dev0: $$(cast balance 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 )\t0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
|
|
@echo "Dev1: $$(cast balance 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 )\t0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
|
|
@echo "Dev2: $$(cast balance 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC )\t0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"
|
|
@echo "Dev3: $$(cast balance 0x90F79bf6EB2c4f870365E785982E1f101E93b906 )\t0x90F79bf6EB2c4f870365E785982E1f101E93b906"
|
|
@echo "Dev4: $$(cast balance 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 )\t0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65"
|
|
@echo "Dev5: $$(cast balance 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc )\t0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc"
|
|
@echo "Dev6: $$(cast balance 0x976EA74026E726554dB657fA54763abd0C3a0aa9 )\t0x976EA74026E726554dB657fA54763abd0C3a0aa9"
|
|
@echo "Dev7: $$(cast balance 0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 )\t0x14dC79964da2C08b23698B3D3cc7Ca32193d9955"
|
|
@echo "Dev8: $$(cast balance 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f )\t0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f"
|
|
@echo "Dev9: $$(cast balance 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 )\t0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
|
|
|
|
|
|
# Utility targets
|
|
|
|
FORCE :
|
|
|
|
# MY_VAR :=
|
|
|
|
foo:
|
|
# Check if MY_VAR is empty
|
|
if [ -z "$(MY_VAR)" ]; then \
|
|
echo "MY_VAR is not set"; \
|
|
exit 0; \
|
|
fi
|