Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

sidestream-tech/notification-service

Repository files navigation

Please note:

This project is no longer being maintained. It was originally developed together with the Sidestream unified auctions ui. See the removal PR here.

Unified Auctions Notification Service

What is "Unified Auctions Notification Service?"?

"Unified Auctions Notification Service" is a server-side application with the purpose of updating users to a specific blockchain contract. Whenever a change is made to this contract the user will be informed via email or other methods. This is to ensure quick response times, when changes were made that could break our products.

The bots can be hosted by any user, provided, they configure related environment variables. For more details, please refer to Environment variables section below.

Setup

# install dependencies
$ npm install

# rebuild and launch server
$ npm run dev

# build for production and launch server
$ npm run build
$ npm run start

Environment variables

Note: env variables are accessible via the secret command under auction-ui/${environment}/notification-service.

  • INFURA_PROJECT_ID: (required) infura project id (can be found in: dashboard -> ethereum ->
  • ETHERSCAN_API_KEY: (required) Etherscan API Key, which is used to automatically download ABIs
  • ETHEREUM_NETWORK: (optional, default mainnet) – internal network name on which the bot poll for auctions.
  • SMTP_*: (optional, required for email usage) - SMTP data for the service to send emails
    • SMTP_HOST: (required) - SMTP host address
    • SMTP_PORT: (optional) - SMTP port. Defaults to 465
    • SMTP_USERNAME: (required) - SMTP username
    • SMTP_PASSWORD: (required) - SMTP password
    • SMTP_EMAIL: (required) - The outgoing address which is displayed to the user
  • RECEIVERS: (required) - a json-string-formatted array of Receivers (See explanation below)
  • POWERED_BY: (optional) - the operator of the service
  • POWERED_BY_LINK: (optional) - a link on which you can contact the operator of the service

Receivers:

Every Receiver requires the following values:

  • receiver - A custom value depending on the notifier type (see examples below)
  • type - The type of notifier (we currently support email and discord)
  • subscriptions - An array of Subscription Ids

You can find examples below:

Email Receiver:

{
  "receiver": "[email protected]",
  "type": "email",
  "subscriptions": ["ChainLogUpdateAddress"]
}

Please make sure to include the required Environment variables.

Discord Receiver:

{
  "receiver": "https://discord.com/api/webhooks/YOUR_WEBHOOK_ADDRESS",
  "type": "discord",
  "subscriptions": ["ChainLogUpdateAddress"]
}

Please provide a Discord Webhook URL to which we can send updates.

You do not need to update any other environment variables to setup a discord notifier.

Event Subscriptions

Users can add their own custom event subscriptions. By default, the project comes with a few predefined subscriptions, however these may need to change depending on the use case or network.

The subscriptions can be found in ./src/constants/SUBSCRIPTIONS.ts.

Every subscription requires the following values:

  • id - Unique identifier. Used for references in email and console logs
  • address - The Ethereum address which expected to emit the event
  • eventName - The name of the event you want to observe
  • formatData - A function that takes the emitted event data and have to return a markdown string that will be displayed in through the different notifiers. It has two values provided to help with the formatting:
    • event - the entire data returned by the event being called
    • formatEtherscanLink - a helper function that takes in type (either address or tx) and the content (either the address or transactionHash).

Example:

export const SUBSCRIPTIONS: EventSubscription[] = [
  {
    id: 'ChainLogUpdateAddress',
    address: '0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F',
    eventName: 'UpdateAddress',
    formatData: (event, formatEtherscanLink) => {
        return `> Key: ${ethers.utils.formatBytes32String(event.args.key)}<br />
                > Address: [${event.args.addr}](${formatEtherscanLink('address', event.args.addr)})`;
    },
  },
]

Development Setup

Please see this centralized guide to get started with your development setup. Namely, you should:

  • have a minimum node and npm version (see package.json engine section)
  • have a certain formatting and linting setup
  • don't forget to create ./notification-service/.env file

Help on both things is given in the linked resources above.