-
Notifications
You must be signed in to change notification settings - Fork 111
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
Zklend liquidation research #444
base: main
Are you sure you want to change the base?
Conversation
…-liquidation-research
@emarc99 Any updates? |
Definitely today, sir. |
…c99/spotnet into zklend-liquidation-research
@emarc99 I guess it's obvious but btw pls make sure all workflows are green (besides Cairo tests) |
Ok, sir. |
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.
Pls use black
and 'isort`
|
||
async def check_liquidation_proof(user_address): | ||
# Initialize the StarkNet client | ||
client = FullNodeClient(node_url=node_url) |
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.
Pls initialize it outside the function as a constant
# Initialize the StarkNet client | ||
client = FullNodeClient(node_url=node_url) | ||
|
||
liquidation_key_output = [ |
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.
Move
liquidation_key_output = [
1004689575290523089480265033644810625213175352109340690572687136992269442551
]
liquidation_selector = (
"0x238a25785a13ab3138feb8f8f517e5a21a377cc1ad47809e9fd5e76daf01df7"
)
outside the function as a constant
|
||
# Fetch liquidation events | ||
events_chunk = await client.get_events( | ||
from_block_number= 101302, |
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.
Replace this magic number with a constant initialized outside the function
from_block_number= 101302, | ||
to_block_number="latest", | ||
follow_continuation_token=True, | ||
chunk_size=150, |
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.
Replace this magic number with a constant initialized outside the function
# Analyze events for the specific user | ||
for event in events: | ||
# print(event) | ||
if event.data[1] == int(user_address, 16): |
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.
Pls write base=16
to be more explicit
# Analyze events for the specific user | ||
for event in events: | ||
# print(event) | ||
if event.data[1] == int(user_address, 16): |
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 unpack this event.data
object to be more explicit (liquidator, address, debt_token, etc = event.data
)
) | ||
|
||
# Print or log the details of the liquidation | ||
print(f"Liquidation Event: {liquidator} liquidated {user_address}'s position.") |
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.
Pls use logger
instead
|
||
|
||
if __name__ == "__main__": | ||
import asyncio |
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.
Pls import it at the begin of the file
|
||
if __name__ == "__main__": | ||
import asyncio | ||
asyncio.run(check_liquidation_proof("0x05685d6b0b493c7c939d65c175305b893870cacad780842c79a611ad9122815f")) |
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.
Pls replace this with a constant initialized at the begin of the file
I will open the PR when I get expected output, please. |
|
||
### User Activity | ||
1. **Check Events in Deployed Spotnet Contract**: The `Events` logs of the spotnet contract were examined on [Starkscan](https://starkscan.co/contract/0x05685d6b0b493c7c939d65c175305b893870cacad780842c79a611ad9122815f#events). Only two events were observed; `LiquidityLooped` and `OwnershipTransferred` | ||
2. **[Check Read Functions](https://starkscan.co/contract/0x05685d6b0b493c7c939d65c175305b893870cacad780842c79a611ad9122815f#read-write-contract-sub-read)**: `is_position_open()` returned 1 (true), while `owner()` returned 0x5c0846b4a80bb664b2f865e4dbc9a5e5eb3c454d124124ab891acc55a7e6fd. |
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 don't think owner
is relevant for this research
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 initially thought it'll be useful, it is not. Will remove it.
|
||
### Portfolio Check | ||
|
||
Upon checking the portfolio of the deployed Spotnet contract, it was found that there is a balance of **1.744172753867558899 zSTRK Token**, while `LiquidityLooped` event showed that the user was able to deposit **1.744172753867558898 STRK** with an initial deposit **1 STRK**. This indicates that the position is not fully liquidated, as the user still holds assets in the zkLend protocol. |
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.
What part was liquidated percentually?
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.
That is a good question, sir. Will add this.
I will open the PR today. |
from starknet_py.net.full_node_client import FullNodeClient | ||
|
||
# Load environment variables | ||
node_url = "https://starknet-mainnet.public.blastapi.io/rpc/v0_7" |
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.
Make is pls constant
|
||
|
||
# Initialize the StarkNet client | ||
client = FullNodeClient(node_url=node_url) |
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.
Make is pls constant
|
||
# Print all liquidation results after processing all events | ||
if liquid_results: | ||
print("Liquidation Results:", liquid_results) |
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.
Use logger
if liquid_results: | ||
print("Liquidation Results:", liquid_results) | ||
else: | ||
print(f"No liquidation events found for user {liquidatee_address}.") |
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.
Use logger
|
||
# Process events for the specific user | ||
for event in events: | ||
# logger.info(f"Event Data: {event}") |
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.
Do we still need this comment code? If not, please delete it
Closes #434