Skip to content

Commit

Permalink
Merge pull request #99 from od-hunter/multiplier-endpoint
Browse files Browse the repository at this point in the history
create endpoint for token multiplier
  • Loading branch information
djeck1432 authored Oct 25, 2024
2 parents 0e491fc + 0162774 commit d08ed80
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
57 changes: 56 additions & 1 deletion web_app/api/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,73 @@

from fastapi import APIRouter, HTTPException

from pydantic import BaseModel
from web_app.api.serializers.transaction import (
LoopLiquidityData,
RepayTransactionDataResponse,
)
from web_app.api.serializers.position import PositionFormData
from web_app.contract_tools.constants import TokenParams
from web_app.contract_tools.constants import (
TokenParams,
TokenMultipliers,
)
from web_app.contract_tools.mixins.deposit import DepositMixin
from web_app.db.crud import PositionDBConnector

router = APIRouter() # Initialize the router
position_db_connector = PositionDBConnector() # Initialize the PositionDBConnector

class TokenMultiplierResponse(BaseModel):
"""
This class defines the structure of the response for the token multiplier
endpoint, encapsulating a dictionary where each token symbol:
(e.g., "ETH", "STRK")
is mapped to its respective multiplier value.
### Parameters:
- **multipliers**: A dictionary containing token symbols as keys:
(e.g., "ETH", "STRK", "USDC")
and their respective multipliers as values.
### Returns:
A structured JSON response with each token and its multiplier.
"""
multipliers: dict[str, float]

class Config:
"""
Metadata for TokenMultiplierResponse
with example JSON response format in **schema_extra**.
"""
schema_extra = {
"example": {
"multipliers": {
"ETH": 5.0,
"STRK": 2.5,
"USDC": 5.0
}
}
}


@router.get(
"/api/get-multipliers",
tags=["Position Operations"],
response_model=TokenMultiplierResponse,
summary="Get token multipliers",
response_description="Returns token multipliers",
)
async def get_multipliers() -> TokenMultiplierResponse:
"""
This Endpoint retrieves the multipliers for tokens like ETH, STRK, and USDC.
"""
multipliers = {
"ETH": TokenMultipliers.ETH,
"STRK": TokenMultipliers.STRK,
"USDC": TokenMultipliers.USDC
}
return TokenMultiplierResponse(multipliers=multipliers)


@router.post(
"/api/create-position",
Expand Down
12 changes: 11 additions & 1 deletion web_app/contract_tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@ class TokenConfig:
"""
Class to hold the token configuration for the pools.
"""

address: str
decimals: int
name: str


@dataclass(frozen=True)
class TokenMultipliers:
"""
Class to hold the predefined multipliers for supported tokens/
"""
ETH: float = 5.0
STRK: float = 2.5
USDC: float = 5.0


class TokenParams:
"""
Class to hold the token configurations for tokens as class-level variables.
Expand Down

0 comments on commit d08ed80

Please sign in to comment.