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

feat: add Uniswap V2 support #4

Merged
merged 17 commits into from
Jan 11, 2025
Merged

feat: add Uniswap V2 support #4

merged 17 commits into from
Jan 11, 2025

Conversation

johnson2427
Copy link
Contributor

@johnson2427 johnson2427 commented Jul 26, 2024

What I did

fixes: #5
fixes: SBK-521

How I did it

How to verify it

Checklist

  • Passes all linting checks (pre-commit and CI jobs)
  • New test cases have been added and are passing
  • Documentation has been updated
  • PR title follows Conventional Commit standard (will be automatically included in the changelog)

uniswap_sdk/v2.json Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
uniswap_sdk/v2.py Outdated Show resolved Hide resolved
Copy link
Member

@fubuloubu fubuloubu left a 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]
#     ...

Copy link

linear bot commented Aug 21, 2024

@fubuloubu
Copy link
Member

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

...

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

@fubuloubu fubuloubu changed the title feat: added Uniswap v2 Factory contract (and sketch of Pool) feat: add Uniswap V2 support Jan 11, 2025
@fubuloubu fubuloubu enabled auto-merge (squash) January 11, 2025 02:27
@fubuloubu fubuloubu merged commit 0cc5cf3 into main Jan 11, 2025
26 checks passed
@fubuloubu fubuloubu deleted the feat/add-v2 branch January 11, 2025 02:32
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.

Add UniswapV2 Factory Contract
2 participants