Skip to content

Commit

Permalink
separate sync and async example
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan-Kim2028 committed Jul 21, 2024
1 parent 5d6a249 commit 876ab37
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/hypersync/get_windows_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import asyncio
import polars as pl
from mev_commit_sdk_py.hypersync_client import Hypersync

# Expand Polars DataFrame output
pl.Config.set_fmt_str_lengths(200)
pl.Config.set_fmt_float("full")

# Create an asynchronous function to manage the queries


async def main():
# Initialize the client
client = Hypersync(url='https://mev-commit.hypersync.xyz')

# Run the queries concurrently
deposits_df, withdraws_df = await asyncio.gather(
client.get_window_deposits(
address='0xe51EF1836Dbef052BfFd2eB3Fe1314365d23129d'),
client.get_window_withdraws(
address='0xe51EF1836Dbef052BfFd2eB3Fe1314365d23129d')
)

# Extract DataFrame columns to lists
deposit_windows: list[int] = deposits_df['windowNumber'].to_list()
withdraw_windows: list[int] = withdraws_df['window'].to_list()

# Take the set difference between deposit_windows and withdraw_windows
windows: list[int] = list(set(deposit_windows) - set(withdraw_windows))

# Print windows with funds still locked
print('Windows with funds still locked:')
print(windows)

# Total the amount of ETH locked
total_deposited = sum(deposits_df.filter(
pl.col('windowNumber').is_in(windows))['depositedAmount'].to_list())
total_withdrawn = sum(withdraws_df.filter(
pl.col('window').is_in(windows))['amount'].to_list())

print(f'Total ETH deposited: {total_deposited / 10**18}')
print(f'Total ETH withdrawn: {total_withdrawn / 10**18}')
print(f'Total ETH locked: {(total_deposited - total_withdrawn) / 10**18}')

# Run the main function
asyncio.run(main())
File renamed without changes.

0 comments on commit 876ab37

Please sign in to comment.