Skip to content

Commit 6f5a7f7

Browse files
authored
feat: add ci (#52)
1 parent 0aabc70 commit 6f5a7f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+380
-850
lines changed

.github/workflows/ci.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
ci:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set alternate npm integrity keys
17+
run: |
18+
echo COREPACK_INTEGRITY_KEYS="$(curl https://registry.npmjs.org/-/npm/v1/keys | jq -c '{npm: .keys}')" >> $GITHUB_ENV
19+
- run: corepack enable
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 22
23+
cache: "pnpm"
24+
- run: |
25+
touch .env
26+
echo GH_COMMIT_SHA="${{ github.event.pull_request.head.sha }}" >> .env
27+
- name: Install dependencies
28+
run: |
29+
pnpm install
30+
- name: Build
31+
run: |
32+
pnpm build
33+
- name: Compile
34+
run: |
35+
pnpm compile
36+
- name: Format check
37+
run: |
38+
pnpm format:check
39+
- name: Lint check
40+
run: |
41+
pnpm lint:check
42+
- name: Test
43+
run: |
44+
pnpm test
45+

.papi/descriptors/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.0-autogenerated.1075724625805823469",
2+
"version": "0.1.0-autogenerated.5713703155598959433",
33
"name": "@polkadot-api/descriptors",
44
"files": [
55
"dist"

.papi/metadata/hydra.scale

470 KB
Binary file not shown.

.papi/polkadot-api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"chain": "ksmcc3_asset_hub",
3232
"metadata": ".papi/metadata/ksmcc3_asset_hub.scale",
3333
"genesis": "0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a"
34+
},
35+
"hydra": {
36+
"wsUrl": "wss://hydration-rpc.n.dwellir.com",
37+
"metadata": ".papi/metadata/hydra.scale",
38+
"genesis": "0xafdc188f45c71dacbaa0b62e16a91f726c7b8699a9748cdf715459de6b7f366d"
3439
}
3540
}
3641
}

eslint.config.ts

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,78 @@
1-
import tseslint from '@typescript-eslint/eslint-plugin';
2-
import prettier from 'eslint-config-prettier';
3-
export default [
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
import prettierConfig from "eslint-config-prettier";
6+
import tsDocsPlugin from "eslint-plugin-tsdoc";
7+
import simpleImportSort from "eslint-plugin-simple-import-sort";
8+
9+
export default tseslint.config(
410
{
5-
files: ['**/*.ts'],
6-
ignores: ['**/node_modules/**', '**/dist/**', '**/build/**'],
11+
ignores: [
12+
"eslint.config.ts",
13+
"**/dist/",
14+
"**/.turbo/",
15+
"**/vitest.*.ts",
16+
"**/vite.config.ts",
17+
"**/rollup.config.js",
18+
"**/node_modules/",
19+
"**/*.test.ts",
20+
],
21+
},
22+
eslint.configs.recommended,
23+
...tseslint.configs.recommendedTypeChecked,
24+
prettierConfig,
25+
{
26+
plugins: {
27+
tsdoc: tsDocsPlugin,
28+
"simple-import-sort": simpleImportSort,
29+
},
730
languageOptions: {
831
parserOptions: {
932
project: ["./packages/*/tsconfig*.json"],
1033
tsconfigRootDir: import.meta.dirname,
1134
},
1235
},
13-
plugins: {
14-
'@typescript-eslint': tseslint,
15-
},
1636
rules: {
17-
'no-console': 'warn',
18-
'no-unused-vars': 'off',
19-
'@typescript-eslint/no-unused-vars': ['warn'],
20-
'@typescript-eslint/explicit-module-boundary-types': 'off',
21-
'@typescript-eslint/no-explicit-any': 'off',
37+
"no-console": "error",
38+
"tsdoc/syntax": "error",
39+
"@typescript-eslint/no-unused-vars": [
40+
"error",
41+
{
42+
args: "all",
43+
argsIgnorePattern: "^_",
44+
caughtErrors: "all",
45+
caughtErrorsIgnorePattern: "^_",
46+
destructuredArrayIgnorePattern: "^_",
47+
varsIgnorePattern: "^_",
48+
ignoreRestSiblings: true,
49+
},
50+
],
51+
"@typescript-eslint/consistent-type-imports": [
52+
"error",
53+
{
54+
prefer: "type-imports",
55+
disallowTypeAnnotations: false,
56+
fixStyle: "separate-type-imports",
57+
},
58+
],
59+
"simple-import-sort/imports": "error",
60+
"simple-import-sort/exports": "error",
2261
},
2362
},
2463
{
64+
files: ["**/*.test.ts"],
2565
rules: {
26-
...prettier.rules,
66+
"@typescript-eslint/no-unsafe-assignment": "off",
2767
},
2868
},
29-
];
69+
{
70+
files: [
71+
"packages/*/**/*.test.ts",
72+
],
73+
rules: {
74+
"no-restricted-syntax": "off",
75+
},
76+
}
77+
);
78+

