|
| 1 | +# Giveth Economy Subgraph |
1 | 2 |
|
2 | | -# GIVEconomy Subgraph |
3 | | -Subgraph for Giveth Economy contracts |
| 3 | +## 1. Project Overview |
4 | 4 |
|
| 5 | +### Purpose |
| 6 | +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. |
5 | 7 |
|
6 | | -## Hosted node endpoints on production |
| 8 | +### Key Features |
| 9 | +- 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. |
| 10 | +- Provides historical snapshots of GIV Power |
| 11 | +- Provides GIVPower locked positions information, e.g. amount, unlocked, unlockable at,... |
| 12 | +- Automatic indexing config generation using handlebars templates |
7 | 13 |
|
8 | | -- Mainnet: `https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-second-mainnet` |
9 | | -- Gnosis: `https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-second-xdai` |
| 14 | +### Live Links |
| 15 | +- Mainnet Subgraph: https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-second-mainnet |
| 16 | +- Gnosis Chain Subgraph: https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-second-xdai |
10 | 17 |
|
11 | | -## Hosted node endpoints on staging |
| 18 | +## 2. System Architecture |
12 | 19 |
|
13 | | -- Goerli: `https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-goerli-staging` |
14 | | -- Gnosis: `https://thegraph.com/hosted-service/subgraph/giveth/giveth-economy-xdai-staging` |
| 20 | +### Flow Diagram |
| 21 | +```mermaid |
| 22 | +flowchart LR |
| 23 | + A(Config networks.yaml) --> |generate manifest| B(Subgraph Deployment yaml file) |
| 24 | + B --> |deploy| C(The Graph) |
| 25 | +``` |
| 26 | + |
| 27 | +### Tech Stack |
| 28 | +- Graph Protocol |
| 29 | +- TypeScript/AssemblyScript |
| 30 | +- GraphQL |
| 31 | +- Handlebars |
15 | 32 |
|
| 33 | +### Data Flow |
| 34 | +1. Smart contracts emit events |
| 35 | +2. Subgraph event handlers process these events |
| 36 | +3. Data is stored in entities according to the schema |
| 37 | +4. GraphQL API provides query access to the indexed data |
16 | 38 |
|
17 | | -## Subgraphs |
| 39 | +## 3. Getting Started |
18 | 40 |
|
19 | | -This repository contains subgraphs for two chains: Ethereum and Gnosis with respective testnet (Goerli) |
| 41 | +### Prerequisites |
| 42 | +- Node.js (v14 or higher) |
| 43 | +- NPM or Yarn package manager |
| 44 | +- Access to The Graph hosted service |
20 | 45 |
|
21 | | -**To prepare root (Ethereum) subgraphs** |
| 46 | +### Installation Steps |
| 47 | +1. Clone the repository: |
| 48 | +```bash |
| 49 | +git clone https://github.com/Giveth/giveconomy-subgraph.git |
| 50 | +cd giveconomy-subgraph |
| 51 | +``` |
22 | 52 |
|
| 53 | +2. Install dependencies: |
23 | 54 | ```bash |
24 | | -# install dependencies |
25 | 55 | yarn install |
| 56 | +``` |
26 | 57 |
|
27 | | -# Set authentication |
| 58 | +3. Authenticate with The Graph: |
| 59 | +```bash |
28 | 60 | yarn auth |
29 | 61 | ``` |
30 | 62 |
|
31 | | -### Build |
32 | | -According to your configuration on networks.yaml |
33 | | -```bash |
34 | | -# build mainnet |
35 | | -yarn build:deployment-mainnet |
| 63 | +### Configuration |
| 64 | +The subgraph configuration is managed through: |
| 65 | +- `subgraph.template.yaml`: Template for subgraph configuration. No need to write manually if you use the networks.yaml file and the generate-manifests command. |
| 66 | +- `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. |
36 | 67 |
|
37 | | -# build deployment 7 |
38 | | -yarn build:deployment-7 |
39 | | -``` |
| 68 | +## 4. Usage Instructions |
40 | 69 |
|
41 | | -### Deploy on Graph's hosted node |
| 70 | +### Running the Application |
| 71 | +To build and deploy the subgraph: |
42 | 72 |
|
43 | | -**For mainnet** |
| 73 | +1. Update the networks.yaml file with the correct contract addresses and start blocks for each network. |
44 | 74 |
|
| 75 | +2. Build: This will generate the subgraph deployment yaml file and subgraph code. |
45 | 76 | ```bash |
46 | | -yarn deploy:mainnet:production |
| 77 | +yarn build |
47 | 78 | ``` |
48 | 79 |
|
49 | | -**For goerli** |
50 | | - |
| 80 | +3. Deploy to specific network: |
51 | 81 | ```bash |
52 | | -yarn deploy:goerli:develop |
| 82 | +# For Gnosis Chain |
| 83 | +yarn deploy:gnosis:production |
| 84 | + |
| 85 | +# For Mainnet |
| 86 | +yarn deploy:mainnet:production |
53 | 87 | ``` |
| 88 | +Look at the corresponding scripts in the package.json to customize it for new networks. |
54 | 89 |
|
55 | | -**For gnosis** |
| 90 | +### Testing |
| 91 | +The subgraph includes linting and type checking: |
| 92 | +```bash |
| 93 | +yarn lint |
| 94 | +``` |
56 | 95 |
|
| 96 | +### Build Issues |
| 97 | +Test type and build issues with build command. |
57 | 98 | ```bash |
58 | | -yarn deploy:gnosis:production |
| 99 | +yarn build |
59 | 100 | ``` |
| 101 | + |
| 102 | +## 5. Deployment Process |
| 103 | + |
| 104 | +### Deployment Steps |
| 105 | +1. Update contract addresses in `networks.yaml` if needed |
| 106 | +2. Generate manifests with updated configurations |
| 107 | +3. Build the subgraph |
| 108 | +4. Deploy to the appropriate environment |
| 109 | + |
| 110 | +### CI/CD Integration |
| 111 | +Deployments are managed through GitHub Actions in the `.github/workflows` directory. |
| 112 | + |
| 113 | +## 6. Troubleshooting |
| 114 | + |
| 115 | +### Common Issues |
| 116 | +1. **Deployment Failures** |
| 117 | + - Check network configuration in `networks.yaml` |
| 118 | + - Verify contract addresses and start blocks |
| 119 | + - Ensure proper authentication with The Graph |
| 120 | + - Check the graph hosted service accessability |
| 121 | + |
| 122 | +2. **Query Errors** |
| 123 | + - Verify entity schema matches the GraphQL schema |
| 124 | + - Check subgraph health, i.e. sync status, indexing status, etc. |
| 125 | + |
| 126 | +### Logs and Debugging |
| 127 | +- Use Graph Protocol's dashboard to monitor indexing status |
| 128 | +- Check deployment logs in The Graph's hosted service |
| 129 | +- Monitor subgraph health through GraphQL queries, e.g. block number,... |
| 130 | +- Unreliable subgraph results due to malfunctioning subgraph nodes |
| 131 | + |
| 132 | +## Schema Documentation |
| 133 | + |
| 134 | +The subgraph defines several key entities: |
| 135 | + |
| 136 | +### Core Entities |
| 137 | +- `GIVPower`: Tracks overall GIV Power balances |
| 138 | +- `ERC20`: Tracks ERC20 token balances, i.e. simple tokens and LP tokens |
| 139 | +- `TokenLock`: Records individual token locks |
| 140 | +- `User`: Manages user balances and relationships |
| 141 | +- `Unipool`: Tracks liquidity pool information |
| 142 | +- `TokenDistro`: Manages token distribution parameters |
| 143 | + |
| 144 | +### Uniswap V3 Entities |
| 145 | +- `UniswapPosition`: Tracks liquidity positions |
| 146 | +- `UniswapV3Pool`: Records pool state |
| 147 | +- `UniswapInfinitePosition`: Manages infinite positions |
| 148 | + |
| 149 | +### Additional Entities |
| 150 | +- `TokenBalance`: User token balances |
| 151 | +- `UnipoolBalance`: User pool balances |
| 152 | +- `TokenAllocation`: Token distribution records |
| 153 | +- `GiversPFPToken`: Givers PFP token information |
| 154 | + |
| 155 | +For detailed schema information, refer to `schema.graphql`. |
0 commit comments