Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-foxes-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': patch
---

add price chart for fixed lbp
4 changes: 2 additions & 2 deletions apps/api/gql/generated-schema-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3570,7 +3570,6 @@ export const schema = gql`
cumulativeFees: Float!
cumulativeVolume: Float!
fees: Float!
intervalTimestamp: Int! @deprecated
projectTokenBalance: Float!
projectTokenPrice: Float!
reservePrice: Float!
Expand Down Expand Up @@ -3701,7 +3700,8 @@ export const schema = gql`
id: String!
range: GqlPoolSnapshotDataRange!
): [GqlReliquaryFarmSnapshot!]!
lbpPriceChart(chain: GqlChain!, dataPoints: Int, id: String!, interval: Int @deprecated): [LBPPriceChartData!]
fixedLbpPriceChart(chain: GqlChain!, dataPoints: Int, id: String!): [LBPPriceChartData!]
lbpPriceChart(chain: GqlChain!, dataPoints: Int, id: String!): [LBPPriceChartData!]

"""
Get the LoopS data
Expand Down
17 changes: 13 additions & 4 deletions apps/api/gql/generated-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2252,8 +2252,6 @@ export interface LbpPriceChartData {
cumulativeFees: Scalars['Float'];
cumulativeVolume: Scalars['Float'];
fees: Scalars['Float'];
/** @deprecated Field no longer supported */
intervalTimestamp: Scalars['Int'];
projectTokenBalance: Scalars['Float'];
projectTokenPrice: Scalars['Float'];
reservePrice: Scalars['Float'];
Expand Down Expand Up @@ -2470,6 +2468,7 @@ export interface Query {
/** Returns all pools for a given filter, specific for aggregators */
aggregatorPools: Array<GqlPoolAggregator>;
beetsPoolGetReliquaryFarmSnapshots: Array<GqlReliquaryFarmSnapshot>;
fixedLbpPriceChart?: Maybe<Array<LbpPriceChartData>>;
lbpPriceChart?: Maybe<Array<LbpPriceChartData>>;
/** Get the LoopS data */
loopsGetData: GqlLoopsData;
Expand Down Expand Up @@ -2538,11 +2537,16 @@ export interface QueryBeetsPoolGetReliquaryFarmSnapshotsArgs {
range: GqlPoolSnapshotDataRange;
}

export interface QueryFixedLbpPriceChartArgs {
chain: GqlChain;
dataPoints?: InputMaybe<Scalars['Int']>;
id: Scalars['String'];
}

export interface QueryLbpPriceChartArgs {
chain: GqlChain;
dataPoints?: InputMaybe<Scalars['Int']>;
id: Scalars['String'];
interval?: InputMaybe<Scalars['Int']>;
}

export interface QueryPoolEventsArgs {
Expand Down Expand Up @@ -4730,7 +4734,6 @@ export type LbpPriceChartDataResolvers<
cumulativeFees?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
cumulativeVolume?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
fees?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
intervalTimestamp?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
projectTokenBalance?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
projectTokenPrice?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
reservePrice?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
Expand Down Expand Up @@ -4985,6 +4988,12 @@ export type QueryResolvers<
ContextType,
RequireFields<QueryBeetsPoolGetReliquaryFarmSnapshotsArgs, 'chain' | 'id' | 'range'>
>;
fixedLbpPriceChart?: Resolver<
Maybe<Array<ResolversTypes['LBPPriceChartData']>>,
ParentType,
ContextType,
RequireFields<QueryFixedLbpPriceChartArgs, 'chain' | 'id'>
>;
lbpPriceChart?: Resolver<
Maybe<Array<ResolversTypes['LBPPriceChartData']>>,
ParentType,
Expand Down
30 changes: 4 additions & 26 deletions apps/api/gql/resolvers/lbp.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,10 @@ export default {
* Get LB Pool price chart data
*/
lbpPriceChart: async (parent: any, { id, chain, dataPoints }) => {
try {
const pool = await prisma.prismaPool.findFirst({
where: {
id,
chain,
type: 'LIQUIDITY_BOOTSTRAPPING',
protocolVersion: 3,
},
});
if (!pool) {
throw new GraphQLError('Pool with id does not exist', { extensions: { code: 'NOT_FOUND' } });
}
const input = {
id: pool.id,
chain: pool.chain,
createTime: pool.createTime,
...(pool.typeData as LBPoolData),
};

const chartData = await priceChartData(input, dataPoints || undefined);

return chartData.map((d) => ({ ...d, intervalTimestamp: d.timestamp }));
} catch (error) {
console.error('Error fetching LB Pool chart:', error);
return null;
}
return LBPController.lbpPriceChart(id, chain, dataPoints ? dataPoints : undefined);
},
fixedLbpPriceChart: async (parent: any, { id, chain, dataPoints }) => {
return LBPController.fixedLbpPriceChart(id, chain, dataPoints ? dataPoints : undefined);
},
},
Mutation: {
Expand Down
6 changes: 4 additions & 2 deletions apps/api/gql/schema/__mocks__/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2141,8 +2141,6 @@ export const aLbpPriceChartData = (overrides?: Partial<LbpPriceChartData>): LbpP
cumulativeFees: overrides && overrides.hasOwnProperty('cumulativeFees') ? overrides.cumulativeFees! : 4.7,
cumulativeVolume: overrides && overrides.hasOwnProperty('cumulativeVolume') ? overrides.cumulativeVolume! : 0.6,
fees: overrides && overrides.hasOwnProperty('fees') ? overrides.fees! : 9.3,
intervalTimestamp:
overrides && overrides.hasOwnProperty('intervalTimestamp') ? overrides.intervalTimestamp! : 7321,
projectTokenBalance:
overrides && overrides.hasOwnProperty('projectTokenBalance') ? overrides.projectTokenBalance! : 9.7,
projectTokenPrice:
Expand Down Expand Up @@ -2362,6 +2360,10 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
overrides && overrides.hasOwnProperty('beetsPoolGetReliquaryFarmSnapshots')
? overrides.beetsPoolGetReliquaryFarmSnapshots!
: [aGqlReliquaryFarmSnapshot()],
fixedLbpPriceChart:
overrides && overrides.hasOwnProperty('fixedLbpPriceChart')
? overrides.fixedLbpPriceChart!
: [aLbpPriceChartData()],
lbpPriceChart:
overrides && overrides.hasOwnProperty('lbpPriceChart') ? overrides.lbpPriceChart! : [aLbpPriceChartData()],
loopsGetData: overrides && overrides.hasOwnProperty('loopsGetData') ? overrides.loopsGetData! : aGqlLoopsData(),
Expand Down
10 changes: 7 additions & 3 deletions apps/api/gql/schema/__mocks__/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2286,8 +2286,6 @@ export type LbpPriceChartData = {
cumulativeFees: Scalars['Float'];
cumulativeVolume: Scalars['Float'];
fees: Scalars['Float'];
/** @deprecated Field no longer supported */
intervalTimestamp: Scalars['Int'];
projectTokenBalance: Scalars['Float'];
projectTokenPrice: Scalars['Float'];
reservePrice: Scalars['Float'];
Expand Down Expand Up @@ -2504,6 +2502,7 @@ export type Query = {
/** Returns all pools for a given filter, specific for aggregators */
aggregatorPools: Array<GqlPoolAggregator>;
beetsPoolGetReliquaryFarmSnapshots: Array<GqlReliquaryFarmSnapshot>;
fixedLbpPriceChart?: Maybe<Array<LbpPriceChartData>>;
lbpPriceChart?: Maybe<Array<LbpPriceChartData>>;
/** Get the LoopS data */
loopsGetData: GqlLoopsData;
Expand Down Expand Up @@ -2572,11 +2571,16 @@ export type QueryBeetsPoolGetReliquaryFarmSnapshotsArgs = {
range: GqlPoolSnapshotDataRange;
};

export type QueryFixedLbpPriceChartArgs = {
chain: GqlChain;
dataPoints?: InputMaybe<Scalars['Int']>;
id: Scalars['String'];
};

export type QueryLbpPriceChartArgs = {
chain: GqlChain;
dataPoints?: InputMaybe<Scalars['Int']>;
id: Scalars['String'];
interval?: InputMaybe<Scalars['Int']>;
};

export type QueryPoolEventsArgs = {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/gql/schema/lbp.gql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type LBPPriceChartData {
timestamp: Int!
projectTokenBalance: Float!
reserveTokenBalance: Float!
intervalTimestamp: Int! @deprecated
projectTokenPrice: Float!
reservePrice: Float!
volume: Float!
Expand All @@ -38,7 +37,8 @@ type LBPPriceChartData {
}

type Query {
lbpPriceChart(id: String!, chain: GqlChain!, interval: Int @deprecated, dataPoints: Int): [LBPPriceChartData!]
lbpPriceChart(id: String!, chain: GqlChain!, dataPoints: Int): [LBPPriceChartData!]
fixedLbpPriceChart(id: String!, chain: GqlChain!, dataPoints: Int): [LBPPriceChartData!]
}

type Mutation {
Expand Down
59 changes: 59 additions & 0 deletions modules/controllers/lbp-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { syncDataFixedLBP } from '../actions/lbp/sync-data-fixedLBP';
import { prisma } from '../../prisma/prisma-client';
import { syncPools } from '../actions/pool/v3/sync-pools';
import { PoolWithMappedJsonFields } from '../../prisma/prisma-types';
import { LBPoolData, FixedLBPData } from '../pool/pool-data';
import { priceChartData } from '../pool/lbp/price-chart-data';
import { priceChartDataFixedLBP } from '../pool/lbp/fixed-lbp-price-chart-data';

export const LBPController = {
async syncData(chain: Chain) {
Expand All @@ -20,6 +23,62 @@ export const LBPController = {

await syncDataFixedLBP(chain, client);
},
async lbpPriceChart(poolId: string, chain: Chain, dataPoints?: number) {
try {
const pool = await prisma.prismaPool.findFirst({
where: {
id: poolId,
chain,
type: 'LIQUIDITY_BOOTSTRAPPING',
protocolVersion: 3,
},
});
if (!pool) {
throw new Error('Pool with id does not exist');
}
const input = {
id: pool.id,
chain: pool.chain,
createTime: pool.createTime,
...(pool.typeData as LBPoolData),
};

const chartData = await priceChartData(input, dataPoints || undefined);

return chartData.map((d) => ({ ...d, intervalTimestamp: d.timestamp }));
} catch (error) {
console.error('Error fetching LB Pool chart:', error);
return null;
}
},
async fixedLbpPriceChart(poolId: string, chain: Chain, dataPoints?: number) {
try {
const pool = await prisma.prismaPool.findFirst({
where: {
id: poolId,
chain,
type: 'FIXED_LBP',
protocolVersion: 3,
},
});
if (!pool) {
throw new Error('Pool with id does not exist');
}
const input = {
id: pool.id,
chain: pool.chain,
createTime: pool.createTime,
...(pool.typeData as FixedLBPData),
};

const chartData = await priceChartDataFixedLBP(input, dataPoints || undefined);

return chartData.map((d) => ({ ...d, intervalTimestamp: d.timestamp }));
} catch (error) {
console.error('Error fetching LB Pool chart:', error);
return null;
}
},
async reloadLbps(chain: Chain) {
const lbps = (await prisma.prismaPool.findMany({
where: {
Expand Down
Loading
Loading