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

add avax network #56

Merged
merged 5 commits into from
May 16, 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
5 changes: 5 additions & 0 deletions app/.env
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ POLYGON_DISABLE=false
POLYGON_START_BLOCK=56154832
POLYGON_START_BLOCK_CONFIG=latest # 'config' or 'latest' or 'db'

AVAX_PROVIDER_URL=https://goerli.infura.io/v3/d7aa2a84a44548819617058aa0a3e347
AVAX_DISABLE=false
AVAX_START_BLOCK=56156884
AVAX_START_BLOCK_CONFIG=latest # 'config' or 'latest' or 'db'

MANTLE_PROVIDER_URL=https://1rpc.io/4n4xz9Bow96oZU2n9/mantle
MANTLE_DISABLE=true
MANTLE_START_BLOCK=26620500
Expand Down
34 changes: 34 additions & 0 deletions app/apps/monitor-service/src/avax/avax.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TopicName } from '@app/utils/topicUtils';
import { Controller, Logger } from '@nestjs/common';
import { EventPattern } from '@nestjs/microservices';
import { AvaxService } from './avax.service';

@Controller()
export class AvaxController {
private readonly logger = new Logger(AvaxController.name);
constructor(private readonly avax: AvaxService) {}

@EventPattern(TopicName.AVAX_NATIVE_TRANSFER)
async handleNativeTransfer(data: any) {
const start = Date.now();
await this.avax.handleNativeTransfer(data);
if (Date.now() - start > 20)
this.logger.warn(`Handle native transfer in : ${Date.now() - start}`);
}

@EventPattern(TopicName.AVAX_ERC20_TRANSFER)
async handleErc20Transfer(data: any) {
const start = Date.now();
await this.avax.handleErc20Transfer(data);
if (Date.now() - start > 20)
this.logger.warn(`Handle erc20 transfer in : ${Date.now() - start}`);
}

@EventPattern(TopicName.AVAX_ERC721_TRANSFER)
async handleErc721Transfer(data: any) {
const start = Date.now();
await this.avax.handleErc721Transfer(data);
if (Date.now() - start > 20)
this.logger.warn(`Handle erc721 transfer in : ${Date.now() - start}`);
}
}
54 changes: 54 additions & 0 deletions app/apps/monitor-service/src/avax/avax.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { EventHistoryModelModule } from '@app/shared_modules/event_history/event_history.module';
import { MonitorModule } from '@app/shared_modules/monitor/monitor.module';
import { ProjectModule } from '@app/shared_modules/project/project.module';
import { WebhookModule } from '@app/shared_modules/webhook/webhook.module';
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { AvaxController } from './avax.controller';
import { AvaxService } from './avax.service';

@Module({
providers: [AvaxService],
controllers: [AvaxController],
exports: [AvaxService],
imports: [
ClientsModule.registerAsync([
{
name: 'WEBHOOK_SERVICE',
useFactory: () => ({
transport: Transport.KAFKA,
options: {
client: {
clientId: 'webhook',
brokers: process.env.KAFKA_BROKERS.split(','),
ssl: process.env.KAFKA_SSL === 'true',
sasl:
process.env.KAFKA_AUTH_ENABLE === 'true'
? {
mechanism: 'plain',
username: process.env.KAFKA_USERNAME || '',
password: process.env.KAFKA_PASSWORD || '',
}
: null,
retry: {
restartOnFailure: async (e) => {
console.log('RESTART ON FAILURE avax module');
console.log(e);
return true;
},
},
},
consumer: {
groupId: 'webhook-consumer',
},
},
}),
},
]),
WebhookModule,
MonitorModule,
ProjectModule,
EventHistoryModelModule,
],
})
export class AvaxModule {}
Loading