From 6b91e152975875d51a3376754b5cbbfa10f6c0ea Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 27 Nov 2024 15:18:38 +0700 Subject: [PATCH] feat: dynamically load supported RPCs --- bin/app.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/app.ts b/bin/app.ts index 4af8448..3a4b726 100644 --- a/bin/app.ts +++ b/bin/app.ts @@ -11,6 +11,7 @@ import dotenv from 'dotenv'; import { STAGE } from '../lib/util/stage'; import { SERVICE_NAME } from './constants'; import { APIStack } from './stacks/api-stack'; +import { ChainId, supportedChains } from '../lib/util/chains'; dotenv.config(); @@ -118,17 +119,26 @@ export class APIPipeline extends Stack { 'arn:aws:secretsmanager:us-east-2:644039819003:secret:prod/param-api/rpc-urls-HJyniu', }); - // Beta us-east-2 + const jsonRpcProviders = {} as {[chainKey: string]: string}; + supportedChains.forEach( + (chainId: ChainId) => { + const mapKey = `RPC_${chainId}`; + jsonRpcProviders[mapKey] = rpcUrls + .secretValueFromJson(mapKey) + .toString(); + } + ); + // Beta us-east-2 const betaUsEast2Stage = new APIStage(this, 'beta-us-east-2', { env: { account: '801328487475', region: 'us-east-2' }, provisionedConcurrency: 2, internalApiKey: internalApiKey.secretValue.toString(), stage: STAGE.BETA, envVars: { + ...jsonRpcProviders, RFQ_WEBHOOK_CONFIG: rfqWebhookConfig.secretValue.toString(), ORDER_SERVICE_URL: urlSecrets.secretValueFromJson('GOUDA_SERVICE_BETA').toString(), - RPC_42161: rpcUrls.secretValueFromJson('RPC_42161').toString(), FILL_LOG_SENDER_ACCOUNT: '321377678687', ORDER_LOG_SENDER_ACCOUNT: '321377678687', URA_ACCOUNT: '665191769009', @@ -147,9 +157,9 @@ export class APIPipeline extends Stack { internalApiKey: internalApiKey.secretValue.toString(), chatbotSNSArn: 'arn:aws:sns:us-east-2:644039819003:SlackChatbotTopic', envVars: { + ...jsonRpcProviders, RFQ_WEBHOOK_CONFIG: rfqWebhookConfig.secretValue.toString(), ORDER_SERVICE_URL: urlSecrets.secretValueFromJson('GOUDA_SERVICE_PROD').toString(), - RPC_42161: rpcUrls.secretValueFromJson('RPC_42161').toString(), FILL_LOG_SENDER_ACCOUNT: '316116520258', ORDER_LOG_SENDER_ACCOUNT: '316116520258', URA_ACCOUNT: '652077092967', @@ -251,7 +261,13 @@ envVars['URA_ACCOUNT'] = process.env['URA_ACCOUNT'] || ''; envVars['BOT_ACCOUNT'] = process.env['BOT_ACCOUNT'] || ''; envVars['UNISWAP_API'] = process.env['UNISWAP_API'] || ''; envVars['ORDER_SERVICE_URL'] = process.env['ORDER_SERVICE_URL'] || ''; -envVars['RPC_42161'] = process.env['RPC_42161'] || ''; +const jsonRpcProviders = {} as {[chainKey: string]: string}; +supportedChains.forEach( + (chainId: ChainId) => { + const mapKey = `RPC_${chainId}`; + jsonRpcProviders[mapKey] = process.env[mapKey] || ''; + } +); new APIStack(app, `${SERVICE_NAME}Stack`, { env: { @@ -263,7 +279,10 @@ new APIStack(app, `${SERVICE_NAME}Stack`, { throttlingOverride: process.env.THROTTLE_PER_FIVE_MINS, chatbotSNSArn: process.env.CHATBOT_SNS_ARN, stage: STAGE.LOCAL, - envVars, + envVars: { + ...envVars, + ...jsonRpcProviders, + }, }); new APIPipeline(app, `${SERVICE_NAME}PipelineStack`, {