1

Based on the doc, it seems that we need to specify the address of the contract we want to track. How could I track the new contract? eg. After deploying a factory contract, we also need to track all the new contract created by the factory.

Understanding that you could do this manually or writing a Cron task to check new contract deployment and script a re-deployment, is there any way to do this programmatically within thegraph.com? eg. How does uniswap track new trading pair after someone adding them (new contract address to track I suppose)?

pragma solidity >=0.5.0;

interface IUniswapV2Factory {
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);

  function getPair(address tokenA, address tokenB) external view returns (address pair);
  function allPairs(uint) external view returns (address pair);
  function allPairsLength() external view returns (uint);

  function feeTo() external view returns (address);
  function feeToSetter() external view returns (address);

  function createPair(address tokenA, address tokenB) external returns (address pair);
}

It's straight forward to track the factory contract. But after createPair, how could I track the newly created contract address pair? Is it possible to do this within thegraph.com? Or do I have to do it the hard way?

Answer: https://thegraph.com/docs/define-a-subgraph#data-source-templates

noooooooob
  • 1,872
  • 3
  • 21
  • 27

3 Answers3

1

Usually, factory contract emits an event when it deploys a new contract. Just track this event. However the question lacks the source code of the contracts so it is hard to say.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
0

You can't use dataSources dynamically. You must create a templates on your subgraph.yaml file for the child contract. If you checked the Uniswap subgraph, the factory contract is a dataSources, but the Pair (the child contract) used templates.

It is explained in the graph documentation.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
yehia tarek
  • 65
  • 2
  • 12
0

you can look into the official doc of subgraph. https://thegraph.com/docs/en/developing/creating-a-subgraph/#data-source-templates