6.7 KiB
Dexorder Dev Environment instructions
Note Makefile to perform these installation and execution instructions.
Installation
- Initialize the submodules with
git submodule initthen pull withgit submodule update - PostgresSQL
- install PostgreSQL
sudo -u postgres psql(Ubuntu)create database dexorder;create user dexorder with password 'redroxed';grant all on database dexorder to dexorder;
- Install Docker
- Ubuntu:
Docker-engine install. Or install Docker Desktop with snap:
snap install dockerFix sudo required:sudo groupadd dockersudo usermod -aG docker $USER alternatively we can use containerd and update the backend/bin/df.sh script.
- Ubuntu:
Docker-engine install. Or install Docker Desktop with snap:
- Install NodeJS
- Suggested to use Node Version Manager
nvm.curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash- Does not work with node v21.0.0 -- error loading sass.
nvm install v20.8.1- If developing remotely with VScode, add forwarding for port 3001 as it is not auto-detected.
npm install --global yarnwe use yarn as the package manager.cd web && yarn install; cd ..cd server && yarn install; cd ..
- Suggested to use Node Version Manager
- Install Python 3.11+
- Python
sudo add-apt-repository ppa:deadsnakes/ppa -ysudo add-apt-repository ppa:deadsnakes/nightly -ysudo apt updatesudo apt install python3.11 -ysudo apt install python3.11-dev -ypython3.11 --version - suggested to create a virtualenv under
backend/venvsudo apt install python3-virtualenvcd backend; virtualenv -p /usr/bin/python3.11 venv; cd .. - Install requirements.txt
source backend/venv/bin/activatecd backend && pip install -r requirements.txt; cd ..
- Python
- Get an ethereum RPC account; both a websocket and http polling url are necessary. alchemy.com has these at the free tier.
cp contract/foundry-default.toml contract/foundry.toml- set the
arbitrum_mockandarbitrum_testaliases at the bottom of thatfoundry.tomlfile:
[profile.default.rpc_endpoints] arbitrum_mock='https://arb-mainnet.g.alchemy.com/v2/Nb705...' arbitrum_test='https://arb-mainnet.g.alchemy.com/v2/Nb705...' cp backend/dexorder-mock.toml backend/dexorder.tomlcp backend/.secret-mock.toml backend/.secret.tomlcp server/.env-mock server/.envcp web/.env-mock web/.envcp contract/src/VaultAddress-default.sol contract/src/VaultAddress.sol- Install a web wallet like MetaMask.
- Configure the wallet for a new chain:
- name "Mock"
- RPC URL http://localhost:8545
- chain ID 31337
- token name ETH. Metamask complains about the token name but ignore the warning.
- Create a Mock account in your wallet
- use "import account" in metamask
- private key is 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
- public address 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
- this is the well-known Dev Account #9 and you can see the private key and address in hardhat startup.
- starts with 10,000 ETH on any anvil chain
- under your Dev Account, import a few important tokens:
- WETH
- 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
- 18 decimals
- USDC.e (Bridged)
- 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8
- 6 decimals
- This is the most-used USDC on Arbitrum
- USDT
- 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9
- 6 decimals
- USDC (Native)
- 0xaf88d065e77c8cC2239327C5EDb3A432268e5831
- 6 decimals
- This is a newer, lesser used USDC on Arbitrum
- WETH
- Configure the wallet for a new chain:
Mock Environment Execution
- run web (port 3000)
cd web && npm run dev
./bin/mock.sh(from top level dexorder directory)- builds contracts
- starts anvil, forking arbitrum_ankr (we should change this to something like arbitrum_anvil so we can each set it to whatever we want )
- runs
forge script Deploy.soland broadcasts init contracts onto the private anvil fork - resets database, all data gone
- starts dragonfly (redis clone) using Docker
- log files for background processes go into
./tmp/*.txt - the script traps ctrl-c to cleanly shut down anvil & dragonfly
- wait until the mock script says "ONCHAIN EXECUTION COMPLETE & SUCCESSFUL"
- run backend
cd backendsource venv/bin/activatePYTHONPATH=src python -u src/dexorder/bin/main.py
- run server (port 3001)
cd servernvm use v20.8.1DEXORDER_PORT=3001 node main.js
- browse to http://localhost:3000
NOTE: you can leave the web process (Vue) running while resetting everything else from #2 onwards. Just refresh the web browser after a new mock deployment
FAQ
Help my Metamask wallet appears frozen
- Metamask is absolute garbage and the fact that it has powered billions in crypto transactions is scary af
- Metamask is making cash hand-over-fist and they haven't fixed shit in their wallet which is still trash
- see #1
Ok but keep in mind that ANY wallet needs to keep track of its user transactions, both completed and in-flight, as well as the account's current nonce. If you were to say, set up Metamask on Mockchain, and then restart mockchain, no wallet could be expected to handle a blockchain reset, right? so you need to manually force Metamask to reset its nonce and forget about past transactions on a mockchain that no longer exists...
So in Metamask, do this dance:
- Make sure some form of local node is running (e.g. mock.sh)
- Open Metamask -using the account and chain that's stuck-
- If Metamask shows a grayed-out box saying "Connecting to Mockchain..." that doesn't go away, then switch to a different chain (Ethereum main chain) and then switch back to Mockchain
- Click the menu dots in the upper right and choose Settings
- Then click Advanced
- then "Clear activity tab data"
this will remove any activity for the account and reset its nonce
the problem you were probably seeing is that metamask sent a tx in-flight, which never completed, and then that blockchain disappeared out from under the tx! metamask cant expect disappearing blockchains so it still is trying to send this tx from another chain using a really high nonce that isnt the "next" nonce for the reset account's chain state