This repository contains the subgraph configurations and deployment scripts for the AstraDeFi platform, which tracks key data from the platform’s smart contracts across multiple networks. Subgraphs are used to efficiently index and query blockchain data, allowing for real-time data retrieval, such as staking balances, rewards, liquidity pool data, and more.
- The Graph: A decentralized protocol for indexing blockchain data.
- Graph CLI: Command-line tool for managing subgraph projects.
- Graph Node: Handles indexing and querying.
- PostgreSQL: Used for storing indexed data.
- Docker: For containerizing the services and dependencies.
- Real-time Data: The subgraph continuously indexes new blocks to reflect real-time data for staking, rewards, liquidity provision, and AMM activities.
- Multiple Contract Support: Easily add and track new contracts in the subgraph.
- Cross-Chain Support: The subgraph tracks contract data across multiple blockchains and testnets, including Ethereum, Base, Polygon, Optimism, and more.
-
Clean Environment:
- Reset Docker, hardhat network, and clean deployment files:
Clean all deployment-related data: remove networks from MetaMask, reset activity data from the advanced settings, and run the necessary commands to clean the environment.
- Reset Docker, hardhat network, and clean deployment files:
-
Compile Contracts:
- Compile all smart contracts using hardhat:
npx hardhat compile
- Compile all smart contracts using hardhat:
-
Start Local Blockchain Node:
- Run a local blockchain node with hardhat:
npx hardhat node
- Run a local blockchain node with hardhat:
-
Deploy Contracts:
- Deploy the staking contract (or other contracts):
npx hardhat run scripts/deploy.ts --network localhost
- Deploy the staking contract (or other contracts):
-
Start PostgreSQL:
- Start the PostgreSQL server:
sudo service postgresql start
- Start the PostgreSQL server:
-
Run Graph Node:
- Navigate to the graph-node directory and start the graph node with Docker:
cd graph-node && cd docker && docker-compose up
- Navigate to the graph-node directory and start the graph node with Docker:
-
Clean and Redeploy Subgraph:
- Remove and redeploy the local subgraph after starting the graph node:
yarn remove-local
yarn create-local
yarn deploy-local
- Remove and redeploy the local subgraph after starting the graph node:
-
EVM Mining Interval:
- Set an interval for block mining in a local hardhat network to avoid stale data:
await network.provider.send("evm_setIntervalMining", [5000]);
- Set an interval for block mining in a local hardhat network to avoid stale data:
To initialize a new subgraph from a smart contract:
graph init --from-contract 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 --network localhost --abi ./abis/Staking.json staking_graph
To add more contracts to the existing subgraph:
graph add 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --abi ../abis/RewardToken.json --contract-name RewardToken
To run a hardhat deploy script:
npx hardhat run scripts/deploy.ts --network localhost
Here are the most important scripts defined in the package.json
:
-
codegen: Generates TypeScript types from the GraphQL schema.
yarn codegen
-
build: Builds the subgraph and prepares it for deployment.
yarn build
-
deploy: Deploys the subgraph to the hosted service.
yarn deploy
-
create-local: Creates a new local subgraph.
yarn create-local
-
remove-local: Removes the local subgraph.
yarn remove-local
-
deploy-local: Deploys the subgraph to the local graph node.
yarn deploy-local
-
test: Runs tests for the subgraph.
yarn test
To test the subgraph with local data:
- Run the local blockchain and deploy the contracts.
- Start the graph node and index the contracts.
- Execute tests with:
yarn test
This repository is licensed under the UNLICENSED license. Feel free to modify and improve the code as per your requirements.