Skip to content

Commit

Permalink
safe iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Nov 15, 2023
1 parent c6ce462 commit 7539083
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions modules/pool/lib/pool-swap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import * as Sentry from '@sentry/node';
import { AllNetworkConfigsKeyedOnChain } from '../../network/network-config';

export class PoolSwapService {
constructor(
private readonly tokenService: TokenService,
) {}
constructor(private readonly tokenService: TokenService) {}

private get balancerSubgraphService() {
return networkContext.services.balancerSubgraphService;
Expand All @@ -39,30 +37,31 @@ export class PoolSwapService {

const allChainsJoinExits: GqlPoolJoinExit[] = [];

for (const chain of args.where!.chainIn!) {
const balancerSubgraphService =
AllNetworkConfigsKeyedOnChain[chain].services.balancerSubgraphService;

const { joinExits } = await balancerSubgraphService.getPoolJoinExits({
where: { pool_in: args.where?.poolIdIn },
first,
skip: args.skip,
orderBy: JoinExit_OrderBy.Timestamp,
orderDirection: OrderDirection.Desc,
});

const mappedJoinExits: GqlPoolJoinExit[] = joinExits.map((joinExit) => ({
...joinExit,
__typename: 'GqlPoolJoinExit',
chain: chain,
poolId: joinExit.pool.id,
amounts: joinExit.amounts.map((amount, index) => ({
address: joinExit.pool.tokensList[index],
amount,
})),
}));

allChainsJoinExits.push(...mappedJoinExits);
if (args.where?.chainIn) {
for (const chain of args.where.chainIn) {
const balancerSubgraphService = AllNetworkConfigsKeyedOnChain[chain].services.balancerSubgraphService;

const { joinExits } = await balancerSubgraphService.getPoolJoinExits({
where: { pool_in: args.where?.poolIdIn },
first,
skip: args.skip,
orderBy: JoinExit_OrderBy.Timestamp,
orderDirection: OrderDirection.Desc,
});

const mappedJoinExits: GqlPoolJoinExit[] = joinExits.map((joinExit) => ({
...joinExit,
__typename: 'GqlPoolJoinExit',
chain: chain,
poolId: joinExit.pool.id,
amounts: joinExit.amounts.map((amount, index) => ({
address: joinExit.pool.tokensList[index],
amount,
})),
}));

allChainsJoinExits.push(...mappedJoinExits);
}
}

return allChainsJoinExits;
Expand All @@ -75,8 +74,7 @@ export class PoolSwapService {
first = 10,
skip = 0,
): Promise<GqlPoolJoinExit[]> {
const balancerSubgraphService =
AllNetworkConfigsKeyedOnChain[chain].services.balancerSubgraphService;
const balancerSubgraphService = AllNetworkConfigsKeyedOnChain[chain].services.balancerSubgraphService;

const { joinExits } = await balancerSubgraphService.getPoolJoinExits({
where: { pool: poolId, user: userAddress },
Expand Down Expand Up @@ -126,8 +124,7 @@ export class PoolSwapService {
first = 10,
skip = 0,
): Promise<GqlPoolSwap[]> {
const balancerSubgraphService =
AllNetworkConfigsKeyedOnChain[chain].services.balancerSubgraphService;
const balancerSubgraphService = AllNetworkConfigsKeyedOnChain[chain].services.balancerSubgraphService;

const result = await balancerSubgraphService.getSwaps({
first,
Expand Down

0 comments on commit 7539083

Please sign in to comment.