-
-
Notifications
You must be signed in to change notification settings - Fork 1
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: added Uniswap v2 Factory contract (and sketch of Pool) #4
base: main
Are you sure you want to change the base?
Conversation
uniswap_sdk/v2.py
Outdated
|
||
def get_all_pools(self) -> Iterator["Pool"]: | ||
df = self.contract.PairCreated.query("*", start_block=-1000) | ||
pairs = df["event_arguments"].apply(lambda x: x.get("pair")) |
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.
yes, this is being done right
side note: would love to have better handling of dataframes within ape for contract logs so that you don't need to do the lambda to get a specific column (e.g. event_arguments
become columns directly)
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'd have to build functionality around pandas itself. Not hard to do, but we'd have to add this to the query plugin. Maybe we flatten the data to fix this?
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.
Maybe we flatten the data to fix this?
Yes, that was my suggestion
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 has been implemented, we will have to ensure we use latest version of ape after this PR is merged
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.
Looking great to start, we can start thinking about what API to add to these classes and how that might integrate with a silverback bot
Maybe something like:
from ape_tokens import tokens
from silverback import SilverbackApp
from uniswap_sdk import v2 as uni_v2
app = SilverbackApp()
uni_v2_factory = uni_v2.Factory()
usdc = tokens["USDC"]
@app.on_startup()
def load_pools(_ss):
# NOTE: requires `app.state` PR
app.state.pools = {
pool.address: pool
for pool in uni_v2_factory.get_pools(usdc)
}
# Eventually do this as a dataframe?
# NOTE: recent feature suggestion to do generic event filters like this
# https://github.com/ApeWorX/silverback/issues/99
@app.on_(uni_v2.V2.UniswapV2Pair.Sync)
def update_liquidity(log):
if pool := app.state.pools.get(log.contract_address):
pool.update_liquidity(**log)
return {pool.address: pool.liquidity}
# TODO: has to be a better way to do this through filter args
# to filter out unnecessary log triggers, something like:
# @app.on_(uni_v2.V2.UniswapV2Pair.Sync, address=app.state.pools)
# def update_liquidity(log):
# pool = app.state.pools.get[log.contract_address]
# ...
What I did
fixes: #5
fixes: SBK-521
How I did it
How to verify it
Checklist