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: added Uniswap v2 Factory contract (and sketch of Pool) #4

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

Conversation

johnson2427
Copy link

@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

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

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)

Copy link
Author

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?

Copy link
Member

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

Copy link
Author

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

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 Show resolved Hide resolved
uniswap_sdk/v2.py 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

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