Skip to content

Commit

Permalink
add voting apr for reliquary
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Sep 18, 2023
1 parent b9b3f56 commit 082c337
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
2 changes: 2 additions & 0 deletions modules/network/fantom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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,
},
});
}
}
}
11 changes: 8 additions & 3 deletions modules/pool/lib/pool-gql-loader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -610,12 +610,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;
Expand Down
1 change: 1 addition & 0 deletions modules/pool/pool.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ enum PrismaPoolAprType {
LINEAR_BOOSTED
PHANTOM_STABLE_BOOSTED
IB_YIELD
VOTING
}

enum PrismaPoolAprItemGroup {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "PrismaPoolAprType" ADD VALUE 'VOTING';
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ enum PrismaPoolAprType {
LINEAR_BOOSTED
PHANTOM_STABLE_BOOSTED
IB_YIELD
VOTING
}

enum PrismaPoolAprItemGroup {
Expand Down

0 comments on commit 082c337

Please sign in to comment.