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

Zklend liquidation research #444

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

emarc99
Copy link
Contributor

@emarc99 emarc99 commented Dec 25, 2024

Closes #434

@emarc99 emarc99 marked this pull request as draft December 25, 2024 14:27
@iamnovichek
Copy link
Collaborator

@emarc99 Any updates?

@emarc99
Copy link
Contributor Author

emarc99 commented Dec 27, 2024

Definitely today, sir.

@iamnovichek
Copy link
Collaborator

iamnovichek commented Dec 28, 2024

@emarc99 I guess it's obvious but btw pls make sure all workflows are green (besides Cairo tests)

@emarc99
Copy link
Contributor Author

emarc99 commented Dec 28, 2024

Ok, sir.

Copy link
Collaborator

@iamnovichek iamnovichek left a 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)
Copy link
Collaborator

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

research/zklend_liquidation_position.py Outdated Show resolved Hide resolved
# Initialize the StarkNet client
client = FullNodeClient(node_url=node_url)

liquidation_key_output = [
Copy link
Collaborator

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,
Copy link
Collaborator

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,
Copy link
Collaborator

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):
Copy link
Collaborator

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):
Copy link
Collaborator

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.")
Copy link
Collaborator

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
Copy link
Collaborator

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"))
Copy link
Collaborator

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

@emarc99
Copy link
Contributor Author

emarc99 commented Dec 28, 2024

I will open the PR when I get expected output, please.

@faurdent faurdent self-requested a review December 29, 2024 07:42
research/zkLend_liquidation_research.md Outdated Show resolved Hide resolved
research/zkLend_liquidation_research.md Show resolved Hide resolved

### 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.
Copy link
Collaborator

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

Copy link
Contributor Author

@emarc99 emarc99 Dec 29, 2024

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.
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@emarc99
Copy link
Contributor Author

emarc99 commented Dec 31, 2024

I will open the PR today.

@emarc99 emarc99 marked this pull request as ready for review January 1, 2025 11:38
from starknet_py.net.full_node_client import FullNodeClient

# Load environment variables
node_url = "https://starknet-mainnet.public.blastapi.io/rpc/v0_7"
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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}.")
Copy link
Collaborator

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}")
Copy link
Collaborator

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

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.

[SmartContract] Research zklend liquidation
3 participants