-
Notifications
You must be signed in to change notification settings - Fork 240
Contributor Modifications Guide
0xdavinchee edited this page Jun 22, 2023
·
7 revisions
Please refer to this section in the README on our conventions for writing tests in Foundry.
- 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.
- IF the feature-goerli endpoint has the desired schema deployed:
- run
yarn generate-graphql-schema
inside thepackages/sdk-core
directory
- run
- IF you only have this schema locally:
- 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
in thepackages/sdk-core
directory.
- Spin up and deploy a local instance of the subgraph and use the local endpoint with this command:
- Next, we need to add/or modify an interface for the new events into
sdk-core/src/events.ts
OR add/modify an entity in the specific entity file. We add the new event underAccountEvents
orOtherEvents
depending on whether the event is specifically related to an account or not. - In addition, there is another file in src/subgraph/events:
events.graphql
which you also need to change. - After this, run
yarn generate:graphql-types
to regenerate the type files for the queries. - 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:sdk-core/src/subgraph/events/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