ponder-sh / ponder

The backend framework for crypto apps
https://ponder.sh
MIT License
662 stars 105 forks source link

`setup` event for multiple networks #977

Open iherger opened 4 months ago

iherger commented 4 months ago

Not sure if this is supposed to work, but it would be great if it did.

I have configured multiple networks as follows (note that there are two networks with the same chainId, which correspond to two different contract deployments):

  networks: {
    arbitrum: {
      chainId: 42161,
      transport: http(process.env.PONDER_RPC_URL_42161),
    },
    ethereum: {
      chainId: 1,
      transport: http(process.env.PONDER_RPC_URL_1),
    },
    polygon: {
      chainId: 137,
      transport: http(process.env.PONDER_RPC_URL_137),
    },
    testnet: {
      chainId: 137,
      transport: http(process.env.PONDER_RPC_URL_137),
    },
  },

I have also defined all those networks for a contract.

Now, the setup event for that contract is invoked 4 times (correct), but the context.network property is somewhat mixed up:

{ name: 'arbitrum', chainId: 42161 }
{ name: 'ethereum', chainId: 1 }
{ name: 'testnet', chainId: 137 }
{ name: 'testnet', chainId: 137 }

Is this supposed to work? Can you have multiple networks with the same chainId?

typedarray commented 4 months ago

Ah - I think we currently assume that there are never multiple networks with the same chainId, so you're seeing undefined/untested behavior here. We should add a validation against this.

That aside, could you share more about why you want this? Do you have both a "test" contract and the prod contract deployed to the same (prod) chain?

iherger commented 4 months ago

We indeed have a test deployment of all contracts on Polygon mainnet (mostly due to third-party integrations being available there).

Am I correct in understanding that you want to prevent the definition of multiple networks with the same chainId? For us, it would be useful to be able to have multiple networks with the same chainId, though.