From 81971731bc92680e2c41446b2944ca61bb6eff18 Mon Sep 17 00:00:00 2001 From: Faouzi Jedidi Date: Wed, 29 Nov 2023 11:45:57 +0400 Subject: [PATCH] Fixed issue causing oracle to fail (#1218) --- .../src/modules/liquidity/liquidity.dto.ts | 12 ++-- .../modules/liquidity/liquidity.service.ts | 68 ++++++++++--------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.dto.ts b/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.dto.ts index c61b768f77..07ac040b9d 100644 --- a/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.dto.ts +++ b/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.dto.ts @@ -1,4 +1,4 @@ -import { ApiProperty } from '@nestjs/swagger'; +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { ChainId } from '@human-protocol/sdk'; import { IsBoolean, IsEnum, IsNumber, IsPositive, IsString } from 'class-validator'; @@ -23,11 +23,13 @@ export class liquidityRequestDto { @IsValidEthereumAddress() public liquidityProvider: string; - @ApiProperty() - public liquidityProviderAPIKEY: string | undefined; + @ApiPropertyOptional() + @IsString() + public liquidityProviderAPIKEY?: string ; - @ApiProperty() - public liquidityProviderAPISecret: string | undefined; + @ApiPropertyOptional() + @IsString() + public liquidityProviderAPISecret?: string; @ApiProperty() @IsBoolean() diff --git a/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.service.ts b/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.service.ts index 4e4ce2f0c2..4c8e0e49c2 100644 --- a/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.service.ts +++ b/packages/apps/hufi/recording-oracle/src/modules/liquidity/liquidity.service.ts @@ -37,7 +37,7 @@ import { signMessage } from '../../common/utils/signature'; import { HEADER_SIGNATURE_KEY } from '../../common/constants'; import { GraphQLClient, gql } from 'graphql-request'; import crypto from "crypto"; -import { DEX } from '../../common/constants/exchange'; +import { CEX, DEX } from '../../common/constants/exchange'; @Injectable() export class LiquidityService { @@ -211,37 +211,8 @@ export class LiquidityService { chain, }; - if (DEX.includes(manifest.exchangeName)) { - const client = this.getGraphQLClient(variables.chain, variables.exchange); - const result: any = await client.request(UniswapQuery, variables); - let positionSnapshots = result?.positionSnapshots; - - const filteredSnapshots = this.filterObjectsByInputTokenSymbol( - positionSnapshots, - variables.token0, - variables.token1, - ); - const liquidityScore = this.calculateLiquidityScore(filteredSnapshots); - - if (liquidityRequest.save) { - try { - await this.pushLiquidityScore( - liquidityRequest.escrowAddress, - liquidityRequest.chainId, - liquidityRequest.liquidityProvider, - liquidityScore, - ); - } catch (error: any) { - console.error(`Error in getLiquidityScore: ${error.message}`); - throw error; - } - } - const response: liquidityResponseDto = { - liquidityScore, - liquidityProvider: liquidityRequest.liquidityProvider, - }; - return response; - } else { + if (CEX.includes(manifest.exchangeName)) + { if (!liquidityRequest.liquidityProviderAPISecret || !liquidityRequest.liquidityProviderAPIKEY) { throw new Error('Empty API keys'); } @@ -260,7 +231,7 @@ export class LiquidityService { .get( `${this.configService.get( ConfigNames.BINANCE_URL, - )}/api/v3/allOrders?${signedQueryString}`, + )}/v3/allOrders?${signedQueryString}`, { headers }, ) .toPromise(); @@ -286,6 +257,37 @@ export class LiquidityService { } throw new Error('No data received from server'); } + else { + const client = this.getGraphQLClient(variables.chain, variables.exchange); + const result: any = await client.request(UniswapQuery, variables); + let positionSnapshots = result?.positionSnapshots; + + const filteredSnapshots = this.filterObjectsByInputTokenSymbol( + positionSnapshots, + variables.token0, + variables.token1, + ); + const liquidityScore = this.calculateLiquidityScore(filteredSnapshots); + + if (liquidityRequest.save) { + try { + await this.pushLiquidityScore( + liquidityRequest.escrowAddress, + liquidityRequest.chainId, + liquidityRequest.liquidityProvider, + liquidityScore, + ); + } catch (error: any) { + console.error(`Error in getLiquidityScore: ${error.message}`); + throw error; + } + } + const response: liquidityResponseDto = { + liquidityScore, + liquidityProvider: liquidityRequest.liquidityProvider, + }; + return response; + } } catch (error: any) { console.error(`Error in getLiquidityScore: ${error.message}`); throw error;