Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add the collateral ratio of the Liquity protocol in troves.py #6578

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

3scava1i3r
Copy link

Closes #3971

Checklist

  • The PR modified the backend for getting collateral ratio of liquity protocol and changes the way get_position() data is retrieved

@CLAassistant
Copy link

CLAassistant commented Sep 7, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@yabirgb yabirgb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to update the docs/api.rst file that contains information about the response of the endpoint that you modified, sadly we don't have autogenerated docs

rotkehlchen/chain/ethereum/modules/liquity/trove.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/liquity/trove.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/liquity/trove.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/liquity/trove.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/liquity/trove.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 7, 2023

Codecov Report

Merging #6578 (6b1dedd) into develop (d03900f) will decrease coverage by 0.20%.
Report is 9 commits behind head on develop.
The diff coverage is 50.00%.

@@             Coverage Diff             @@
##           develop    #6578       /-   ##
===========================================
- Coverage    71.44%   71.25%   -0.20%     
===========================================
  Files         1127     1130        3     
  Lines        99948   100063      115     
  Branches     11630    11640       10     
===========================================
- Hits         71412    71298     -114     
- Misses       26906    27124      218     
- Partials      1630     1641       11     
Flag Coverage Δ
backend 63.73% <50.00%> (-0.42%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
rotkehlchen/chain/aggregator.py 73.52% <0.00%> (-0.44%) ⬇️
...otkehlchen/chain/ethereum/modules/liquity/trove.py 59.62% <52.63%> (-18.46%) ⬇️

... and 52 files with indirect coverage changes

@3scava1i3r
Copy link
Author

You forgot to update the docs/api.rst file that contains information about the response of the endpoint that you modified, sadly we don't have autogenerated docs

added the same

Copy link
Member

@yabirgb yabirgb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much and sorry for taking so long to look at this. Just a few minor comments. Was also just checking yesterday on the frontend team in case there was an issue for the api design and if it would make sense to show the collateral with the troves, they said that is a good place for it and then the api design is okey.

If you notice there is a test that failed to execute. It has some special mocking that we were doing before introducing VCR. The reason why it fails is because there is a remote call to the contract (for the two values that you request) that are not found there. Maybe it would make sense to remove this and migrate to VCR as we do for other tests, the setup is a bit more complicated since you need to create a PR in other repo with the cassette. THis would help you https://rotki.readthedocs.io/en/stable/contribute.html#mocking-networking-in-the-tests

Please if you find any issue with this ping me in discord and I'll check with to answer asap. Also sorry for the delay in the review again.

@@ -52,6 52,11 @@ def serialize(self) -> dict[str, Any]:
return result


class GetPositionsResult(TypedDict):
balances: dict[ChecksumEvmAddress, Trove]
total_collateral_ratio: Optional[float]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use FVal for flating point values. Is a special class that prevents us from decimal point errors

Suggested change
total_collateral_ratio: Optional[float]
total_collateral_ratio: Optional[FVal]

Comment on lines 89 to 91
def _calculate_total_collateral_ratio(
self, eth_price: Price, lusd_price: Price,
) -> Optional[float]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _calculate_total_collateral_ratio(
self, eth_price: Price, lusd_price: Price,
) -> Optional[float]:
def _calculate_total_collateral_ratio(
self, eth_price: Price, lusd_price: Price,
) -> Optional[FVal]:

Also can you add a small docstring explaining what this function does? it helps for people reding in the future and also people not familiar with liquity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note in the docstrings we include possible errors that can be raised by functions

@@ -102,13 101,25 @@ def get_positions(
arguments=[],
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line

Comment on lines 107 to 110
if system_debt != 0:
total_collateral_ratio = eth_price * system_collateral / system_debt * lusd_price
else:
total_collateral_ratio = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it is defined now if the call for system_collateral raises RemoteError it will happen that system_debt won't be defined and this will raises an unknown variable error. There should be a return None on the except RemoteError

Comment on lines 195 to 198
final_result = GetPositionsResult(
balances=data,
total_collateral_ratio=total_collateral_ratio,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that maybe is clear to do

Suggested change
final_result = GetPositionsResult(
balances=data,
total_collateral_ratio=total_collateral_ratio,
)
final_result = GetPositionsResult(
balances=data,
total_collateral_ratio=self._calculate_total_collateral_ratio(eth_price, lusd_price),
)

what do you think? and move the price queries just before they are needed

log.error(f'Failed to query liquity contracts for protocol collateral ratio: {e}')

if system_debt != 0:
total_collateral_ratio = eth_price * system_collateral / system_debt * lusd_price
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When doing operations with decimal numbers we use floats. Irc call only returns primitive types (can you confirm this). What we do in the code is transform this in FVal to always work with instances of FVal

Suggested change
total_collateral_ratio = eth_price * system_collateral / system_debt * lusd_price
total_collateral_ratio = eth_price * FVal(system_collateral) / FVal(system_debt) * lusd_price

Comment on lines 7072 to 7073
},
"total_collateral_ratio": "0.003138414276398289779741030787"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add the two keys total_collateral_ratio and balances to the under result explaining what they are. You can check other endpoints to see how we do it.

Also can you use a more realistic value? when calling it I got

                "total_collateral_ratio": "2.217361196766775300136584335"

I believe you got this value because comes from the tests and there the prices are mocked. When I checked other frontends they show 222% what seems correct 🥳

@3scava1i3r
Copy link
Author

Just confirming that I am still working on the same

@LefterisJP
Copy link
Member

Just confirming that I am still working on the same

hey @3scava1i3r the PR has been open for 9 months with no activity. Please respond within this week if you can finish it or we can either close it or take it over and finish it ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add status of the Liquity protocol to the frontend
4 participants