From 25522c7053a5dd79384cb5e048fce2c6c990d951 Mon Sep 17 00:00:00 2001 From: Rebegea Dragos-Alexandru Date: Thu, 28 Nov 2024 22:00:13 +0200 Subject: [PATCH 1/4] EGLD-000000: add EGLD-000000 support --- src/endpoints/tokens/token.service.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/endpoints/tokens/token.service.ts b/src/endpoints/tokens/token.service.ts index 0f7782fc8..1d37d5c23 100644 --- a/src/endpoints/tokens/token.service.ts +++ b/src/endpoints/tokens/token.service.ts @@ -838,6 +838,21 @@ export class TokenService { token => token.transactions ?? 0, ); + const egldIdentifier = 'EGLD-000000'; + const egldToken = new TokenDetailed({ + identifier: egldIdentifier, + name: 'EGLD', + type: TokenType.FungibleESDT, + assets: await this.assetsService.getTokenAssets(egldIdentifier), + decimals: 18, + isLowLiquidity: false, + price: await this.dataApiService.getEsdtTokenPrice(egldIdentifier), + supply: '0', + circulatingSupply: '0', + marketCap: 0, + }); + tokens = [egldToken, ...tokens]; + return tokens; } From 43d2515115488788cc1656e1e122681eeb826679 Mon Sep 17 00:00:00 2001 From: Rebegea Dragos-Alexandru Date: Thu, 28 Nov 2024 22:05:55 +0200 Subject: [PATCH 2/4] EGLD-000000: add EGLD-000000 support --- src/endpoints/tokens/token.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/endpoints/tokens/token.service.ts b/src/endpoints/tokens/token.service.ts index 1d37d5c23..c30d187c1 100644 --- a/src/endpoints/tokens/token.service.ts +++ b/src/endpoints/tokens/token.service.ts @@ -846,12 +846,12 @@ export class TokenService { assets: await this.assetsService.getTokenAssets(egldIdentifier), decimals: 18, isLowLiquidity: false, - price: await this.dataApiService.getEsdtTokenPrice(egldIdentifier), + price: await this.dataApiService.getEgldPrice(), supply: '0', circulatingSupply: '0', marketCap: 0, }); - tokens = [egldToken, ...tokens]; + tokens = [...tokens, egldToken]; return tokens; } From 8627abd24f54f67143ef4033a4dd5f0bd780c77a Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 2 Dec 2024 13:53:53 +0200 Subject: [PATCH 3/4] filter out egld-000000 from all tokens response + tests fixes --- src/endpoints/tokens/token.controller.ts | 4 ++-- src/endpoints/tokens/token.service.ts | 9 +++++---- src/test/unit/services/tokens.spec.ts | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/endpoints/tokens/token.controller.ts b/src/endpoints/tokens/token.controller.ts index e3d1e1854..864a8576e 100644 --- a/src/endpoints/tokens/token.controller.ts +++ b/src/endpoints/tokens/token.controller.ts @@ -341,7 +341,7 @@ export class TokenController { } @Get("/tokens/:identifier/roles/:address") - @ApiOperation({ summary: 'Token address roles', description: 'Returns roles detalils for a specific address of a given token', deprecated: true }) + @ApiOperation({ summary: 'Token address roles', description: 'Returns roles details for a specific address of a given token', deprecated: true }) @ApiOkResponse({ type: TokenRoles }) @ApiNotFoundResponse({ description: 'Token not found' }) async getTokenRolesForAddress( @@ -435,7 +435,7 @@ export class TokenController { } @Get("/tokens/:identifier/transfers/count") - @ApiOperation({ summary: 'Account transfer count', description: 'Return total count of tranfers triggerred by a user account (type = Transaction), as well as transfers triggerred by smart contracts (type = SmartContractResult)' }) + @ApiOperation({ summary: 'Account transfer count', description: 'Return total count of transfers triggerred by a user account (type = Transaction), as well as transfers triggerred by smart contracts (type = SmartContractResult)' }) @ApiOkResponse({ type: Number }) @ApiQuery({ name: 'sender', description: 'Address of the transfer sender', required: false }) @ApiQuery({ name: 'receiver', description: 'Search by multiple receiver addresses, comma-separated', required: false }) diff --git a/src/endpoints/tokens/token.service.ts b/src/endpoints/tokens/token.service.ts index c30d187c1..9a44b0ba5 100644 --- a/src/endpoints/tokens/token.service.ts +++ b/src/endpoints/tokens/token.service.ts @@ -48,6 +48,7 @@ import { NftSubType } from "../nfts/entities/nft.sub.type"; export class TokenService { private readonly logger = new OriginLogger(TokenService.name); private readonly nftSubTypes = [NftSubType.DynamicNonFungibleESDT, NftSubType.DynamicMetaESDT, NftSubType.NonFungibleESDTv2, NftSubType.DynamicSemiFungibleESDT]; + private readonly egldIdentifierInMultiTransfer = 'EGLD-000000'; constructor( private readonly esdtService: EsdtService, @@ -126,7 +127,8 @@ export class TokenService { this.applyTickerFromAssets(token); } - return tokens.map(item => ApiUtils.mergeObjects(new TokenDetailed(), item)); + const allTokens = tokens.map(item => ApiUtils.mergeObjects(new TokenDetailed(), item)); + return allTokens.filter(t => t.identifier !== this.egldIdentifierInMultiTransfer); } applyTickerFromAssets(token: Token) { @@ -838,12 +840,11 @@ export class TokenService { token => token.transactions ?? 0, ); - const egldIdentifier = 'EGLD-000000'; const egldToken = new TokenDetailed({ - identifier: egldIdentifier, + identifier: this.egldIdentifierInMultiTransfer, name: 'EGLD', type: TokenType.FungibleESDT, - assets: await this.assetsService.getTokenAssets(egldIdentifier), + assets: await this.assetsService.getTokenAssets(this.egldIdentifierInMultiTransfer), decimals: 18, isLowLiquidity: false, price: await this.dataApiService.getEgldPrice(), diff --git a/src/test/unit/services/tokens.spec.ts b/src/test/unit/services/tokens.spec.ts index 222e5ae15..f025eaddb 100644 --- a/src/test/unit/services/tokens.spec.ts +++ b/src/test/unit/services/tokens.spec.ts @@ -134,6 +134,7 @@ describe('Token Service', () => { provide: DataApiService, useValue: { getEsdtTokenPrice: jest.fn(), + getEgldPrice: jest.fn(), }, }, { @@ -690,6 +691,7 @@ describe('Token Service', () => { jest.spyOn(tokenService as any, 'applyMexPairTradesCount').mockImplementation(() => Promise.resolve()); jest.spyOn(cacheService as any, 'batchApplyAll').mockImplementation(() => Promise.resolve()); jest.spyOn(dataApiService, 'getEsdtTokenPrice').mockResolvedValue(100); + jest.spyOn(dataApiService, 'getEgldPrice').mockResolvedValue(100); jest.spyOn(tokenService as any, 'fetchTokenDataFromUrl').mockResolvedValue(100); jest.spyOn(esdtService, 'getTokenSupply').mockResolvedValue(mockTokenSupply as EsdtSupply); @@ -710,7 +712,7 @@ describe('Token Service', () => { expect(assetsService.getTokenAssets).toHaveBeenCalledWith(mockToken.identifier); mockToken.name = mockTokenAssets.name; }); - expect(assetsService.getTokenAssets).toHaveBeenCalledTimes(mockTokens.length); + expect(assetsService.getTokenAssets).toHaveBeenCalledTimes(mockTokens.length + 1); // add 1 for EGLD-000000 expect((collectionService as any).getNftCollections).toHaveBeenCalledWith(expect.anything(), { type: [TokenType.MetaESDT] }); @@ -763,6 +765,24 @@ describe('Token Service', () => { token => token.isLowLiquidity ? 0 : (token.marketCap ?? 0), token => token.transactions ?? 0, ); + + mockTokens.push(new TokenDetailed({ + identifier: 'EGLD-000000', + name: 'EGLD', + canPause: false, + canUpgrade: false, + canWipe: false, + price: 100, + decimals: 18, + isLowLiquidity: false, + marketCap: 0, + circulatingSupply: '0', + supply: '0', + assets: { + name: 'mockName', + } as TokenAssets, + })); + expect(result).toEqual(mockTokens); }); }); From e85a094ba5556badfcd65b1a90ef542d1c3665a3 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 2 Dec 2024 15:05:38 +0200 Subject: [PATCH 4/4] refacotring --- src/endpoints/tokens/token.service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/endpoints/tokens/token.service.ts b/src/endpoints/tokens/token.service.ts index 9a44b0ba5..3ceb5183a 100644 --- a/src/endpoints/tokens/token.service.ts +++ b/src/endpoints/tokens/token.service.ts @@ -127,8 +127,9 @@ export class TokenService { this.applyTickerFromAssets(token); } - const allTokens = tokens.map(item => ApiUtils.mergeObjects(new TokenDetailed(), item)); - return allTokens.filter(t => t.identifier !== this.egldIdentifierInMultiTransfer); + return tokens + .map(item => ApiUtils.mergeObjects(new TokenDetailed(), item)) + .filter(t => t.identifier !== this.egldIdentifierInMultiTransfer); } applyTickerFromAssets(token: Token) {