Skip to content

Commit

Permalink
config refactor avoiding circular dep issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Oct 17, 2023
1 parent 725d93f commit 5a9d06c
Show file tree
Hide file tree
Showing 39 changed files with 2,050 additions and 1,657 deletions.
140 changes: 4 additions & 136 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 data: NetworkData = {
chain: {
slug: 'arbitrum',
id: 42161,
Expand Down Expand Up @@ -219,119 +203,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),
new PhantomStableAprService(),
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(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
},
{
name: 'sync-new-pools-from-subgraph',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'sync-tokens-from-pool-tokens',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
{
name: 'update-liquidity-24h-ago-for-all-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
{
name: 'cache-average-block-time',
interval: every(1, 'hours'),
},
{
name: 'sync-staking-for-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
{
name: 'sync-latest-snapshots-for-all-pools',
interval: every(1, 'hours'),
},
{
name: 'update-lifetime-values-for-all-pools',
interval: every(30, 'minutes'),
},
{
name: 'sync-changed-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(2, 'minutes') : every(20, 'seconds'),
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(30, 'minutes') : every(10, 'minutes'),
},
{
name: 'user-sync-staked-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(30, 'minutes') : every(10, '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(1, 'hours'),
},
{
name: 'sync-vebal-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(9, 'minutes') : every(3, 'minutes'),
},
{
name: 'sync-vebal-totalSupply',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
],
};
43 changes: 43 additions & 0 deletions modules/network/arbitrum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { data } from './data';
import { workerJobs } from './workers';
import { createServices } from './services';

let services: ReturnType<typeof createServices>;

export class arbitrumNetworkConfig {
static data = data;
static workerJobs = workerJobs;
static provider = new JsonRpcProvider({ url: data.rpcUrl, timeout: 60000 })

static get contentService() {
if (!services) services = createServices();

return services.contentService;
}

static get poolAprServices() {
if (!services) services = createServices();

return services.poolAprServices;
}

static get poolStakingServices() {
if (!services) services = createServices();

return services.poolStakingServices;
}

static get tokenPriceHandlers() {
if (!services) services = createServices();

return services.tokenPriceHandlers;
}

static get userStakedBalanceServices() {
if (!services) services = createServices();

return services.userStakedBalanceServices;
}

};
35 changes: 35 additions & 0 deletions modules/network/arbitrum/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 { data } from './data';

export const createServices = () => ({
contentService: new GithubContentService(),
poolAprServices: [
new IbTokensAprService(data.ibAprConfig),
new PhantomStableAprService(),
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 } 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 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(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
},
{
name: 'sync-new-pools-from-subgraph',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'sync-tokens-from-pool-tokens',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
{
name: 'update-liquidity-24h-ago-for-all-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
{
name: 'cache-average-block-time',
interval: every(1, 'hours'),
},
{
name: 'sync-staking-for-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
{
name: 'sync-latest-snapshots-for-all-pools',
interval: every(1, 'hours'),
},
{
name: 'update-lifetime-values-for-all-pools',
interval: every(30, 'minutes'),
},
{
name: 'sync-changed-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(2, 'minutes') : every(20, 'seconds'),
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(30, 'minutes') : every(10, 'minutes'),
},
{
name: 'user-sync-staked-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(30, 'minutes') : every(10, '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(1, 'hours'),
},
{
name: 'sync-vebal-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(9, 'minutes') : every(3, 'minutes'),
},
{
name: 'sync-vebal-totalSupply',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(5, 'minutes'),
},
];
Loading

0 comments on commit 5a9d06c

Please sign in to comment.