Prerequisites
- Before you proceed, ensure you have your app registered in dialect dashboard
- setup a interface to view alerts triggered.
Project Setup
Create a new project directory and initialize it:Install Dependencies
Install the required packages:TypeScript Configuration
Create atsconfig.json file:
tsconfig.json
Update package.json
Add the module type to yourpackage.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 useNodeDialectSolanaWalletAdapter 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
Createsrc/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:- Client SDK Initialization - Setting up Dialect and Saros SDKs
- On-Chain Tracking - Listen to pool creation events
- 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 calledpool-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 usinglistenNewPoolAddress 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 yourpackage.json file to execute pool-tracker.ts script:
diff package.json
