Skip to content

Derive Uniswap.exchange rather than Exchange.factory #28

Description

@davekay100

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions