Skip to content

Commit

Permalink
chore: update monitor & dialect sdk to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbl committed Apr 25, 2024
1 parent 5319a80 commit 982e282
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 576 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"client:start:local-dev": "dotenv -e .env.local-dev -e .env.client -- ts-node test/client.ts"
},
"dependencies": {
"@dialectlabs/monitor": "^3.3.3",
"@dialectlabs/sdk": "^0.11.0",
"@dialectlabs/blockchain-sdk-solana": "^1.2.0",
"@dialectlabs/monitor": "^3.5.1",
"@dialectlabs/sdk": "^1.9.1",
"@nestjs/axios": "^0.1.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
Expand All @@ -30,8 +31,7 @@
"@nestjs/schedule": "^2.1.0",
"@nestjs/terminus": "^9.1.0",
"@solana/spl-governance": "^0.3.28",
"@solana/spl-token": "^0.4.3",
"@solana/spl-token-registry": "^0.2.3775",
"@solana/spl-token": "0.2.0",
"bn.js": "^5.1.3",
"borsh": "^0.3.1",
"bs58": "^4.0.1",
Expand Down Expand Up @@ -63,9 +63,9 @@
"dotenv-cli": "^7.4.1",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "28.1.2",
"prettier": "^2.3.2",
"prettier": "^3.2.5",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.5",
Expand Down
34 changes: 16 additions & 18 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { Module } from '@nestjs/common';
import { LoggerModule } from 'nestjs-pino';
import { HttpModule } from '@nestjs/axios';
import {
Dialect,
Environment,
NodeDialectWalletAdapter,
SolanaNetwork,
} from '@dialectlabs/sdk';
import { DialectSdk } from './dialect-sdk';
import { Dialect, DialectSdk, Environment } from '@dialectlabs/sdk';
import { ConfigModule } from '@nestjs/config';
import { RealmsRestService } from './realms-rest-service';
import { RealmsService } from './realms.service';
Expand All @@ -19,6 +13,11 @@ import { HealthController } from './health.controller';
import { TerminusModule } from '@nestjs/terminus';
import { CachingHealth } from './caching.health';
import { EventEmitterModule } from '@nestjs/event-emitter';
import {
NodeDialectSolanaWalletAdapter,
Solana,
SolanaSdkFactory,
} from '@dialectlabs/blockchain-sdk-solana';

@Module({
imports: [
Expand Down Expand Up @@ -52,18 +51,17 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
NewProposalsMonitoringService,
ProposalStateChangeMonitoringService,
{
provide: DialectSdk,
useValue: Dialect.sdk({
environment: process.env.DIALECT_SDK_ENVIRONMENT as Environment,
solana: {
network: process.env.DIALECT_SDK_SOLANA_NETWORK_NAME as SolanaNetwork,
rpcUrl: process.env.DIALECT_SDK_SOLANA_RPC_URL,
},
dialectCloud: {
url: process.env.DIALECT_SDK_DIALECT_CLOUD_URL,
provide: DialectSdk<Solana>,
useValue: Dialect.sdk(
{
environment: process.env.DIALECT_SDK_ENVIRONMENT as Environment,
},
wallet: NodeDialectWalletAdapter.create(),
}),
SolanaSdkFactory.create({
// IMPORTANT: must set environment variable DIALECT_SDK_CREDENTIALS
// to your dapp's Solana messaging wallet keypair e.g. [170,23, . . . ,300]
wallet: NodeDialectSolanaWalletAdapter.create(),
}),
),
},
],
})
Expand Down
16 changes: 0 additions & 16 deletions src/dialect-sdk.ts

This file was deleted.

17 changes: 10 additions & 7 deletions src/new-proposals-monitoring.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import {
} from '@dialectlabs/monitor';
import { Duration } from 'luxon';

import { DialectSdk } from './dialect-sdk';
import { NOTIF_TYPE_ID_PROPOSALS } from './main';
import {
ProposalWithMetadata,
RealmData,
RealmsService,
} from './realms.service';
import { ConsoleNotificationSink } from './console-notification-sink';
import { OnEvent } from '@nestjs/event-emitter';
import { CachingEventType } from './realms-cache';
import {
TwitterNotification,
TwitterNotificationsSink,
} from './twitter-notifications-sink';
import { Solana } from '@dialectlabs/blockchain-sdk-solana';
import { DialectSdk } from '@dialectlabs/sdk';

@Injectable()
export class NewProposalsMonitoringService {
Expand All @@ -34,7 +34,7 @@ export class NewProposalsMonitoringService {
private readonly monitor: Monitor<RealmData> = this.createMonitor();

constructor(
private readonly sdk: DialectSdk,
private readonly sdk: DialectSdk<Solana>,
private readonly realmsService: RealmsService,
) {}

Expand Down Expand Up @@ -98,13 +98,16 @@ export class NewProposalsMonitoringService {
realmId,
value,
);
this.logger.log(
`Sending message for ${context.origin.subscribers.length} subscribers of realm ${realmId} : ${message}`,
);
return {
const notification: DialectSdkNotification = {
title: `New proposal for ${realmName}`,
message,
};
this.logger.log(
`Sending notification ${JSON.stringify(notification)} to ${
context.origin.subscribers.length
} subscribers of realm ${realmName}`,
);
return notification;
},
{ dispatch: 'multicast', to: ({ origin }) => origin.subscribers },
)
Expand Down
9 changes: 5 additions & 4 deletions src/proposal-state-monitoring.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@dialectlabs/monitor';
import { Duration } from 'luxon';

import { DialectSdk } from './dialect-sdk';
import { NOTIF_TYPE_ID_PROPOSALS } from './main';
import { ProposalData, RealmsService } from './realms.service';
import {
Expand All @@ -19,8 +18,9 @@ import {
Realm,
} from '@solana/spl-governance';
import { CachingEventType, fmtTokenAmount, RealmMints } from './realms-cache';
import { ConsoleNotificationSink } from './console-notification-sink';
import { OnEvent } from '@nestjs/event-emitter';
import { DialectSdk } from '@dialectlabs/sdk';
import { Solana } from '@dialectlabs/blockchain-sdk-solana';

interface ProposalVotingStats {
yesCount: number;
Expand All @@ -34,7 +34,7 @@ export class ProposalStateChangeMonitoringService {
private readonly monitor: Monitor<ProposalData> = this.createMonitor();

constructor(
private readonly sdk: DialectSdk,
private readonly sdk: DialectSdk<Solana>,
private readonly realmsService: RealmsService,
) {}

Expand Down Expand Up @@ -87,13 +87,14 @@ export class ProposalStateChangeMonitoringService {
.dialectSdk(
({ value, context }) => {
const realmId: string = context.origin.realm.pubkey.toBase58();
const realmName: string = context.origin.realm.account.name;
const notification = this.constructNotification(
context.origin.realm.account,
realmId,
value,
);
this.logger.log(
`Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmId}
`Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmName}
${notification.title}
${notification.message}
`,
Expand Down
2 changes: 2 additions & 0 deletions src/realms-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from './realms-sdk';
import { groupBy, keyBy } from 'lodash';
import { EventEmitter2 } from '@nestjs/event-emitter';

export interface CachingEvent {
type: CachingEventType;
}
Expand All @@ -33,6 +34,7 @@ export interface InitialCachingFinished extends CachingEvent {
export enum CachingEventType {
InitialCachingFinished = 'caching.initial_finished',
}

export interface RealmMints {
mint?: RawMint;
councilMint?: RawMint;
Expand Down
5 changes: 2 additions & 3 deletions src/realms-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ export async function fetchRealmsWithMints(realms: ProgramAccount<Realm>[]) {
const chunkedMints = chunk(mints, 100);
for (const chunked of chunkedMints) {
await sleepSecs(1);
const multipleAccountsInfo = await connection.getMultipleAccountsInfo(
chunked,
);
const multipleAccountsInfo =
await connection.getMultipleAccountsInfo(chunked);
accInfoAcc.push(...multipleAccountsInfo);
}
const mintAccounts = compact(accInfoAcc);
Expand Down
10 changes: 2 additions & 8 deletions src/realms.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { ResourceId, SourceData } from '@dialectlabs/monitor';
import {
ProgramAccount,
Proposal,
Realm,
TokenOwnerRecord,
} from '@solana/spl-governance';
import { ProgramAccount, Proposal, Realm } from '@solana/spl-governance';
import { PublicKey } from '@solana/web3.js';
import { Injectable, Logger } from '@nestjs/common';
import { RealmsCache } from './realms-cache';
import { chain, groupBy } from 'lodash';
import * as process from 'process';
import { chain } from 'lodash';

export interface RealmData {
realm: ProgramAccount<Realm>;
Expand Down
Loading

0 comments on commit 982e282

Please sign in to comment.