Skip to content

Commit

Permalink
separating services and config data
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Oct 18, 2023
1 parent b463feb commit bab6d62
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 334 deletions.
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
35 changes: 1 addition & 34 deletions modules/network/arbitrum/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { arbitrumNetworkData as data } from './data';
import { arbitrumWorkerJobs as workerJobs } from './workers';
import { createArbitrumServices as createServices } from './services';

let services: ReturnType<typeof createServices>;
export * from './services';

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;
}

};
34 changes: 1 addition & 33 deletions modules/network/avalanche/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { avalancheNetworkData as data } from './data';
import { avalancheWorkerJobs as workerJobs } from './workers';
import { createAvalancheServices as createServices } from './services';

let services: ReturnType<typeof createServices>;
export * from './services';

export class AvalancheNetworkConfig {
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;
}
};
34 changes: 1 addition & 33 deletions modules/network/base/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { baseNetworkData as data } from './data';
import { baseWorkerJobs as workerJobs } from './workers';
import { createBaseServices as createServices } from './services';

let services: ReturnType<typeof createServices>;
export * from './services';

export class BaseNetworkConfig {
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;
}
};
34 changes: 1 addition & 33 deletions modules/network/fantom/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { fantomNetworkData as data } from './data';
import { fantomWorkerJobs as workerJobs } from './workers';
import { createFantomServices as createServices } from './services';

let services: ReturnType<typeof createServices>;
export * from './services';

export class FantomNetworkConfig {
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;
}
};
34 changes: 1 addition & 33 deletions modules/network/gnosis/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { gnosisNetworkData as data } from './data';
import { gnosisWorkerJobs as workerJobs } from './workers';
import { createGnosisServices as createServices } from './services';

let services: ReturnType<typeof createServices>;
export * from './services';

export class GnosisNetworkConfig {
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;
}
};
33 changes: 0 additions & 33 deletions modules/network/mainnet/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { mainnetNetworkData as data } from './data';
import { mainnetWorkerJobs as workerJobs } from './workers';
import { createMainnetServices as createServices } from './services';

let services: ReturnType<typeof createServices>;

export class MainnetNetworkConfig {
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;
}
};
8 changes: 6 additions & 2 deletions modules/network/network-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import { AaveAprConfig, IbAprConfig } from './apr-config-types';

export interface NetworkConfig {
data: NetworkData;
provider: BaseProvider;
workerJobs: WorkerJob[];
}

export interface NetworkServices {
contentService: ContentService;
poolStakingServices: PoolStakingService[];
poolAprServices: PoolAprService[];
userStakedBalanceServices: UserStakedBalanceService[];
tokenPriceHandlers: TokenPriceHandler[];
provider: BaseProvider;
workerJobs: WorkerJob[];
}

export interface WorkerJob {
name: string;
interval: number;
Expand Down
9 changes: 6 additions & 3 deletions modules/network/network-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FantomNetworkConfig } from './fantom';
import { OptimismNetworkConfig } from './optimism';
import { NetworkConfig } from './network-config-types';
import type { NetworkConfig } from './network-config-types';
import { MainnetNetworkConfig } from './mainnet';
import { ArbitrumNetworkConfig } from './arbitrum';
import { PolygonNetworkConfig } from './polygon';
Expand All @@ -21,5 +21,8 @@ export const AllNetworkConfigs: { [chainId: string]: NetworkConfig } = {
'8453': BaseNetworkConfig,
};

export const BalancerChainIds = ['1', '137', '42161', '100', '1101', '43114', '8453'];
export const BeethovenChainIds = ['250', '10'];
export const BalancerChainIds = ['1', '137', '42161', '100', '1101', '43114', '8453'] as const;
export const BeethovenChainIds = ['250', '10'] as const;
const allChains = [...BalancerChainIds, ...BeethovenChainIds] as const;

export type ChainIDs = typeof allChains[number];
Loading

0 comments on commit bab6d62

Please sign in to comment.