Skip to content

Commit

Permalink
fix pool type mapping for StablePhantom
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Jan 11, 2024
1 parent 14dcc83 commit f09f5b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions modules/pool/subgraph-mapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { subgraphToPrisma } from './subgraph-mapper';
import { subgraphToPrismaCreate } from './subgraph-mapper';
import { poolFactory, poolTokenFactory } from '../../test/factories';

describe('subgraphToPrisma', () => {
describe('subgraphToPrismaCreate', () => {
const weightedPool = poolFactory.build({
poolType: 'Weighted',
});
Expand All @@ -11,6 +11,11 @@ describe('subgraphToPrisma', () => {
amp: '0.1',
});

const oldStablePool = poolFactory.build({
poolType: 'StablePhantom',
amp: '0.1',
});

const linearPool = poolFactory.build({
poolType: 'Linear',
wrappedIndex: 1,
Expand All @@ -34,38 +39,45 @@ describe('subgraphToPrisma', () => {
});

it('should return correct object for weighted pool', () => {
const result = subgraphToPrisma(weightedPool, 'MAINNET', 1, []);
const result = subgraphToPrismaCreate(weightedPool, 'MAINNET', 1, []);
expect(result.data.type).toBe('WEIGHTED');
});

it('should return correct object for stable pool', () => {
const result = subgraphToPrisma(stablePool, 'MAINNET', 1, []);
const result = subgraphToPrismaCreate(stablePool, 'MAINNET', 1, []);
expect(result.data.type).toBe('COMPOSABLE_STABLE');
expect(result.data.stableDynamicData?.create.amp).toBe(stablePool.amp);
});

it('should return correct object for old stable pool', () => {
const result = subgraphToPrismaCreate(oldStablePool, 'MAINNET', 1, []);
expect(result.data.type).toBe('COMPOSABLE_STABLE');
expect(result.data.version).toBe(0);
expect(result.data.stableDynamicData?.create.amp).toBe(oldStablePool.amp);
});

it('should return correct object for linear pool', () => {
const result = subgraphToPrisma(linearPool, 'MAINNET', 1, []);
const result = subgraphToPrismaCreate(linearPool, 'MAINNET', 1, []);
expect(result.data.type).toBe('LINEAR');
expect(result.data.linearDynamicData?.create.upperTarget).toBe(linearPool.upperTarget);
expect(result.data.linearData?.create.wrappedIndex).toBe(linearPool.wrappedIndex);
});

it('should return correct object for element pool', () => {
const result = subgraphToPrisma(elementPool, 'MAINNET', 1, []);
const result = subgraphToPrismaCreate(elementPool, 'MAINNET', 1, []);
expect(result.data.type).toBe('ELEMENT');
expect(result.data.elementData?.create.principalToken).toBe(elementPool.principalToken);
});

it('should return correct object for gyro pool', () => {
const result = subgraphToPrisma(gyroPool, 'MAINNET', 1, []);
const result = subgraphToPrismaCreate(gyroPool, 'MAINNET', 1, []);
expect(result.data.type).toBe('GYROE');
expect(result.data.gyroData?.create.alpha).toBe(gyroPool.alpha);
expect(result.data.gyroData?.create.tauAlphaX).toBe(gyroPool.tauAlphaX);
});

it('should return correct object for fx pool', () => {
const result = subgraphToPrisma(fxPool, 'MAINNET', 1, []);
const result = subgraphToPrismaCreate(fxPool, 'MAINNET', 1, []);
expect(result.data.type).toBe('FX');
expect(result.data.data['alpha']).toBe(gyroPool.alpha);
});
Expand All @@ -83,7 +95,7 @@ describe('subgraphToPrisma', () => {
});

it('should recognise nested pools', () => {
const result = subgraphToPrisma(poolWithNestedPools, 'MAINNET', 1, nestedPools);
const result = subgraphToPrismaCreate(poolWithNestedPools, 'MAINNET', 1, nestedPools);
expect(result.data.type).toBe('COMPOSABLE_STABLE');
expect(result.data.tokens.createMany.data[0].nestedPoolId).toBe(linearPool.id);
});
Expand Down
2 changes: 1 addition & 1 deletion modules/pool/subgraph-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const subgraphMapper = (
nestedPools: { id: string; address: string }[],
) => {
const type = mapSubgraphPoolTypeToPoolType(pool.poolType!);
const version = mapPoolTypeVersion(type, pool.poolTypeVersion!);
const version = mapPoolTypeVersion(pool.poolType!, pool.poolTypeVersion!);

const base = {
id: pool.id,
Expand Down

0 comments on commit f09f5b1

Please sign in to comment.