Skip to main content
Dialect alerts is a powerful infra that helps developers setup up in-app, push, email, telegram notifications for users with simple setup by abstracting the complexity of the messaging services. This recipe demostrates how to setup a monitoring system to alert users via Dialect notifications when new pools are created with a specific token on DLMM.

Prerequisites

Project Setup

Create a new project directory and initialize it:

Install Dependencies

Install the required packages:

TypeScript Configuration

Create a tsconfig.json file:
tsconfig.json

Update package.json

Add the module type to your package.json:
package.json

Create Service Files

Wallet Adapter

We will be needing a wallet adapter that will be used by dialect sdk to sign messages. it is prefered to use NodeDialectSolanaWalletAdapter from @dialectlabs/blockchain-sdk-solana . But now I will show you how to create a custom wallet adapter that will be used by dialect sdk to sign messages.
src/wallet.js

Saros DLMM Service

Create src/service.js and create an instance of LiquidityBookServices from @saros-finance/dlmm-sdk. This client object will be sufficient for our monitoring system.
src/service.js

Main Monitoring Script

Let’s split the monitoring system into three main components:
  1. Client SDK Initialization - Setting up Dialect and Saros SDKs
  2. On-Chain Tracking - Listen to pool creation events
  3. Monitor Setup - Monitor setup that will process and emit alerts to dialect infra, that will be used to send notifications to users.

1. Client SDK Initialization

First, let’s set up the Dialect SDK client in a separate file called pool-tracker.ts.
The wallet used here is the registered wallet in dialect dashboard.
src/pool-tracker.ts

2. On-Chain Tracking

Now we will track the new DLMM pool creations for PYUSD token on devnet. We will setup a source that will receive the data that we are interested in and emit it to the monitor setup. Then by using listenNewPoolAddress and fetchPoolMetadata methods we will be able to track the new pool created for PYUSD token.
src/pool-tracker.ts diff

3. Monitor Setup

Now setup the monitor that will listen to the subject, process the data given by the subject and emit the alert to the dialect desired message.
The transform step is used to add constraints on the data and filter out unwanted messages. But in our case we are not adding any constraints on the data.
The notify step is used to emit the alert to the dialect desired message and dialectSdk is used process the raw data into the desired message.
src/pool-tracker.ts diff

Running the Monitor

update your package.json file to execute pool-tracker.ts script:
diff package.json
Build and run the project:
On Pool creation, you should see the following output: