The Giveth Economy Subgraph is a Graph Protocol subgraph that is built for the Giveth Economy smart contracts. It is used to index and make queryable the Giveth Economy smart contracts.
- Supports GIVeconomy DeFi protocol variety of balances, e.g. GIV Power, GIV Token Lock, GIV Merkle Distro, GIV Uniswap V3 Liquidity Mining, Givers PFP, etc.
- Provides historical snapshots of GIV Power
- Provides GIVPower locked positions information, e.g. amount, unlocked, unlockable at,...
- Automatic indexing config generation using handlebars templates
- Mainnet Subgraph: https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-second-mainnet
- Gnosis Chain Subgraph: https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-second-xdai
flowchart LR
A(Config networks.yaml) --> |generate manifest| B(Subgraph Deployment yaml file)
B --> |deploy| C(The Graph)
- Graph Protocol
- TypeScript/AssemblyScript
- GraphQL
- Handlebars
- Smart contracts emit events
- Subgraph event handlers process these events
- Data is stored in entities according to the schema
- GraphQL API provides query access to the indexed data
- Node.js (v14 or higher)
- NPM or Yarn package manager
- Access to The Graph hosted service
- Clone the repository:
git clone https://github.com/Giveth/giveconomy-subgraph.git
cd giveconomy-subgraph
- Install dependencies:
yarn install
- Authenticate with The Graph:
yarn auth
The subgraph configuration is managed through:
subgraph.template.yaml
: Template for subgraph configuration. No need to write manually if you use the networks.yaml file and the generate-manifests command.networks.yaml
: A template to configure contract addresses and start blocks for each network. This will be processed by the generate-manifests command to create the subgraph deployment yaml file.
To build and deploy the subgraph:
-
Update the networks.yaml file with the correct contract addresses and start blocks for each network.
-
Build: This will generate the subgraph deployment yaml file and subgraph code.
yarn build
- Deploy to specific network:
# For Gnosis Chain
yarn deploy:gnosis:production
# For Mainnet
yarn deploy:mainnet:production
Look at the corresponding scripts in the package.json to customize it for new networks.
The subgraph includes linting and type checking:
yarn lint
Test type and build issues with build command.
yarn build
- Update contract addresses in
networks.yaml
if needed - Generate manifests with updated configurations
- Build the subgraph
- Deploy to the appropriate environment
Deployments are managed through GitHub Actions in the .github/workflows
directory.
-
Deployment Failures
- Check network configuration in
networks.yaml
- Verify contract addresses and start blocks
- Ensure proper authentication with The Graph
- Check the graph hosted service accessability
- Check network configuration in
-
Query Errors
- Verify entity schema matches the GraphQL schema
- Check subgraph health, i.e. sync status, indexing status, etc.
- Use Graph Protocol's dashboard to monitor indexing status
- Check deployment logs in The Graph's hosted service
- Monitor subgraph health through GraphQL queries, e.g. block number,...
- Unreliable subgraph results due to malfunctioning subgraph nodes
The subgraph defines several key entities:
GIVPower
: Tracks overall GIV Power balancesERC20
: Tracks ERC20 token balances, i.e. simple tokens and LP tokensTokenLock
: Records individual token locksUser
: Manages user balances and relationshipsUnipool
: Tracks liquidity pool informationTokenDistro
: Manages token distribution parameters
UniswapPosition
: Tracks liquidity positionsUniswapV3Pool
: Records pool stateUniswapInfinitePosition
: Manages infinite positions
TokenBalance
: User token balancesUnipoolBalance
: User pool balancesTokenAllocation
: Token distribution recordsGiversPFPToken
: Givers PFP token information
For detailed schema information, refer to schema.graphql
.