{"id":20245051,"url":"https://github.com/interlay/polkabtc-stats","last_synced_at":"2025-08-21T16:24:48.553Z","repository":{"id":50124077,"uuid":"329896039","full_name":"interlay/polkabtc-stats","owner":"interlay","description":"PolkaBTC Stats","archived":false,"fork":false,"pushed_at":"2021-06-04T10:28:48.000Z","size":5998,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T02:41:26.103Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/interlay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-15T11:41:43.000Z","updated_at":"2021-06-03T15:40:19.000Z","dependencies_parsed_at":"2022-08-25T17:52:15.791Z","dependency_job_id":null,"html_url":"https://github.com/interlay/polkabtc-stats","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/interlay/polkabtc-stats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interlay%2Fpolkabtc-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interlay%2Fpolkabtc-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interlay%2Fpolkabtc-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interlay%2Fpolkabtc-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/interlay","download_url":"https://codeload.github.com/interlay/polkabtc-stats/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interlay%2Fpolkabtc-stats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271507264,"owners_count":24771823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T09:18:42.936Z","updated_at":"2025-08-21T16:24:48.508Z","avatar_url":"https://github.com/interlay.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PolkaBTC Stats API\n\nThis repository serves as a monitoring solution and API wrapper of ongoing events in the [PolkaBTC parachain](https://polkabtc.io/).\n\n\n### Monitoring\n\npolkabtc-stats includes a service to extract all events from the BTC-Parachain into a PostgreSQL database for further processing.\n\nWhen first starting, the service connects to a BTC-Parachain archive node to process all events from genesis and stores them into a PostgreSQL database.\nWhen it reaches the current block, it goes into a monitoring mode such that only the latest events from incoming blocks are parsed.\nOn restarting, the service first checks the last processed block in the database and will continue to process events from blocks not yet in the database.\n\n### API wrapper\n\n`polkabtc-stats` also provides an API wrapping around the PostgreSQL database, to aggregate and make available historic data about PolkaBTC parachain operation.\n\nWhen the service is running, queries to the PostgreSQL database can be made. The package provides pre-defined views to display relevant statistics.\nThis includes for example:\n\n- All issue requests\n- All redeem requests\n- Percentage of completed issue requests\n- Percentage of completed redeem requests\n\n### A note on decentralization\n\nAnybody can freely host their own instance of this database and use it to serve a local version of the dashboards contained in the official [PolkaBTC UI](https://github.com/interlay/polkabtc-ui). Interlay is hosting its own version for monitoring purposes.\n\n## Usage\n\n*For the current instructions on running against a local parachain alongside the monitoring service, see the *Testing* section below.*\n\n**Prerequisite:** As the pg-native driver is used for the database, you need to ensure `libpq` is installed locally; on some systems, this may require installing the development version of relevant postgresql packages in addition to postgresql itself (e.g. `libpq-dev` or `postgresql-libs-devel`). See [the NPM page](https://www.npmjs.com/package/pg-native) for more details.\n\nEnsure the proper environment variables for the PostgreSQL connection are set, e.g.:\n\n```shell\nPGHOST=yourhost\nPGPORT=15432\nPGDATABASE=database\nPGUSER=youruser\nPGPASSWORD=yourpassword\n```\n\nStart the service with:\n\n```shell\nexport PGSSLMODE=require # for secure connections\n\nyarn install\nyarn build # generate the routes and run typechecking\nyarn dev # start the server with file watching\n```\n\nThen navigate to `localhost:3007/docs` for the SwaggerUI, or to the defined routes to make use of the APIs.\n\n### Deployment\n\nRun `yarn start` instead.\n\n## Client\n\nFor client generation, ensure `java` is in the path (this is not necessary just to run the stats server).\n\n```shell\nyarn client\n```\n\nThis builds the client generated from the OpenAPI spec (which can then be published using `yarn publish`).\n\n## Testing\n\nTo build the database from the [btc-parachain](https://github.com/interlay/btc-parachain) setup postgresql and run the\nincluded monitoring service.\n\n```shell\ndocker run --rm --name postgres \\\n    -p 5432:5432 \\\n    -e POSTGRES_USER=user \\\n    -e POSTGRES_PASSWORD=password \\\n    postgres:11\n\nexport PGDATABASE=\"postgres\"\nexport PGUSER=\"user\"\nexport PGPASSWORD=\"password\"\n\nMONITOR=1 yarn dev\n```\n\nTo persist the database, mount a local volume on the docker container.\n\n```shell\nmkdir -p $HOME/docker/volumes/postgres\ndocker run --rm --name postgres \\\n    -p 5432:5432 \\\n    -e POSTGRES_USER=user \\\n    -e POSTGRES_PASSWORD=password \\\n    -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data \\\n    postgres:11\n```\n\n### Usage\n\n```typescript\nimport * as polkabtcStats from \"@interlay/polkabtc-stats\";\nconst statsApi = new polkabtcStats.StatsApi(new polkabtcStats.Configuration({ basePath: \"http://localhost:3001\" }));\nconst issues = (await statsApi.getTotalSuccessfulIssues()).data;\n```\n\n### Autogenerated paths\n\n`src/` is the only directory containing hand-written code. Do not edit files in the other directories.\n\n* `build/` contains the OpenAPI server (including the json definition and the routes to be served), generated from the definitons in `src`. Generated using `yarn build`.\n* `client/` contains the generated typescript client, as an intermediate step in packaging the client.\n* `dist/` contains the compiled client, publishable as an npm package. Generated (alongside `client/`) using `yarn client`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterlay%2Fpolkabtc-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finterlay%2Fpolkabtc-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterlay%2Fpolkabtc-stats/lists"}