Skip to content

Commit

Permalink
sync onchain state for all pools
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Sep 27, 2024
1 parent 2f7ca9b commit dffd0b5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/actions/v2/pool/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './add-pools';
export * from './sync-pools';
export * from './sync-changed-pools';
export * from './sync-onchain-state-for-all-pools';
43 changes: 43 additions & 0 deletions modules/actions/v2/pool/sync-onchain-state-for-all-pools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Chain } from '@prisma/client';
import { prisma } from '../../../../prisma/prisma-client';
import { PoolOnChainDataService } from '../../../pool/lib/pool-on-chain-data.service';
import { getViemClient } from '../../../sources/viem-client';

export const syncOnchainStateForAllPools = async (
chain: Chain,
vaultAddress: string,
balancerQueriesAddress: string,
yieldProtocolFeePercentage: string,
swapProtocolFeePercentage: string,
gyroConfig?: string,
): Promise<string[]> => {
const viemClient = getViemClient(chain);
const latestBlock = await viemClient.getBlockNumber();

const poolOnChainDataService = new PoolOnChainDataService(() => ({
vaultAddress,
balancerQueriesAddress,
yieldProtocolFeePercentage,
swapProtocolFeePercentage,
gyroConfig,
}));

// Update status for all the pools
const ids = await prisma.prismaPool
.findMany({
where: { chain },
select: { id: true },
})
.then((pools) => pools.map((pool) => pool.id));

const tokenPrices = await prisma.prismaTokenCurrentPrice.findMany({
where: {
chain,
},
});

await poolOnChainDataService.updateOnChainStatus(ids, chain);
await poolOnChainDataService.updateOnChainData(ids, chain, Number(latestBlock), tokenPrices);

return ids;
};
20 changes: 19 additions & 1 deletion modules/controllers/v2/pools-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import config from '../../../config';
import { chainIdToChain } from '../../network/chain-id-to-chain';
import { addPools } from '../../actions/v2/pool/add-pools';
import { getV2SubgraphClient } from '../../subgraphs/balancer-subgraph';
import { syncPools, syncChangedPools } from '../../actions/v2/pool';
import { syncPools, syncChangedPools, syncOnchainStateForAllPools } from '../../actions/v2/pool';
import { getViemClient } from '../../sources/viem-client';

export function PoolsController(tracer?: any) {
Expand Down Expand Up @@ -54,5 +54,23 @@ export function PoolsController(tracer?: any) {
gyroConfig,
);
},

async syncOnchainAllPools(chainId: string) {
const chain = chainIdToChain[chainId];
const vaultAddress = config[chain].balancer.v2.vaultAddress;
const balancerQueriesAddress = config[chain].balancer.v2.balancerQueriesAddress;
const yieldProtocolFeePercentage = config[chain].balancer.v2.defaultYieldFeePercentage;
const swapProtocolFeePercentage = config[chain].balancer.v2.defaultSwapFeePercentage;
const gyroConfig = config[chain].gyro?.config;

return syncOnchainStateForAllPools(
chain,
vaultAddress,
balancerQueriesAddress,
yieldProtocolFeePercentage,
swapProtocolFeePercentage,
gyroConfig,
);
},
};
}
2 changes: 2 additions & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ async function run(job: string = process.argv[2], chain: string = process.argv[3
return V2.PoolsController().syncPools(chain);
} else if (job === 'sync-changed-pools-v2') {
return V2.PoolsController().syncChangedPools(chain);
} else if (job === 'sync-all-pools-v2') {
return V2.PoolsController().syncOnchainAllPools(chain);
} else if (job === 'add-pools-v3') {
return PoolController().addPoolsV3(chain);
} else if (job === 'reload-pools-v3') {
Expand Down

0 comments on commit dffd0b5

Please sign in to comment.