Skip to content

Commit

Permalink
V3 canary (#43)
Browse files Browse the repository at this point in the history
* fix remaining phantomstable pool type checks

* Update on change only (#30)

* only update gauges if necessary

* only update masterchef farms if necessary

* Token yields update (#28)

* renaming ib to yb

i suppose ib stands for yield bearing

* new aprs

* removing obsolete ankr apr handler

* fix plutusdao APR url

* removing sentry integrations (#36)

* create separate featuredPools endpoint for v3 (#34)

* create separate featuredPools endpoint for v3

* cleanup

* require chains param

* stop token price purge for now (#41)

---------

Co-authored-by: gmbronco <[email protected]>
  • Loading branch information
franzns and gmbronco authored Jan 16, 2024
1 parent a6418e6 commit fcd9c85
Show file tree
Hide file tree
Showing 55 changed files with 590 additions and 390 deletions.
9 changes: 7 additions & 2 deletions modules/content/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export interface HomeScreenFeaturedPoolGroup {
id: string;
items: (HomeScreenFeaturedPoolGroupItemPoolId | HomeScreenFeaturedPoolGroupItemExternalLink)[];
title: string;
primary: boolean;
chain: GqlChain;
}

interface HomeScreenFeaturedPoolGroupItemPoolId {
Expand All @@ -32,6 +30,12 @@ interface HomeScreenFeaturedPoolGroupItemExternalLink {
image: string;
}

export interface FeaturedPool {
poolId: string;
primary: boolean;
chain: GqlChain;
}

export interface HomeScreenNewsItem {
id: string;
timestamp: string;
Expand All @@ -45,5 +49,6 @@ export interface ContentService {
syncTokenContentData(): Promise<void>;
syncPoolContentData(): Promise<void>;
getFeaturedPoolGroups(chains: Chain[]): Promise<HomeScreenFeaturedPoolGroup[]>;
getFeaturedPools(chains: Chain[]): Promise<FeaturedPool[]>;
getNewsItems(): Promise<HomeScreenNewsItem[]>;
}
29 changes: 14 additions & 15 deletions modules/content/github-content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Chain, Prisma } from '@prisma/client';
import axios from 'axios';
import { prisma } from '../../prisma/prisma-client';
import { networkContext } from '../network/network-context.service';
import { ContentService, HomeScreenFeaturedPoolGroup, HomeScreenNewsItem } from './content-types';
import { ContentService, FeaturedPool, HomeScreenFeaturedPoolGroup, HomeScreenNewsItem } from './content-types';
import { chainIdToChain } from '../network/network-config';

const POOLS_METADATA_URL = 'https://raw.githubusercontent.com/balancer/metadata/main/pools/featured.json';
Expand Down Expand Up @@ -139,7 +139,10 @@ export class GithubContentService implements ContentService {
});
}

if ((pool?.type === 'PHANTOM_STABLE' || pool?.type === 'LINEAR') && !tokenTypes.includes('PHANTOM_BPT')) {
if (
(pool?.type === 'COMPOSABLE_STABLE' || pool?.type === 'LINEAR') &&
!tokenTypes.includes('PHANTOM_BPT')
) {
types.push({
id: `${token.address}-phantom-bpt`,
chain: networkContext.chain,
Expand All @@ -165,25 +168,21 @@ export class GithubContentService implements ContentService {
await prisma.prismaTokenType.createMany({ skipDuplicates: true, data: types });
}
async syncPoolContentData(): Promise<void> {}

async getFeaturedPoolGroups(chains: Chain[]): Promise<HomeScreenFeaturedPoolGroup[]> {
return [];
}

async getFeaturedPools(chains: Chain[]): Promise<FeaturedPool[]> {
const { data } = await axios.get<FeaturedPoolMetadata[]>(POOLS_METADATA_URL);
const pools = data.filter((pool) => chains.includes(chainIdToChain[pool.chainId]));
return pools.map(({ id, imageUrl, primary, chainId }) => ({
id,
_type: 'homeScreenFeaturedPoolGroupPoolId',
title: 'Popular pools',
items: [
{
_key: '',
_type: 'homeScreenFeaturedPoolGroupPoolId',
poolId: id,
},
],
icon: imageUrl,
return pools.map(({ id, primary, chainId }) => ({
poolId: id,
chain: chainIdToChain[chainId],
primary: Boolean(primary),
})) as HomeScreenFeaturedPoolGroup[];
})) as FeaturedPool[];
}

async getNewsItems(): Promise<HomeScreenNewsItem[]> {
return [];
}
Expand Down
62 changes: 53 additions & 9 deletions modules/content/sanity-content.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { isSameAddress } from '@balancer-labs/sdk';
import { Chain, Prisma, PrismaPoolCategoryType } from '@prisma/client';
import { prisma } from '../../prisma/prisma-client';
import { ConfigHomeScreen, ContentService, HomeScreenFeaturedPoolGroup, HomeScreenNewsItem } from './content-types';
import {
ConfigHomeScreen,
ContentService,
FeaturedPool,
HomeScreenFeaturedPoolGroup,
HomeScreenNewsItem,
} from './content-types';
import SanityClient from '@sanity/client';
import { env } from '../../app/env';
import { chainToIdMap } from '../network/network-config';
Expand Down Expand Up @@ -166,7 +172,10 @@ export class SanityContentService implements ContentService {
});
}

if ((pool?.type === 'PHANTOM_STABLE' || pool?.type === 'LINEAR') && !tokenTypes.includes('PHANTOM_BPT')) {
if (
(pool?.type === 'COMPOSABLE_STABLE' || pool?.type === 'LINEAR') &&
!tokenTypes.includes('PHANTOM_BPT')
) {
types.push({
id: `${token.address}-phantom-bpt`,
chain: this.chain,
Expand Down Expand Up @@ -276,18 +285,53 @@ export class SanityContentService implements ContentService {
}
`);
if (data) {
featuredPoolGroups.push(
...data.featuredPoolGroups.map((pool, i) => ({
...pool,
chain: chain,
primary: i === 0 ? true : false,
})),
);
featuredPoolGroups.push(...data.featuredPoolGroups);
}
}
return featuredPoolGroups;
}

public async getFeaturedPools(chains: Chain[]): Promise<FeaturedPool[]> {
const featuredPools: FeaturedPool[] = [];
for (const chain of chains) {
const data = await this.getSanityClient().fetch<ConfigHomeScreen | null>(`
*[_type == "homeScreen" && chainId == ${chainToIdMap[chain]}][0]{
...,
"featuredPoolGroups": featuredPoolGroups[]{
...,
"icon": icon.asset->url + "?w=64",
"items": items[]{
...,
"image": image.asset->url + "?w=600"
}
},
"newsItems": newsItems[]{
...,
"image": image.asset->url + "?w=800"
}
}
`);
if (data) {
const featuredPoolGroupItems = data.featuredPoolGroups.find(
(group) => group.id === 'popular-pools',
)?.items;
if (featuredPoolGroupItems) {
for (let i = 0; i < featuredPoolGroupItems.length; i++) {
const group = featuredPoolGroupItems[i];
if (group._type === 'homeScreenFeaturedPoolGroupPoolId') {
featuredPools.push({
poolId: group.poolId,
primary: i === 0 ? true : false,
chain: chain,
});
}
}
}
}
}
return featuredPools;
}

public async getNewsItems(): Promise<HomeScreenNewsItem[]> {
const data = await this.getSanityClient().fetch<ConfigHomeScreen | null>(`
*[_type == "homeScreen" && chainId == ${chainToIdMap[this.chain]}][0]{
Expand Down
16 changes: 3 additions & 13 deletions modules/network/apr-config-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export interface IbAprConfig {
export interface YbAprConfig {
aave?: AaveAprConfig;
ankr?: AnkrAprConfig;
bloom?: BloomAprConfig;
beefy?: BeefyAprConfig;
sftmx?: SftmxAprConfig;
Expand All @@ -14,6 +13,8 @@ export interface IbAprConfig {
tetu?: TetuAprConfig;
tranchess?: TranchessAprConfig;
yearn?: YearnAprConfig;
stakewise?: string;
etherfi?: string;
defaultHandlers?: DefaultHandlerAprConfig;
fixedAprHandler?: FixedAprConfig;
}
Expand All @@ -34,17 +35,6 @@ export interface AaveAprConfig {
};
}

export interface AnkrAprConfig {
sourceUrl: string;
tokens: {
[underlyingAssetName: string]: {
address: string;
serviceName: string;
isIbYield?: boolean;
};
};
}

export interface BeefyAprConfig {
sourceUrl: string;
tokens: {
Expand Down
29 changes: 24 additions & 5 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ 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 { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.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';

const arbitrumNetworkData: NetworkData = {
export const arbitrumNetworkData: NetworkData = {
chain: {
slug: 'arbitrum',
id: 42161,
Expand Down Expand Up @@ -93,7 +93,7 @@ const arbitrumNetworkData: NetworkData = {
poolIdsToExclude: [],
},
},
ibAprConfig: {
ybAprConfig: {
aave: {
v3: {
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v3-arbitrum',
Expand Down Expand Up @@ -175,6 +175,25 @@ const arbitrumNetworkData: NetworkData = {
path: 'sfrxethApr',
isIbYield: true,
},
sFRAX: {
tokenAddress: '0xe3b3fe7bca19ca77ad877a5bebab186becfad906',
sourceUrl: 'https://api.frax.finance/v2/frax/sfrax/summary/history?range=1d',
path: 'items.0.sfraxApr',
isIbYield: true,
},
ankrETH: {
tokenAddress: '0xe05a08226c49b636acf99c40da8dc6af83ce5bb3',
sourceUrl: 'https://api.staking.ankr.com/v1alpha/metrics',
path: 'services.{serviceName == "eth"}.apy',
isIbYield: true,
},
plsRDNT: {
tokenAddress: '0x6dbf2155b0636cb3fd5359fccefb8a2c02b6cb51',
sourceUrl: 'https://www.plutusdao.io/api/getPlsRdntInfo',
path: 'apr',
scale: 10000,
isIbYield: true,
},
},
},
beefy: {
Expand Down Expand Up @@ -215,8 +234,8 @@ export const arbitrumNetworkConfig: NetworkConfig = {
contentService: new GithubContentService(),
provider: new ethers.providers.JsonRpcProvider({ url: arbitrumNetworkData.rpcUrl, timeout: 60000 }),
poolAprServices: [
new IbTokensAprService(
arbitrumNetworkData.ibAprConfig,
new YbTokensAprService(
arbitrumNetworkData.ybAprConfig,
arbitrumNetworkData.chain.prismaId,
arbitrumNetworkData.balancer.yieldProtocolFeePercentage,
arbitrumNetworkData.balancer.swapProtocolFeePercentage,
Expand Down
24 changes: 10 additions & 14 deletions modules/network/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { gaugeSubgraphService } from '../subgraphs/gauge-subgraph/gauge-subgraph
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 { YbTokensAprService } from '../pool/lib/apr-data-sources/yb-tokens-apr.service';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const avalancheNetworkData: NetworkData = {
Expand Down Expand Up @@ -91,7 +91,7 @@ const avalancheNetworkData: NetworkData = {
poolIdsToExclude: [],
},
},
ibAprConfig: {
ybAprConfig: {
aave: {
v3: {
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v3-avalanche',
Expand Down Expand Up @@ -141,16 +141,6 @@ const avalancheNetworkData: NetworkData = {
},
},
},
ankr: {
sourceUrl: 'https://api.staking.ankr.com/v1alpha/metrics',
tokens: {
ankrAVAX: {
address: '0xc3344870d52688874b06d844e0c36cc39fc727f6',
serviceName: 'avax',
isIbYield: true,
},
},
},
defaultHandlers: {
sAVAX: {
tokenAddress: '0x2b2c81e08f1af8835a78bb2a90ae924ace0ea4be',
Expand All @@ -173,6 +163,12 @@ const avalancheNetworkData: NetworkData = {
// M * -12 = A (M is monthly rate and A is APR) => (M/x) = (A/100) => (A / -12x) = (A / 100) [replacing M by A/-12] => x = 100/-12 = -8,33333
scale: -8.3333,
},
ankrAVAX: {
tokenAddress: '0xc3344870d52688874b06d844e0c36cc39fc727f6',
sourceUrl: 'https://api.staking.ankr.com/v1alpha/metrics',
path: 'services.{serviceName == "avax"}.apy',
isIbYield: true,
},
},
},
beefy: {
Expand Down Expand Up @@ -209,8 +205,8 @@ export const avalancheNetworkConfig: NetworkConfig = {
contentService: new GithubContentService(),
provider: new ethers.providers.JsonRpcProvider({ url: avalancheNetworkData.rpcUrl, timeout: 60000 }),
poolAprServices: [
new IbTokensAprService(
avalancheNetworkData.ibAprConfig,
new YbTokensAprService(
avalancheNetworkData.ybAprConfig,
avalancheNetworkData.chain.prismaId,
avalancheNetworkData.balancer.yieldProtocolFeePercentage,
avalancheNetworkData.balancer.swapProtocolFeePercentage,
Expand Down
8 changes: 4 additions & 4 deletions modules/network/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { gaugeSubgraphService } from '../subgraphs/gauge-subgraph/gauge-subgraph
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { coingeckoService } from '../coingecko/coingecko.service';
import { env } from '../../app/env';
import { IbTokensAprService } from '../pool/lib/apr-data-sources/ib-tokens-apr.service';
import { YbTokensAprService } from '../pool/lib/apr-data-sources/yb-tokens-apr.service';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';

const baseNetworkData: NetworkData = {
Expand Down Expand Up @@ -66,7 +66,7 @@ const baseNetworkData: NetworkData = {
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
ibAprConfig: {
ybAprConfig: {
defaultHandlers: {
cbETH: {
tokenAddress: '0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22',
Expand Down Expand Up @@ -129,8 +129,8 @@ export const baseNetworkConfig: NetworkConfig = {
contentService: new GithubContentService(),
provider: new ethers.providers.JsonRpcProvider({ url: baseNetworkData.rpcUrl, timeout: 60000 }),
poolAprServices: [
new IbTokensAprService(
baseNetworkData.ibAprConfig,
new YbTokensAprService(
baseNetworkData.ybAprConfig,
baseNetworkData.chain.prismaId,
baseNetworkData.balancer.yieldProtocolFeePercentage,
baseNetworkData.balancer.swapProtocolFeePercentage,
Expand Down
Loading

0 comments on commit fcd9c85

Please sign in to comment.