-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'djeck1432:main' into fix/dashboard
- Loading branch information
Showing
25 changed files
with
766 additions
and
133 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
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,44 @@ | ||
|
||
FROM python:3.12-slim | ||
|
||
# Environment settings | ||
ENV PYTHONUNBUFFERED 1 | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
|
||
# Set PATH for Poetry | ||
ENV PATH="/root/.local/bin:$PATH" | ||
|
||
# Add system-level dependencies (including gcc and npm) | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
libpq-dev gcc g++ make libffi-dev build-essential \ | ||
curl nodejs npm \ | ||
dos2unix \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Poetry | ||
RUN curl -sSL https://install.python-poetry.org | python3 - | ||
|
||
# Create app directory | ||
RUN mkdir /app | ||
WORKDIR /app | ||
|
||
# Copy the pyproject.toml and poetry.lock files into container's /app/ directory | ||
COPY pyproject.toml poetry.lock /app/ | ||
|
||
# Install dependencies from the poetry.lock file | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install --no-dev --no-interaction --no-root | ||
|
||
# Copy the rest of the application code | ||
ADD . /app | ||
|
||
# Install StarknetKit via npm with legacy-peer-deps flag | ||
RUN npm install @argent/get-starknet --legacy-peer-deps --save | ||
|
||
# Set the entrypoint script as executable | ||
# Copy the rest of the application code and set the entrypoint | ||
COPY . /app | ||
RUN dos2unix /app/entrypoint.sh | ||
|
||
EXPOSE 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
version: '3.8' | ||
|
||
networks: | ||
app_network: | ||
driver: bridge | ||
|
||
services: | ||
backend: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.windows | ||
command: ["/bin/bash", "-c", "chmod +x /app/entrypoint.sh && /app/entrypoint.sh"] | ||
container_name: backend_dev | ||
volumes: | ||
- .:/app | ||
env_file: | ||
- .env.dev | ||
ports: | ||
- "8000:8000" | ||
networks: | ||
- app_network | ||
depends_on: | ||
- db | ||
environment: | ||
- DB_HOST=db | ||
- DB_PORT=5432 | ||
- DB_NAME=spotnet | ||
- DB_USER=postgres | ||
- DB_PASSWORD=password | ||
|
||
db: | ||
image: postgres:16 | ||
container_name: postgres_dev | ||
environment: | ||
POSTGRES_DB: spotnet | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
volumes: | ||
- postgres_data_dev:/var/lib/postgresql/data | ||
- ./init-db:/docker-entrypoint-initdb.d | ||
networks: | ||
- app_network | ||
ports: | ||
- "5432:5432" | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
frontend: | ||
build: | ||
context: ./frontend | ||
dockerfile: Dockerfile.dev | ||
container_name: frontend_dev | ||
volumes: | ||
- ./frontend:/app | ||
ports: | ||
- "3000:80" | ||
networks: | ||
- app_network | ||
depends_on: | ||
- backend | ||
|
||
volumes: | ||
postgres_data_dev: |
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,71 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { axiosInstance } from 'utils/axios'; | ||
|
||
const TOKEN_CONFIG = { | ||
ETH: { | ||
id: 'ethereum', | ||
collateralFactor: 0.8, | ||
borrowFactor: 0.9, | ||
decimals: 18 | ||
}, | ||
USDC: { | ||
id: 'usd-coin', | ||
collateralFactor: 0.85, | ||
borrowFactor: 0.9, | ||
decimals: 6 | ||
}, | ||
STRK: { | ||
id: 'starknet', | ||
collateralFactor: 0.75, | ||
borrowFactor: 0.85, | ||
decimals: 18 | ||
} | ||
}; | ||
|
||
const fetchTokenPrice = async (tokenId) => { | ||
const { data } = await axiosInstance.get( | ||
`https://api.coingecko.com/api/v3/simple/price?ids=${tokenId}&vs_currencies=usd` | ||
); | ||
return data[tokenId].usd; | ||
}; | ||
|
||
export const useHealthFactor = (selectedToken, tokenAmount, selectedMultiplier) => { | ||
const tokenId = selectedToken ? TOKEN_CONFIG[selectedToken]?.id : null; | ||
|
||
const { data: tokenPrice = 0, error } = useQuery({ | ||
queryKey: ['tokenPrice', tokenId], | ||
queryFn: () => fetchTokenPrice(tokenId), | ||
enabled: !!tokenId, | ||
staleTime: 30000, | ||
cacheTime: 60000, | ||
}); | ||
|
||
const calculateHealthFactor = () => { | ||
if (!tokenAmount || !selectedMultiplier || !tokenPrice) { | ||
return 0; | ||
} | ||
|
||
try { | ||
const amount = parseFloat(tokenAmount); | ||
const multiplier = parseFloat(selectedMultiplier); | ||
const tokenConfig = TOKEN_CONFIG[selectedToken]; | ||
|
||
const collateralValue = amount * tokenPrice * tokenConfig.collateralFactor; | ||
const borrowedAmount = amount * tokenPrice * (multiplier - 1); | ||
const adjustedDebtValue = borrowedAmount / tokenConfig.borrowFactor; | ||
const healthFactorValue = collateralValue / adjustedDebtValue; | ||
|
||
return Number(healthFactorValue.toFixed(6)); | ||
} catch (error) { | ||
console.error('Error calculating health factor:', error); | ||
return 0; | ||
} | ||
}; | ||
|
||
return { | ||
healthFactor: calculateHealthFactor(), | ||
tokenPrice, | ||
isLoading: !error && !tokenPrice, | ||
isError: !!error | ||
}; | ||
}; |
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
Oops, something went wrong.