Skip to content

Commit

Permalink
update deprecated pairs query (#1335)
Browse files Browse the repository at this point in the history
* update deprecated pairs query

* add tradesCount24h

* add mex pair status and apply filter by state
  • Loading branch information
cfaur09 committed Sep 25, 2024
1 parent d5cb860 commit abd7725
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 64 deletions.
27 changes: 27 additions & 0 deletions src/endpoints/mex/entities/mex.pair.status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { registerEnumType } from "@nestjs/graphql";

export enum MexPairStatus {
active = 'Active',
inactive = 'Inactive',
paused = 'Paused',
partial = 'Partial',
}

registerEnumType(MexPairStatus, {
name: 'MexPairStatus',
description: 'MexPairStatus object type.',
valuesMap: {
active: {
description: 'Active state.',
},
inactive: {
description: 'Inactive state.',
},
paused: {
description: 'Pause state.',
},
partial: {
description: 'Partial state.',
},
},
});
4 changes: 4 additions & 0 deletions src/endpoints/mex/entities/mex.pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export class MexPair {
@ApiProperty({ type: Number, nullable: true })
tradesCount: number | undefined = undefined;

@Field(() => Number, { description: 'Mex pair trades count 24h.', nullable: true })
@ApiProperty({ type: Number, nullable: true })
tradesCount24h: number | undefined = undefined;

@Field(() => Number, { description: 'Mex pair deploy date in unix time.', nullable: true })
@ApiProperty({ type: Number, nullable: true })
deployedAt: number | undefined = undefined;
Expand Down
138 changes: 74 additions & 64 deletions src/endpoints/mex/mex.pair.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Constants } from "@multiversx/sdk-nestjs-common";
import { CacheService } from "@multiversx/sdk-nestjs-cache";
import { BadRequestException, Injectable } from "@nestjs/common";
import { gql } from "graphql-request";
import { CacheInfo } from "src/utils/cache.info";
import { GraphQlService } from "src/common/graphql/graphql.service";
import { MexPair } from "./entities/mex.pair";
import { MexPairState } from "./entities/mex.pair.state";
import { MexPairType } from "./entities/mex.pair.type";
import { MexSettingsService } from "./mex.settings.service";
import { OriginLogger } from "@multiversx/sdk-nestjs-common";
import { ApiConfigService } from "src/common/api-config/api.config.service";
import { MexPairExchange } from "./entities/mex.pair.exchange";
import { MexPairsFilter } from "./entities/mex.pairs..filter";
import { Constants } from '@multiversx/sdk-nestjs-common';
import { CacheService } from '@multiversx/sdk-nestjs-cache';
import { BadRequestException, Injectable } from '@nestjs/common';
import { gql } from 'graphql-request';
import { CacheInfo } from 'src/utils/cache.info';
import { GraphQlService } from 'src/common/graphql/graphql.service';
import { MexPair } from './entities/mex.pair';
import { MexPairState } from './entities/mex.pair.state';
import { MexPairType } from './entities/mex.pair.type';
import { MexSettingsService } from './mex.settings.service';
import { OriginLogger } from '@multiversx/sdk-nestjs-common';
import { ApiConfigService } from 'src/common/api-config/api.config.service';
import { MexPairExchange } from './entities/mex.pair.exchange';
import { MexPairsFilter } from './entities/mex.pairs..filter';
import { MexPairStatus } from './entities/mex.pair.status';

@Injectable()
export class MexPairService {
Expand Down Expand Up @@ -52,7 +53,7 @@ export class MexPairService {
CacheInfo.MexPairs.key,
async () => await this.getAllMexPairsRaw(),
CacheInfo.MexPairs.ttl,
Constants.oneSecond() * 30
Constants.oneSecond() * 30,
);
}

Expand All @@ -71,63 +72,69 @@ export class MexPairService {
}

const pairsLimit = gql`
query PairCount {
factory {
pairCount
}
}`;
query PairCount {
factory {
pairCount
}
}`;

const pairsLimitResult: any = await this.graphQlService.getExchangeServiceData(pairsLimit);
const totalPairs = pairsLimitResult?.factory?.pairCount;

const variables = {
"offset": 0,
"pairsLimit": totalPairs,
pagination: { first: totalPairs },
filters: { state: MexPairStatus.active },
};

const query = gql`
query ($offset: Int, $pairsLimit: Int) {
pairs(offset: $offset, limit: $pairsLimit) {
address
liquidityPoolToken {
identifier
name
__typename
}
liquidityPoolTokenPriceUSD
firstToken {
name
identifier
decimals
previous24hPrice
__typename
}
secondToken {
name
identifier
decimals
previous24hPrice
__typename
}
firstTokenPrice
firstTokenPriceUSD
secondTokenPrice
secondTokenPriceUSD
info {
reserves0
reserves1
totalSupply
__typename
query filteredPairs($pagination: ConnectionArgs!, $filters: PairsFilter!) {
filteredPairs(pagination: $pagination, filters: $filters) {
edges {
cursor
node {
address
liquidityPoolToken {
identifier
name
__typename
}
liquidityPoolTokenPriceUSD
firstToken {
name
identifier
decimals
previous24hPrice
__typename
}
secondToken {
name
identifier
decimals
previous24hPrice
__typename
}
firstTokenPrice
firstTokenPriceUSD
secondTokenPrice
secondTokenPriceUSD
info {
reserves0
reserves1
totalSupply
__typename
}
state
type
lockedValueUSD
volumeUSD24h
hasFarms
hasDualFarms
tradesCount
tradesCount24h
deployedAt
__typename
}
}
state
type
lockedValueUSD
volumeUSD24h
hasFarms
hasDualFarms
tradesCount
deployedAt
__typename
}
}
`;
Expand All @@ -137,7 +144,8 @@ export class MexPairService {
return [];
}

return result.pairs.map((pair: any) => this.getPairInfo(pair)).filter((x: MexPair | undefined) => x && x.state === MexPairState.active);
return result.filteredPairs.edges
.map((edge: any) => this.getPairInfo(edge.node));
} catch (error) {
this.logger.error('An error occurred while getting all mex pairs');
this.logger.error(error);
Expand Down Expand Up @@ -192,6 +200,7 @@ export class MexPairService {
hasFarms: pair.hasFarms,
hasDualFarms: pair.hasDualFarms,
tradesCount: Number(pair.tradesCount),
tradesCount24h: Number(pair.tradesCount24h),
deployedAt: Number(pair.deployedAt),
state,
type,
Expand Down Expand Up @@ -220,6 +229,7 @@ export class MexPairService {
hasFarms: pair.hasFarms,
hasDualFarms: pair.hasDualFarms,
tradesCount: Number(pair.tradesCount),
tradesCount24h: Number(pair.tradesCount24h),
deployedAt: Number(pair.deployedAt),
state,
type,
Expand Down

0 comments on commit abd7725

Please sign in to comment.