-
Notifications
You must be signed in to change notification settings - Fork 44
Integrate staking amount requirement #3632
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
Open
flopez7
wants to merge
10
commits into
develop
Choose a base branch
from
feat/staking-requirement
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
01bd3e2
Integrate staking amount requirement
flopez7 23be3be
Add stake eligibility checks in Human App
flopez7 bc96490
- Added new ExchangeApiKeys module in Human App.
flopez7 c3a6886
simplify error handling in Gate and Mexc
flopez7 65fe558
add AES encryption key to .env.example and improve error handling in …
flopez7 b58f09f
add staking eligibility env var to enable or disable this functionality
flopez7 853833a
Generate unit tests for AesEncriptionService, AuthService, GateExchan…
flopez7 e796253
Refactor GateExchangeClient and MexcExchangeClient to use fetchWithHa…
flopez7 d9f9dd4
Add unit tests for staking requirement in HUMAN App
flopez7 5b92eac
Refactor exchange client methods to improve error handling and code s…
flopez7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export enum HttpMethod { | ||
| GET = 'GET', | ||
| POST = 'POST', | ||
| DELETE = 'DELETE', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/apps/human-app/server/src/modules/exchange-api-keys/exchange-api-keys.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { | ||
| Body, | ||
| Controller, | ||
| Delete, | ||
| Get, | ||
| HttpCode, | ||
| Param, | ||
| Post, | ||
| Request, | ||
| } from '@nestjs/common'; | ||
| import { | ||
| ApiBearerAuth, | ||
| ApiBody, | ||
| ApiOperation, | ||
| ApiResponse, | ||
| ApiTags, | ||
| } from '@nestjs/swagger'; | ||
| import { RequestWithUser } from '../../common/interfaces/jwt'; | ||
| import { ExchangeApiKeysService } from '../../modules/exchange-api-keys/exchange-api-keys.service'; | ||
| import { InjectMapper } from '@automapper/nestjs'; | ||
| import { Mapper } from '@automapper/core'; | ||
| import { | ||
| EnrollExchangeApiKeysCommand, | ||
| EnrollExchangeApiKeysDto, | ||
| RetrieveExchangeApiKeysResponse, | ||
| } from './model/exchange-api-keys.model'; | ||
|
|
||
| @ApiTags('Exchange-Api-Keys') | ||
| @ApiBearerAuth() | ||
| @Controller('/exchange-api-keys') | ||
| export class ExchangeApiKeysController { | ||
| constructor( | ||
| private readonly service: ExchangeApiKeysService, | ||
| @InjectMapper() private readonly mapper: Mapper, | ||
| ) {} | ||
|
|
||
| @ApiOperation({ summary: 'Enroll API keys for exchange' }) | ||
| @ApiBody({ type: EnrollExchangeApiKeysDto }) | ||
| @ApiResponse({ status: 200, description: 'Exchange API keys enrolled' }) | ||
| @HttpCode(200) | ||
| @Post('/:exchange_name') | ||
| async enroll( | ||
| @Param('exchange_name') exchangeName: string, | ||
| @Body() dto: EnrollExchangeApiKeysDto, | ||
| @Request() req: RequestWithUser, | ||
| ): Promise<{ id: number }> { | ||
| const command = this.mapper.map( | ||
| dto, | ||
| EnrollExchangeApiKeysDto, | ||
| EnrollExchangeApiKeysCommand, | ||
| ); | ||
| command.token = req.token; | ||
| command.exchangeName = exchangeName; | ||
| return this.service.enroll(command); | ||
| } | ||
|
|
||
| @ApiOperation({ summary: 'Delete API keys for exchange' }) | ||
| @ApiResponse({ status: 204, description: 'Exchange API keys deleted' }) | ||
| @HttpCode(204) | ||
| @Delete('/') | ||
| async delete(@Request() req: RequestWithUser): Promise<void> { | ||
| await this.service.delete(req.token); | ||
| } | ||
|
|
||
| @ApiOperation({ | ||
| summary: 'Retrieve API keys for exchange', | ||
| }) | ||
| @Get('/') | ||
| async retrieve( | ||
| @Request() req: RequestWithUser, | ||
| ): Promise<RetrieveExchangeApiKeysResponse> { | ||
| return this.service.retrieve(req.token); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...s/apps/human-app/server/src/modules/exchange-api-keys/exchange-api-keys.mapper.profile.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Mapper, createMap } from '@automapper/core'; | ||
| import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { | ||
| EnrollExchangeApiKeysCommand, | ||
| EnrollExchangeApiKeysDto, | ||
| } from './model/exchange-api-keys.model'; | ||
|
|
||
| @Injectable() | ||
| export class ExchangeApiKeysProfile extends AutomapperProfile { | ||
| constructor(@InjectMapper() mapper: Mapper) { | ||
| super(mapper); | ||
| } | ||
|
|
||
| override get profile() { | ||
| return (mapper: Mapper) => { | ||
| createMap(mapper, EnrollExchangeApiKeysDto, EnrollExchangeApiKeysCommand); | ||
| }; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
packages/apps/human-app/server/src/modules/exchange-api-keys/exchange-api-keys.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { ExchangeApiKeysController } from '../../modules/exchange-api-keys/exchange-api-keys.controller'; | ||
| import { ExchangeApiKeysService } from '../../modules/exchange-api-keys/exchange-api-keys.service'; | ||
| import { ReputationOracleModule } from '../../integrations/reputation-oracle/reputation-oracle.module'; | ||
| import { ExchangeApiKeysProfile } from './exchange-api-keys.mapper.profile'; | ||
|
|
||
| @Module({ | ||
| imports: [ReputationOracleModule], | ||
| controllers: [ExchangeApiKeysController], | ||
| providers: [ExchangeApiKeysService, ExchangeApiKeysProfile], | ||
| exports: [ExchangeApiKeysService], | ||
| }) | ||
| export class ExchangeApiKeysModule {} |
23 changes: 23 additions & 0 deletions
23
packages/apps/human-app/server/src/modules/exchange-api-keys/exchange-api-keys.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { ReputationOracleGateway } from '../../integrations/reputation-oracle/reputation-oracle.gateway'; | ||
| import { | ||
| EnrollExchangeApiKeysCommand, | ||
| RetrieveExchangeApiKeysResponse, | ||
| } from './model/exchange-api-keys.model'; | ||
|
|
||
| @Injectable() | ||
| export class ExchangeApiKeysService { | ||
| constructor(private readonly reputationOracle: ReputationOracleGateway) {} | ||
|
|
||
| enroll(command: EnrollExchangeApiKeysCommand): Promise<{ id: number }> { | ||
| return this.reputationOracle.enrollExchangeApiKeys(command); | ||
| } | ||
|
|
||
| delete(token: string): Promise<void> { | ||
| return this.reputationOracle.deleteExchangeApiKeys(token); | ||
| } | ||
|
|
||
| retrieve(token: string): Promise<RetrieveExchangeApiKeysResponse> { | ||
| return this.reputationOracle.retrieveExchangeApiKeys(token); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...ages/apps/human-app/server/src/modules/exchange-api-keys/model/exchange-api-keys.model.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { AutoMap } from '@automapper/classes'; | ||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { IsString } from 'class-validator'; | ||
|
|
||
| export class EnrollExchangeApiKeysDto { | ||
| @AutoMap() | ||
| @IsString() | ||
| @ApiProperty() | ||
| apiKey: string; | ||
|
|
||
| @AutoMap() | ||
| @IsString() | ||
| @ApiProperty() | ||
| secretKey: string; | ||
| } | ||
|
|
||
| export class EnrollExchangeApiKeysCommand { | ||
| @AutoMap() | ||
| apiKey: string; | ||
| @AutoMap() | ||
| secretKey: string; | ||
| token: string; | ||
| exchangeName: string; | ||
| } | ||
|
|
||
| export class EnrollExchangeApiKeysData { | ||
| @AutoMap() | ||
| apiKey: string; | ||
| @AutoMap() | ||
| secretKey: string; | ||
| } | ||
|
|
||
| export class RetrieveExchangeApiKeysResponse { | ||
| apiKey: string; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.