Skip to content

Commit

Permalink
Add XCM transfers support (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacha authored Aug 6, 2024
1 parent 2ad8fff commit 39ded68
Show file tree
Hide file tree
Showing 18 changed files with 1,096 additions and 349 deletions.
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module.exports = {
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
"rules": {
"@typescript-eslint/camelcase": ["error", { "properties": "never" } ]
},
rules: {},
env: {
node: true,
},
Expand Down
4 changes: 2 additions & 2 deletions charts/polkadot-watcher-transaction/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: Polkadot Watcher
name: polkadot-watcher-transaction
version: v1.3.6
appVersion: v1.3.6
version: v1.4.0
appVersion: v1.4.0
apiVersion: v2
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-watcher-transaction",
"version": "1.3.6",
"version": "1.4.0",
"description": "Monitor events on Polkadot networks, specifically transactions",
"repository": "git@github.com:w3f/polkadot-watcher-csv-exporter.git",
"author": "W3F Infrastructure Team <devops@web3.foundation>",
Expand All @@ -16,11 +16,11 @@
"prepare": "yarn build",
"pretest": "yarn lint",
"test": "mocha --timeout 60000 --require ts-node/register --exit test/*.ts test/**/*.ts",
"e2e-test": "mocha --timeout 300000 --require ts-node/register --exit e2e-test/**/*.ts",
"test:integration": "mocha --timeout 60000 --require ts-node/register --exit test/integration/*.ts",
"start": "node ./dist/index.js start"
},
"dependencies": {
"@polkadot/api": "^12.0.1",
"@polkadot/api": "^12.2.3",
"@w3f/config": "^0.1.1",
"@w3f/logger": "^0.4.2",
"commander": "^4.0.0",
Expand All @@ -39,8 +39,8 @@
"@types/node": "14.18.20",
"@types/sinon": "10.0.11",
"@types/tmp": "0.2.3",
"@typescript-eslint/eslint-plugin": "2.34.0",
"@typescript-eslint/parser": "2.34.0",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@w3f/polkadot-api-client": "^1.3.0",
"@w3f/test-utils": "^1.4.0",
"chai": "4.3.6",
Expand All @@ -53,5 +53,8 @@
"tmp": "0.2.1",
"ts-node": "10.8.0",
"typescript": "4.7.2"
},
"resolutions": {
"@polkadot/api": "^12.2.3"
}
}
76 changes: 76 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Balance } from '@polkadot/types/interfaces';
import { ChainId } from './types';
import BN from 'bn.js';

