Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Jan 18, 2024
1 parent 48c1f90 commit 00fd3e0
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions modules/pool/subgraph-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const subgraphToPrismaCreate = (
const prismaPoolRecordWithAssociations = {
data: {
...dbData.base,
poolTypeSpecificData: dbData.data,
poolTypeSpecificData: dbData.staticTypeData,
tokens: {
createMany: {
data: dbData.tokens,
Expand All @@ -31,7 +31,7 @@ export const subgraphToPrismaCreate = (
? {
create: {
id: dbData.base.id,
...(dbData.data as ReturnType<typeof dataMapper['LINEAR']>),
...(dbData.staticTypeData as ReturnType<typeof staticTypeDataMapper['LINEAR']>),
},
}
: undefined,
Expand All @@ -40,15 +40,15 @@ export const subgraphToPrismaCreate = (
? {
create: {
id: dbData.base.id,
...(dbData.data as ReturnType<typeof dataMapper['ELEMENT']>),
...(dbData.staticTypeData as ReturnType<typeof staticTypeDataMapper['ELEMENT']>),
},
}
: undefined,
gyroData: ['GYRO', 'GYRO3', 'GYROE'].includes(dbData.base.type)
? {
create: {
id: dbData.base.id,
...(dbData.data as ReturnType<typeof dataMapper['GYRO']>),
...(dbData.staticTypeData as ReturnType<typeof staticTypeDataMapper['GYRO']>),
},
}
: undefined,
Expand All @@ -57,15 +57,15 @@ export const subgraphToPrismaCreate = (
? {
create: {
id: dbData.base.id,
...(dbData.dynamicTypeData as ReturnType<typeof dynamicMapper['LINEAR']>),
...(dbData.dynamicTypeData as ReturnType<typeof dynamicTypeDataMapper['LINEAR']>),
},
}
: undefined,
stableDynamicData: ['STABLE', 'COMPOSABLE_STABLE', 'META_STABLE'].includes(dbData.base.type)
? {
create: {
id: dbData.base.id,
...(dbData.dynamicTypeData as ReturnType<typeof dynamicMapper['STABLE']>),
...(dbData.dynamicTypeData as ReturnType<typeof dynamicTypeDataMapper['STABLE']>),
},
}
: undefined,
Expand All @@ -86,7 +86,7 @@ export const subgraphToPrismaUpdate = (

const prismaPoolRecordWithDataAssociations = {
...baseWithoutId,
poolTypeSpecificData: dbData.data,
poolTypeSpecificData: dbData.staticTypeData,
tokens: {
update: dbData.tokens.map((token) => ({
where: {
Expand All @@ -104,37 +104,37 @@ export const subgraphToPrismaUpdate = (
dbData.base.type === 'LINEAR'
? {
update: {
...(dbData.data as ReturnType<typeof dataMapper['LINEAR']>),
...(dbData.staticTypeData as ReturnType<typeof staticTypeDataMapper['LINEAR']>),
},
}
: undefined,
elementData:
dbData.base.type === 'ELEMENT'
? {
update: {
...(dbData.data as ReturnType<typeof dataMapper['ELEMENT']>),
...(dbData.staticTypeData as ReturnType<typeof staticTypeDataMapper['ELEMENT']>),
},
}
: undefined,
gyroData: ['GYRO', 'GYRO3', 'GYROE'].includes(dbData.base.type)
? {
update: {
...(dbData.data as ReturnType<typeof dataMapper['GYRO']>),
...(dbData.staticTypeData as ReturnType<typeof staticTypeDataMapper['GYRO']>),
},
}
: undefined,
linearDynamicData:
dbData.base.type === 'LINEAR'
? {
update: {
...(dbData.dynamicTypeData as ReturnType<typeof dynamicMapper['LINEAR']>),
...(dbData.dynamicTypeData as ReturnType<typeof dynamicTypeDataMapper['LINEAR']>),
},
}
: undefined,
stableDynamicData: ['STABLE', 'COMPOSABLE_STABLE', 'META_STABLE'].includes(dbData.base.type)
? {
update: {
...(dbData.dynamicTypeData as ReturnType<typeof dynamicMapper['STABLE']>),
...(dbData.dynamicTypeData as ReturnType<typeof dynamicTypeDataMapper['STABLE']>),
},
}
: undefined,
Expand Down Expand Up @@ -175,12 +175,14 @@ const subgraphMapper = (
totalLiquidity: Math.max(parseFloat(pool.totalLiquidity), 0),
};

const data: ReturnType<typeof dataMapper[keyof typeof dataMapper]> | {} = Object.keys(dataMapper).includes(type)
? dataMapper[type as keyof typeof dataMapper](pool)
const staticTypeData: ReturnType<typeof staticTypeDataMapper[keyof typeof staticTypeDataMapper]> | {} = Object.keys(
staticTypeDataMapper,
).includes(type)
? staticTypeDataMapper[type as keyof typeof staticTypeDataMapper](pool)
: {};

const dynamicTypeData = Object.keys(dynamicMapper).includes(type)
? dynamicMapper[type as keyof typeof dynamicMapper](pool, blockNumber)
const dynamicTypeData = Object.keys(dynamicTypeDataMapper).includes(type)
? dynamicTypeDataMapper[type as keyof typeof dynamicTypeDataMapper](pool, blockNumber)
: {};

const tokens =
Expand Down Expand Up @@ -211,7 +213,7 @@ const subgraphMapper = (
base,
dynamicData,
tokens,
data,
staticTypeData,
dynamicTypeData,
};
};
Expand Down Expand Up @@ -265,7 +267,7 @@ const mapPoolTypeVersion = (poolType: string, poolTypeVersion: number): number =
return version;
};

const dataMapper = {
const staticTypeDataMapper = {
ELEMENT: element,
FX: fx,
GYRO: gyro,
Expand All @@ -274,7 +276,7 @@ const dataMapper = {
LINEAR: linear,
};

const dynamicMapper = {
const dynamicTypeDataMapper = {
STABLE: stableDynamic,
COMPOSABLE_STABLE: stableDynamic,
META_STABLE: stableDynamic,
Expand Down

0 comments on commit 00fd3e0

Please sign in to comment.