The subgraph contains 2 entities
- ID - Address of pool
- Name - description
- totalSupply
- ID - Date
- Asset!
- pricePerShare
- Run
yarn codegen
to generate Graph-queryable Solidity code (in./generated
) - Run
yarn install
to installnode_modules
- You can use production subgraph to explore the data struct: https://api.thegraph.com/subgraphs/name/dkirsche/asset-price-history or you can set up a local subgraph (see below)
- Go to https://curve.fi/contracts and find the swap address
- Copy ABI from Etherscan's contract
- Update subgraph.yaml
yarn codegen
- Add the necessary callbacks in
mappings/
directory
When defining the GraphQL schema, you can supply startBlock of the contract to significantly speed up deployment:
// https://thegraph.com/docs/define-a-subgraph#start-blocks
Note: The contract creation block can be quickly looked up on Etherscan:
1. Search for the contract by entering its address in the search bar.
2. Click on the creation transaction hash in the Contract Creator section.
3. Load the transaction details page where you'll find the start block for that contract.
- Setup an ETH mainnet locally. You can use AlchemyAPI: https://alchemyapi.io/?r=2190e565-4752-43b5-ba0f-ed0cf4948249. Make sure to choose Mainnet and Production as your blockchain. Fork a local ETH mainnet by running (make sure hardhat is installed). I'm forking at earliest block number found in subgraph.yaml (https://etherscan.io/blocks?p=59078)
# https://hardhat.org/guides/mainnet-forking.html
npx hardhat node --fork https://eth-mainnet.alchemyapi.io/v2/QXyXlwAgmRhb84fAp_9abui_Rn8nhP7a --fork-block-number 10796945
``
This will create a local blockchain accessible from http://127.0.0.1:8545/.
2a. Follow instructions to get local graph node running: https://thegraph.com/docs/quick-start#3.-initialize-a-new-subgraph
2b (alternative) Start a Graph node. Easiest way is to use scaffold-eth with the following changes:
change network to 'mainnet:http://host.docker.internal:8545' rm -rf docker/graph-node/data/ yarn graph-run-node
3. `NETWORK=mainnet BLOCKCHAIN=ethereum yarn prepare:subgraph`
4. Run `yarn create-local && yarn deploy-local` create and deploy the subgraph.