Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for FX pools #29

Merged
merged 23 commits into from
Jan 18, 2024
Merged

Add support for FX pools #29

merged 23 commits into from
Jan 18, 2024

Conversation

gmbronco
Copy link
Collaborator

This pull request adds:

  • support for FX pools by adding a parser for the subgraph data. In the mapper I'm extracting the structure we had in the pool-creator-service and splitting it into two parts:
    • mapping data from subgraph to DB schema
    • building prisma create object with all the nested tables.
      This helps with testing and adding updates, or upserts will be easier, since we have the clean data object.
  • I changed foreign keys constrains related to pools to allow for deleting a pool with all associated records.
  • added fishery for setting up object factories in tests

Copy link
Collaborator

@franzns franzns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall nice changes! I wonder whether we should extract the json thing to it's own PR and make it for all pool types, maybe even including pool specific dynamic data.

nestedPools: { id: string; address: string }[],
) => {
const type = mapSubgraphPoolTypeToPoolType(pool.poolType!);
const version = mapPoolTypeVersion(type, pool.poolTypeVersion!);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to pass pool.poolType other wise it wont ever have phantonStable as pool type

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

import { Chain, PrismaPoolType } from '@prisma/client';
import { BalancerPoolFragment } from '../subgraphs/balancer-subgraph/generated/balancer-subgraph-types';
import { AddressZero } from '@ethersproject/constants';
import * as dataMappers from './pool-data';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we explicitely import the dataMappers instead of doing it with wildcards and exports?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely, we have the option to individually import all the dataMappers. before I change that, let me ask what you think. my rationale for using a namespace is to keep it clear where these functions are coming from. especially around handling types. to make it work with individual imports i'd probably need to add a suffix, like fxDataMapper and it would end up quite similar to the current dataMappers.fx.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to have all the imported functions in the header.

const prismaPoolRecordWithAssociations = {
data: {
...dbData.base,
data: dbData.data, // DISCUSS: simplify DB schema by migrating from individual tables to a JSON column with types enforced on read. And same with dynamic data.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few thoughts:

  • instead if calling it data we should call it poolTypeSpecificData
  • If I understand this correctly, fxPool type data is only under data but linear, stable etc. speicifc data is under their own tables AND under data? I wonder if we should remove the data from this PR and export that change into its own PR, also removing the pool type specific tables.
  • Adding to above suggested to extract that change to its own PR: It could then also get rid of the pool type specific dynamic data tables and have a poolTypeSpecificDynamicData column (or table? thinking about update patterns)
  • Are we sure that we dont use/aggregate the data in the pool type specific tables? (or dynamic data tables?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data column in now renamed to poolTypeSpecificData. Ready to start the work on migrating other tables in the new PR.

@@ -192,18 +132,13 @@ export class PoolCreatorService {
await prismaBulkExecuteOperations(operations);
}

private async createPoolRecord(pool: BalancerPoolFragment, blockNumber: number) {
const poolType = this.mapSubgraphPoolTypeToPoolType(pool.poolType || '');
private async createPoolRecord(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also needs to pass the nestedPools when called in syncNewPoolsFromSubgraph?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, fixed

expect(result.data.type).toBe('WEIGHTED');
});

it('should return correct object for stable pool', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test for phantom stable, will probably fail

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added one and it was failing indeed.

modules/pool/pool-data/fx.ts Show resolved Hide resolved
@@ -65,7 +66,7 @@ model PrismaPoolLinearData {

id String
poolId String
pool PrismaPool @relation(fields:[poolId, chain], references: [id, chain])
pool PrismaPool @relation(fields:[poolId, chain], references: [id, chain], onDelete: Cascade)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are delete cascade now, maybe we can also simplify poolService.deletePool()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, cleaned it up a bit

Copy link
Collaborator

@franzns franzns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall nice changes! I wonder whether we should extract the json thing to it's own PR and make it for all pool types, maybe even including pool specific dynamic data.

Copy link
Collaborator

@franzns franzns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we leave out the dynamicData for now?
Also, we are now saving the poolSpecificData for all pool types, but are not reading it. Only for fx pools. Are you planning to extract the 'jsob' from this PR or are you creating a new PR with that uses the data on the 'jsonb' column? I would not add it here, as this PR is already big enough..

Comment on lines +288 to +289
export type StableDynamicData = ReturnType<typeof stableDynamic>;
export type LinearDynamicData = ReturnType<typeof linearDynamic>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this? it's unused afaik.

Comment on lines 277 to 281
const dynamicMapper = {
STABLE: dataMappers.stableDynamic,
COMPOSABLE_STABLE: dataMappers.stableDynamic,
META_STABLE: dataMappers.stableDynamic,
LINEAR: dataMappers.linearDynamic,
STABLE: stableDynamic,
COMPOSABLE_STABLE: stableDynamic,
META_STABLE: stableDynamic,
LINEAR: linearDynamic,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this? it's unused afaik.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapper is subgraph schema related, so more data we parse to DB schema the better. think about it as a layer. it makes it easy to compose what is needed for any pool syncing we would want to do.

we still read these data from subgraph in pool create jobs, once removed where would it go? just keep it blank until onchain calls fill it in?

@gmbronco
Copy link
Collaborator Author

I'd like to merge it as it is. Next steps:

  • migrate other pool types data tables to jsonb
  • and dynamic data to jsonb

Perhaps in 2 PRs, to keep it easy on us.

@franzns franzns merged commit bf17d89 into v3-canary Jan 18, 2024
1 check passed
@gmbronco gmbronco deleted the fix-fx branch March 11, 2024 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants