-
Notifications
You must be signed in to change notification settings - Fork 237
Contributor Modifications Guide
0xdavinchee edited this page Apr 13, 2022
·
7 revisions
- When we make upgrades/updates to our contracts, we may choose to add a new event, update the name of the event or the name of one of the fields.
- If we are interested in indexing these new events and returning this data, we need to add do the following to add this information to the subgraph:
- Add the new entity to the
schema.graphql
file inpackages/subgraph
. - Create a mapping handler function in the appropriate folder (
src/mappings/[contract]
). - Add the new entity under
dataSources.mapping.entities
to the appropriate dataSource indataSources
in bothsubgraph.template.yaml
andtest-subgraph.template.yaml
. - Add the new/modified event under
dataSources.mapping.eventHandlers
and its handler (name of handler function). Look at the subgraph.template.yaml as an example.
Note: if you want to run tests/subgraph locally after an event has been modified (contract ABI changes, so you need to rebuild contracts), look at tasks/testenv-ctl.sh
for further guidance on the necessary steps required to do so.
- Now, we need to update the
sdk-core/src/subgraph/schema.graphql
file. We can do this by runningyarn generate-graphql-schema
inside thepackages/sdk-core
directory if a subgraph with the new schema has been deployed to the feature-matic endpoint. If it hasn't been deployed, we must spin up and deploy a local instance of the subgraph and use the local endpoint with this command:npx get-graphql-schema http://localhost:8000/subgraphs/name/superfluid-test > src/subgraph/schema.graphql
. - Next, we need to add an interface for the new events into
sdk-core/src/events.ts
or a new entity into the specific entity file. We add the new event underAccountEvents
orOtherEvents
depending on whether the event is specifically related to an account or not. - Then, we need to add the event to the query in
sdk-core/src/subgraph/queries/getAllEvents.graphql
. This will ensure that thegetAllEvents.ts
file gets generated properly. We also need to add a query for the new event, add this query to the larger events query and a query fragment in:events.graphql
. - Lastly, we must add a case for our new event in
sdk-core/src/mapGetAllEventsQueryEvents.ts
(for event entities, for HOL entities, each entity will have its own file and mapping function). We specify the name of the entity for the case:case "EntityName":
and return a typeGuard object passing in the desired event as the generic and we map each of the properties accordingly.
- Governance Overview
- For Contributors
- Development Process
- Protocol EVMv1 Operations
- Protocol EVMv1 Technical Notes
- Protocol EVMv1 Core Subgraph