-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add settlement contract buffers value monitoring test #75
Conversation
One comment here is that there are illiquid/random tokens whose value might look high but which can never be effectively be traded at the price reported by coingecko or ethplorer. To mitigate that, we could only focus on a list of "reasonable" tokens. See, e.g., here: https://tokenlists.org/, the Kleros token list being a candidate one. |
resp = requests.get( | ||
"https://api.ethplorer.io/\ | ||
getAddressInfo/\ | ||
0x9008D19f58AAbD9eD0D60971565AA8510560ab41?\ | ||
apiKey=freekey", | ||
headers=header, | ||
timeout=REQUEST_TIMEOUT, | ||
) | ||
rsp = resp.json() |
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.
This should probably be moved to some EthplorerAPI
. Not sure what part of the parsing of the response can be abstracted away into the API as well.
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.
Would you mind if I keep this as is? I know this introduces an inconsistency but APIs that are very unlikely to be reused in any other way, such as this one, might not worth the effort properly incorporating them in the project. If you insist on this though, I can take care of it.
After a loong time, I got around to implementing some of the suggested changes. Could you have a look @fhenneke ? Thanks! |
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 added a few comments.
I was not able to get all API requests to return meaningful results. So a final buffer accounting was not shown to me yet. Does it work for you already?
src/apis/klerosapi.py
Outdated
def __init__(self) -> None: | ||
self.logger = get_logger() | ||
|
||
def get_token_list(self) -> list[str]: |
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 get_token_list(self) -> list[str]: | |
def get_token_list(self) -> Optional[list[str]]: |
src/apis/klerosapi.py
Outdated
Returns the Kleros token list. | ||
""" | ||
kleros_url = "http://t2crtokens.eth.link" | ||
|
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.
kleros_list: Optional[list[str]] = None | |
src/apis/klerosapi.py
Outdated
self.logger.warning( | ||
f"Connection error while fetching the Kleros token list, error: {err}" | ||
) | ||
return kleros_list |
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.
Without the changes on setting a default, this sometimes crashes.
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.
Added what is now L36-37, to address the issue.
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.
It still crashes for we when the request times out. Our current convention for that case is to use None
as result.
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.
And all these since I cannot catch a general exception here due to the mypy,pylint etc.... Will have another look.
timeout=REQUEST_TIMEOUT, | ||
) | ||
ethplorer_rsp = ethplorer_data.json() | ||
kleros_list = self.kleros_api.get_token_list() |
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.
Handle the case of empty kleros_list here somehow. For example
kleros_list = self.kleros_api.get_token_list() | |
kleros_list = self.kleros_api.get_token_list() | |
if kleros_list is None: | |
kleros_list = [] |
or maybe just skip the hash?
a509276
to
f58aac0
Compare
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 still cannot get the call to kleros to work.
Did some edits, mainly adding 2 more lists and incorporating some comments. Could you have another look @fhenneke ? (sorry for the back and forth and thanks for checking in this in detail) |
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.
Except for the small comments this looks good to me.
Running the code
from src.monitoring_tests.buffers_monitoring_test import (
BuffersMonitoringTest,
)
buffer_test = BuffersMonitoringTest()
buffer_test.counter = 150
tx_hash = "0x65d07be85b9e067466259079e77e8fe72ac897535fcbda549a526c80e2ba09b4"
buffer_test.run(tx_hash)
returns
WARNING - Connection error while fetching a token list, error: HTTPSConnectionPool(host='t2crtokens.eth.link', port=443): Read timed out. (read timeout=5)
INFO - Buffer value is 97862.06651828821 USD
True
Co-authored-by: Felix Henneke <felix.henneke@protonmail.com>
Co-authored-by: Felix Henneke <felix.henneke@protonmail.com>
This PR adds a test that monitors the value of buffers by using price feeds from ethplorer and coingecko, while restricting the tokens that are checked to the ones included in one of the following lists (whichever can be recovered at the time of the check):
It checks the value of buffers every
BUFFER_INTERVAL
settlements, a constant currently set to150
, and if the value is aboveBUFFER_VALUE_THRESHOLD
USD, a constant currently set to200,000
, it generates an alert.The purpose of this PR is to get a better understanding of how quickly our buffers' value increases, since this might be relevant if we want to reduce the bonding pool size requirements.