Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
chore(apps): Removed external dependencies used for fetching APY (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin authored Dec 27, 2023
1 parent d3bf468 commit dd406a4
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { Injectable } from '@nestjs/common';
import axios from 'axios';

import { Erc20 } from '~contract/contracts/viem';
import { GetDataPropsParams } from '~position/template/app-token.template.types';
import { WrapperTemplateTokenFetcher } from '~position/template/wrapper.template.token-fetcher';

@Injectable()
export abstract class AbracadabraBridgedStakedSpellTokenFetcher extends WrapperTemplateTokenFetcher {
async getApy(): Promise<number> {
const { data } = await axios.get<{ apr: number }>('/api/v1/ethereum/SpellStakingInfo', {
baseURL: 'https://analytics.back.popsicle.finance',
});
return data.apr;
}

async getReserves({ appToken }: GetDataPropsParams<Erc20>) {
const liquidity = appToken.supply * appToken.price;
return [liquidity / appToken.tokens[0].price];
Expand Down
21 changes: 1 addition & 20 deletions src/apps/beefy/common/beefy.vault.token-definition-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { ZERO_ADDRESS } from '~app-toolkit/constants/address';
import { Cache } from '~cache/cache.decorator';
import { Network } from '~types/network.interface';

type ApyData = Record<string, number>;

type BeefyMarketResponse = {
id: string;
name: string;
Expand Down Expand Up @@ -41,20 +39,8 @@ export class BeefyVaultTokenDefinitionsResolver {
return vaultData;
}

@Cache({
key: `studio:beefy:vault-apy`,
ttl: 5 * 60, // 60 minutes
})
private async getVaultApyData() {
const { data } = await Axios.get<ApyData>(`https://beefy-api.herokuapp.com/apy`);
return data;
}

async getVaultDefinitions(network: Network) {
const [definitionsDataRaw, apyData] = await Promise.all([
this.getVaultDefinitionsData(network),
this.getVaultApyData(),
]);
const definitionsDataRaw = await this.getVaultDefinitionsData(network);

const vaultDefinitions = definitionsDataRaw.map(t => {
const tokenAddress = t.tokenAddress?.toLowerCase() ?? ZERO_ADDRESS; // Beefy doesn't have the concept of ZERO address to represent ETH
Expand All @@ -74,14 +60,9 @@ export class BeefyVaultTokenDefinitionsResolver {
id: t.id,
marketName: t.name,
symbol: t.token,
apy: apyData[t.id] ?? 0,
};
});

return vaultDefinitions;
}

async getVaultApys() {
return await this.getVaultApyData();
}
}
6 changes: 0 additions & 6 deletions src/apps/beefy/common/beefy.vault.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.te
import {
DefaultAppTokenDataProps,
GetAddressesParams,
GetDataPropsParams,
GetDisplayPropsParams,
GetPricePerShareParams,
GetTokenPropsParams,
Expand All @@ -24,7 +23,6 @@ export type BeefyVaultTokenDefinition = {
id: string;
marketName: string;
symbol: string;
apy: number;
};

export abstract class BeefyVaultTokenFetcher extends AppTokenTemplatePositionFetcher<
Expand Down Expand Up @@ -72,8 +70,4 @@ export abstract class BeefyVaultTokenFetcher extends AppTokenTemplatePositionFet
async getLabel({ appToken }: GetDisplayPropsParams<BeefyVaultToken>) {
return `${getLabelFromToken(appToken.tokens[0])} Vault`;
}

getApy({ definition }: GetDataPropsParams<BeefyVaultToken, DefaultAppTokenDataProps, BeefyVaultTokenDefinition>) {
return Promise.resolve(definition.apy * 100);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Inject } from '@nestjs/common';
import Axios from 'axios';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { Performance } from '~apps/hedgefarm/avalanche/hedgefarm.types';
import { CacheOnInterval } from '~cache/cache-on-interval.decorator';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import { GetDataPropsParams, GetPricePerShareParams } from '~position/template/app-token.template.types';
import { GetPricePerShareParams } from '~position/template/app-token.template.types';

import { HedgefarmViemContractFactory } from '../contracts';
import { AlphaTwo } from '../contracts/viem';
Expand Down Expand Up @@ -37,19 +34,4 @@ export class AvalancheHedgefarmAlphaTwoTokenFetcher extends AppTokenTemplatePosi
async getPricePerShare({ contract }: GetPricePerShareParams<AlphaTwo>) {
return [Number(await contract.read.lastUpdatedPricePerShare()) / 10 ** 8];
}

async getApy(_params: GetDataPropsParams<AlphaTwo>) {
const performance = await this.getPerformance();
return performance.averageApy;
}

@CacheOnInterval({
key: `studio:hedgefarm:alpha-two:performance`,
timeout: 15 * 60 * 1000,
failOnMissingData: false,
})
async getPerformance(): Promise<Performance> {
const url = 'https://api.hedgefarm.workers.dev/alpha2/performance';
return await Axios.get<Performance>(url).then(v => v.data);
}
}
34 changes: 0 additions & 34 deletions src/apps/openleverage/common/openleverage-pool.apy-helper.ts

This file was deleted.

13 changes: 1 addition & 12 deletions src/apps/openleverage/common/openleverage.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.te
import {
GetUnderlyingTokensParams,
GetPricePerShareParams,
GetDataPropsParams,
GetDisplayPropsParams,
} from '~position/template/app-token.template.types';

import { OpenleverageViemContractFactory } from '../contracts';
import { OpenleverageLpool } from '../contracts/viem';

import { OpenleveragePoolAPYHelper } from './openleverage-pool.apy-helper';

type OpenLeveragePoolsResponse = {
pools: {
id: string;
Expand All @@ -36,8 +33,6 @@ export abstract class OpenleveragePoolTokenFetcher extends AppTokenTemplatePosit

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(OpenleveragePoolAPYHelper)
private readonly openleveragePoolAPYHelper: OpenleveragePoolAPYHelper,
@Inject(OpenleverageViemContractFactory) protected readonly contractFactory: OpenleverageViemContractFactory,
) {
super(appToolkit);
Expand Down Expand Up @@ -66,13 +61,7 @@ export abstract class OpenleveragePoolTokenFetcher extends AppTokenTemplatePosit
return [exchangeRate];
}

async getApy({ appToken }: GetDataPropsParams<OpenleverageLpool>) {
const poolDetailMap = await this.openleveragePoolAPYHelper.getApy();
return (poolDetailMap[appToken.address]?.lendingYieldY || 0) * 100;
}

async getLabel({ appToken }: GetDisplayPropsParams<OpenleverageLpool>) {
const poolDetailMap = await this.openleveragePoolAPYHelper.getApy();
return getLabelFromToken(appToken.tokens[0]) + '/' + poolDetailMap[appToken.address]?.token1Symbol;
return getLabelFromToken(appToken.tokens[0]);
}
}
5 changes: 1 addition & 4 deletions src/apps/openleverage/openleverage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { Module } from '@nestjs/common';
import { AbstractApp } from '~app/app.dynamic-module';

import { BinanceSmartChainOpenleveragePoolTokenFetcher } from './binance-smart-chain/openleverage.pool.token-fetcher';
import { OpenleveragePoolAPYHelper } from './common/openleverage-pool.apy-helper';
import { OpenleverageViemContractFactory } from './contracts';
import { EthereumOpenleveragePoolTokenFetcher } from './ethereum/openleverage.pool.token-fetcher';

@Module({
providers: [
OpenleverageViemContractFactory,
EthereumOpenleveragePoolTokenFetcher,
BinanceSmartChainOpenleveragePoolTokenFetcher,

OpenleverageViemContractFactory,
OpenleveragePoolAPYHelper,
],
})
export class OpenleverageAppModule extends AbstractApp() {}

0 comments on commit dd406a4

Please sign in to comment.