-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from drift-labs/sina/risk-dashboard-monorepo-up…
…date Big PR: Moving server and client to the same repo
- Loading branch information
Showing
51 changed files
with
2,491 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.venv | ||
cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RPC_URL="" | ||
BACKEND_URL=http://localhost:8000 | ||
DEV=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Build Image And Deploy | ||
on: | ||
push: | ||
branches: [master, sina/risk-dashboard-monorepo-update] # Temporarily allow this branch run the workflow | ||
|
||
jobs: | ||
build-frontend: | ||
runs-on: ubicloud | ||
env: | ||
ECR_REPO_URI: 875427118836.dkr.ecr.eu-west-1.amazonaws.com/v2-risk-dashboard | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@master | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_PROD }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_PROD }} | ||
aws-region: "eu-west-1" | ||
|
||
- name: Log in to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Install kubectl | ||
run: | | ||
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.23.7/2022-06-29/bin/linux/amd64/kubectl | ||
curl https://s3.us-west-2.amazonaws.com/amazon-eks/1.23.7/2022-06-29/bin/linux/amd64/kubectl.sha256 | ||
openssl sha1 -sha256 kubectl | ||
chmod +x ./kubectl | ||
kubectl version --client=true | ||
- name: Docker build | ||
run: | | ||
ECR_REPO_URI=875427118836.dkr.ecr.eu-west-1.amazonaws.com/v2-risk-dashboard | ||
docker build -f ./Dockerfile-frontend -t $ECR_REPO_URI:${{github.sha}}-frontend -t $ECR_REPO_URI:latest-frontend . | ||
docker push $ECR_REPO_URI:${{github.sha}}-frontend | ||
docker push $ECR_REPO_URI:latest-frontend | ||
build-backend: | ||
runs-on: ubicloud | ||
env: | ||
ECR_REPO_URI: 875427118836.dkr.ecr.eu-west-1.amazonaws.com/v2-risk-dashboard | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@master | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_PROD }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_PROD }} | ||
aws-region: "eu-west-1" | ||
|
||
- name: Log in to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Docker build | ||
run: | | ||
ECR_REPO_URI=875427118836.dkr.ecr.eu-west-1.amazonaws.com/v2-risk-dashboard | ||
docker build -f ./Dockerfile-backend -t $ECR_REPO_URI:${{github.sha}}-backend -t $ECR_REPO_URI:latest-backend . | ||
docker push $ECR_REPO_URI:${{github.sha}}-backend | ||
docker push $ECR_REPO_URI:latest-backend | ||
deploy: | ||
runs-on: ubicloud | ||
needs: [build-frontend, build-backend] | ||
env: | ||
ECR_REPO_URI: 875427118836.dkr.ecr.eu-west-1.amazonaws.com/v2-risk-dashboard | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@master | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_PROD }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_PROD }} | ||
aws-region: "eu-west-1" | ||
|
||
- name: Log in to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Restart deployment | ||
run: | | ||
aws eks update-kubeconfig --name drift-prod-cluster --region eu-west-1 --role-arn arn:aws:iam::875427118836:role/k8sAdmin | ||
kubectl rollout restart -n mainnet-beta deployment/risk-dashboard-frontend | ||
kubectl rollout restart -n mainnet-beta deployment/risk-dashboard-backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
venv | ||
.mypy_cache | ||
/__pycache__/ | ||
/src/__pycache__/ | ||
/src/sections/__pycache__ | ||
**/__pycache__/ | ||
.env | ||
.venv | ||
pickles/* | ||
cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[server] | ||
runOnSave = true | ||
|
||
[theme] | ||
base = "dark" | ||
|
||
[browser] | ||
gatherUsageStats = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM python:3.10-slim-bullseye | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
|
||
RUN apt-get update && apt-get install -y gcc python3-dev | ||
RUN pip install --trusted-host pypi.python.org -r requirements.txt | ||
EXPOSE 8000 | ||
|
||
CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from backend.state import BackendRequest | ||
from backend.state import BackendState | ||
from backend.utils.matrix import get_matrix | ||
from backend.utils.user_metrics import get_usermap_df | ||
from backend.utils.waiting_for import waiting_for | ||
from driftpy.drift_client import DriftClient | ||
from driftpy.pickle.vat import Vat | ||
from fastapi import APIRouter | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/matrix/{mode}/{perp_market_index}") | ||
async def get_asset_liability_matrix( | ||
request: BackendRequest, mode: int, perp_market_index: int | ||
): | ||
backend_state: BackendState = request.state.backend_state | ||
vat: Vat = backend_state.vat | ||
drift_client: DriftClient = backend_state.dc | ||
|
||
with waiting_for("Getting asset liability matrix"): | ||
res, df = await get_matrix(drift_client, vat, mode, perp_market_index) | ||
|
||
return { | ||
"res": res.to_dict(), | ||
"df": df.to_dict(), | ||
} |
Oops, something went wrong.