Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config refactor avoiding circular dep issues #485

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/middleware/sessionMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function sessionMiddleware(req: Request, res: Response, next: NextF

Sentry.setUser({ id: accountAddress?.toLowerCase() });

if (chainId && networkContext.isValidChainId(chainId)) {
if (chainId && networkContext.isValidChainId(chainId as any)) {
initRequestScopedContext();
setRequestScopedContextValue('chainId', chainId);

Expand Down
2 changes: 1 addition & 1 deletion modules/content/content.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { networkContext } from '../network/network-context.service';
const contentResolvers: Resolvers = {
Query: {
contentGetNewsItems: async () => {
return await networkContext.config.contentService.getNewsItems();
return await networkContext.services.contentService.getNewsItems();
},
},
};
Expand Down
148 changes: 4 additions & 144 deletions modules/network/arbitrum.ts → modules/network/arbitrum/data.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import { BigNumber, ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig, NetworkData } from './network-config-types';
import { tokenService } from '../token/token.service';
import { PhantomStableAprService } from '../pool/lib/apr-data-sources/phantom-stable-apr.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/boosted-pool-apr.service';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/swap-fee-apr.service';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { GaugeStakingService } from '../pool/lib/staking/gauge-staking.service';
import { BptPriceHandlerService } from '../token/lib/token-price-handlers/bpt-price-handler.service';
import { LinearWrappedTokenPriceHandlerService } from '../token/lib/token-price-handlers/linear-wrapped-token-price-handler.service';
import { SwapsPriceHandlerService } from '../token/lib/token-price-handlers/swaps-price-handler.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../worker/intervals';
import { GithubContentService } from '../content/github-content.service';
import { gaugeSubgraphService } from '../subgraphs/gauge-subgraph/gauge-subgraph.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { coingeckoService } from '../coingecko/coingecko.service';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { env } from '../../app/env';
import { BigNumber } from '@ethersproject/bignumber';
import { env } from '../../../app/env';
import { DeploymentEnv, NetworkData } from "../network-config-types";

const arbitrumNetworkData: NetworkData = {
export const arbitrumNetworkData: NetworkData = {
chain: {
slug: 'arbitrum',
id: 42161,
Expand Down Expand Up @@ -221,127 +205,3 @@ const arbitrumNetworkData: NetworkData = {
},
},
};

export const arbitrumNetworkConfig: NetworkConfig = {
data: arbitrumNetworkData,
contentService: new GithubContentService(),
provider: new ethers.providers.JsonRpcProvider({ url: arbitrumNetworkData.rpcUrl, timeout: 60000 }),
poolAprServices: [
new IbTokensAprService(
arbitrumNetworkData.ibAprConfig,
arbitrumNetworkData.chain.prismaId,
arbitrumNetworkData.balancer.yieldProtocolFeePercentage,
arbitrumNetworkData.balancer.swapProtocolFeePercentage,
),
new PhantomStableAprService(
arbitrumNetworkData.chain.prismaId,
arbitrumNetworkData.balancer.yieldProtocolFeePercentage,
),
new BoostedPoolAprService(),
new SwapFeeAprService(arbitrumNetworkData.balancer.swapProtocolFeePercentage),
new GaugeAprService(tokenService, [arbitrumNetworkData.bal!.address]),
],
poolStakingServices: [new GaugeStakingService(gaugeSubgraphService, arbitrumNetworkData.bal!.address)],
tokenPriceHandlers: [
new CoingeckoPriceHandlerService(coingeckoService),
new BptPriceHandlerService(),
new LinearWrappedTokenPriceHandlerService(),
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
/*
For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3.
This is needed because the minimum alarm period is 1 minute and we want the alarm to trigger already after 1 minute instead of 3.

For every 1 days jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3.
This is needed because the maximum alarm evaluation period is 1 day (period * evaluationPeriod).
*/
workerJobs: [
{
name: 'update-token-prices',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-liquidity-for-inactive-pools',
interval: every(1, 'days'),
alarmEvaluationPeriod: 1,
alarmDatapointsToAlarm: 1,
},
{
name: 'update-liquidity-for-active-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(8, 'minutes') : every(4, 'minutes'),
},
{
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(7, 'minutes') : every(5, 'minutes'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(9, 'minutes') : every(5, 'minutes'),
},
{
name: 'sync-new-pools-from-subgraph',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(12, 'minutes') : every(8, 'minutes'),
},
{
name: 'sync-tokens-from-pool-tokens',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(7, 'minutes'),
},
{
name: 'update-liquidity-24h-ago-for-all-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(15, 'minutes') : every(8, 'minutes'),
},
{
name: 'cache-average-block-time',
interval: every(1, 'hours'),
},
{
name: 'sync-staking-for-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(15, 'minutes') : every(10, 'minutes'),
},
{
name: 'sync-latest-snapshots-for-all-pools',
interval: every(90, 'minutes'),
},
{
name: 'update-lifetime-values-for-all-pools',
interval: every(45, 'minutes'),
},
{
name: 'sync-changed-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(2, 'minutes') : every(1, 'minutes'),
alarmEvaluationPeriod: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? 3 : 1,
alarmDatapointsToAlarm: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? 3 : 1,
},
{
name: 'user-sync-wallet-balances-for-all-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(29, 'minutes') : every(9, 'minutes'),
},
{
name: 'user-sync-staked-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(31, 'minutes') : every(11, 'minutes'),
},
{
name: 'sync-coingecko-coinids',
interval: every(2, 'hours'),
},
{
name: 'purge-old-tokenprices',
interval: every(1, 'days'),
alarmEvaluationPeriod: 1,
alarmDatapointsToAlarm: 1,
},
{
name: 'update-fee-volume-yield-all-pools',
interval: every(75, 'minutes'),
},
{
name: 'sync-vebal-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(20, 'minutes') : every(14, 'minutes'),
},
{
name: 'sync-vebal-totalSupply',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(20, 'minutes') : every(16, 'minutes'),
},
],
};
9 changes: 9 additions & 0 deletions modules/network/arbitrum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { arbitrumNetworkData as data } from './data';
import { arbitrumWorkerJobs as workerJobs } from './workers';

export class ArbitrumNetworkConfig {
franzns marked this conversation as resolved.
Show resolved Hide resolved
static data = data;
static workerJobs = workerJobs;
static provider = new JsonRpcProvider({ url: data.rpcUrl, timeout: 60000 })
};
43 changes: 43 additions & 0 deletions modules/network/arbitrum/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { tokenService } from '../../token/token.service';
import { PhantomStableAprService } from '../../pool/lib/apr-data-sources/phantom-stable-apr.service';
import { BoostedPoolAprService } from '../../pool/lib/apr-data-sources/boosted-pool-apr.service';
import { SwapFeeAprService } from '../../pool/lib/apr-data-sources/swap-fee-apr.service';
import { GaugeAprService } from '../../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { GaugeStakingService } from '../../pool/lib/staking/gauge-staking.service';
import { BptPriceHandlerService } from '../../token/lib/token-price-handlers/bpt-price-handler.service';
import { LinearWrappedTokenPriceHandlerService } from '../../token/lib/token-price-handlers/linear-wrapped-token-price-handler.service';
import { SwapsPriceHandlerService } from '../../token/lib/token-price-handlers/swaps-price-handler.service';
import { UserSyncGaugeBalanceService } from '../../user/lib/user-sync-gauge-balance.service';
import { GithubContentService } from '../../content/github-content.service';
import { gaugeSubgraphService } from '../../subgraphs/gauge-subgraph/gauge-subgraph.service';
import { CoingeckoPriceHandlerService } from '../../token/lib/token-price-handlers/coingecko-price-handler.service';
import { coingeckoService } from '../../coingecko/coingecko.service';
import { IbTokensAprService } from '../../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { arbitrumNetworkData as data } from './data';

export const arbitrumCreateServices = () => ({
franzns marked this conversation as resolved.
Show resolved Hide resolved
contentService: new GithubContentService(),
poolAprServices: [
new IbTokensAprService(
data.ibAprConfig,
data.chain.prismaId,
data.balancer.yieldProtocolFeePercentage,
data.balancer.swapProtocolFeePercentage,
),
new PhantomStableAprService(
data.chain.prismaId,
data.balancer.yieldProtocolFeePercentage,
),
new BoostedPoolAprService(),
new SwapFeeAprService(data.balancer.swapProtocolFeePercentage),
new GaugeAprService(tokenService, [data.bal!.address]),
],
poolStakingServices: [new GaugeStakingService(gaugeSubgraphService, data.bal!.address)],
tokenPriceHandlers: [
new CoingeckoPriceHandlerService(coingeckoService),
new BptPriceHandlerService(),
new LinearWrappedTokenPriceHandlerService(),
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
});
99 changes: 99 additions & 0 deletions modules/network/arbitrum/workers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { every } from '../../../worker/intervals';
import { env } from '../../../app/env';
import { DeploymentEnv, WorkerJob } from '../network-config-types';

/*
For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3.
This is needed because the minimum alarm period is 1 minute and we want the alarm to trigger already after 1 minute instead of 3.

For every 1 days jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3.
This is needed because the maximum alarm evaluation period is 1 day (period * evaluationPeriod).
*/
export const arbitrumWorkerJobs: WorkerJob[] = [
{
name: 'update-token-prices',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-liquidity-for-inactive-pools',
interval: every(1, 'days'),
alarmEvaluationPeriod: 1,
alarmDatapointsToAlarm: 1,
},
{
name: 'update-liquidity-for-active-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(8, 'minutes') : every(4, 'minutes'),
},
{
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(7, 'minutes') : every(5, 'minutes'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(9, 'minutes') : every(5, 'minutes'),
},
{
name: 'sync-new-pools-from-subgraph',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(12, 'minutes') : every(8, 'minutes'),
},
{
name: 'sync-tokens-from-pool-tokens',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(7, 'minutes'),
},
{
name: 'update-liquidity-24h-ago-for-all-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(15, 'minutes') : every(8, 'minutes'),
},
{
name: 'cache-average-block-time',
interval: every(1, 'hours'),
},
{
name: 'sync-staking-for-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(15, 'minutes') : every(10, 'minutes'),
},
{
name: 'sync-latest-snapshots-for-all-pools',
interval: every(90, 'minutes'),
},
{
name: 'update-lifetime-values-for-all-pools',
interval: every(45, 'minutes'),
},
{
name: 'sync-changed-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(2, 'minutes') : every(1, 'minutes'),
alarmEvaluationPeriod: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? 3 : 1,
alarmDatapointsToAlarm: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? 3 : 1,
},
{
name: 'user-sync-wallet-balances-for-all-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(29, 'minutes') : every(9, 'minutes'),
},
{
name: 'user-sync-staked-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(31, 'minutes') : every(11, 'minutes'),
},
{
name: 'sync-coingecko-coinids',
interval: every(2, 'hours'),
},
{
name: 'purge-old-tokenprices',
interval: every(1, 'days'),
alarmEvaluationPeriod: 1,
alarmDatapointsToAlarm: 1,
},
{
name: 'update-fee-volume-yield-all-pools',
interval: every(75, 'minutes'),
},
{
name: 'sync-vebal-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(20, 'minutes') : every(14, 'minutes'),
},
{
name: 'sync-vebal-totalSupply',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(20, 'minutes') : every(16, 'minutes'),
},
];
Loading