export const ZeroBN = new BN(0);
Expand All @@ -8,3 +9,78 @@ export const retriesBeforeLeave = 5
export const delayBeforeRetryMillis = 5000 //5 seconds
export const dataFileName = "lastChecked.txt"
export const environment = "production"
export const chainsInfo = {
kusama: { id: 'kusama' as ChainId, decimals: [12], tokens: ['KSM'], SS58: 2 },
polkadot: { id: 'polkadot' as ChainId, decimals: [10], tokens: ['DOT'], SS58: 0 },
development: { id: 'polkadot' as ChainId, decimals: [10], tokens: ['DOT'], SS58: 0 }
}
export const parachainNames = {
polkadot: {
"1000": "AssetHub",
"1001": "Collectives",
"1002": "BridgeHub",
"1004": "People",
"2000": "Acala",
"2002": "Clover",
"2004": "Moonbeam",
"2006": "Astar",
"2008": "Crust",
"2012": "Parallel",
"2013": "Litentry",
"2025": "SORA",
"2026": "Nodle",
"2030": "Bifrost",
"2031": "Centrifuge",
"2032": "Interlay",
"2034": "Hydration",
"2035": "Phala Network",
"2037": "Unique Network",
"2040": "Polkadex",
"2043": "NeuroWeb",
"2046": "Darwinia2",
"2051": "Ajuna",
"2056": "Aventus",
"2086": "KILT Protocol",
"2090": "OAK Network",
"2092": "Zeitgeist",
"2093": "Hashed Network",
"2094": "Pendulum",
"2104": "Manta",
"3338": "peaq",
"3345": "Energy Web X",
"3346": "Continuum",
"3369": "Mythos"
},
kusama: {
"1000": "AssetHub",
"1001": "Collectives",
"1002": "BridgeHub",
"1004": "People",
"1005": "Coretime",
"2000": "Karura",
"2001": "Bifrost",
"2004": "Khala Network",
"2007": "Shiden",
"2011": "SORA",
"2012": "Crust Shadow",
"2023": "Moonriver",
"2024": "Genshiro",
"2048": "Robonomics",
"2084": "Calamari",
"2087": "Picasso",
"2090": "Basilisk",
"2092": "Kintsugi",
"2095": "Quartz",
"2096": "Pioneer",
"2105": "Crab2",
"2106": "Litmus",
"2110": "Mangata",
"2113": "Kabocha",
"2114": "Turing Network",
"2119": "Bajun Network",
"2239": "Acurast",
"2241": "krest",
"3339": "Curio",
"3344": "Xode"
}
};
5 changes: 3 additions & 2 deletions src/notifier/matrixbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ export class Matrixbot implements Notifier {

let description: string;
let alertname: string;
const chainName = data.networkId[0].toUpperCase() + data.networkId.slice(1)
const checkUrl = data.hash ? `https://${data.networkId}.subscan.io/extrinsic/${data.hash} for details.` : `https://${data.networkId}.subscan.io/account/${data.address}?tab=transfer for details.`

if (data.txType === TransactionType.Sent) {
description = `New Transfer of ${data.amount} sent from the account ${data.name}, check ${checkUrl}`;
description = `New Transfer of ${data.amount} ${data.token} sent from the ${chainName} account ${data.name}, check ${checkUrl}`;
alertname = 'TransferSent';
} else {
description = `New Transfer of ${data.amount} received in the account ${data.name}, check ${checkUrl}`;
description = `New Transfer of ${data.amount} ${data.token} received in the ${chainName} account ${data.name}, check ${checkUrl}`;
alertname = 'TransferReceived';
}
msg.alerts[0].labels.alertname = alertname;
Expand Down
17 changes: 8 additions & 9 deletions src/subscriber.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import '@polkadot/api-augment/polkadot'
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Logger, LoggerSingleton } from './logger';
import { Text } from '@polkadot/types/primitive';
import {
InputConfig, PromClient, SubscriberConfig, TransactionData, TransactionType
} from './types';
import { InputConfig, PromClient, SubscriberConfig, TransactionData, TransactionType, TypeRegistry } from './types';
import { EventScannerBased } from './subscriptionModules/eventScannerBased';
import { SubscriptionModuleConstructorParams } from './subscriptionModules/ISubscribscriptionModule';
import { Notifier } from './notifier/INotifier';
import { BalanceBelowThreshold } from './subscriptionModules/balanceBelowThreshold';


export const registry = new TypeRegistry()

export class Subscriber {
private chain: Text;
private api: ApiPromise;
private networkId: string;
private endpoint: string;
Expand Down Expand Up @@ -75,7 +74,7 @@ export class Subscriber {
private _initAPI = async (): Promise<void> =>{
const provider = new WsProvider(this.endpoint);

this.api = new ApiPromise({provider})
this.api = new ApiPromise({provider, registry})
if(this.api){
this.api.on("error", error => {
if( error.toString().includes("FATAL") || JSON.stringify(error).includes("FATAL") ){
Expand All @@ -86,14 +85,14 @@ export class Subscriber {
}
await this.api.isReadyOrError;

this.chain = await this.api.rpc.system.chain();
this.networkId = this.chain.toString().toLowerCase()
const chain = await this.api.rpc.system.chain();
this.networkId = chain.toString().toLowerCase()
const [nodeName, nodeVersion] = await Promise.all([
this.api.rpc.system.name(),
this.api.rpc.system.version()
]);
this.logger.info(
`You are connected to chain ${this.chain} using ${nodeName} v${nodeVersion}`
`You are connected to chain ${this.networkId} using ${nodeName} v${nodeVersion}`
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/subscriptionModules/ISubscribscriptionModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/interface-name-prefix */

import { ApiPromise } from "@polkadot/api";
import { Notifier } from "../notifier/INotifier";
import { SubscriberConfig } from "../types";
Expand Down
2 changes: 1 addition & 1 deletion src/subscriptionModules/balanceBelowThreshold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class BalanceBelowThreshold implements ISubscriptionModule{
this.promClient.updateDesiredBalance(this.networkId,account.name,account.address,account.threshold)
}

await this.api.query.system.account.multi(this.subscriptions.map(a => a.address), (balances) => {
await this.api.query.system.account.multi(this.subscriptions.map(a => a.address), (balances: any) => {
this.subscriptions.forEach((account, index) => {
const free = balances[index].data.free;
let balance = this.formatBalance(free.toBigInt());
Expand Down
Loading

0 comments on commit 39ded68

Please sign in to comment.