Skip to content

Commit

Permalink
OCT-517: feat: add endpoint for effective-deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
paulperegud committed Jul 14, 2023
1 parent a1e493a commit 7065a98
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
14 changes: 14 additions & 0 deletions backend/app/controllers/deposits.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions backend/app/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 25 additions & 0 deletions backend/app/infrastructure/routes/deposits.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -24,6 +25,15 @@
},
)

user_effective_deposit_model = api.model(
"EffectiveDeposit",
{
"effectiveDeposit": fields.String(
required=True, description="Effective GLM deposit, in wei"
),
},
)

@ns.route("/<int:epoch>/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.",
Expand Down Expand Up @@ -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/<string:address>/<int:epoch>")
@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,
}
16 changes: 0 additions & 16 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
});
Expand All @@ -28,7 +14,5 @@ pkgs.mkShell {
yarn16
pkgs.git
pkgs.ripgrep
pkgs.poetry
python
];
}

0 comments on commit 7065a98

Please sign in to comment.