diff --git a/backend/app/controllers/deposits.py b/backend/app/controllers/deposits.py new file mode 100644 index 0000000000..6b6adcffa4 --- /dev/null +++ b/backend/app/controllers/deposits.py @@ -0,0 +1,14 @@ +from typing import List + +from app import database +from app.core.common import UserDeposit +from app.exceptions import EffectiveDepositNotFound + + +def get_by_user_and_epoch( + user_address: str, epoch: int +) -> UserDeposit: + deposit = database.deposits.get_by_user_address_and_epoch(user_address, epoch) + if deposit is None: + raise EffectiveDepositNotFound(user_address, epoch) + return deposit diff --git a/backend/app/exceptions.py b/backend/app/exceptions.py index 7bb538c7e3..ac72bfc89a 100644 --- a/backend/app/exceptions.py +++ b/backend/app/exceptions.py @@ -101,6 +101,15 @@ def __init__(self, address: str): super().__init__(self.description.format(address), self.code) +class EffectiveDepositNotFound(OctantException): + code = 404 + description = ( + "Effective deposit for user {} for epoch {} not found" + ) + def __init__(self, address: str, epoch: int): + super().__init__(self.description.format(address, epoch), self.code) + + def handle_octant_exception(e: OctantException): print_stacktrace() response = e.to_json() diff --git a/backend/app/infrastructure/routes/deposits.py b/backend/app/infrastructure/routes/deposits.py index f6e0355402..a9adca2fe7 100644 --- a/backend/app/infrastructure/routes/deposits.py +++ b/backend/app/infrastructure/routes/deposits.py @@ -1,6 +1,7 @@ from flask_restx import Resource, Namespace, fields from app.database import pending_epoch_snapshot +import app.controllers.deposits as deposits_controller from app.extensions import api ns = Namespace("deposits", description="Octant deposits") @@ -24,6 +25,15 @@ }, ) +user_effective_deposit_model = api.model( + "EffectiveDeposit", + { + "effectiveDeposit": fields.String( + required=True, description="Effective GLM deposit, in wei" + ), + }, +) + @ns.route("//total_effective") @ns.doc( description="Returns value of total effective deposits made by the end of an epoch. Latest data and data for any given point in time from the past is available in the Subgraph.", @@ -52,3 +62,18 @@ class LockedRatio(Resource): def get(self, epoch): locked_ratio = pending_epoch_snapshot.get_by_epoch_num(epoch).locked_ratio return {"lockedRatio": locked_ratio} + + +@ns.route("/users//") +@ns.doc( + description="Returns user's effective deposit for particular epoch.", + params={"epoch": "Epoch number or keyword 'current'", "address": "User ethereum address in hexadecimal form (case-insensitive, prefixed with 0x)"} +) +class UserEffectiveDeposit(Resource): + @ns.marshal_with(user_effective_deposit_model) + @ns.response(200, "User effective deposit successfully retrieved") + def get(self, address: str, epoch: int): + result = deposits_controller.get_by_user_and_epoch(address, epoch) + return { + "effectiveDeposit": result.effective_deposit, + } diff --git a/shell.nix b/shell.nix index 5d0b93c918..30534b48b5 100644 --- a/shell.nix +++ b/shell.nix @@ -3,20 +3,6 @@ let sources = import ./nix/sources.nix; pkgs16 = import sources.nixpkgs16 {}; pkgs = import sources.nixpkgs {}; - python = pkgs.python310.withPackages (ps: with ps; [ - web3 - pip - requests - flask - pytest - setuptools - importmagic # for emacs - epc # for emacs - ]); - # yarn16 = pkgs.yarn.override (oldAttrs: { - # buildInputs = [ pkgs.nodejs-16_x ]; - # }); - # yarn16 = pkgs.yarn.override { buildInputs = [ pkgs.nodejs-16_x ]; }; yarn16 = pkgs16.yarn.overrideAttrs (finalAttrs: previousAttrs: { buildInputs = [ pkgs16.nodejs-16_x ]; }); @@ -28,7 +14,5 @@ pkgs.mkShell { yarn16 pkgs.git pkgs.ripgrep - pkgs.poetry - python ]; }