Files
dexorder/install.md
2023-12-02 19:15:07 -08:00

7.0 KiB

Dexorder Dev Environment instructions

Note Makefile to perform these installation and execution instructions.

Installation

  1. Initialize the submodules with git submodule init then pull with git submodule update
  2. PostgresSQL
    1. install PostgreSQL
    2. sudo -u postgres psql (Ubuntu)
      1. create database dexorder;
      2. create user dexorder with password 'redroxed';
      3. grant all on database dexorder to dexorder;
  3. Install Docker
    • Ubuntu: Docker-engine install. Or install Docker Desktop with snap: snap install docker Fix sudo required: sudo groupadd docker sudo usermod -aG docker $USER
    • alternatively we can use containerd and update the backend/bin/df.sh script.
  4. Install NodeJS
    1. Suggested to use Node Version Manager nvm.
      1. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
      2. Does not work with node v21.0.0 -- error loading sass.
      3. nvm install v20.8.1
      4. If developing remotely with VScode, add forwarding for port 3001 as it is not auto-detected.
    2. npm install --global yarn we use yarn as the package manager.
    3. cd web && yarn install; cd ..
    4. cd server && yarn install; cd ..
  5. Install Python 3.11+
    1. Python sudo add-apt-repository ppa:deadsnakes/ppa -y sudo add-apt-repository ppa:deadsnakes/nightly -y sudo apt update sudo apt install python3.11 -y sudo apt install python3.11-dev -y python3.11 --version
    2. suggested to create a virtualenv under backend/venv sudo apt install python3-virtualenv cd backend; virtualenv -p /usr/bin/python3.11 venv; cd ..
    3. Install requirements.txt source backend/venv/bin/activate cd backend && pip install -r requirements-lock.txt; cd ..
  6. Get an ethereum RPC account; both a websocket and http polling url are necessary. alchemy.com has these at the free tier.
    1. cp contract/foundry-default.toml contract/foundry.toml
    2. set the arbitrum_mock and arbitrum_test aliases at the bottom of that foundry.toml file:
    [profile.default.rpc_endpoints]
    arbitrum_mock='https://arb-mainnet.g.alchemy.com/v2/Nb705...'
    arbitrum_test='https://arb-mainnet.g.alchemy.com/v2/Nb705...'
    
  7. cp backend/dexorder-mock.toml backend/dexorder.toml
  8. cp backend/.secret-mock.toml backend/.secret.toml
  9. cp server/.env.mock server/.env
  10. cp web/.env.mock web/.env
  11. cp contract/src/VaultAddress-default.sol contract/src/VaultAddress.sol
  12. Install a web wallet like MetaMask.
    1. 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.
    2. Create a Mock account in your wallet
      1. use "import account" in metamask
      2. 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
      3. under your Dev Account, import a few important tokens:
        1. WETH
          • 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
          • 18 decimals
        2. USDC.e (Bridged)
          • 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8
          • 6 decimals
          • This is the most-used USDC on Arbitrum
        3. USDT
          • 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9
          • 6 decimals
        4. USDC (Native)
          • 0xaf88d065e77c8cC2239327C5EDb3A432268e5831
          • 6 decimals
          • This is a newer, lesser used USDC on Arbitrum

Mock Environment Execution

  1. run web (port 3000)
    1. cd web && npm run dev
  2. ./bin/mock.sh (from top level dexorder directory)
    1. builds contracts
    2. starts anvil, forking arbitrum_ankr (we should change this to something like arbitrum_anvil so we can each set it to whatever we want )
    3. runs forge script Deploy.sol and broadcasts init contracts onto the private anvil fork
    4. resets database, all data gone
    5. starts dragonfly (redis clone) using Docker
    6. log files for background processes go into ./tmp/*.txt
    7. the script traps ctrl-c to cleanly shut down anvil & dragonfly
  3. wait until the mock script says "ONCHAIN EXECUTION COMPLETE & SUCCESSFUL"
  4. run backend
    1. cd backend
    2. source venv/bin/activate
    3. PYTHONPATH=src python -u src/dexorder/bin/main.py
  5. run server (port 3001)
    1. cd server
    2. nvm use v20.8.1
    3. DEXORDER_PORT=3001 node main.js
  6. 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

Deployment

  1. Follow these instructions to install gcloud CLI

https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl

  1. Get authorization from Tim and log in.

gcloud.init https://kubernetes.io/docs/reference/kubectl/cheatsheet/

FAQ

Help my Metamask wallet appears frozen

  1. Metamask is absolute garbage and the fact that it has powered billions in crypto transactions is scary af
  2. Metamask is making cash hand-over-fist and they haven't fixed shit in their wallet which is still trash
  3. 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:

  1. Make sure some form of local node is running (e.g. mock.sh)
  2. Open Metamask -using the account and chain that's stuck-
  3. 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
  4. Click the menu dots in the upper right and choose Settings
  5. Then click Advanced
  6. 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