Skip to content

Commit

Permalink
create tokens on update (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco authored Jan 31, 2024
1 parent efb1ded commit c52ca85
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/pool/lib/pool-creator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class PoolCreatorService {
let counter = 1;
for (const subgraphPool of sortedSubgraphPools) {
console.log(`Syncing pool ${counter} of ${sortedSubgraphPools.length}`);
console.log(`Pool ID: ${subgraphPool.id}`);
counter = counter + 1;
const existsInDb = !!existingPools.find((pool) => pool.id === subgraphPool.id);

Expand Down Expand Up @@ -200,6 +201,27 @@ export class PoolCreatorService {
const { tokens, ...poolWithoutTokens } = prismaPoolRecordWithAssociations;

// Make sure all tokens are there, for managed pools tokenlist can change
// Sometimes the token is not in the DB, so we need to create it
await prisma.prismaToken.createMany({
skipDuplicates: true,
data: [
...pool.tokens!.map((token) => ({
address: token.address,
symbol: token.symbol,
name: token.name,
decimals: token.decimals,
chain: this.chain,
})),
{
address: pool.address,
symbol: pool.symbol || '',
name: pool.name || '',
decimals: 18,
chain: this.chain,
},
],
});

for (const token of tokens.update) {
await prisma.prismaPoolToken.upsert({
where: token.where,
Expand Down

0 comments on commit c52ca85

Please sign in to comment.