Skip to content

Commit

Permalink
feat(rest-api): Primary RPCs get omnirpc (#3294)
Browse files Browse the repository at this point in the history
* Primary RPCs get omnirpc
  • Loading branch information
abtestingalpha authored Oct 15, 2024
1 parent ed60f17 commit 31a3ce9
Show file tree
Hide file tree
Showing 6 changed files with 689 additions and 58 deletions.
1 change: 1 addition & 0 deletions packages/rest-api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OMNIRPC_BASE_URL=
1 change: 1 addition & 0 deletions packages/rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@ethersproject/units": "5.7.0",
"@synapsecns/sdk-router": "^0.11.4",
"bignumber": "^1.1.0",
"dotenv": "^16.4.5",
"ethers": "5.7.2",
"express": "^4.18.2",
"express-validator": "^7.2.0",
Expand Down
89 changes: 45 additions & 44 deletions packages/rest-api/src/constants/chains.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import _ from 'lodash'

import { Chain } from '../types'
import { getOmniRpcUrl } from '../utils/getOmniRpcUrl'

export const ETHEREUM: Chain = {
id: 1,
name: 'Ethereum',
rpcUrls: {
primary: 'https://ethereum.blockpi.network/v1/rpc/public',
fallback: 'https://rpc.ankr.com/eth',
primary: getOmniRpcUrl(1),
fallback: 'https://ethereum.blockpi.network/v1/rpc/public',
},
explorerUrl: 'https://etherscan.com',
explorerName: 'Etherscan',
Expand All @@ -27,8 +28,8 @@ export const ARBITRUM: Chain = {
id: 42161,
name: 'Arbitrum',
rpcUrls: {
primary: 'https://arbitrum.blockpi.network/v1/rpc/public',
fallback: 'https://arb1.arbitrum.io/rpc',
primary: getOmniRpcUrl(42161),
fallback: 'https://arbitrum.blockpi.network/v1/rpc/public',
},
explorerUrl: 'https://arbiscan.io',
explorerName: 'Arbiscan',
Expand All @@ -48,8 +49,8 @@ export const BNBCHAIN: Chain = {
id: 56,
name: 'BNB Chain',
rpcUrls: {
primary: 'https://bsc-dataseed1.ninicoin.io/',
fallback: 'https://bsc-dataseed2.ninicoin.io',
primary: getOmniRpcUrl(56),
fallback: 'https://bsc-dataseed1.ninicoin.io/',
},
explorerUrl: 'https://bscscan.com',
explorerName: 'BscScan',
Expand All @@ -69,8 +70,8 @@ export const AVALANCHE: Chain = {
id: 43114,
name: 'Avalanche',
rpcUrls: {
primary: 'https://api.avax.network/ext/bc/C/rpc',
fallback: 'https://1rpc.io/avax/c',
primary: getOmniRpcUrl(43114),
fallback: 'https://api.avax.network/ext/bc/C/rpc',
},
explorerUrl: 'https://snowtrace.io/',
explorerName: 'Snowtrace',
Expand All @@ -90,8 +91,8 @@ export const CANTO: Chain = {
id: 7700,
name: 'Canto',
rpcUrls: {
primary: 'https://mainnode.plexnode.org:8545',
fallback: 'https://canto.slingshot.finance',
primary: getOmniRpcUrl(7700),
fallback: 'https://mainnode.plexnode.org:8545',
},
explorerUrl: 'https://tuber.build/',
explorerName: 'Canto Explorer',
Expand All @@ -111,8 +112,8 @@ export const OPTIMISM: Chain = {
id: 10,
name: 'Optimism',
rpcUrls: {
primary: 'https://mainnet.optimism.io',
fallback: 'https://1rpc.io/op',
primary: getOmniRpcUrl(10),
fallback: 'https://mainnet.optimism.io',
},
explorerUrl: 'https://optimistic.etherscan.io',
explorerName: 'Optimism Explorer',
Expand All @@ -132,8 +133,8 @@ export const POLYGON: Chain = {
id: 137,
name: 'Polygon',
rpcUrls: {
primary: 'https://polygon-bor.publicnode.com',
fallback: 'https://polygon.llamarpc.com',
primary: getOmniRpcUrl(137),
fallback: 'https://polygon-bor.publicnode.com',
},
explorerUrl: 'https://polygonscan.com',
explorerName: 'PolygonScan',
Expand All @@ -153,8 +154,8 @@ export const DFK: Chain = {
id: 53935,
name: 'DFK Chain',
rpcUrls: {
primary: 'https://subnets.avax.network/defi-kingdoms/dfk-chain/rpc',
fallback: 'https://dfkchain.api.onfinality.io/public',
primary: getOmniRpcUrl(53935),
fallback: 'https://subnets.avax.network/defi-kingdoms/dfk-chain/rpc',
},
explorerUrl: 'https://subnets.avax.network/defi-kingdoms',
explorerName: 'DFK Subnet Explorer',
Expand All @@ -174,8 +175,8 @@ export const KLAYTN: Chain = {
id: 8217,
name: 'Klaytn',
rpcUrls: {
primary: 'https://klaytn.blockpi.network/v1/rpc/public',
fallback: 'https://klaytn.api.onfinality.io/public',
primary: getOmniRpcUrl(8217),
fallback: 'https://klaytn.blockpi.network/v1/rpc/public',
},
explorerUrl: 'https://scope.klaytn.com',
explorerName: 'Klaytn Explorer',
Expand All @@ -195,8 +196,8 @@ export const FANTOM: Chain = {
id: 250,
name: 'Fantom',
rpcUrls: {
primary: 'https://rpc.ftm.tools',
fallback: 'https://fantom-rpc.gateway.pokt.network/',
primary: getOmniRpcUrl(250),
fallback: 'https://rpc.ftm.tools',
},
explorerUrl: 'https://ftmscan.com',
explorerName: 'FTMScan',
Expand All @@ -216,8 +217,8 @@ export const CRONOS: Chain = {
id: 25,
name: 'Cronos',
rpcUrls: {
primary: 'https://evm-cronos.crypto.org',
fallback: 'https://cronos.blockpi.network/v1/rpc/public',
primary: getOmniRpcUrl(25),
fallback: 'https://evm-cronos.crypto.org',
},
explorerUrl: 'https://cronoscan.com',
explorerName: 'CronoScan',
Expand All @@ -237,8 +238,8 @@ export const BOBA: Chain = {
id: 288,
name: 'Boba Chain',
rpcUrls: {
primary: 'https://mainnet.boba.network',
fallback: 'https://replica.boba.network',
primary: getOmniRpcUrl(288),
fallback: 'https://mainnet.boba.network',
},
explorerUrl: 'https://bobascan.com',
explorerName: 'Boba Explorer',
Expand All @@ -258,8 +259,8 @@ export const METIS: Chain = {
id: 1088,
name: 'Metis',
rpcUrls: {
primary: 'https://andromeda.metis.io/?owner=1088',
fallback: 'https://metis-mainnet.public.blastapi.io',
primary: getOmniRpcUrl(1088),
fallback: 'https://andromeda.metis.io/?owner=1088',
},
explorerUrl: 'https://andromeda-explorer.metis.io',
explorerName: 'Metis Explorer',
Expand All @@ -279,8 +280,8 @@ export const AURORA: Chain = {
id: 1313161554,
name: 'Aurora',
rpcUrls: {
primary: 'https://mainnet.aurora.dev',
fallback: 'https://1rpc.io/aurora',
primary: getOmniRpcUrl(1313161554),
fallback: 'https://mainnet.aurora.dev',
},
explorerUrl: 'https://explorer.mainnet.aurora.dev',
explorerName: 'Aurora Explorer',
Expand All @@ -300,8 +301,8 @@ export const HARMONY: Chain = {
id: 1666600000,
name: 'Harmony',
rpcUrls: {
primary: 'https://api.harmony.one',
fallback: 'https://api.s0.t.hmny.io',
primary: getOmniRpcUrl(1666600000),
fallback: 'https://api.harmony.one',
},
explorerUrl: 'https://explorer.harmony.one',
explorerName: 'Harmony Explorer',
Expand All @@ -321,8 +322,8 @@ export const MOONBEAM: Chain = {
id: 1284,
name: 'Moonbeam',
rpcUrls: {
primary: 'https://rpc.api.moonbeam.network',
fallback: 'https://moonbeam.public.blastapi.io',
primary: getOmniRpcUrl(1284),
fallback: 'https://rpc.api.moonbeam.network',
},
explorerUrl: 'https://moonbeam.moonscan.io',
explorerName: 'Moonbeam Explorer',
Expand All @@ -342,8 +343,8 @@ export const MOONRIVER: Chain = {
id: 1285,
name: 'Moonriver',
rpcUrls: {
primary: 'https://rpc.api.moonriver.moonbeam.network',
fallback: 'https://moonriver.public.blastapi.io',
primary: getOmniRpcUrl(1285),
fallback: 'https://rpc.api.moonriver.moonbeam.network',
},
explorerUrl: 'https://moonriver.moonscan.io',
explorerName: 'Moonriver Explorer',
Expand All @@ -363,8 +364,8 @@ export const DOGE: Chain = {
id: 2000,
name: 'Dogechain',
rpcUrls: {
primary: 'https://rpc.dogechain.dog',
fallback: 'https://rpc01-sg.dogechain.dog',
primary: getOmniRpcUrl(2000),
fallback: 'https://rpc.dogechain.dog',
},
explorerUrl: 'https://explorer.dogechain.dog',
explorerName: 'Dogechain Explorer',
Expand All @@ -384,8 +385,8 @@ export const BASE: Chain = {
id: 8453,
name: 'Base',
rpcUrls: {
primary: 'https://base.blockpi.network/v1/rpc/public',
fallback: 'https://developer-access-mainnet.base.org',
primary: getOmniRpcUrl(8453),
fallback: 'https://base.blockpi.network/v1/rpc/public',
},
explorerUrl: 'https://basescan.org',
explorerName: 'BaseScan',
Expand All @@ -405,9 +406,9 @@ export const BLAST: Chain = {
id: 81457,
name: 'Blast',
rpcUrls: {
primary:
primary: getOmniRpcUrl(81457),
fallback:
'https://lingering-indulgent-replica.blast-mainnet.quiknode.pro/6667a8f4be701cb6549b415d567bc706fb2f13a8/',
fallback: 'https://blast.blockpi.network/v1/rpc/publicChain',
},
explorerUrl: 'https://blastscan.io',
explorerName: 'Blastscan',
Expand All @@ -427,8 +428,8 @@ export const SCROLL: Chain = {
id: 534352,
name: 'Scroll',
rpcUrls: {
primary: 'https://rpc.scroll.io/',
fallback: 'https://scroll.blockpi.network/v1/rpc/public',
primary: getOmniRpcUrl(534352),
fallback: 'https://rpc.scroll.io/',
},
explorerUrl: 'https://scrollscan.com',
explorerName: 'Scrollscan',
Expand All @@ -448,8 +449,8 @@ export const LINEA: Chain = {
id: 59144,
name: 'Linea',
rpcUrls: {
primary: 'https://rpc.linea.build',
fallback: 'https://linea.blockpi.network/v1/rpc/public',
primary: getOmniRpcUrl(59144),
fallback: 'https://rpc.linea.build',
},
explorerUrl: 'https://lineascan.build',
explorerName: 'LineaScan',
Expand Down
3 changes: 2 additions & 1 deletion packages/rest-api/src/services/synapseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { SynapseSDK } from '@synapsecns/sdk-router'
import { CHAINS_ARRAY } from '../constants/chains'

const providers = CHAINS_ARRAY.map(
(chain) => new JsonRpcProvider(chain.rpcUrls.primary)
(chain) =>
new JsonRpcProvider(chain.rpcUrls.primary || chain.rpcUrls.fallback)
)
const chainIds = CHAINS_ARRAY.map((chain) => chain.id)

Expand Down
10 changes: 10 additions & 0 deletions packages/rest-api/src/utils/getOmniRpcUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as dotenv from 'dotenv'

dotenv.config()

export const getOmniRpcUrl = (chainId: number) => {
if (!process.env.OMNIRPC_BASE_URL) {
return null
}
return `${process.env.OMNIRPC_BASE_URL}/${chainId}`
}
Loading

0 comments on commit 31a3ce9

Please sign in to comment.