Skip to content

Commit

Permalink
Merge pull request #365 from ooochoche/add-extra-deposit
Browse files Browse the repository at this point in the history
feat: add_extra_deposit method
  • Loading branch information
djeck1432 authored Dec 15, 2024
2 parents 4c5e06d + a59148d commit 9b10621
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
35 changes: 35 additions & 0 deletions web_app/api/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,41 @@ async def open_position(position_id: str) -> str:
return position_status


@router.post(
"/api/add-extra-deposit/{position_id}",
tags=["Position Operations"],
summary="Add extra deposit to a user position",
response_description="Returns the result of extra deposit",
)
async def add_extra_deposit(
position_id: int,
amount: str
):
"""
This endpoint adds extra deposit to a user position.
### Parameters:
- **position_id**: The position ID.
- **amount**: The amount of the token being deposited.
"""

if not position_id:
raise HTTPException(status_code=404, detail="Position ID is required")

if not amount:
raise HTTPException(status_code=404, detail="Amount is required")

position = position_db_connector.get_position_by_id(position_id)

if not position:
raise HTTPException(status_code=404, detail="Position not found")

position_db_connector.add_extra_deposit_to_position(position, amount)

return {"detail": "Successfully added extra deposit"}



@router.get(
"/api/user-positions/{wallet_id}",
tags=["Position Operations"],
Expand Down
15 changes: 15 additions & 0 deletions web_app/contract_tools/blockchain_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,20 @@ async def is_opened_position(self, contract_address: str) -> bool:
calldata=[],
)

async def add_extra_deposit(self, contract_address: str, token_address: str, amount: str) -> Any:
"""
Adds extra deposit to position.
:param contract_address: The contract address.
:param token_address: The token address.
:param amount: The amount to deposit.
"""

return await self._func_call(
addr=self._convert_address(contract_address),
selector="extra_deposit",
calldata=[self._convert_address(token_address), amount],
)


CLIENT = StarknetClient()
10 changes: 10 additions & 0 deletions web_app/db/crud/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,13 @@ def delete_all_user_positions(self, user_id: uuid.UUID) -> None:
db.commit()
except SQLAlchemyError as e:
logger.error(f"Error deleting positions for user {user_id}: {str(e)}")

def add_extra_deposit_to_position(self, position: Position, amount: str) -> None:
"""
Adds extra deposit to a position in the database.
:param position: Position
:param amount: str
:return: None
"""
position.amount = str(int(position.amount) + int(amount))
self.write_to_db(position)

0 comments on commit 9b10621

Please sign in to comment.