Skip to content

Commit

Permalink
more chain passing
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Mar 1, 2024
1 parent c71fcef commit ae4f263
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
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
11 changes: 10 additions & 1 deletion worker/job-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,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

0 comments on commit ae4f263

Please sign in to comment.