-
-
Notifications
You must be signed in to change notification settings - Fork 3
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: add Uniswap V2 support #4
Conversation
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]
# ...
Updated the API, now looks like this: from ape_tokens import tokens
from uniswap_sdk import v2
yfi = tokens["YFI"]
factory = v2.Factory()
yfi_pairs = factory[yfi] # List of all UniswapV2Pair contracts where YFI is one of the pair
... And then you can put that into a table or something to do filtering and solving with We will come up with a complementary API for v3 |
What I did
fixes: #5
fixes: SBK-521
How I did it
How to verify it
Checklist