Skip to content

Commit

Permalink
Merge branch 'feat/pricing-revamp' of github.com:balancer/backend int…
Browse files Browse the repository at this point in the history
…o feat/pricing-revamp
  • Loading branch information
franzns committed Mar 1, 2024
2 parents 4e7a85b + ae4f263 commit f286ca2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
15 changes: 6 additions & 9 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,11 +266,8 @@ export class DatastudioService {
}
const rewardsPerDay = parseFloat(rewarder.rewardPerSecond) * secondsPerDay;
const rewardsValuePerDay =
tokenService.getPriceForToken(
tokenPrices,
rewarder.tokenAddress,
networkContext.chain,
) * rewardsPerDay;
tokenService.getPriceForToken(tokenPrices, rewarder.tokenAddress, chain) *
rewardsPerDay;
if (rewardsPerDay > 0) {
allEmissionDataRows.push([
endOfYesterday.format('DD MMM YYYY'),
Expand Down Expand Up @@ -313,8 +311,7 @@ export class DatastudioService {
}
const rewardsPerDay = parseFloat(reward.rewardPerSecond) * secondsPerDay;
const rewardsValuePerDay =
tokenService.getPriceForToken(tokenPrices, reward.tokenAddress, networkContext.chain) *
rewardsPerDay;
tokenService.getPriceForToken(tokenPrices, reward.tokenAddress, chain) * rewardsPerDay;
if (rewardsPerDay > 0) {
allEmissionDataRows.push([
endOfYesterday.format('DD MMM YYYY'),
Expand Down
17 changes: 9 additions & 8 deletions modules/pool/lib/pool-apr-updater.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PoolAprService } from '../pool-types';
import _ from 'lodash';
import { prismaBulkExecuteOperations } from '../../../prisma/prisma-util';
import { networkContext } from '../../network/network-context.service';
import { Chain } from '@prisma/client';

export class PoolAprUpdaterService {
constructor() {}
Expand All @@ -13,10 +14,10 @@ export class PoolAprUpdaterService {
return networkContext.config.poolAprServices;
}

public async updatePoolAprs() {
public async updatePoolAprs(chain: Chain) {
const pools = await prisma.prismaPool.findMany({
...poolWithTokens,
where: { chain: networkContext.chain },
where: { chain: chain },
});

const failedAprServices = [];
Expand All @@ -31,7 +32,7 @@ export class PoolAprUpdaterService {
}

const aprItems = await prisma.prismaPoolAprItem.findMany({
where: { chain: networkContext.chain },
where: { chain: chain },
select: { poolId: true, apr: true },
});

Expand All @@ -42,7 +43,7 @@ export class PoolAprUpdaterService {
for (const poolId in grouped) {
operations.push(
prisma.prismaPoolDynamicData.update({
where: { id_chain: { id: poolId, chain: networkContext.chain } },
where: { id_chain: { id: poolId, chain: chain } },
data: { apr: _.sumBy(grouped[poolId], (item) => item.apr) },
}),
);
Expand All @@ -54,9 +55,9 @@ export class PoolAprUpdaterService {
}
}

public async reloadAllPoolAprs() {
await prisma.prismaPoolAprRange.deleteMany({ where: { chain: networkContext.chain } });
await prisma.prismaPoolAprItem.deleteMany({ where: { chain: networkContext.chain } });
await this.updatePoolAprs();
public async reloadAllPoolAprs(chain: Chain) {
await prisma.prismaPoolAprRange.deleteMany({ where: { chain: chain } });
await prisma.prismaPoolAprItem.deleteMany({ where: { chain: chain } });
await this.updatePoolAprs(chain);
}
}
4 changes: 2 additions & 2 deletions modules/pool/pool.gql
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ extend type Mutation {
poolUpdateVolumeAndFeeValuesForAllPools: String!
poolSyncSwapsForLast48Hours: String!
poolSyncSanityPoolData: String!
poolUpdateAprs: String!
poolUpdateAprs(chain: GqlChain!): String!
poolSyncPoolAllTokensRelationship: String!
poolReloadAllPoolAprs: String!
poolReloadAllPoolAprs(chain: GqlChain!): String!
poolSyncTotalShares: String!
poolReloadStakingForAllPools(stakingTypes: [GqlPoolStakingType!]!): String!
poolSyncStakingForPools: String!
Expand Down
8 changes: 4 additions & 4 deletions modules/pool/pool.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ const balancerResolvers: Resolvers = {

return 'success';
},
poolUpdateAprs: async (parent, {}, context) => {
poolUpdateAprs: async (parent, { chain }, context) => {
isAdminRoute(context);

await poolService.updatePoolAprs();
await poolService.updatePoolAprs(chain);

return 'success';
},
Expand All @@ -177,10 +177,10 @@ const balancerResolvers: Resolvers = {

return 'success';
},
poolReloadAllPoolAprs: async (parent, {}, context) => {
poolReloadAllPoolAprs: async (parent, { chain }, context) => {
isAdminRoute(context);

await poolService.reloadAllPoolAprs();
await poolService.reloadAllPoolAprs(chain);

return 'success';
},
Expand Down
8 changes: 4 additions & 4 deletions modules/pool/pool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ export class PoolService {
await Promise.all(this.poolStakingServices.map((stakingService) => stakingService.syncStakingForPools()));
}

public async updatePoolAprs() {
await this.poolAprUpdaterService.updatePoolAprs();
public async updatePoolAprs(chain: Chain) {
await this.poolAprUpdaterService.updatePoolAprs(chain);
}

public async syncChangedPools() {
await this.poolSyncService.syncChangedPools();
}

public async reloadAllPoolAprs() {
await this.poolAprUpdaterService.reloadAllPoolAprs();
public async reloadAllPoolAprs(chain: Chain) {
await this.poolAprUpdaterService.reloadAllPoolAprs(chain);
}

public async updateLiquidity24hAgoForAllPools() {
Expand Down
23 changes: 21 additions & 2 deletions worker/job-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { syncLatestFXPrices } from '../modules/token/latest-fx-price';
import { AllNetworkConfigs } from '../modules/network/network-config';
import { sftmxService } from '../modules/sftmx/sftmx.service';
import { JobsController } from '../modules/controllers/jobs-controller';
import { chainIdToChain } from '../modules/network/chain-id-to-chain';

const runningJobs: Set<string> = new Set();

Expand Down Expand Up @@ -162,7 +163,16 @@ export function configureWorkerRoutes(app: Express) {
);
break;
case 'update-pool-apr':
await runIfNotAlreadyRunning(job.name, chainId, () => poolService.updatePoolAprs(), res, next);
await runIfNotAlreadyRunning(
job.name,
chainId,
() => {
const chain = chainIdToChain[chainId];
return poolService.updatePoolAprs(chain);
},
res,
next,
);
break;
case 'load-on-chain-data-for-pools-with-active-updates':
await runIfNotAlreadyRunning(
Expand Down Expand Up @@ -282,7 +292,16 @@ export function configureWorkerRoutes(app: Express) {
);
break;
case 'feed-data-to-datastudio':
await runIfNotAlreadyRunning(job.name, chainId, () => datastudioService.feedPoolData(), res, next);
await runIfNotAlreadyRunning(
job.name,
chainId,
() => {
const chain = chainIdToChain[chainId];
return datastudioService.feedPoolData(chain);
},
res,
next,
);
break;
case 'sync-latest-reliquary-snapshots':
await runIfNotAlreadyRunning(
Expand Down

0 comments on commit f286ca2

Please sign in to comment.