281 lines
9.3 KiB
Makefile
281 lines
9.3 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
|
|
|
|
# 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
|
|
|
|
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
|
|
|
|
webhost : FORCE version.json
|
|
cd web && node --version && npm --version
|
|
cd web && npm run build && npm run host # 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 # Anvil
|
|
# DEXORDER_USE_HARDHAT=1 TAG=mock ./bin/mock # HardHat
|
|
|
|
mirrorprice : FORCE
|
|
MIRROR_POLLING=5 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_all : install_postgres install_docker install_node install_python install_foundry install_submodules
|
|
|
|
install_postgres :
|
|
sudo apt-get install -y postgresql
|
|
|
|
install_docker_snap : # full docker desktop
|
|
snap install docker
|
|
sudo groupadd docker
|
|
sudo usermod -aG docker $(USER)
|
|
|
|
install_docker :
|
|
sudo apt-get install -y docker.io
|
|
# # Add Docker's official GPG key:
|
|
# sudo apt-get install ca-certificates curl
|
|
# sudo install -m 0755 -d /etc/apt/keyrings
|
|
# sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
|
# sudo chmod a+r /etc/apt/keyrings/docker.asc
|
|
#
|
|
# # Add the repository to Apt sources:
|
|
# echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
|
|
# | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
# sudo apt-get update
|
|
# sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
|
|
|
|
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) && nvm alias default $(NODE_VERSION) && npm install --global yarn
|
|
|
|
install_python :
|
|
sudo add-apt-repository ppa:deadsnakes/ppa -y
|
|
sudo add-apt-repository ppa:deadsnakes/nightly -y
|
|
sudo apt-get update
|
|
sudo apt-get install -y python3-virtualenv $(PYTHON_VERSION) $(PYTHON_VERSION)-dev
|
|
$(PYTHON_VERSION) --version
|
|
|
|
install_foundry :
|
|
curl -L https://foundry.paradigm.xyz | bash
|
|
~/.foundry/bin/foundryup
|
|
sudo apt-get install -y jq
|
|
|
|
install_submodules :
|
|
git submodule init && git submodule update
|
|
# todo next step not needed after we hard-copy libs over
|
|
cd contract && git submodule init && git submodule update
|
|
|
|
# Init targets
|
|
|
|
init_all : init_postgres init_yarn init_venv init_configs init_foundry
|
|
|
|
init_postgres :
|
|
cd /tmp; \
|
|
echo "\
|
|
drop database if exists dexorder; \
|
|
drop user if exists dexorder; \
|
|
create database dexorder; \
|
|
create user dexorder with password 'redroxed'; \
|
|
grant all on database dexorder to dexorder; \
|
|
" | \
|
|
sudo -u postgres psql
|
|
|
|
init_yarn :
|
|
# 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/conf/mock/dexorder-mock.toml backend/dexorder.toml
|
|
cp backend/conf/mock/.secret-mock.toml backend/.secret.toml
|
|
cp server/.env-mock server/.env
|
|
cp web/.env-mock web/.env
|
|
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 && git submodule init && git submodule update
|
|
|
|
# deploy
|
|
|
|
deploy-contract :
|
|
cd contract; make build
|
|
cd contract; RPCURL=https://rpc.alpha.dexorder.trade ./bin/deploy alpha mock
|
|
|
|
deploy-backend :
|
|
bin/deploy backend
|
|
|
|
deploy-server :
|
|
bin/deploy server
|
|
|
|
deploy-web :
|
|
bin/deploy 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
|