Skip to content

Commit

Permalink
hardcode chain id to provide
Browse files Browse the repository at this point in the history
  • Loading branch information
unicorn-here committed Jul 7, 2023
1 parent 82b8592 commit 85a1296
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
1 change: 0 additions & 1 deletion bin/stacks/routing-api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export class RoutingAPIStack extends cdk.Stack {
routingLambdaName: routingLambda.functionName,
poolCacheLambdaNameArray,
ipfsPoolCacheLambdaName: ipfsPoolCachingLambda ? ipfsPoolCachingLambda.functionName : undefined,
jsonRpcProviders: jsonRpcProviders,
})

const lambdaIntegration = new aws_apigateway.LambdaIntegration(routingLambdaAlias)
Expand Down
6 changes: 2 additions & 4 deletions bin/stacks/routing-dashboard-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export interface RoutingDashboardProps extends cdk.NestedStackProps {
routingLambdaName: string
poolCacheLambdaNameArray: string[]
ipfsPoolCacheLambdaName?: string
jsonRpcProviders: { [chainName: string]: string }
}

export class RoutingDashboardStack extends cdk.NestedStack {
constructor(scope: Construct, name: string, props: RoutingDashboardProps) {
super(scope, name, props)

const { apiName, routingLambdaName, poolCacheLambdaNameArray, ipfsPoolCacheLambdaName, jsonRpcProviders } = props
const { apiName, routingLambdaName, poolCacheLambdaNameArray, ipfsPoolCacheLambdaName } = props
const region = cdk.Stack.of(this).region

const TESTNETS = [
Expand Down Expand Up @@ -442,8 +441,7 @@ export class RoutingDashboardStack extends cdk.NestedStack {
const rpcProvidersWidgetsForRoutingDashboard = new RpcProvidersWidgetsFactory(
NAMESPACE,
region,
MAINNETS.concat(TESTNETS),
jsonRpcProviders
MAINNETS.concat(TESTNETS)
).generateWidgets()

new aws_cloudwatch.CfnDashboard(this, 'RoutingAPIDashboard', {
Expand Down
37 changes: 25 additions & 12 deletions lib/dashboards/rpc-providers-widgets-factory.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
import { WidgetsFactory } from './core/widgets-factory'
import { Widget } from './core/model/widget'
import { ChainId } from '@uniswap/sdk-core'
import { deriveProviderName } from '../handlers/evm/provider/ProviderName'
import _ from 'lodash'
import { ID_TO_NETWORK_NAME } from '@uniswap/smart-order-router/build/main/util/chains'
import { ProviderName } from '../handlers/evm/provider/ProviderName'

const ID_TO_PROVIDER = (id: ChainId): string => {
switch (id) {
case ChainId.MAINNET:
case ChainId.OPTIMISM:
case ChainId.SEPOLIA:
case ChainId.POLYGON:
case ChainId.POLYGON_MUMBAI:
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
case ChainId.AVALANCHE:
case ChainId.GOERLI:
return ProviderName.INFURA
case ChainId.CELO:
case ChainId.BNB:
return ProviderName.QUIKNODE
case ChainId.CELO_ALFAJORES:
return ProviderName.FORNO
default:
return ProviderName.UNKNOWN
}
}

export class RpcProvidersWidgetsFactory implements WidgetsFactory {
region: string
namespace: string
chains: Array<ChainId>
jsonRpcProviders: { [chainName: string]: string }

constructor(
namespace: string,
region: string,
chains: Array<ChainId>,
jsonRpcProviders: { [chainName: string]: string }
) {
constructor(namespace: string, region: string, chains: Array<ChainId>) {
this.namespace = namespace
this.region = region
this.chains = chains
this.jsonRpcProviders = jsonRpcProviders
}

generateWidgets(): Widget[] {
Expand All @@ -38,9 +53,7 @@ export class RpcProvidersWidgetsFactory implements WidgetsFactory {
const metrics = _.flatMap(chainsWithIndices, (chainIdAndIndex) => {
const chainId = chainIdAndIndex.chainId
const index = chainIdAndIndex.index
const url = this.jsonRpcProviders[`WEB3_RPC_${chainId.toString()}`]!
if (url === undefined) return []
const providerName = deriveProviderName(url)
const providerName = ID_TO_PROVIDER(chainId)

const metric1 = `m${index * 2 + 1}`
const metric2 = `m${index * 2 + 2}`
Expand Down

0 comments on commit 85a1296

Please sign in to comment.