-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
added the same |
There was a problem hiding this 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] |
There was a problem hiding this comment.
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
total_collateral_ratio: Optional[float] | |
total_collateral_ratio: Optional[FVal] |
def _calculate_total_collateral_ratio( | ||
self, eth_price: Price, lusd_price: Price, | ||
) -> Optional[float]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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=[], | |||
) | |||
|
There was a problem hiding this comment.
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
if system_debt != 0: | ||
total_collateral_ratio = eth_price * system_collateral / system_debt * lusd_price | ||
else: | ||
total_collateral_ratio = None |
There was a problem hiding this comment.
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
final_result = GetPositionsResult( | ||
balances=data, | ||
total_collateral_ratio=total_collateral_ratio, | ||
) |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
total_collateral_ratio = eth_price * system_collateral / system_debt * lusd_price | |
total_collateral_ratio = eth_price * FVal(system_collateral) / FVal(system_debt) * lusd_price |
}, | ||
"total_collateral_ratio": "0.003138414276398289779741030787" |
There was a problem hiding this comment.
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 🥳
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. |
Closes #3971
Checklist