diff --git a/modules/network/fantom.ts b/modules/network/fantom.ts index 4f333f3a4..16d4a7d56 100644 --- a/modules/network/fantom.ts +++ b/modules/network/fantom.ts @@ -25,6 +25,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 { BeetswarsGaugeVotingAprService } from '../pool/lib/apr-data-sources/fantom/beetswars-gauge-voting-apr'; const fantomNetworkData: NetworkData = { chain: { @@ -306,6 +307,7 @@ export const fantomNetworkConfig: NetworkConfig = { new SwapFeeAprService(fantomNetworkData.balancer.swapProtocolFeePercentage), new MasterchefFarmAprService(fantomNetworkData.beets!.address), new ReliquaryFarmAprService(fantomNetworkData.beets!.address), + new BeetswarsGaugeVotingAprService(), ], poolStakingServices: [ new MasterChefStakingService(masterchefService, fantomNetworkData.masterchef!.excludedFarmIds), diff --git a/modules/pool/lib/apr-data-sources/fantom/beetswars-gauge-voting-apr.ts b/modules/pool/lib/apr-data-sources/fantom/beetswars-gauge-voting-apr.ts new file mode 100644 index 000000000..e392b6f52 --- /dev/null +++ b/modules/pool/lib/apr-data-sources/fantom/beetswars-gauge-voting-apr.ts @@ -0,0 +1,51 @@ +import { PoolAprService } from '../../../pool-types'; +import { PrismaPoolWithTokens } from '../../../../../prisma/prisma-types'; +import axios from 'axios'; +import { prisma } from '../../../../../prisma/prisma-client'; +import { networkContext } from '../../../../network/network-context.service'; +import { PrismaPoolAprType } from '@prisma/client'; + +export class BeetswarsGaugeVotingAprService implements PoolAprService { + private readonly FRESH_BEETS_POOL_ID = '0x9e4341acef4147196e99d648c5e43b3fc9d026780002000000000000000005ec'; + + public getAprServiceName(): string { + return 'BeetswarsGaugeVotingAprService'; + } + + public async updateAprForPools(pools: PrismaPoolWithTokens[]): Promise { + if (pools.map((pool) => pool.id).includes(this.FRESH_BEETS_POOL_ID)) { + const response = await axios.get('https://www.beetswars.live/api/trpc/chart.chartdata'); + + const votingAprs: number[] = response.data.result.data.json.chartdata.votingApr; + + const minApr = 0; + const maxApr = votingAprs[votingAprs.length - 1]; + const itemId = `${this.FRESH_BEETS_POOL_ID}-voting-apr`; + + await prisma.prismaPoolAprItem.upsert({ + where: { id_chain: { id: itemId, chain: networkContext.chain } }, + update: { + range: { + update: { min: minApr, max: maxApr }, + }, + }, + create: { + id: itemId, + chain: networkContext.chain, + poolId: this.FRESH_BEETS_POOL_ID, + title: 'Voting APR', + apr: 0, + range: { + create: { + id: `${itemId}-range`, + min: minApr, + max: maxApr, + }, + }, + type: PrismaPoolAprType.VOTING, + group: null, + }, + }); + } + } +} diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index 9a888f599..e036278eb 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -33,7 +33,7 @@ import { import { isSameAddress } from '@balancer-labs/sdk'; import _ from 'lodash'; import { prisma } from '../../../prisma/prisma-client'; -import { Prisma } from '@prisma/client'; +import { Prisma, PrismaPoolAprType } from '@prisma/client'; import { isWeightedPoolV2 } from './pool-utils'; import { oldBnum } from '../../big-number/old-big-number'; import { networkContext } from '../../network/network-context.service'; @@ -614,12 +614,17 @@ export class PoolGqlLoaderService { currentAprRangeMaxTotal += maxApr; switch (aprItem.type) { - case 'NATIVE_REWARD': { + case PrismaPoolAprType.NATIVE_REWARD: { currentNativeAprRangeMin += minApr; currentNativeAprRangeMax += maxApr; break; } - case 'THIRD_PARTY_REWARD': { + case PrismaPoolAprType.THIRD_PARTY_REWARD: { + currentThirdPartyAprRangeMin += minApr; + currentThirdPartyAprRangeMax += maxApr; + break; + } + case PrismaPoolAprType.VOTING: { currentThirdPartyAprRangeMin += minApr; currentThirdPartyAprRangeMax += maxApr; break; diff --git a/modules/pool/pool.prisma b/modules/pool/pool.prisma index f31279e72..bcab89d2b 100644 --- a/modules/pool/pool.prisma +++ b/modules/pool/pool.prisma @@ -293,6 +293,7 @@ enum PrismaPoolAprType { LINEAR_BOOSTED PHANTOM_STABLE_BOOSTED IB_YIELD + VOTING } enum PrismaPoolAprItemGroup { diff --git a/prisma/migrations/20230918081047_add_voting_apr_type/migration.sql b/prisma/migrations/20230918081047_add_voting_apr_type/migration.sql new file mode 100644 index 000000000..4394abbfd --- /dev/null +++ b/prisma/migrations/20230918081047_add_voting_apr_type/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "PrismaPoolAprType" ADD VALUE 'VOTING'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3ba9f59b6..1d2572799 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -339,6 +339,7 @@ enum PrismaPoolAprType { LINEAR_BOOSTED PHANTOM_STABLE_BOOSTED IB_YIELD + VOTING } enum PrismaPoolAprItemGroup {