Skip to content

Commit

Permalink
Pricing revamp (#180)
Browse files Browse the repository at this point in the history
* price handler helper

* linear

* price handlers

* remove unused

* fix

* pass chain as param

* more chain passing

* remove unused

* redo updates

* remove unused

* adding retrieval of historical prices

* fix historical pricing

---------

Co-authored-by: gmbronco <[email protected]>
  • Loading branch information
franzns and gmbronco authored Mar 11, 2024
1 parent 265da76 commit f64a491
Show file tree
Hide file tree
Showing 51 changed files with 817 additions and 1,231 deletions.
7 changes: 5 additions & 2 deletions modules/actions/pool/update-on-chain-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ export async function updateOnChainDataForPools(
balanceUSD:
poolToken.address === pool.address
? 0
: tokenService.getPriceForToken(tokenPricesForCurrentChain, poolToken.address) *
parseFloat(balance),
: tokenService.getPriceForToken(
tokenPricesForCurrentChain,
poolToken.address,
chain,
) * parseFloat(balance),
},
}),
);
Expand Down
2 changes: 1 addition & 1 deletion modules/beets/beets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class BeetsService {

public async getBeetsPrice(): Promise<string> {
const tokenPrices = await tokenService.getTokenPrices();
return tokenService.getPriceForToken(tokenPrices, networkContext.data.beets!.address).toString();
return tokenService.getPriceForToken(tokenPrices, networkContext.data.beets!.address, 'FANTOM').toString();
}
}

Expand Down
12 changes: 0 additions & 12 deletions modules/coingecko/coingecko-types.ts

This file was deleted.

247 changes: 0 additions & 247 deletions modules/coingecko/coingecko.service.ts

This file was deleted.

10 changes: 6 additions & 4 deletions modules/datastudio/datastudio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { oneDayInSeconds, secondsPerDay } from '../common/time';
import { isComposableStablePool, isWeightedPoolV2 } from '../pool/lib/pool-utils';
import { networkContext } from '../network/network-context.service';
import { DeploymentEnv } from '../network/network-config-types';
import { Chain } from '@prisma/client';

export class DatastudioService {
constructor(private readonly secretsManager: SecretsManager, private readonly jwtClientHelper: GoogleJwtClient) {}

public async feedPoolData() {
public async feedPoolData(chain: Chain) {
const privateKey = await this.secretsManager.getSecret('backend-v3-datafeed-privatekey');
const jwtClient = await this.jwtClientHelper.getAuthorizedSheetsClient(privateKey);

Expand Down Expand Up @@ -89,7 +90,7 @@ export class DatastudioService {
dynamicData: {
totalLiquidity: { gte: 5000 },
},
chain: networkContext.chain,
chain: chain,
},
include: {
dynamicData: true,
Expand Down Expand Up @@ -265,7 +266,8 @@ export class DatastudioService {
}
const rewardsPerDay = parseFloat(rewarder.rewardPerSecond) * secondsPerDay;
const rewardsValuePerDay =
tokenService.getPriceForToken(tokenPrices, rewarder.tokenAddress) * rewardsPerDay;
tokenService.getPriceForToken(tokenPrices, rewarder.tokenAddress, chain) *
rewardsPerDay;
if (rewardsPerDay > 0) {
allEmissionDataRows.push([
endOfYesterday.format('DD MMM YYYY'),
Expand Down Expand Up @@ -309,7 +311,7 @@ export class DatastudioService {
}
const rewardsPerDay = parseFloat(reward.rewardPerSecond) * secondsPerDay;
const rewardsValuePerDay =
tokenService.getPriceForToken(tokenPrices, reward.tokenAddress) * rewardsPerDay;
tokenService.getPriceForToken(tokenPrices, reward.tokenAddress, chain) * rewardsPerDay;
if (rewardsPerDay > 0) {
allEmissionDataRows.push([
endOfYesterday.format('DD MMM YYYY'),
Expand Down
11 changes: 0 additions & 11 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/boosted-pool
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/swap-fee-apr.service';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { GaugeStakingService } from '../pool/lib/staking/gauge-staking.service';
import { BptPriceHandlerService } from '../token/lib/token-price-handlers/bpt-price-handler.service';
import { LinearWrappedTokenPriceHandlerService } from '../token/lib/token-price-handlers/linear-wrapped-token-price-handler.service';
import { SwapsPriceHandlerService } from '../token/lib/token-price-handlers/swaps-price-handler.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../worker/intervals';
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 { 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';
Expand Down Expand Up @@ -227,12 +222,6 @@ export const arbitrumNetworkConfig: NetworkConfig = {
new GaugeAprService(tokenService, [arbitrumNetworkData.bal!.address]),
],
poolStakingServices: [new GaugeStakingService(gaugeSubgraphService, arbitrumNetworkData.bal!.address)],
tokenPriceHandlers: [
new CoingeckoPriceHandlerService(coingeckoService),
new BptPriceHandlerService(),
new LinearWrappedTokenPriceHandlerService(),
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(
Expand Down
11 changes: 0 additions & 11 deletions modules/network/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/boosted-pool
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/swap-fee-apr.service';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { GaugeStakingService } from '../pool/lib/staking/gauge-staking.service';
import { BptPriceHandlerService } from '../token/lib/token-price-handlers/bpt-price-handler.service';
import { LinearWrappedTokenPriceHandlerService } from '../token/lib/token-price-handlers/linear-wrapped-token-price-handler.service';
import { SwapsPriceHandlerService } from '../token/lib/token-price-handlers/swaps-price-handler.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../worker/intervals';
import { GithubContentService } from '../content/github-content.service';
import { gaugeSubgraphService } from '../subgraphs/gauge-subgraph/gauge-subgraph.service';
import { coingeckoService } from '../coingecko/coingecko.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { env } from '../../app/env';
import { YbTokensAprService } from '../pool/lib/apr-data-sources/yb-tokens-apr.service';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';
Expand Down Expand Up @@ -202,12 +197,6 @@ export const avalancheNetworkConfig: NetworkConfig = {
new GaugeAprService(tokenService, [avalancheNetworkData.bal!.address]),
],
poolStakingServices: [new GaugeStakingService(gaugeSubgraphService, avalancheNetworkData.bal!.address)],
tokenPriceHandlers: [
new CoingeckoPriceHandlerService(coingeckoService),
new BptPriceHandlerService(),
new LinearWrappedTokenPriceHandlerService(),
new SwapsPriceHandlerService(),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(
Expand Down
Loading

0 comments on commit f64a491

Please sign in to comment.