From e7c907d9e6e9b20683f669232ba77db3bc917876 Mon Sep 17 00:00:00 2001 From: kevin <35275952+kaladinlight@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:43:35 -0600 Subject: [PATCH] feat: nownodes optimism (#1011) --- .circleci/config.yml | 42 +++++++++++++++---- node/coinstacks/optimism/api/src/app.ts | 2 + .../coinstacks/optimism/api/src/controller.ts | 8 +++- node/coinstacks/optimism/sample.env | 8 ++-- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7d4e68b57..4993de619 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -420,9 +420,11 @@ aliases: assetName: optimism pulumi-stack: public-us-east-2 pulumi-dir: coinstacks/optimism/pulumi - rpc-url: http://optimism-svc.unchained.svc.cluster.local:8545 - indexer-url: http://optimism-svc.unchained.svc.cluster.local:8001 - indexer-ws-url: ws://optimism-svc.unchained.svc.cluster.local:8001/websocket + indexer-url: https://optimism-index.nownodes.io + indexer-ws-url: wss://optimism-index.nownodes.io/wss + indexer-api-key: $NOW_NODES_API_KEY + rpc-url: https://optimism.nownodes.io + rpc-api-key: $NOW_NODES_API_KEY api-autoscaling: true api-replicas: 2 api-max-replicas: 6 @@ -451,13 +453,23 @@ aliases: service-memory-limit-3: 8Gi service-storage-size-3: 500Gi + - &optimism-fallback + <<: *optimism + indexer-url: http://optimism-svc.unchained.svc.cluster.local:8001 + indexer-ws-url: ws://optimism-svc.unchained.svc.cluster.local:8001/websocket + indexer-api-key: "" + rpc-url: http://optimism-svc.unchained.svc.cluster.local:8545 + rpc-api-key: "" + - &optimism-dev <<: *optimism environment: dev pulumi-stack: public-dev-us-east-2 - rpc-url: http://optimism-svc.unchained-dev.svc.cluster.local:8545 - indexer-url: http://optimism-svc.unchained-dev.svc.cluster.local:8001 - indexer-ws-url: ws://optimism-svc.unchained-dev.svc.cluster.local:8001/websocket + indexer-url: https://optimism-index.nownodes.io + indexer-ws-url: wss://optimism-index.nownodes.io/wss + indexer-api-key: $NOW_NODES_API_KEY_DEV + rpc-url: https://optimism.nownodes.io + rpc-api-key: $NOW_NODES_API_KEY_DEV api-replicas: 1 api-max-replicas: 2 api-memory-limit: 500Mi @@ -1612,4 +1624,20 @@ workflows: pulumi-command: up -f --yes requires: - approve ethereum fallback - <<: [*ethereum-fallback, *only-main] \ No newline at end of file + <<: [*ethereum-fallback, *only-main] + + ####### OPTIMISM + - approve-coinstack: + name: approve optimism fallback + type: approval + requires: + - lint and test project (persist to workspace) + <<: *only-main + + - deploy-coinstack-node: + name: deploy optimism fallback + organization: TAXISTAKE + pulumi-command: up -f --yes + requires: + - approve optimism fallback + <<: [*optimism-fallback, *only-main] \ No newline at end of file diff --git a/node/coinstacks/optimism/api/src/app.ts b/node/coinstacks/optimism/api/src/app.ts index 566f40b48..65ff149f6 100644 --- a/node/coinstacks/optimism/api/src/app.ts +++ b/node/coinstacks/optimism/api/src/app.ts @@ -19,6 +19,7 @@ import { RegisterRoutes } from './routes' const PORT = process.env.PORT ?? 3000 const INDEXER_WS_URL = process.env.INDEXER_WS_URL +const INDEXER_API_KEY = process.env.INDEXER_API_KEY if (!INDEXER_WS_URL) throw new Error('INDEXER_WS_URL env var not set') @@ -92,6 +93,7 @@ const transactionHandler: TransactionHandler = async (block const registry = new Registry({ addressFormatter, blockHandler, transactionHandler }) const blockbook = new WebsocketClient(INDEXER_WS_URL, { + apiKey: INDEXER_API_KEY, blockHandler: [registry.onBlock.bind(registry), gasOracle.onBlock.bind(gasOracle)], transactionHandler: registry.onTransaction.bind(registry), }) diff --git a/node/coinstacks/optimism/api/src/controller.ts b/node/coinstacks/optimism/api/src/controller.ts index f10f76d1a..34251c393 100644 --- a/node/coinstacks/optimism/api/src/controller.ts +++ b/node/coinstacks/optimism/api/src/controller.ts @@ -14,8 +14,10 @@ import { OptimismGasEstimate, OptimismGasFees } from './models' const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY const INDEXER_URL = process.env.INDEXER_URL const INDEXER_WS_URL = process.env.INDEXER_WS_URL +const INDEXER_API_KEY = process.env.INDEXER_API_KEY const NETWORK = process.env.NETWORK const RPC_URL = process.env.RPC_URL +const RPC_API_KEY = process.env.RPC_API_KEY if (!ETHERSCAN_API_KEY) throw new Error('ETHERSCAN_API_KEY env var not set') if (!INDEXER_URL) throw new Error('INDEXER_URL env var not set') @@ -31,8 +33,9 @@ export const logger = new Logger({ const CHAIN_ID: Record = { mainnet: 10 } const GAS_PRICE_ORACLE_ADDRESS = '0x420000000000000000000000000000000000000F' -const blockbook = new Blockbook({ httpURL: INDEXER_URL, wsURL: INDEXER_WS_URL, logger }) -const provider = new ethers.providers.JsonRpcProvider(RPC_URL) +const blockbook = new Blockbook({ httpURL: INDEXER_URL, wsURL: INDEXER_WS_URL, apiKey: INDEXER_API_KEY, logger }) +const headers = RPC_API_KEY ? { 'api-key': RPC_API_KEY } : undefined +const provider = new ethers.providers.JsonRpcProvider({ url: RPC_URL, headers }) export const gasOracle = new GasOracle({ logger, provider, coinstack: 'optimism' }) export const service = new Service({ @@ -43,6 +46,7 @@ export const service = new Service({ provider, logger, rpcUrl: RPC_URL, + rpcApiKey: RPC_API_KEY, }) // assign service to be used for all instances of EVM diff --git a/node/coinstacks/optimism/sample.env b/node/coinstacks/optimism/sample.env index 1c93c6090..8607ecfbb 100644 --- a/node/coinstacks/optimism/sample.env +++ b/node/coinstacks/optimism/sample.env @@ -1,9 +1,11 @@ # SECRET ENVIRONMENT VARIABLES ETHERSCAN_API_KEY= +INDEXER_API_KEY= +RPC_API_KEY= # ENVIRONMENT VARIABLES -INDEXER_URL=https://dev-indexer.optimism.shapeshift.com -INDEXER_WS_URL=wss://dev-indexer.optimism.shapeshift.com/websocket +INDEXER_URL=https://optimism-index.nownodes.io +INDEXER_WS_URL=wss://optimism-index.nownodes.io/wss LOG_LEVEL=debug NETWORK=mainnet -RPC_URL=https://dev-daemon.optimism.shapeshift.com \ No newline at end of file +RPC_URL=https://optimism.nownodes.io \ No newline at end of file