examples/telegram-bot/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,13 @@
2828
"devDependencies": {
2929
"@types/jest": "^29.5.14",
3030
"@types/node": "^22.14.1",
31-
"@typescript-eslint/eslint-plugin": "^8.31.0",
32-
"@typescript-eslint/parser": "^8.31.0",
3331
"eslint": "^9.25.1",
34-
"eslint-config-prettier": "^10.1.2",
35-
"eslint-plugin-prettier": "^5.2.6",
3632
"jest": "^29.7.0",
3733
"nodemon": "^3.1.9",
3834
"prettier": "^3.5.3",
3935
"ts-jest": "^29.3.2",
4036
"ts-node": "^10.9.2",
4137
"typescript": "^5.8.3",
42-
"typescript-eslint-parser": "^22.0.0",
4338
"jiti": "^2.3.3"
4439
}
4540
}

packages/common/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
"format:write": "prettier --write src",
3333
"test": "vitest run",
3434
"test:cov": "vitest run --coverage",
35-
"test:watch": "vitest",
36-
"setup": "tsx ./scripts/setup-chains.ts"
35+
"test:watch": "vitest"
3736
},
3837
"dependencies": {
3938
"@noble/curves": "^1.6.0",

packages/common/src/api/api.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { polkadot } from "@polkadot-api/descriptors"
22
import type { ChainDefinition, TypedApi } from "polkadot-api"
3+
34
import {
4-
getChainById,
5-
getDescriptors,
6-
isChainIdAssetHub,
7-
isChainIdRelay,
85
type Chain,
96
type ChainId,
107
type ChainIdAssetHub,
118
type ChainIdRelay,
129
type Descriptors,
10+
getChainById,
11+
getDescriptors,
12+
isChainIdAssetHub,
13+
isChainIdRelay,
1314
type KnownChainId
1415
} from "../chains"
15-
import { getClient, type ClientOptions } from "../clients/client"
16+
import { type ClientOptions,getClient } from "../clients/client"
1617

1718
export type LightClients = ClientOptions["lightClients"]
1819
type ApiBase<Id extends ChainId> = Id extends KnownChainId
@@ -47,15 +48,18 @@ export const getApiInner = async <Id extends ChainId>(
4748

4849
const descriptors = getDescriptors(chain.id)
4950
const client = await getClient(chainId, chains, { lightClients })
50-
if (!client) throw new Error(`Could not create client for chain ${chainId}/${lightClients}`)
51+
if (!client) throw new Error(`Could not create client for chain ${chainId}`)
5152

5253
const api = client.getTypedApi(descriptors ?? polkadot) as Api<Id>
5354

5455
api.chainId = chainId as Id
5556
api.chain = chain
5657
api.waitReady = (() => {
57-
// Track subscription for cleanup
58-
let subscription: any = null
58+
59+
type Subscription = {
60+
unsubscribe: () => void
61+
}
62+
let subscription: Subscription | null = null
5963

6064
// Create the actual Promise
6165
const readyPromise = new Promise<void>((resolve, reject) => {
@@ -69,13 +73,15 @@ export const getApiInner = async <Id extends ChainId>(
6973
subscription = client.bestBlocks$.subscribe({
7074
next: () => {
7175
clearTimeout(timeoutId)
76+
7277
if (subscription) subscription.unsubscribe()
7378
resolve()
7479
},
75-
error: err => {
80+
error: (err: Error) => {
7681
clearTimeout(timeoutId)
82+
7783
if (subscription) subscription.unsubscribe()
78-
reject(err)
84+
reject(new Error(err.message))
7985
}
8086
})
8187
})
@@ -87,7 +93,7 @@ export const getApiInner = async <Id extends ChainId>(
8793
}
8894

8995
const getApiCacheId = (chainId: ChainId, lightClient: LightClients): string =>
90-
`${chainId}-${lightClient?.enable ?? "false"}`
96+
`${chainId}-${JSON.stringify(lightClient?.enable ?? false)}`
9197

9298
const API_CACHE = new Map<string, Promise<Api<ChainId>>>()
9399

@@ -110,7 +116,7 @@ export const getApi = async <Id extends ChainId, Papi = Api<Id>>(
110116

111117
/**
112118
* Disconnects an API instance and cleans up associated resources
113-
* @param api The API instance to disconnect
119+
* @param api - The API instance to disconnect
114120
* @returns Promise that resolves when disconnection is complete
115121
*/
116122
export const disconnect = async <Id extends ChainId>(api: Api<Id>): Promise<void> => {

packages/common/src/chains/chains.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { polkadot, polkadot_asset_hub, west, west_asset_hub } from "@polkadot-api/descriptors"
1+
import { hydra,polkadot, polkadot_asset_hub, west, west_asset_hub } from "@polkadot-api/descriptors"
22

33
import {
4-
polkadotChain,
54
polkadotAssetHubChain,
6-
westendChain,
7-
westendAssetHubChain
8-
} from "./supported-chains"
5+
polkadotChain,
6+
westendAssetHubChain,
7+
westendChain} from "./supported-chains"
98
type DescriptorsRelayType = {
109
polkadot: typeof polkadot
1110
west: typeof west
@@ -16,8 +15,9 @@ type DescriptorsAssetHubType = {
1615
west_asset_hub: typeof west_asset_hub
1716
}
1817

19-
// todo: add para descriptors
20-
type DescriptorsParaType = {}
18+
type DescriptorsParaType = {
19+
hydra: typeof hydra
20+
}
2121

2222
const DESCRIPTORS_RELAY: DescriptorsRelayType = {
2323
polkadot,
@@ -29,7 +29,9 @@ const DESCRIPTORS_ASSET_HUB: DescriptorsAssetHubType = {
2929
west_asset_hub
3030
}
3131

32-
const DESCRIPTORS_PARA: DescriptorsParaType = {}
32+
const DESCRIPTORS_PARA: DescriptorsParaType = {
33+
hydra
34+
}
3335

3436
export const DESCRIPTORS_ALL = {
3537
...DESCRIPTORS_RELAY,
@@ -84,13 +86,13 @@ export type ChainAssetHub = Chain & { chainId: 1000 }
8486
export const getChainById = <T extends Chain>(id: ChainId, chains: Chain[]): T => {
8587
const foundChain = chains.find(chain => chain.id === id) as T
8688
if (!foundChain) throw new Error(`Could not find chain ${id}`)
87-
return foundChain as T
89+
return foundChain
8890
}
8991

9092
export const getChainByName = <T extends Chain>(name: string, chains: Chain[]): T => {
9193
const foundChain = chains.find(chain => chain.name === name) as T
9294
if (!foundChain) throw new Error(`Could not find chain ${name}`)
93-
return foundChain as T
95+
return foundChain
9496
}
9597

9698
const SUPPORTED_CHAINS: Chain[] = [

packages/common/src/chains/supported-chains.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Chain } from "./chains"
1+
import type { Chain } from "./chains"
22

33
export type Assign<T, U> = {
44
[K in keyof T]: K extends keyof U ? U[K] : T[K]
@@ -64,3 +64,17 @@ export const westendAssetHubChain = createChain({
6464
decimals: 12,
6565
symbol: "WND"
6666
})
67+
68+
export const hydraChain = createChain({
69+
id: "hydra",
70+
name: "Hydration",
71+
specName: "hydra",
72+
wsUrls: ["wss://hydration-rpc.n.dwellir.com"],
73+
relay: "polkadot",
74+
type: "para",
75+
chainId: null,
76+
blockExplorerUrl: "https://hydration.subscan.io",
77+
prefix: 42,
78+
decimals: 12,
79+
symbol: "HDX"
80+
})

0 commit comments

Comments
 (0)