Skip to content

Commit

Permalink
Merge pull request #2 from MogageNicolae/Dune-mock-API-Service
Browse files Browse the repository at this point in the history
Dune simulator implementation + hatom borrow events parser service
  • Loading branch information
GuticaStefan committed Sep 17, 2024
2 parents 7b1a230 + cd5e35b commit a93082f
Show file tree
Hide file tree
Showing 112 changed files with 4,765 additions and 12,850 deletions.
10 changes: 8 additions & 2 deletions .env.devnet
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
NETWORK=devnet
API_URL=https://devnet-api.multiversx.com
NETWORK=mainnet
API_URL=https://api.multiversx.com
DATA_API_CEX_URL=https://data-api.multiversx.com/v1/quotes/cex
DATA_API_XEXCHANGE_URL=https://data-api.multiversx.com/v1/quotes/xexchange
# DUNE_API_URL=http://localhost:3001/api/v1/table
DUNE_API_URL=https://api.dune.com/api/v1/table
DUNE_NAMESPACE=stefanmvx
DUNE_API_KEY=
6 changes: 6 additions & 0 deletions .env.mainnet
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
NETWORK=mainnet
API_URL=https://api.multiversx.com
DATA_API_CEX_URL=https://data-api.multiversx.com/v1/quotes/cex
DATA_API_XEXCHANGE_URL=https://data-api.multiversx.com/v1/quotes/xexchange
DUNE_API_URL=http://localhost:3001/api/v1/table
# DUNE_API_URL=https://api.dune.com/api/v1/table
DUNE_NAMESPACE=stefanmvx
DUNE_API_KEY=test
10 changes: 8 additions & 2 deletions .env.testnet
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
NETWORK=testnet
API_URL=https://testnet-api.multiversx.com
NETWORK=mainnet
API_URL=https://api.multiversx.com
DATA_API_CEX_URL=https://data-api.multiversx.com/v1/quotes/cex
DATA_API_XEXCHANGE_URL=https://data-api.multiversx.com/v1/quotes/xexchange
# DUNE_API_URL=http://localhost:3001/api/v1/table
DUNE_API_URL=https://api.dune.com/api/v1/table
DUNE_NAMESPACE=stefanmvx
DUNE_API_KEY=
26 changes: 5 additions & 21 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,8 @@ module.exports = {
pattern: 'apps/api',
},
{
type: 'apps/cache-warmer',
pattern: 'apps/cache-warmer',
},
{
type: 'apps/queue-worker',
pattern: 'apps/queue-worker',
},
{
type: 'apps/transactions-processor',
pattern: 'apps/transactions-processor',
type: 'apps/dune-simulator',
pattern: 'apps/dune-simulator',
},
{
type: 'libs/common',
Expand Down Expand Up @@ -82,24 +74,16 @@ module.exports = {
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'apps/cache-warmer',
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'apps/queue-worker',
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'apps/transactions-processor',
from: 'apps/dune-simulator',
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'libs/database',
allow: ['libs/common', 'libs/entities']
allow: ['libs/common', 'libs/entities', 'apps/dune-simulator']
},
{
from: 'libs/services',
allow: ['libs/common', 'libs/entities', 'libs/database']
allow: ['libs/common', 'libs/entities', 'libs/database', 'apps/api', 'apps/dune-simulator']
},
{
from: 'libs/common',
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ lerna-debug.log*
# Environment
.env
.env.custom
/scripts/insertCsv.ts
scripts/
out_csv/
18 changes: 11 additions & 7 deletions .multiversx/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ apps:
port: 3000
privatePort: 4000
useCachingInterceptor: true
cacheWarmer:
port: 4001
queueWorker:
port: 4002
transactionsProcessor:
port: 4003
maxLookBehind: 100
duneSimulator:
port: 3001
privatePort: 4001
useCachingInterceptor: true
libs:
common:
network: ${NETWORK}
urls:
api: ${API_URL}
dataApiCex: ${DATA_API_CEX_URL}
dataApiXexchange: ${DATA_API_XEXCHANGE_URL}
duneApi: ${DUNE_API_URL}
database:
host: 'localhost'
port: 27017
Expand All @@ -25,6 +25,10 @@ libs:
redis:
host: '127.0.0.1'
port: 6379
features:
dune:
namespace: ${DUNE_NAMESPACE}
apiKey: ${DUNE_API_KEY}
nativeAuth:
# maxExpirySeconds:
acceptedOrigins:
Expand Down
22 changes: 0 additions & 22 deletions TODO

This file was deleted.

24 changes: 24 additions & 0 deletions apps/api/src/config/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,28 @@ import { Injectable } from "@nestjs/common";
@Injectable()
export class AppConfigService {
readonly config = configuration().apps.api;

getDuneNamespace(): string {
return configuration().libs.common.features.dune.namespace ?? "";
}

getDuneApiKey(): string {
return configuration().libs.common.features.dune.apiKey ?? "";
}

getApiUrl(): string {
return configuration().libs.common.urls.api ?? "";
}

getDataApiCexUrl(): string {
return configuration().libs.common.urls.dataApiCex ?? "";
}

getDataApiXexchangeUrl(): string {
return configuration().libs.common.urls.dataApiXexchange ?? "";
}

getDuneApiUrl(): string {
return configuration().libs.common.urls.duneApi ?? "";
}
}
16 changes: 0 additions & 16 deletions apps/api/src/endpoints/auth/auth.controller.ts

This file was deleted.

13 changes: 0 additions & 13 deletions apps/api/src/endpoints/auth/auth.module.ts

This file was deleted.

10 changes: 2 additions & 8 deletions apps/api/src/endpoints/endpoints.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { Module } from "@nestjs/common";
import { DynamicModuleUtils } from "@libs/common";
import { AuthModule } from "./auth/auth.module";
import { TokenModule } from "./token/token.module";
import { UserModule } from "./user/user.module";
import { ExampleModule } from "./example/example.module";
import { EventsModule } from "./events/events.module";

@Module({
imports: [
AuthModule,
TokenModule,
UserModule,
ExampleModule,
EventsModule,
],
providers: [
DynamicModuleUtils.getNestJsApiConfigService(),
Expand Down
48 changes: 48 additions & 0 deletions apps/api/src/endpoints/events/entities/event.log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ApiProperty } from "@nestjs/swagger";

export class EventLog {
constructor(init?: Partial<EventLog>) {
Object.assign(this, init);
}
@ApiProperty()
eventId: string = '';

@ApiProperty()
txHash: string = '';

@ApiProperty()
shardId: number = 0;

@ApiProperty()
timestamp: number = 0;

@ApiProperty()
address: string = '';

@ApiProperty()
identifier: string = '';

@ApiProperty()
topics: string[] = [];

@ApiProperty()
data: string = '';

@ApiProperty()
additionalData: string[] = [];

@ApiProperty()
txOrder: number = 0;

@ApiProperty()
eventOrder: number = 0;
}

export class EventsLog {
constructor(init?: Partial<EventsLog>) {
Object.assign(this, init);
}

@ApiProperty({ type: EventLog, isArray: true })
events: EventLog[] = [];
}
1 change: 1 addition & 0 deletions apps/api/src/endpoints/events/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./event.log";
29 changes: 29 additions & 0 deletions apps/api/src/endpoints/events/events.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Body, Controller, Param, Post } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { EventLog } from "./entities/event.log";
import { HatomBorrowEventsService, LiquidityEventsService } from "@libs/services/events";

@Controller('/events')
@ApiTags('events')
export class EventsController {
constructor(
private readonly liquidityService: LiquidityEventsService,
private readonly hatomBorrowService: HatomBorrowEventsService,
) { }

@Post("/liquidity-webhook")
async liquidityWebhook(
@Body() body: EventLog[],
): Promise<void> {
await this.liquidityService.liquidityWebhook(body);
}

@Post("/hatom-webhook/:borrowed_token")
async hatomBorrowWebhook(
@Body() body: EventLog[],
@Param('borrowed_token') borrowedToken: string,
): Promise<void> {
await this.hatomBorrowService.hatomBorrowWebhook(body, borrowedToken);
}

}
13 changes: 13 additions & 0 deletions apps/api/src/endpoints/events/events.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from "@nestjs/common";
import { ServicesModule } from "@libs/services/services.module";
import { EventsController } from "./events.controller";

@Module({
imports: [
ServicesModule,
],
controllers: [
EventsController,
],
})
export class EventsModule { }
16 changes: 0 additions & 16 deletions apps/api/src/endpoints/example/entities/event.log.ts

This file was deleted.

58 changes: 0 additions & 58 deletions apps/api/src/endpoints/example/example.controller.ts

This file was deleted.

Loading

0 comments on commit a93082f

Please sign in to comment.