diff --git a/packages/api/src/graphql/resolvers/candle.ts b/packages/api/src/graphql/resolvers/CandleResolver.ts similarity index 100% rename from packages/api/src/graphql/resolvers/candle.ts rename to packages/api/src/graphql/resolvers/CandleResolver.ts diff --git a/packages/api/src/graphql/resolvers/EpochResolver.ts b/packages/api/src/graphql/resolvers/EpochResolver.ts new file mode 100644 index 000000000..b5a10cde6 --- /dev/null +++ b/packages/api/src/graphql/resolvers/EpochResolver.ts @@ -0,0 +1,29 @@ +import { Resolver, Query, Arg, Int } from 'type-graphql'; +import dataSource from '../../db'; +import { Epoch } from '../../models/Epoch'; +import { EpochType } from '../types'; +import { mapEpochToType } from './mappers'; + +@Resolver(() => EpochType) +export class EpochResolver { + @Query(() => [EpochType]) + async epochs( + @Arg('marketId', () => Int, { nullable: true }) marketId?: number + ): Promise { + try { + const where: { market?: { id: number } } = {}; + if (marketId) { + where.market = { id: marketId }; + } + + const epochs = await dataSource.getRepository(Epoch).find({ + where, + }); + + return epochs.map(mapEpochToType); + } catch (error) { + console.error('Error fetching epochs:', error); + throw new Error('Failed to fetch epochs'); + } + } +} \ No newline at end of file diff --git a/packages/api/src/graphql/resolvers/MarketResolver.ts b/packages/api/src/graphql/resolvers/MarketResolver.ts new file mode 100644 index 000000000..ffdcd0a71 --- /dev/null +++ b/packages/api/src/graphql/resolvers/MarketResolver.ts @@ -0,0 +1,53 @@ +import { Resolver, Query, Arg, Int, FieldResolver, Root } from 'type-graphql'; +import dataSource from '../../db'; +import { Market } from '../../models/Market'; +import { Epoch } from '../../models/Epoch'; +import { MarketType, EpochType } from '../types'; +import { mapMarketToType, mapEpochToType } from './mappers'; + +@Resolver(() => MarketType) +export class MarketResolver { + @Query(() => [MarketType]) + async markets(): Promise { + try { + const markets = await dataSource.getRepository(Market).find(); + return markets.map(mapMarketToType); + } catch (error) { + console.error('Error fetching markets:', error); + throw new Error('Failed to fetch markets'); + } + } + + @Query(() => MarketType, { nullable: true }) + async market( + @Arg('chainId', () => Int) chainId: number, + @Arg('address', () => String) address: string + ): Promise { + try { + const market = await dataSource.getRepository(Market).findOne({ + where: { chainId, address }, + }); + + if (!market) return null; + + return mapMarketToType(market); + } catch (error) { + console.error('Error fetching market:', error); + throw new Error('Failed to fetch market'); + } + } + + @FieldResolver(() => [EpochType]) + async epochs(@Root() market: Market): Promise { + try { + const epochs = await dataSource.getRepository(Epoch).find({ + where: { market: { id: market.id } }, + }); + + return epochs.map(mapEpochToType); + } catch (error) { + console.error('Error fetching epochs:', error); + throw new Error('Failed to fetch epochs'); + } + } +} \ No newline at end of file diff --git a/packages/api/src/graphql/resolvers/PositionResolver.ts b/packages/api/src/graphql/resolvers/PositionResolver.ts new file mode 100644 index 000000000..fdae05d96 --- /dev/null +++ b/packages/api/src/graphql/resolvers/PositionResolver.ts @@ -0,0 +1,51 @@ +import { Resolver, Query, Arg, Int } from 'type-graphql'; +import dataSource from '../../db'; +import { Position } from '../../models/Position'; +import { PositionType } from '../types'; +import { hydrateTransactions } from '../../helpers/hydrateTransactions'; +import { mapPositionToType } from './mappers'; +@Resolver(() => PositionType) +export class PositionResolver { + @Query(() => [PositionType]) + async positions( + @Arg('owner', () => String, { nullable: true }) owner?: string, + @Arg('chainId', () => Int, { nullable: true }) chainId?: number, + @Arg('marketAddress', () => String, { nullable: true }) marketAddress?: string + ): Promise { + try { + const where: any = {}; + if (owner) { + where.owner = owner; + } + if (chainId && marketAddress) { + where.epoch = { + market: { + chainId, + address: marketAddress, + }, + }; + } + + const positions = await dataSource.getRepository(Position).find({ + where, + relations: [ + 'epoch', + 'epoch.market', + 'epoch.market.resource', + 'transactions', + 'transactions.event' + ], + }); + + const hydratedPositions = positions.map((position) => { + const hydratedTransactions = hydrateTransactions(position.transactions, false); + return { ...position, transactions: hydratedTransactions }; + }); + + return hydratedPositions.map(mapPositionToType); + } catch (error) { + console.error('Error fetching positions:', error); + throw new Error('Failed to fetch positions'); + } + } +} \ No newline at end of file diff --git a/packages/api/src/graphql/resolvers/ResourceResolver.ts b/packages/api/src/graphql/resolvers/ResourceResolver.ts new file mode 100644 index 000000000..65709860f --- /dev/null +++ b/packages/api/src/graphql/resolvers/ResourceResolver.ts @@ -0,0 +1,38 @@ +import { Resolver, Query, Arg } from 'type-graphql'; +import dataSource from '../../db'; +import { Resource } from '../../models/Resource'; +import { ResourceType } from '../types'; +import { mapResourceToType } from './mappers'; + +@Resolver(() => ResourceType) +export class ResourceResolver { + @Query(() => [ResourceType]) + async resources(): Promise { + try { + const resources = await dataSource.getRepository(Resource).find(); + return resources.map(mapResourceToType); + } catch (error) { + console.error('Error fetching resources:', error); + throw new Error('Failed to fetch resources'); + } + } + + @Query(() => ResourceType, { nullable: true }) + async resource( + @Arg('slug', () => String) slug: string + ): Promise { + try { + const resource = await dataSource.getRepository(Resource).findOne({ + where: { slug }, + relations: ['markets', 'resourcePrices'], + }); + + if (!resource) return null; + + return mapResourceToType(resource); + } catch (error) { + console.error('Error fetching resource:', error); + throw new Error('Failed to fetch resource'); + } + } +} \ No newline at end of file diff --git a/packages/api/src/graphql/resolvers/TransactionResolver.ts b/packages/api/src/graphql/resolvers/TransactionResolver.ts new file mode 100644 index 000000000..7a51779af --- /dev/null +++ b/packages/api/src/graphql/resolvers/TransactionResolver.ts @@ -0,0 +1,31 @@ +import { Resolver, Query, Arg, Int } from 'type-graphql'; +import dataSource from '../../db'; +import { Transaction } from '../../models/Transaction'; +import { TransactionType } from '../types'; +import { hydrateTransactions } from '../../helpers/hydrateTransactions'; +import { mapTransactionToType } from './mappers'; +@Resolver(() => TransactionType) +export class TransactionResolver { + @Query(() => [TransactionType]) + async transactions( + @Arg('positionId', () => Int, { nullable: true }) positionId?: number + ): Promise { + try { + const where: any = {}; + if (positionId) { + where.position = { id: positionId }; + } + + const transactions = await dataSource.getRepository(Transaction).find({ + where, + relations: ['event', 'position'], + }); + + const hydratedTransactions = hydrateTransactions(transactions, false); + return hydratedTransactions.map(mapTransactionToType); + } catch (error) { + console.error('Error fetching transactions:', error); + throw new Error('Failed to fetch transactions'); + } + } +} \ No newline at end of file diff --git a/packages/api/src/graphql/resolvers/index.ts b/packages/api/src/graphql/resolvers/index.ts index 7734ef47d..d9843d49e 100644 --- a/packages/api/src/graphql/resolvers/index.ts +++ b/packages/api/src/graphql/resolvers/index.ts @@ -1,293 +1,6 @@ -import { Resolver, Query, Arg, Int, FieldResolver, Root } from 'type-graphql'; -import dataSource from '../../db'; -import { Market } from '../../models/Market'; -import { Resource } from '../../models/Resource'; -import { Position } from '../../models/Position'; -import { Transaction } from '../../models/Transaction'; -import { Epoch } from '../../models/Epoch'; -import { ResourcePrice } from '../../models/ResourcePrice'; -import { IndexPrice } from '../../models/IndexPrice'; -import { - hydrateTransactions, - HydratedTransaction, -} from '../../helpers/hydrateTransactions'; - -import { - MarketType, - ResourceType, - PositionType, - TransactionType, - EpochType, - ResourcePriceType, - IndexPriceType, -} from '../types'; - -const mapMarketToType = (market: Market): MarketType => ({ - id: market.id, - address: market.address, - chainId: market.chainId, - public: market.public, - epochs: market.epochs?.map(mapEpochToType) || [], - resource: market.resource ? mapResourceToType(market.resource) : null, - deployTimestamp: market.deployTimestamp, - deployTxnBlockNumber: market.deployTxnBlockNumber, - owner: market.owner, - collateralAsset: market.collateralAsset, -}); - -const mapResourceToType = (resource: Resource): ResourceType => ({ - id: resource.id, - name: resource.name, - slug: resource.slug, - markets: resource.markets?.map(mapMarketToType) || [], - resourcePrices: resource.resourcePrices?.map(mapResourcePriceToType) || [], -}); - -const mapEpochToType = (epoch: Epoch): EpochType => ({ - id: epoch.id, - epochId: epoch.epochId, - startTimestamp: epoch.startTimestamp, - endTimestamp: epoch.endTimestamp, - market: mapMarketToType(epoch.market), - positions: epoch.positions?.map(mapPositionToType) || [], - indexPrices: epoch.indexPrices?.map(mapIndexPriceToType) || [], - settled: epoch.settled, - settlementPriceD18: epoch.settlementPriceD18, -}); - -const mapPositionToType = (position: Position): PositionType => ({ - id: position.id, - positionId: position.positionId, - owner: position.owner, - isLP: position.isLP, - baseToken: position.baseToken, - quoteToken: position.quoteToken, - collateral: position.collateral, - epoch: mapEpochToType(position.epoch), - transactions: position.transactions?.map(mapTransactionToType) || [], - borrowedBaseToken: position.borrowedBaseToken, - borrowedQuoteToken: position.borrowedQuoteToken, - lpBaseToken: position.lpBaseToken, - lpQuoteToken: position.lpQuoteToken, - isSettled: position.isSettled, - lowPriceTick: position.lowPriceTick, - highPriceTick: position.highPriceTick, -}); - -const mapTransactionToType = ( - transaction: HydratedTransaction | Transaction -): TransactionType => ({ - id: transaction.id, - type: transaction.type, - timestamp: transaction.event?.timestamp - ? Number(BigInt(transaction.event.timestamp)) - : 0, - transactionHash: transaction.event?.transactionHash || null, - position: transaction.position - ? mapPositionToType(transaction.position) - : null, - baseToken: transaction.baseToken, - quoteToken: transaction.quoteToken, - collateral: transaction.collateral, - lpBaseDeltaToken: transaction.lpBaseDeltaToken, - lpQuoteDeltaToken: transaction.lpQuoteDeltaToken, - baseTokenDelta: (transaction as HydratedTransaction).baseTokenDelta || '0', - quoteTokenDelta: (transaction as HydratedTransaction).quoteTokenDelta || '0', - collateralDelta: (transaction as HydratedTransaction).collateralDelta || '0', - tradeRatioD18: transaction.tradeRatioD18 || null, -}); - -const mapResourcePriceToType = (price: ResourcePrice): ResourcePriceType => ({ - id: price.id, - timestamp: price.timestamp, - value: price.value, - resource: price.resource ? mapResourceToType(price.resource) : null, - blockNumber: price.blockNumber, -}); - -const mapIndexPriceToType = (price: IndexPrice): IndexPriceType => ({ - id: price.id, - timestamp: price.timestamp, - value: price.value, - epoch: price.epoch ? mapEpochToType(price.epoch) : null, -}); - -@Resolver(() => MarketType) -export class MarketResolver { - @Query(() => [MarketType]) - async markets(): Promise { - try { - const markets = await dataSource.getRepository(Market).find(); - return markets.map(mapMarketToType); - } catch (error) { - console.error('Error fetching markets:', error); - throw new Error('Failed to fetch markets'); - } - } - - @Query(() => MarketType, { nullable: true }) - async market( - @Arg('chainId', () => Int) chainId: number, - @Arg('address', () => String) address: string - ): Promise { - try { - const market = await dataSource.getRepository(Market).findOne({ - where: { chainId, address }, - }); - - if (!market) return null; - - return mapMarketToType(market); - } catch (error) { - console.error('Error fetching market:', error); - throw new Error('Failed to fetch market'); - } - } - - @FieldResolver(() => [EpochType]) - async epochs(@Root() market: Market): Promise { - try { - const epochs = await dataSource.getRepository(Epoch).find({ - where: { market: { id: market.id } }, - }); - - return epochs.map(mapEpochToType); - } catch (error) { - console.error('Error fetching epochs:', error); - throw new Error('Failed to fetch epochs'); - } - } -} - -@Resolver(() => ResourceType) -export class ResourceResolver { - @Query(() => [ResourceType]) - async resources(): Promise { - try { - const resources = await dataSource.getRepository(Resource).find(); - return resources.map(mapResourceToType); - } catch (error) { - console.error('Error fetching resources:', error); - throw new Error('Failed to fetch resources'); - } - } - - @Query(() => ResourceType, { nullable: true }) - async resource( - @Arg('slug', () => String) slug: string - ): Promise { - try { - const resource = await dataSource.getRepository(Resource).findOne({ - where: { slug }, - relations: ['markets', 'resourcePrices'], - }); - - if (!resource) return null; - - return mapResourceToType(resource); - } catch (error) { - console.error('Error fetching resource:', error); - throw new Error('Failed to fetch resource'); - } - } -} - -@Resolver(() => PositionType) -export class PositionResolver { - @Query(() => [PositionType]) - async positions( - @Arg('owner', () => String, { nullable: true }) owner?: string, - @Arg('chainId', () => Int, { nullable: true }) chainId?: number, - @Arg('marketAddress', () => String, { nullable: true }) marketAddress?: string - ): Promise { - try { - const where: any = {}; - if (owner) { - where.owner = owner; - } - if (chainId && marketAddress) { - where.epoch = { - market: { - chainId, - address: marketAddress, - }, - }; - } - - const positions = await dataSource.getRepository(Position).find({ - where, - relations: [ - 'epoch', - 'epoch.market', - 'epoch.market.resource', - 'transactions', - 'transactions.event' - ], - }); - - const hydratedPositions = positions.map((position) => { - const hydratedTransactions = hydrateTransactions(position.transactions, false); - return { ...position, transactions: hydratedTransactions }; - }); - - return hydratedPositions.map(mapPositionToType); - } catch (error) { - console.error('Error fetching positions:', error); - throw new Error('Failed to fetch positions'); - } - } -} - -@Resolver(() => TransactionType) -export class TransactionResolver { - @Query(() => [TransactionType]) - async transactions( - @Arg('positionId', () => Int, { nullable: true }) positionId?: number - ): Promise { - try { - const where: any = {}; - if (positionId) { - where.position = { id: positionId }; - } - - const transactions = await dataSource.getRepository(Transaction).find({ - where, - relations: ['event', 'position'], - }); - - const hydratedTransactions = hydrateTransactions(transactions, false); - console.log(hydratedTransactions); - - return hydratedTransactions.map(mapTransactionToType); - } catch (error) { - console.error('Error fetching transactions:', error); - throw new Error('Failed to fetch transactions'); - } - } -} - -@Resolver(() => EpochType) -export class EpochResolver { - @Query(() => [EpochType]) - async epochs( - @Arg('marketId', () => Int, { nullable: true }) marketId?: number - ): Promise { - try { - const where: { market?: { id: number } } = {}; - if (marketId) { - where.market = { id: marketId }; - } - - const epochs = await dataSource.getRepository(Epoch).find({ - where, - }); - - return epochs.map(mapEpochToType); - } catch (error) { - console.error('Error fetching epochs:', error); - throw new Error('Failed to fetch epochs'); - } - } -} - -export { CandleResolver } from './candle'; +export { MarketResolver } from './MarketResolver'; +export { ResourceResolver } from './ResourceResolver'; +export { PositionResolver } from './PositionResolver'; +export { TransactionResolver } from './TransactionResolver'; +export { EpochResolver } from './EpochResolver'; +export { CandleResolver } from './CandleResolver'; diff --git a/packages/api/src/graphql/resolvers/mappers.ts b/packages/api/src/graphql/resolvers/mappers.ts new file mode 100644 index 000000000..d50cccdcd --- /dev/null +++ b/packages/api/src/graphql/resolvers/mappers.ts @@ -0,0 +1,107 @@ +import { Market } from '../../models/Market'; +import { Resource } from '../../models/Resource'; +import { Position } from '../../models/Position'; +import { Transaction } from '../../models/Transaction'; +import { Epoch } from '../../models/Epoch'; +import { ResourcePrice } from '../../models/ResourcePrice'; +import { IndexPrice } from '../../models/IndexPrice'; +import { HydratedTransaction } from '../../helpers/hydrateTransactions'; +import { + MarketType, + ResourceType, + PositionType, + TransactionType, + EpochType, + ResourcePriceType, + IndexPriceType, +} from '../types'; + +export const mapMarketToType = (market: Market): MarketType => ({ + id: market.id, + address: market.address, + chainId: market.chainId, + public: market.public, + epochs: market.epochs?.map(mapEpochToType) || [], + resource: market.resource ? mapResourceToType(market.resource) : null, + deployTimestamp: market.deployTimestamp, + deployTxnBlockNumber: market.deployTxnBlockNumber, + owner: market.owner, + collateralAsset: market.collateralAsset, +}); + +export const mapResourceToType = (resource: Resource): ResourceType => ({ + id: resource.id, + name: resource.name, + slug: resource.slug, + markets: resource.markets?.map(mapMarketToType) || [], + resourcePrices: resource.resourcePrices?.map(mapResourcePriceToType) || [], +}); + +export const mapEpochToType = (epoch: Epoch): EpochType => ({ + id: epoch.id, + epochId: epoch.epochId, + startTimestamp: epoch.startTimestamp, + endTimestamp: epoch.endTimestamp, + market: mapMarketToType(epoch.market), + positions: epoch.positions?.map(mapPositionToType) || [], + indexPrices: epoch.indexPrices?.map(mapIndexPriceToType) || [], + settled: epoch.settled, + settlementPriceD18: epoch.settlementPriceD18, +}); + +export const mapPositionToType = (position: Position): PositionType => ({ + id: position.id, + positionId: position.positionId, + owner: position.owner, + isLP: position.isLP, + baseToken: position.baseToken, + quoteToken: position.quoteToken, + collateral: position.collateral, + epoch: mapEpochToType(position.epoch), + transactions: position.transactions?.map(mapTransactionToType) || [], + borrowedBaseToken: position.borrowedBaseToken, + borrowedQuoteToken: position.borrowedQuoteToken, + lpBaseToken: position.lpBaseToken, + lpQuoteToken: position.lpQuoteToken, + isSettled: position.isSettled, + lowPriceTick: position.lowPriceTick, + highPriceTick: position.highPriceTick, +}); + +export const mapTransactionToType = ( + transaction: HydratedTransaction | Transaction +): TransactionType => ({ + id: transaction.id, + type: transaction.type, + timestamp: transaction.event?.timestamp + ? Number(BigInt(transaction.event.timestamp)) + : 0, + transactionHash: transaction.event?.transactionHash || null, + position: transaction.position + ? mapPositionToType(transaction.position) + : null, + baseToken: transaction.baseToken, + quoteToken: transaction.quoteToken, + collateral: transaction.collateral, + lpBaseDeltaToken: transaction.lpBaseDeltaToken, + lpQuoteDeltaToken: transaction.lpQuoteDeltaToken, + baseTokenDelta: (transaction as HydratedTransaction).baseTokenDelta || '0', + quoteTokenDelta: (transaction as HydratedTransaction).quoteTokenDelta || '0', + collateralDelta: (transaction as HydratedTransaction).collateralDelta || '0', + tradeRatioD18: transaction.tradeRatioD18 || null, +}); + +export const mapResourcePriceToType = (price: ResourcePrice): ResourcePriceType => ({ + id: price.id, + timestamp: price.timestamp, + value: price.value, + resource: price.resource ? mapResourceToType(price.resource) : null, + blockNumber: price.blockNumber, +}); + +export const mapIndexPriceToType = (price: IndexPrice): IndexPriceType => ({ + id: price.id, + timestamp: price.timestamp, + value: price.value, + epoch: price.epoch ? mapEpochToType(price.epoch) : null, +}); \ No newline at end of file diff --git a/packages/api/src/graphql/types/CandleType.ts b/packages/api/src/graphql/types/CandleType.ts new file mode 100644 index 000000000..bb38895b6 --- /dev/null +++ b/packages/api/src/graphql/types/CandleType.ts @@ -0,0 +1,19 @@ +import { Field, ObjectType, Int } from 'type-graphql'; + +@ObjectType() +export class CandleType { + @Field(() => Int) + timestamp: number; + + @Field(() => String) + open: string; + + @Field(() => String) + high: string; + + @Field(() => String) + low: string; + + @Field(() => String) + close: string; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/EpochType.ts b/packages/api/src/graphql/types/EpochType.ts new file mode 100644 index 000000000..f4eb48314 --- /dev/null +++ b/packages/api/src/graphql/types/EpochType.ts @@ -0,0 +1,34 @@ +import { Field, ObjectType, ID, Int } from 'type-graphql'; +import { MarketType } from './MarketType'; +import { PositionType } from './PositionType'; +import { IndexPriceType } from './IndexPriceType'; + +@ObjectType() +export class EpochType { + @Field(() => ID) + id: number; + + @Field(() => Int) + epochId: number; + + @Field(() => Int, { nullable: true }) + startTimestamp: number | null; + + @Field(() => Int, { nullable: true }) + endTimestamp: number | null; + + @Field(() => MarketType) + market: MarketType; + + @Field(() => [PositionType]) + positions: PositionType[]; + + @Field(() => [IndexPriceType]) + indexPrices: IndexPriceType[]; + + @Field(() => Boolean, { nullable: true }) + settled: boolean | null; + + @Field(() => String, { nullable: true }) + settlementPriceD18: string | null; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/IndexPriceType.ts b/packages/api/src/graphql/types/IndexPriceType.ts new file mode 100644 index 000000000..0c0f2ff97 --- /dev/null +++ b/packages/api/src/graphql/types/IndexPriceType.ts @@ -0,0 +1,17 @@ +import { Field, ObjectType, ID, Int } from 'type-graphql'; +import { EpochType } from './EpochType'; + +@ObjectType() +export class IndexPriceType { + @Field(() => ID) + id: number; + + @Field(() => Int) + timestamp: number; + + @Field(() => String) + value: string; + + @Field(() => EpochType, { nullable: true }) + epoch: EpochType | null; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/MarketType.ts b/packages/api/src/graphql/types/MarketType.ts new file mode 100644 index 000000000..ebaaf4559 --- /dev/null +++ b/packages/api/src/graphql/types/MarketType.ts @@ -0,0 +1,36 @@ +import { Field, ObjectType, ID, Int } from 'type-graphql'; +import { EpochType } from './EpochType'; +import { ResourceType } from './ResourceType'; + +@ObjectType() +export class MarketType { + @Field(() => ID) + id: number; + + @Field(() => String) + address: string; + + @Field(() => Int) + chainId: number; + + @Field(() => Boolean) + public: boolean; + + @Field(() => [EpochType]) + epochs: EpochType[]; + + @Field(() => ResourceType, { nullable: true }) + resource: ResourceType | null; + + @Field(() => Int, { nullable: true }) + deployTimestamp: number | null; + + @Field(() => Int, { nullable: true }) + deployTxnBlockNumber: number | null; + + @Field(() => String, { nullable: true }) + owner: string | null; + + @Field(() => String, { nullable: true }) + collateralAsset: string | null; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/PositionType.ts b/packages/api/src/graphql/types/PositionType.ts new file mode 100644 index 000000000..31fc34607 --- /dev/null +++ b/packages/api/src/graphql/types/PositionType.ts @@ -0,0 +1,54 @@ +import { Field, ObjectType, ID, Int } from 'type-graphql'; +import { EpochType } from './EpochType'; +import { TransactionType } from './TransactionType'; + +@ObjectType() +export class PositionType { + @Field(() => ID) + id: number; + + @Field(() => Int) + positionId: number; + + @Field(() => String) + owner: string; + + @Field(() => Boolean) + isLP: boolean; + + @Field(() => String) + baseToken: string; + + @Field(() => String) + quoteToken: string; + + @Field(() => String) + collateral: string; + + @Field(() => EpochType) + epoch: EpochType; + + @Field(() => [TransactionType]) + transactions: TransactionType[]; + + @Field(() => String, { nullable: true }) + borrowedBaseToken: string | null; + + @Field(() => String, { nullable: true }) + borrowedQuoteToken: string | null; + + @Field(() => String, { nullable: true }) + lpBaseToken: string | null; + + @Field(() => String, { nullable: true }) + lpQuoteToken: string | null; + + @Field(() => Boolean, { nullable: true }) + isSettled: boolean | null; + + @Field(() => String, { nullable: true }) + lowPriceTick: string | null; + + @Field(() => String, { nullable: true }) + highPriceTick: string | null; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/ResourcePriceType.ts b/packages/api/src/graphql/types/ResourcePriceType.ts new file mode 100644 index 000000000..3e5002a54 --- /dev/null +++ b/packages/api/src/graphql/types/ResourcePriceType.ts @@ -0,0 +1,20 @@ +import { Field, ObjectType, ID, Int } from 'type-graphql'; +import { ResourceType } from './ResourceType'; + +@ObjectType() +export class ResourcePriceType { + @Field(() => ID) + id: number; + + @Field(() => Int) + timestamp: number; + + @Field(() => String) + value: string; + + @Field(() => ResourceType, { nullable: true }) + resource: ResourceType | null; + + @Field(() => Int) + blockNumber: number; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/ResourceType.ts b/packages/api/src/graphql/types/ResourceType.ts new file mode 100644 index 000000000..6049465c8 --- /dev/null +++ b/packages/api/src/graphql/types/ResourceType.ts @@ -0,0 +1,21 @@ +import { Field, ObjectType, ID } from 'type-graphql'; +import { MarketType } from './MarketType'; +import { ResourcePriceType } from './ResourcePriceType'; + +@ObjectType() +export class ResourceType { + @Field(() => ID) + id: number; + + @Field(() => String) + name: string; + + @Field(() => String) + slug: string; + + @Field(() => [MarketType]) + markets: MarketType[]; + + @Field(() => [ResourcePriceType]) + resourcePrices: ResourcePriceType[]; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/TransactionType.ts b/packages/api/src/graphql/types/TransactionType.ts new file mode 100644 index 000000000..6e70b262e --- /dev/null +++ b/packages/api/src/graphql/types/TransactionType.ts @@ -0,0 +1,47 @@ +import { Field, ObjectType, ID, Int } from 'type-graphql'; +import { PositionType } from './PositionType'; + +@ObjectType() +export class TransactionType { + @Field(() => ID) + id: number; + + @Field(() => String) + type: string; + + @Field(() => Int) + timestamp: number; + + @Field(() => String, { nullable: true }) + transactionHash: string | null; + + @Field(() => PositionType, { nullable: true }) + position: PositionType | null; + + @Field(() => String, { nullable: true }) + baseToken: string | null; + + @Field(() => String, { nullable: true }) + quoteToken: string | null; + + @Field(() => String, { nullable: true }) + collateral: string | null; + + @Field(() => String, { nullable: true }) + lpBaseDeltaToken: string | null; + + @Field(() => String, { nullable: true }) + lpQuoteDeltaToken: string | null; + + @Field(() => String, { nullable: true }) + baseTokenDelta: string | null; + + @Field(() => String, { nullable: true }) + quoteTokenDelta: string | null; + + @Field(() => String, { nullable: true }) + collateralDelta: string | null; + + @Field(() => String, { nullable: true }) + tradeRatioD18: string | null; +} \ No newline at end of file diff --git a/packages/api/src/graphql/types/index.ts b/packages/api/src/graphql/types/index.ts index 363a1635c..693a9219d 100644 --- a/packages/api/src/graphql/types/index.ts +++ b/packages/api/src/graphql/types/index.ts @@ -1,229 +1,8 @@ -import { Field, ObjectType, ID, Int } from 'type-graphql'; - -@ObjectType() -export class MarketType { - @Field(() => ID) - id: number; - - @Field(() => String) - address: string; - - @Field(() => Int) - chainId: number; - - @Field(() => Boolean) - public: boolean; - - @Field(() => [EpochType]) - epochs: EpochType[]; - - @Field(() => ResourceType, { nullable: true }) - resource: ResourceType | null; - - @Field(() => Int, { nullable: true }) - deployTimestamp: number | null; - - @Field(() => Int, { nullable: true }) - deployTxnBlockNumber: number | null; - - @Field(() => String, { nullable: true }) - owner: string | null; - - @Field(() => String, { nullable: true }) - collateralAsset: string | null; -} - -@ObjectType() -export class ResourceType { - @Field(() => ID) - id: number; - - @Field(() => String) - name: string; - - @Field(() => String) - slug: string; - - @Field(() => [MarketType]) - markets: MarketType[]; - - @Field(() => [ResourcePriceType]) - resourcePrices: ResourcePriceType[]; -} - -@ObjectType() -export class PositionType { - @Field(() => ID) - id: number; - - @Field(() => Int) - positionId: number; - - @Field(() => String) - owner: string; - - @Field(() => Boolean) - isLP: boolean; - - @Field(() => String) - baseToken: string; - - @Field(() => String) - quoteToken: string; - - @Field(() => String) - collateral: string; - - @Field(() => EpochType) - epoch: EpochType; - - @Field(() => [TransactionType]) - transactions: TransactionType[]; - - @Field(() => String, { nullable: true }) - borrowedBaseToken: string | null; - - @Field(() => String, { nullable: true }) - borrowedQuoteToken: string | null; - - @Field(() => String, { nullable: true }) - lpBaseToken: string | null; - - @Field(() => String, { nullable: true }) - lpQuoteToken: string | null; - - @Field(() => Boolean, { nullable: true }) - isSettled: boolean | null; - - @Field(() => String, { nullable: true }) - lowPriceTick: string | null; - - @Field(() => String, { nullable: true }) - highPriceTick: string | null; -} - -@ObjectType() -export class TransactionType { - @Field(() => ID) - id: number; - - @Field(() => String) - type: string; - - @Field(() => Int) - timestamp: number; - - @Field(() => String, { nullable: true }) - transactionHash: string | null; - - @Field(() => PositionType, { nullable: true }) - position: PositionType | null; - - @Field(() => String, { nullable: true }) - baseToken: string | null; - - @Field(() => String, { nullable: true }) - quoteToken: string | null; - - @Field(() => String, { nullable: true }) - collateral: string | null; - - @Field(() => String, { nullable: true }) - lpBaseDeltaToken: string | null; - - @Field(() => String, { nullable: true }) - lpQuoteDeltaToken: string | null; - - @Field(() => String, { nullable: true }) - baseTokenDelta: string | null; - - @Field(() => String, { nullable: true }) - quoteTokenDelta: string | null; - - @Field(() => String, { nullable: true }) - collateralDelta: string | null; - - @Field(() => String, { nullable: true }) - tradeRatioD18: string | null; -} - -@ObjectType() -export class EpochType { - @Field(() => ID) - id: number; - - @Field(() => Int) - epochId: number; - - @Field(() => Int, { nullable: true }) - startTimestamp: number | null; - - @Field(() => Int, { nullable: true }) - endTimestamp: number | null; - - @Field(() => MarketType) - market: MarketType; - - @Field(() => [PositionType]) - positions: PositionType[]; - - @Field(() => [IndexPriceType]) - indexPrices: IndexPriceType[]; - - @Field(() => Boolean, { nullable: true }) - settled: boolean | null; - - @Field(() => String, { nullable: true }) - settlementPriceD18: string | null; -} - -@ObjectType() -export class ResourcePriceType { - @Field(() => ID) - id: number; - - @Field(() => Int) - timestamp: number; - - @Field(() => String) - value: string; - - @Field(() => ResourceType, { nullable: true }) - resource: ResourceType | null; - - @Field(() => Int) - blockNumber: number; -} - -@ObjectType() -export class IndexPriceType { - @Field(() => ID) - id: number; - - @Field(() => Int) - timestamp: number; - - @Field(() => String) - value: string; - - @Field(() => EpochType, { nullable: true }) - epoch: EpochType | null; -} - -@ObjectType() -export class CandleType { - @Field(() => Int) - timestamp: number; - - @Field(() => String) - open: string; - - @Field(() => String) - high: string; - - @Field(() => String) - low: string; - - @Field(() => String) - close: string; -} +export { MarketType } from './MarketType'; +export { ResourceType } from './ResourceType'; +export { PositionType } from './PositionType'; +export { TransactionType } from './TransactionType'; +export { EpochType } from './EpochType'; +export { ResourcePriceType } from './ResourcePriceType'; +export { IndexPriceType } from './IndexPriceType'; +export { CandleType } from './CandleType';