Skip to content

Commit

Permalink
Merge pull request #530 from beethovenxfi/v3-canary
Browse files Browse the repository at this point in the history
V3 canary
  • Loading branch information
franzns authored Nov 16, 2023
2 parents 5e6bcd4 + b54f815 commit 33b70b8
Show file tree
Hide file tree
Showing 37 changed files with 539 additions and 377 deletions.
3 changes: 2 additions & 1 deletion modules/balancer/balancer.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import moment from 'moment';
import { Resolvers } from '../../schema';

const balancerResolvers: Resolvers = {
Query: {
balancerQueryTest: async (parent, {}, context) => {
return 'test';
return `${moment().utc().valueOf()}`;
},
},
Mutation: {
Expand Down
2 changes: 1 addition & 1 deletion modules/beethoven/beets.gql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extend type Query {

userGetFbeetsBalance: GqlUserFbeetsBalance!

userGetPoolSnapshots(poolId: String!, range: GqlUserSnapshotDataRange!): [GqlUserPoolSnapshot!]!
userGetPoolSnapshots(poolId: String!, chain: GqlChain!, range: GqlUserSnapshotDataRange!): [GqlUserPoolSnapshot!]!
userGetRelicSnapshots(farmId: String!, range: GqlUserSnapshotDataRange!): [GqlUserRelicSnapshot!]!

userGetPortfolioSnapshots(days: Int!): [GqlUserPortfolioSnapshot!]!
Expand Down
3 changes: 2 additions & 1 deletion modules/beethoven/beets.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ const beetsResolvers: Resolvers = {
...balance,
};
},
userGetPoolSnapshots: async (parent, { poolId, range }, context) => {
userGetPoolSnapshots: async (parent, { poolId, chain, range }, context) => {
const accountAddress = getRequiredAccountAddress(context);

return userService.getUserBalanceSnapshotsForPool(
accountAddress.toLowerCase(),
poolId.toLowerCase(),
chain,
range,
);
},
Expand Down
33 changes: 0 additions & 33 deletions modules/content/sanity-content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ interface SanityToken {
interface SanityPoolConfig {
incentivizedPools: string[];
blacklistedPools: string[];
poolFilters: {
id: string;
title: string;
pools: string[];
}[];
}

const SANITY_TOKEN_TYPE_MAP: { [key: string]: string } = {
Expand Down Expand Up @@ -209,13 +204,11 @@ export class SanityContentService implements ContentService {
const response = await getSanityClient().fetch(`*[_type == "config" && chainId == ${networkContext.chainId}][0]{
incentivizedPools,
blacklistedPools,
poolFilters
}`);

const config: SanityPoolConfig = {
incentivizedPools: response?.incentivizedPools ?? [],
blacklistedPools: response?.blacklistedPools ?? [],
poolFilters: response?.poolFilters ?? [],
};

const categories = await prisma.prismaPoolCategory.findMany({ where: { chain: networkContext.chain } });
Expand All @@ -224,32 +217,6 @@ export class SanityContentService implements ContentService {

await this.updatePoolCategory(incentivized, config.incentivizedPools, 'INCENTIVIZED');
await this.updatePoolCategory(blacklisted, config.blacklistedPools, 'BLACK_LISTED');

await prisma.$transaction([
prisma.prismaPoolFilterMap.deleteMany({ where: { chain: networkContext.chain } }),
prisma.prismaPoolFilter.deleteMany({ where: { chain: networkContext.chain } }),
prisma.prismaPoolFilter.createMany({
data: config.poolFilters.map((item) => ({
id: item.id,
chain: networkContext.chain,
title: item.title,
})),
skipDuplicates: true,
}),
prisma.prismaPoolFilterMap.createMany({
data: config.poolFilters
.map((item) => {
return item.pools.map((poolId) => ({
id: `${item.id}-${poolId}`,
chain: networkContext.chain,
poolId,
filterId: item.id,
}));
})
.flat(),
skipDuplicates: true,
}),
]);
}

private async updatePoolCategory(currentPoolIds: string[], newPoolIds: string[], category: PrismaPoolCategoryType) {
Expand Down
54 changes: 0 additions & 54 deletions modules/gnosis/gnosis-safe.service.ts

This file was deleted.

4 changes: 4 additions & 0 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/
import { coingeckoService } from '../coingecko/coingecko.service';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { env } from '../../app/env';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const arbitrumNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -249,6 +250,9 @@ export const arbitrumNetworkConfig: NetworkConfig = {
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(arbitrumNetworkData.subgraphs.balancer, arbitrumNetworkData.chain.id),
},
/*
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.
Expand Down
4 changes: 4 additions & 0 deletions modules/network/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { coingeckoService } from '../coingecko/coingecko.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { env } from '../../app/env';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const avalancheNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -239,6 +240,9 @@ export const avalancheNetworkConfig: NetworkConfig = {
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(avalancheNetworkData.subgraphs.balancer, avalancheNetworkData.chain.id),
},
/*
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.
Expand Down
4 changes: 4 additions & 0 deletions modules/network/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/
import { coingeckoService } from '../coingecko/coingecko.service';
import { env } from '../../app/env';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const baseNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -137,6 +138,9 @@ export const baseNetworkConfig: NetworkConfig = {
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(baseNetworkData.subgraphs.balancer, baseNetworkData.chain.id),
},
/*
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.
Expand Down
4 changes: 4 additions & 0 deletions modules/network/fantom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { coingeckoService } from '../coingecko/coingecko.service';
import { env } from '../../app/env';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { BeetswarsGaugeVotingAprService } from '../pool/lib/apr-data-sources/fantom/beetswars-gauge-voting-apr';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const fantomNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -343,6 +344,9 @@ export const fantomNetworkConfig: NetworkConfig = {
),
new UserSyncReliquaryFarmBalanceService(fantomNetworkData.reliquary!.address),
],
services: {
balancerSubgraphService: new BalancerSubgraphService(fantomNetworkData.subgraphs.balancer, fantomNetworkData.chain.id),
},
/*
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.
Expand Down
4 changes: 4 additions & 0 deletions modules/network/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { coingeckoService } from '../coingecko/coingecko.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { env } from '../../app/env';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const gnosisNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -166,6 +167,9 @@ export const gnosisNetworkConfig: NetworkConfig = {
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(gnosisNetworkData.subgraphs.balancer, gnosisNetworkData.chain.id),
},
/*
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.
Expand Down
28 changes: 16 additions & 12 deletions modules/network/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { coingeckoService } from '../coingecko/coingecko.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { env } from '../../app/env';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const underlyingTokens = {
USDC: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
Expand All @@ -25,7 +26,7 @@ const underlyingTokens = {
wETH: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
};

export const mainnetNetworkData: NetworkData = {
const data: NetworkData = {
chain: {
slug: 'ethereum',
id: 1,
Expand Down Expand Up @@ -367,32 +368,35 @@ export const mainnetNetworkData: NetworkData = {
};

export const mainnetNetworkConfig: NetworkConfig = {
data: mainnetNetworkData,
data,
contentService: new GithubContentService(),
provider: new ethers.providers.JsonRpcProvider({ url: mainnetNetworkData.rpcUrl, timeout: 60000 }),
provider: new ethers.providers.JsonRpcProvider({ url: data.rpcUrl, timeout: 60000 }),
poolAprServices: [
new IbTokensAprService(
mainnetNetworkData.ibAprConfig,
mainnetNetworkData.chain.prismaId,
mainnetNetworkData.balancer.yieldProtocolFeePercentage,
mainnetNetworkData.balancer.swapProtocolFeePercentage,
data.ibAprConfig,
data.chain.prismaId,
data.balancer.yieldProtocolFeePercentage,
data.balancer.swapProtocolFeePercentage,
),
new PhantomStableAprService(
mainnetNetworkData.chain.prismaId,
mainnetNetworkData.balancer.yieldProtocolFeePercentage,
data.chain.prismaId,
data.balancer.yieldProtocolFeePercentage,
),
new BoostedPoolAprService(),
new SwapFeeAprService(mainnetNetworkData.balancer.swapProtocolFeePercentage),
new GaugeAprService(tokenService, [mainnetNetworkData.bal!.address]),
new SwapFeeAprService(data.balancer.swapProtocolFeePercentage),
new GaugeAprService(tokenService, [data.bal!.address]),
],
poolStakingServices: [new GaugeStakingService(gaugeSubgraphService, mainnetNetworkData.bal!.address)],
poolStakingServices: [new GaugeStakingService(gaugeSubgraphService, data.bal!.address)],
tokenPriceHandlers: [
new CoingeckoPriceHandlerService(coingeckoService),
new BptPriceHandlerService(),
new LinearWrappedTokenPriceHandlerService(),
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(data.subgraphs.balancer, 1),
},
/*
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.
Expand Down
7 changes: 7 additions & 0 deletions modules/network/network-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BaseProvider } from '@ethersproject/providers';
import { GqlChain } from '../../schema';
import { ContentService } from '../content/content-types';
import { AaveAprConfig, IbAprConfig } from './apr-config-types';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

export interface NetworkConfig {
data: NetworkData;
Expand All @@ -17,7 +18,13 @@ export interface NetworkConfig {
tokenPriceHandlers: TokenPriceHandler[];
provider: BaseProvider;
workerJobs: WorkerJob[];
services: NetworkServices;
}

interface NetworkServices {
balancerSubgraphService: BalancerSubgraphService;
}

export interface WorkerJob {
name: string;
interval: number;
Expand Down
4 changes: 4 additions & 0 deletions modules/network/network-context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export class NetworkContextService {
public get protocolSupportedChainIds(): string[] {
return this.isBalancerChain ? BalancerChainIds : BeethovenChainIds;
}

public get services() {
return this.config.services;
}
}

export const networkContext = new NetworkContextService(env.DEFAULT_CHAIN_ID);
4 changes: 4 additions & 0 deletions modules/network/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { coingeckoService } from '../coingecko/coingecko.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { env } from '../../app/env';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const optimismNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -294,6 +295,9 @@ export const optimismNetworkConfig: NetworkConfig = {
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(optimismNetworkData.subgraphs.balancer, optimismNetworkData.chain.id),
},
/*
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.
Expand Down
4 changes: 4 additions & 0 deletions modules/network/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { coingeckoService } from '../coingecko/coingecko.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { env } from '../../app/env';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const polygonNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -284,6 +285,9 @@ export const polygonNetworkConfig: NetworkConfig = {
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(polygonNetworkData.subgraphs.balancer, polygonNetworkData.chain.id),
},
/*
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.
Expand Down
5 changes: 5 additions & 0 deletions modules/network/zkevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/
import { coingeckoService } from '../coingecko/coingecko.service';
import { env } from '../../app/env';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const zkevmNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -72,6 +73,7 @@ const zkevmNetworkData: NetworkData = {
composableStablePoolFactories: [
'0x8ea89804145c007e7d226001a96955ad53836087',
'0x956ccab09898c0af2aca5e6c229c3ad4e93d9288',
'0x577e5993b9cc480f07f98b5ebd055604bd9071c4'
],
weightedPoolV2Factories: ['0x03f3fb107e74f2eac9358862e91ad3c692712054'],
swapProtocolFeePercentage: 0.5,
Expand Down Expand Up @@ -184,6 +186,9 @@ export const zkevmNetworkConfig: NetworkConfig = {
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(zkevmNetworkData.subgraphs.balancer, zkevmNetworkData.chain.id),
},
/*
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.
Expand Down
Loading

0 comments on commit 33b70b8

Please sign in to comment.