Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Egld 000000 support #1401

Merged
merged 5 commits into from
Dec 2, 2024
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
4 changes: 2 additions & 2 deletions src/endpoints/tokens/token.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 })
Expand Down
19 changes: 18 additions & 1 deletion src/endpoints/tokens/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -126,7 +127,9 @@ export class TokenService {
this.applyTickerFromAssets(token);
}

return tokens.map(item => ApiUtils.mergeObjects(new TokenDetailed(), item));
return tokens
.map(item => ApiUtils.mergeObjects(new TokenDetailed(), item))
.filter(t => t.identifier !== this.egldIdentifierInMultiTransfer);
}

applyTickerFromAssets(token: Token) {
Expand Down Expand Up @@ -838,6 +841,20 @@ export class TokenService {
token => token.transactions ?? 0,
);

const egldToken = new TokenDetailed({
identifier: this.egldIdentifierInMultiTransfer,
name: 'EGLD',
type: TokenType.FungibleESDT,
assets: await this.assetsService.getTokenAssets(this.egldIdentifierInMultiTransfer),
decimals: 18,
isLowLiquidity: false,
price: await this.dataApiService.getEgldPrice(),
supply: '0',
circulatingSupply: '0',
marketCap: 0,
});
tokens = [...tokens, egldToken];

return tokens;
}

Expand Down
22 changes: 21 additions & 1 deletion src/test/unit/services/tokens.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ describe('Token Service', () => {
provide: DataApiService,
useValue: {
getEsdtTokenPrice: jest.fn(),
getEgldPrice: jest.fn(),
},
},
{
Expand Down Expand Up @@ -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);

Expand All @@ -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] });
Expand Down Expand Up @@ -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);
});
});
Expand Down