Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add voting apr for reliquary #475

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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