Skip to content

Commit

Permalink
feat: nownodes optimism (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight authored Jul 22, 2024
1 parent b792d5f commit e7c907d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
42 changes: 35 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1612,4 +1624,20 @@ workflows:
pulumi-command: up -f --yes
requires:
- approve ethereum fallback
<<: [*ethereum-fallback, *only-main]
<<: [*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]
2 changes: 2 additions & 0 deletions node/coinstacks/optimism/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -92,6 +93,7 @@ const transactionHandler: TransactionHandler<BlockbookTx, evm.Tx> = 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),
})
Expand Down
8 changes: 6 additions & 2 deletions node/coinstacks/optimism/api/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -31,8 +33,9 @@ export const logger = new Logger({
const CHAIN_ID: Record<string, number> = { 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({
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions node/coinstacks/optimism/sample.env
Original file line number Diff line number Diff line change
@@ -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
RPC_URL=https://optimism.nownodes.io

0 comments on commit e7c907d

Please sign in to comment.