rain_metadata/subgraph/
mod.rs

1use crate::error::Error;
2
3/// All known subgraph endpoints
4#[derive(Debug, Clone)]
5pub struct KnownSubgraphs;
6
7impl KnownSubgraphs {
8    /// Rain known subgraphs on ethereum mainnet
9    pub const ETHEREUM: [&'static str; 3] = [
10        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-ethereum", // legacy endpoint
11        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-np-eth", // np endpoint
12        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-npe2-eth", // npe2 endpoint
13    ];
14
15    /// Rain known subgraphs on polygon mainnet
16    pub const POLYGON: [&'static str; 3] = [
17        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-polygon", // legacy endpoint
18        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-np-matic", // np endpoint
19        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-npe2-mati", // npe2 endpoint
20    ];
21
22    /// Rain known subgraphs on mumbai (polygon testnet)
23    pub const MUMBAI: [&'static str; 3] = [
24        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry", // legacy endpoint
25        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-np", // np endpoint
26        "https://api.thegraph.com/subgraphs/name/rainlanguage/interpreter-registry-npe2", // npe2 endpoint
27    ];
28
29    /// Rain NPE2 subgraphs of all supported networks
30    pub const NPE2: [&'static str; 3] = [Self::ETHEREUM[2], Self::POLYGON[2], Self::MUMBAI[2]];
31
32    /// Rain NativeParser subgraphs of all supported networks
33    pub const NP: [&'static str; 3] = [Self::ETHEREUM[1], Self::POLYGON[1], Self::MUMBAI[1]];
34
35    /// Rain legacy(non NativeParser) subgraphs of all supported networks
36    pub const LEGACY: [&'static str; 3] = [Self::ETHEREUM[0], Self::POLYGON[0], Self::MUMBAI[0]];
37
38    /// All Rain known subgraph endpoint URLs
39    pub const ALL: [&'static str; 9] = [
40        Self::ETHEREUM[0],
41        Self::ETHEREUM[1],
42        Self::ETHEREUM[2],
43        Self::POLYGON[0],
44        Self::POLYGON[1],
45        Self::POLYGON[2],
46        Self::MUMBAI[0],
47        Self::MUMBAI[1],
48        Self::MUMBAI[2],
49    ];
50
51    /// get the subgraph endpoint from a chain id
52    pub fn of_chain(chain_id: u64) -> Result<[&'static str; 3], Error> {
53        match chain_id {
54            1 => Ok(Self::ETHEREUM),
55            137 => Ok(Self::POLYGON),
56            80001 => Ok(Self::MUMBAI),
57            _ => Err(Error::UnsupportedNetwork),
58        }
59    }
60}