Skip to content

Commit

Permalink
adding sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Jan 19, 2024
1 parent 7d6f342 commit 4ce5355
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 14 deletions.
4 changes: 0 additions & 4 deletions app/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export const schema = {
optional: true,
type: String,
},
SUPPORTED_NETWORKS: {
optional: true,
type: String,
},
WORKER_QUEUE_URL: {
optional: true,
type: String,
Expand Down
1 change: 1 addition & 0 deletions modules/common/Base.gql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ enum GqlChain {
OPTIMISM
POLYGON
ZKEVM
SEPOLIA
}
2 changes: 1 addition & 1 deletion modules/datastudio/datastudio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class DatastudioService {
}

if (pool.dynamicData) {
const protocolYieldFeePercentage = parseFloat(pool.dynamicData.protocolYieldFee);
const protocolYieldFeePercentage = parseFloat(pool.dynamicData.protocolYieldFee || '');
const protocolSwapFeePercentage = parseFloat(pool.dynamicData.protocolSwapFee);
sharesChange = `${
parseFloat(pool.dynamicData.totalShares) - parseFloat(pool.dynamicData.totalShares24hAgo)
Expand Down
4 changes: 0 additions & 4 deletions modules/network/network-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ export interface NetworkData {
beefy?: {
linearPools: string[];
};
lido?: {
wstEthContract: string;
wstEthAprEndpoint: string;
};
stader?: {
sFtmxContract: string;
};
Expand Down
6 changes: 5 additions & 1 deletion modules/network/network-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { zkevmNetworkConfig } from './zkevm';
import { avalancheNetworkConfig } from './avalanche';
import { baseNetworkConfig } from './base';
import { Chain } from '@prisma/client';
import { sepoliaNetworkConfig } from './sepolia';

export const AllNetworkConfigs: { [chainId: string]: NetworkConfig } = {
'250': fantomNetworkConfig,
Expand All @@ -20,6 +21,7 @@ export const AllNetworkConfigs: { [chainId: string]: NetworkConfig } = {
'1101': zkevmNetworkConfig,
'43114': avalancheNetworkConfig,
'8453': baseNetworkConfig,
'11155111': sepoliaNetworkConfig,
};

export const AllNetworkConfigsKeyedOnChain: { [chain in Chain]: NetworkConfig } = {
Expand All @@ -32,6 +34,7 @@ export const AllNetworkConfigsKeyedOnChain: { [chain in Chain]: NetworkConfig }
ZKEVM: zkevmNetworkConfig,
AVALANCHE: avalancheNetworkConfig,
BASE: baseNetworkConfig,
SEPOLIA: sepoliaNetworkConfig,
};

export const chainIdToChain: { [id: string]: Chain } = {
Expand All @@ -44,9 +47,10 @@ export const chainIdToChain: { [id: string]: Chain } = {
'8453': Chain.BASE,
'42161': Chain.ARBITRUM,
'43114': Chain.AVALANCHE,
'11155111': Chain.SEPOLIA,
};

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

export const chainToIdMap = Object.values(AllNetworkConfigs).reduce((acc, config) => {
Expand Down
245 changes: 245 additions & 0 deletions modules/network/sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
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 { YbTokensAprService } from '../pool/lib/apr-data-sources/yb-tokens-apr.service';
import { env } from '../../app/env';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

export const sepoliaNetworkData: NetworkData = {
chain: {
slug: 'sepolia',
id: 11155111,
nativeAssetAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
wrappedNativeAssetAddress: '0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
prismaId: 'SEPOLIA',
gqlId: 'SEPOLIA',
},
subgraphs: {
startDate: '2021-08-23',
balancer: 'https://api.studio.thegraph.com/query/24660/balancer-sepolia-v2/version/latest',
beetsBar: 'https://',
blocks: 'https://',
gauge: 'https://api.studio.thegraph.com/query/24660/balancer-gauges-sepolia-beta/version/latest',
// veBalLocks: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-gauges',
userBalances: 'https://',
},
eth: {
address: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
addressFormatted: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
symbol: 'ETH',
name: 'Ether',
},
weth: {
address: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
addressFormatted: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
},
coingecko: {
nativeAssetId: 'ethereum',
platformId: 'ethereum',
excludedTokenAddresses: [],
},
rpcUrl: env.INFURA_API_KEY
? `https://sepolia.infura.io/v3/${env.INFURA_API_KEY}`
: 'https://gateway.tenderly.co/public/sepolia',
rpcMaxBlockRange: 700,
protocolToken: 'bal',
bal: {
address: '0xb19382073c7A0aDdbb56Ac6AF1808Fa49e377B75',
},
// veBal: {
// address: '0xc128a9954e6c874ea3d62ce62b468ba073093f25',
// delegationProxy: '0x81cfae226343b24ba12ec6521db2c79e7aeeb310',
// },
balancer: {
vaultV2Address: '0xba12222222228d8ba445958a75a0704d566bf2c8',
v2DefaultSwapFeePercentage: '0.5',
v2DefaultYieldFeePercentage: '0.5',
vaultV3Address: '0xba12222222228d8ba445958a75a0704d566bf2c8',
v3DefaultSwapFeePercentage: '0.5',
v3DefaultYieldFeePercentage: '0.5',
},
multicall: '0x80c7dd17b01855a6d2347444a0fcc36136a314de',
multicall3: '0xca11bde05977b3631167028862be2a173976ca11',
avgBlockSpeed: 1,
sor: {
main: {
url: 'https://uu6cfghhd5lqa7py3nojxkivd40zuugb.lambda-url.ca-central-1.on.aws/',
maxPools: 8,
forceRefresh: false,
gasPrice: BigNumber.from(10),
swapGas: BigNumber.from('1000000'),
poolIdsToExclude: [],
},
canary: {
url: 'https://ksa66wlkjbvteijxmflqjehsay0jmekw.lambda-url.eu-central-1.on.aws/',
maxPools: 8,
forceRefresh: false,
gasPrice: BigNumber.from(10),
swapGas: BigNumber.from('1000000'),
poolIdsToExclude: [],
},
},
ybAprConfig: {},
datastudio: {
main: {
user: 'datafeed-service@datastudio-366113.iam.gserviceaccount.com',
sheetId: '11anHUEb9snGwvB-errb5HvO8TvoLTRJhkDdD80Gxw1Q',
databaseTabName: 'Database v2',
compositionTabName: 'Pool Composition v2',
emissionDataTabName: 'EmissionData',
},
canary: {
user: 'datafeed-service@datastudio-366113.iam.gserviceaccount.com',
sheetId: '1HnJOuRQXGy06tNgqjYMzQNIsaCSCC01Yxe_lZhXBDpY',
databaseTabName: 'Database v2',
compositionTabName: 'Pool Composition v2',
emissionDataTabName: 'EmissionData',
},
},
monitoring: {
main: {
alarmTopicArn: 'arn:aws:sns:ca-central-1:118697801881:api_alarms',
},
canary: {
alarmTopicArn: 'arn:aws:sns:eu-central-1:118697801881:api_alarms',
},
},
};

export const sepoliaNetworkConfig: NetworkConfig = {
data: sepoliaNetworkData,
contentService: new GithubContentService(),
provider: new ethers.providers.JsonRpcProvider({ url: sepoliaNetworkData.rpcUrl, timeout: 60000 }),
poolAprServices: [
new YbTokensAprService(sepoliaNetworkData.ybAprConfig, sepoliaNetworkData.chain.prismaId),
new PhantomStableAprService(sepoliaNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [sepoliaNetworkData.bal!.address]),
],
poolStakingServices: [new GaugeStakingService(gaugeSubgraphService, sepoliaNetworkData.bal!.address)],
tokenPriceHandlers: [
new CoingeckoPriceHandlerService(coingeckoService),
new BptPriceHandlerService(),
new LinearWrappedTokenPriceHandlerService(),
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(
sepoliaNetworkData.subgraphs.balancer,
sepoliaNetworkData.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.
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(90, 'minutes'),
},
{
name: 'update-lifetime-values-for-all-pools',
interval: every(50, 'minutes'),
},
{
name: 'sync-changed-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(2, 'minutes') : every(30, '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(5, '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-staked-balances',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(5, 'minutes') : every(20, 'seconds'),
alarmEvaluationPeriod: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? 3 : 1,
alarmDatapointsToAlarm: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? 3 : 1,
},
{
name: 'sync-coingecko-coinids',
interval: every(2, 'hours'),
},
{
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'),
// },
// {
// name: 'feed-data-to-datastudio',
// interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(5, 'minutes') : every(5, 'minutes'),
// },
],
};
2 changes: 1 addition & 1 deletion modules/pool/pool.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ model PrismaPoolDynamicData {
blockNumber Int
updatedAt DateTime @updatedAt
protocolYieldFee String @default("0")
protocolYieldFee String?
protocolSwapFee String @default("0")
swapFee String
swapEnabled Boolean
Expand Down
2 changes: 1 addition & 1 deletion modules/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain, PrismaPoolStaking, PrismaPoolStakingType } from '@prisma/client';
import { prisma } from '../../prisma/prisma-client';
import { GqlPoolJoinExit, GqlPoolSwap, GqlUserSnapshotDataRange } from '../../schema';
import { GqlPoolJoinExit, GqlPoolSwap } from '../../schema';
import { PoolSwapService } from '../pool/lib/pool-swap.service';
import { tokenService } from '../token/token.service';
import { UserBalanceService } from './lib/user-balance.service';
Expand Down
1 change: 1 addition & 0 deletions prisma/base.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum Chain {
MAINNET
OPTIMISM
POLYGON
SEPOLIA
ZKEVM
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterEnum
ALTER TYPE "Chain" ADD VALUE 'SEPOLIA';

-- AlterTable
ALTER TABLE "PrismaPoolDynamicData" ADD COLUMN "protocolSwapFee" TEXT NOT NULL DEFAULT '0';
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum Chain {
MAINNET
OPTIMISM
POLYGON
SEPOLIA
ZKEVM
}

Expand Down Expand Up @@ -174,7 +175,7 @@ model PrismaPoolDynamicData {
blockNumber Int
updatedAt DateTime @updatedAt
protocolYieldFee String @default("0")
protocolYieldFee String?
protocolSwapFee String @default("0")
swapFee String
swapEnabled Boolean
Expand Down
10 changes: 9 additions & 1 deletion worker/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createAlerts } from './create-alerts';
import { createMonitors } from './create-monitors';
import { sleep } from '../modules/common/promise';
import { scheduleJobs } from './job-queue';
import { DeploymentEnv } from '../modules/network/network-config-types';

export async function startScheduler() {
Sentry.init({
Expand All @@ -15,7 +16,14 @@ export async function startScheduler() {
});

try {
const chainIds = env.SUPPORTED_NETWORKS ? env.SUPPORTED_NETWORKS.split(',') : Object.keys(AllNetworkConfigs);
const SEPOLIA_ID = '11155111';
let chainIds: string[] = [SEPOLIA_ID];

if (env.DEPLOYMENT_ENV === 'canary' || env.DEPLOYMENT_ENV === 'main') {
// use all chains, remove sepolia
chainIds = Object.keys(AllNetworkConfigs).filter((chainId) => chainId !== SEPOLIA_ID);
}

for (const chainId of chainIds) {
scheduleJobs(chainId);
if (process.env.AWS_ALERTS === 'true') {
Expand Down

0 comments on commit 4ce5355

Please sign in to comment.