Skip to content

Commit

Permalink
upsert task
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Mar 7, 2024
1 parent 29dfa03 commit a56a538
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions modules/controllers/jobs-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ export function JobsController(tracer?: any) {

await upsertPools(newPools, viemClient, vaultAddress, chain, latestBlock);
},
/**
* Adds new pools found in subgraph to the database
*
* @param chainId
*/
async upsertPools(chainId: string) {
const chain = chainIdToChain[chainId];
const {
subgraphs: { balancerV3, balancerPoolsV3 },
balancer: {
v3: { vaultAddress },
},
} = config[chain];

// Guard against unconfigured chains
if (!balancerV3 || !balancerPoolsV3 || !vaultAddress) {
throw new Error(`Chain not configured: ${chain}`);
}

const client = getV3JoinedSubgraphClient(balancerV3, balancerPoolsV3);
const allPools = await client.getAllInitializedPools();

const viemClient = getViemClient(chain);
const latestBlock = await viemClient.getBlockNumber();

await upsertPools(allPools, viemClient, vaultAddress, chain, latestBlock);
},
/**
* Syncs database pools state with the onchain state
*
Expand Down

0 comments on commit a56a538

Please sign in to comment.