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

Derive Uniswap.exchange rather than Exchange.factory #28

Open
davekaj opened this issue Feb 27, 2020 · 1 comment
Open

Derive Uniswap.exchange rather than Exchange.factory #28

davekaj opened this issue Feb 27, 2020 · 1 comment

Comments

@davekaj
Copy link
Contributor

davekaj commented Feb 27, 2020

See the condensed schema below for Uniswap and Exchange

# Uniswap global values across all exchanges
type Uniswap @entity {
    id: ID!
    exchanges: [Exchange!]!
    .........
}

type Exchange @entity {
    id: ID!                                 # Uniswap Exchange address
   ...........
    # Fields used to help derived relationship
    factory: Uniswap! @derivedFrom(field: "exchanges")
}

This is a bad pattern because we are deriving factory from exchange, while factory -> exchange has a relationship of 1-n . Right now we are deriving the factory from the exchanges, even though we know factory will always have id 1 and that there is only one factory. We should do the following:

# Uniswap global values across all exchanges
type Uniswap @entity {
    id: ID!
    exchanges: [Exchange!]! @derivedFrom(field: "factory")
    ......
}

type Exchange @entity {
    id: ID!                                 # Uniswap Exchange address
   ...........
    factory: Uniswap! 
}

And set each Exchanges factory value to the string 1. This will allow for simpler sql queries within graph-node

@davekaj davekaj changed the title Derived Uniswap.exchange rather than Exchange.factory Derive Uniswap.exchange rather than Exchange.factory Feb 27, 2020
@lutter
Copy link
Collaborator

lutter commented Mar 6, 2020

Changing this is particularly pressing for Transaction and how events link to it as the current setup is causing a lot of very slow queries right now, and I haven't figured out a way to speed them up with additional indexes etc. If, for example, AddLiquidityEvent stored the Transaction it belongs to, and Transaction.addLiquidityEvents was derived, those queries would run a lot faster.

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

No branches or pull requests

2 participants