Skip to content

Commit

Permalink
Merge pull request #547 from beethovenxfi/v3-canary
Browse files Browse the repository at this point in the history
V3 canary
  • Loading branch information
franzns authored Dec 4, 2023
2 parents f8b4f52 + 7311e8c commit 9efd857
Show file tree
Hide file tree
Showing 36 changed files with 1,609 additions and 660 deletions.
19 changes: 6 additions & 13 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { loadRestRoutesBeethoven } from './modules/beethoven/loadRestRoutes';
import { loadRestRoutesBalancer } from './modules/balancer/loadRestRoutes';
import { loadRestRoutes } from './modules/common/loadRestRoutes';
import { env } from './app/env';
import createExpressApp from 'express';
import { corsMiddleware } from './app/middleware/corsMiddleware';
Expand All @@ -12,10 +11,8 @@ import {
ApolloServerPluginLandingPageGraphQLPlayground,
ApolloServerPluginUsageReporting,
} from 'apollo-server-core';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { beethovenSchema } from './graphql_schema_generated_beethoven';
import { balancerSchema } from './graphql_schema_generated_balancer';
import { balancerResolvers, beethovenResolvers } from './app/gql/resolvers';
import { schema } from './graphql_schema_generated';
import { resolvers } from './app/gql/resolvers';
import helmet from 'helmet';
import GraphQLJSON from 'graphql-type-json';
import * as Sentry from '@sentry/node';
Expand Down Expand Up @@ -76,11 +73,7 @@ async function startServer() {
app.use(contextMiddleware);
app.use(sessionMiddleware);

if (env.PROTOCOL === 'beethoven') {
loadRestRoutesBeethoven(app);
} else if (env.PROTOCOL === 'balancer') {
loadRestRoutesBalancer(app);
}
loadRestRoutes(app);

const httpServer = http.createServer(app);

Expand All @@ -103,9 +96,9 @@ async function startServer() {
const server = new ApolloServer({
resolvers: {
JSON: GraphQLJSON,
...(env.PROTOCOL === 'beethoven' ? beethovenResolvers : balancerResolvers),
...resolvers,
},
typeDefs: env.PROTOCOL === 'beethoven' ? beethovenSchema : balancerSchema,
typeDefs: schema,
introspection: true,
plugins,
context: ({ req }) => req.context,
Expand Down
8 changes: 2 additions & 6 deletions app/gql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ import { loadFilesSync } from '@graphql-tools/load-files';
import path from 'path';
import { mergeResolvers } from '@graphql-tools/merge';

const balancerResolversArray = loadFilesSync(path.join(__dirname, '../../modules/!(beethoven)/**/*.resolvers.*'));

const beethovenResolversArray = loadFilesSync(path.join(__dirname, '../../modules/!(balancer)/**/*.resolvers.*'));

export const balancerResolvers = mergeResolvers(balancerResolversArray);
export const beethovenResolvers = mergeResolvers(beethovenResolversArray);
const resolversArray = loadFilesSync(path.join(__dirname, '../../modules/**/*.resolvers.*'));
export const resolvers = mergeResolvers(resolversArray);
24 changes: 3 additions & 21 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,13 @@ generates:
schema: ${USER_SNAPSHOT_SUBGRAPH}
plugins:
- schema-ast
graphql_schema_generated_balancer.ts:
schema:
- ./modules/**/*.gql
- '!./modules/beethoven/beets.gql'
- '!./modules/**/*.beets.gql'
plugins:
- add:
content: |
import { gql } from 'apollo-server-express';
export const balancerSchema = gql`
#\n# THIS FILE IS AUTOGENERATED — DO NOT EDIT IT\n#
- schema-ast
- add:
placement: 'append'
content: '`;'
graphql_schema_generated_beethoven.ts:
schema:
- ./modules/**/*.gql
- '!./modules/balancer/balancer.gql'
- '!./modules/**/*.balancer.gql'
graphql_schema_generated.ts:
schema: ./modules/**/*.gql
plugins:
- add:
content: |
import { gql } from 'apollo-server-express';
export const beethovenSchema = gql`
export const schema = gql`
#\n# THIS FILE IS AUTOGENERATED — DO NOT EDIT IT\n#
- schema-ast
- add:
Expand Down
5 changes: 0 additions & 5 deletions modules/balancer/loadRestRoutes.ts

This file was deleted.

12 changes: 7 additions & 5 deletions modules/coingecko/coingecko.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ interface CoinId {
that happen.
*/
const tokensPerInterval = env.COINGECKO_API_KEY ? ((env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? 10 : 5) : 3;
const requestRateLimiter = new RateLimiter({ tokensPerInterval, interval: 'minute' });
const tokensPerMinute = env.COINGECKO_API_KEY ? 10 : 3;
const requestRateLimiter = new RateLimiter({ tokensPerInterval: tokensPerMinute, interval: 'minute' });
//max 10 addresses per request because of URI size limit, pro is max 180 because of URI limit
const addressChunkSize = env.COINGECKO_API_KEY ? 180 : 20;

export class CoingeckoService {
private readonly baseUrl: string;
Expand Down Expand Up @@ -104,10 +106,10 @@ export class CoingeckoService {
* Rate limit for the CoinGecko API is 10 calls each second per IP address.
*/
public async getTokenPrices(addresses: string[]): Promise<TokenPrices> {
//max 180 addresses per request because of URI size limit
const addressesPerRequest = 180;
const addressesPerRequest = addressChunkSize;
try {
if (addresses.length / addressesPerRequest > 10) throw new Error('Too many requests for rate limit.');
// if (addresses.length / addressesPerRequest > tokensPerMinute)
// throw new Error('Too many requests for rate limit.');

const tokenDefinitions = await tokenService.getTokenDefinitions([networkContext.chain]);
const mapped = addresses.map((address) => this.getMappedTokenDetails(address, tokenDefinitions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Express } from 'express';
import { beetsGetCirculatingSupply } from '../beets/lib/beets';
import { tokenService } from '../token/token.service';

export function loadRestRoutesBeethoven(app: Express) {
export function loadRestRoutes(app: Express) {
app.use('/health', (req, res) => res.sendStatus(200));
app.use('/circulating_supply', (req, res) => {
beetsGetCirculatingSupply().then((result) => {
res.send(result);
});
});

app.use('/late-quartet', async (req, res) => {
const tokenPrices = await tokenService.getTokenPrices();
// app.use('/late-quartet', async (req, res) => {
// const tokenPrices = await tokenService.getTokenPrices();

res.send({
bptPrice: tokenService.getPriceForToken(tokenPrices, '0xf3a602d30dcb723a74a0198313a7551feaca7dac'),
});
});
// res.send({
// bptPrice: tokenService.getPriceForToken(tokenPrices, '0xf3a602d30dcb723a74a0198313a7551feaca7dac'),
// });
// });
}
Loading

0 comments on commit 9efd857

Please sign in to comment.