Skip to content

Commit 5eac359

Browse files
committed
chore: add pallet utils and update types network
1 parent 61ecf2a commit 5eac359

2 files changed

Lines changed: 307 additions & 0 deletions

File tree

src/lib/types/network.ts

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
/**
2+
* Parachain information
3+
*/
4+
export interface Parachain {
5+
/** Parachain ID */
6+
paraId: number;
7+
/** Human-readable parachain name */
8+
name: string;
9+
/** Native token symbol */
10+
symbol: string;
11+
}
12+
13+
/**
14+
* XCM configuration for networks
15+
*/
16+
export interface XcmConfig {
17+
/** XCM version supported */
18+
version: 'V3' | 'V4';
19+
/** Supported XCM methods */
20+
supportedMethods: string[];
21+
/** Default weight limit */
22+
defaultWeightLimit: 'Unlimited' | 'Limited';
23+
/** Maximum message size in bytes */
24+
maxMessageSize: number;
25+
/** Whether XCM is fully supported */
26+
fullySupported: boolean;
27+
/** Whether XCM is enabled */
28+
xcmEnabled: boolean;
29+
/** Whether this is a testnet */
30+
isTestnet?: boolean;
31+
/** Known limitations */
32+
limitations?: string[];
33+
/** Supported XCM routes */
34+
supportedRoutes?: string[];
35+
/** Additional notes */
36+
notes?: string[];
37+
}
38+
39+
/**
40+
* Network health status
41+
*/
42+
export interface NetworkHealth {
43+
/** Whether the network is online */
44+
online: boolean;
45+
/** Response time in milliseconds */
46+
responseTime?: number;
47+
/** Latest block number */
48+
latestBlock?: number;
49+
/** Last check timestamp */
50+
lastCheck?: Date;
51+
}
52+
153
/**
254
* Network configuration type
355
*/
@@ -22,4 +74,197 @@ export interface Network {
2274
descriptorKey: string;
2375
/** Path to use when importing chain spec */
2476
chainSpecPath: string;
77+
/** Network type for categorization */
78+
networkType: 'polkadot' | 'kusama' | 'paseo' | 'westend';
79+
/** XCM configuration */
80+
xcmConfig?: XcmConfig;
81+
/** System parachains */
82+
systemParachains?: Parachain[];
83+
/** Supported parachains */
84+
supportedParachains?: Parachain[];
85+
/** Alternative RPC endpoints */
86+
alternativeEndpoints?: string[];
87+
/** Network health check endpoint */
88+
healthEndpoint?: string;
89+
/** Network health status */
90+
health?: NetworkHealth;
91+
/** Network color for UI theming */
92+
color?: string;
93+
/** Network icon/logo URL */
94+
icon?: string;
95+
/** Genesis hash for verification */
96+
genesisHash?: string;
97+
/** Chain specification version */
98+
specVersion?: number;
99+
/** Transaction version */
100+
transactionVersion?: number;
101+
/** Whether the network supports smart contracts */
102+
supportsContracts?: boolean;
103+
/** Supported account formats */
104+
accountFormats?: ('sr25519' | 'ed25519' | 'ecdsa')[];
105+
/** Network-specific features */
106+
features?: {
107+
/** Governance system type */
108+
governance?: 'democracy' | 'council' | 'opengov' | 'collective';
109+
/** Staking system available */
110+
staking?: boolean;
111+
/** Identity pallet available */
112+
identity?: boolean;
113+
/** Multisig support */
114+
multisig?: boolean;
115+
/** Proxy support */
116+
proxy?: boolean;
117+
/** Treasury available */
118+
treasury?: boolean;
119+
/** Bounties available */
120+
bounties?: boolean;
121+
/** Tips available */
122+
tips?: boolean;
123+
/** Society pallet */
124+
society?: boolean;
125+
/** Vesting schedules */
126+
vesting?: boolean;
127+
/** Recovery pallet */
128+
recovery?: boolean;
129+
/** Scheduler pallet */
130+
scheduler?: boolean;
131+
/** Preimage pallet */
132+
preimage?: boolean;
133+
/** Asset management */
134+
assets?: boolean;
135+
/** NFT support */
136+
nfts?: boolean;
137+
/** Uniques pallet */
138+
uniques?: boolean;
139+
};
140+
/** Network-specific metadata */
141+
metadata?: {
142+
/** Official website */
143+
website?: string;
144+
/** Social media links */
145+
social?: {
146+
twitter?: string;
147+
discord?: string;
148+
telegram?: string;
149+
github?: string;
150+
reddit?: string;
151+
};
152+
/** Documentation links */
153+
documentation?: string;
154+
/** Wiki or help resources */
155+
wiki?: string;
156+
/** API documentation */
157+
apiDocs?: string;
158+
/** Whitepaper or technical docs */
159+
whitepaper?: string;
160+
};
161+
/** Rate limiting configuration */
162+
rateLimit?: {
163+
/** Requests per minute */
164+
requestsPerMinute: number;
165+
/** Burst capacity */
166+
burstCapacity?: number;
167+
/** Cooldown period in seconds */
168+
cooldownPeriod?: number;
169+
};
170+
/** Connection settings */
171+
connection?: {
172+
/** Connection timeout in milliseconds */
173+
timeout?: number;
174+
/** Retry attempts */
175+
retryAttempts?: number;
176+
/** Auto-reconnect */
177+
autoReconnect?: boolean;
178+
/** Keep-alive interval */
179+
keepAlive?: number;
180+
};
181+
/** Development settings */
182+
development?: {
183+
/** Local development endpoint */
184+
localEndpoint?: string;
185+
/** Docker compose available */
186+
dockerCompose?: boolean;
187+
/** Parachain template available */
188+
parachainTemplate?: boolean;
189+
/** Test data available */
190+
testData?: boolean;
191+
};
25192
}
193+
194+
/**
195+
* Network selection criteria
196+
*/
197+
export interface NetworkFilter {
198+
/** Filter by test/production */
199+
testOnly?: boolean;
200+
/** Filter by XCM support */
201+
xcmEnabled?: boolean;
202+
/** Filter by specific features */
203+
features?: (keyof Network['features'])[];
204+
/** Filter by network type */
205+
networkType?: Network['networkType'][];
206+
/** Filter by online status */
207+
onlineOnly?: boolean;
208+
}
209+
210+
/**
211+
* Network comparison result
212+
*/
213+
export interface NetworkComparison {
214+
/** Networks being compared */
215+
networks: Network[];
216+
/** Common features */
217+
commonFeatures: string[];
218+
/** Unique features per network */
219+
uniqueFeatures: Record<string, string[]>;
220+
/** Performance comparison */
221+
performance: Record<string, {
222+
responseTime: number;
223+
blockTime: number;
224+
throughput: number;
225+
}>;
226+
}
227+
228+
/**
229+
* Network validation result
230+
*/
231+
export interface NetworkValidation {
232+
/** Whether the network configuration is valid */
233+
isValid: boolean;
234+
/** Validation errors */
235+
errors: string[];
236+
/** Validation warnings */
237+
warnings: string[];
238+
/** Connection test result */
239+
connectionTest?: {
240+
success: boolean;
241+
responseTime?: number;
242+
error?: string;
243+
};
244+
}
245+
246+
/**
247+
* Network metrics for monitoring
248+
*/
249+
export interface NetworkMetrics {
250+
/** Network identifier */
251+
networkId: string;
252+
/** Current block height */
253+
blockHeight: number;
254+
/** Block time in seconds */
255+
blockTime: number;
256+
/** Number of active validators */
257+
activeValidators: number;
258+
/** Total issuance */
259+
totalIssuance: string;
260+
/** Active accounts */
261+
activeAccounts: number;
262+
/** Finalized block hash */
263+
finalizedHash: string;
264+
/** Peer count */
265+
peerCount: number;
266+
/** Sync status */
267+
syncStatus: 'syncing' | 'synced' | 'offline';
268+
/** Last update timestamp */
269+
lastUpdate: Date;
270+
}

src/utils/pallet.utils.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
2+
// @ts-nocheck
3+
import type { ApiPromise } from "@polkadot/api";
4+
import type { SubmittableExtrinsics } from '@polkadot/api/types';
5+
6+
7+
export const PALLET_MAPPINGS: Record<string, string[]> = {
8+
xcm: ['xcmPallet', 'polkadotXcm', 'xTokens', 'xtokens'],
9+
xcmp: ['xcmpQueue', 'cumulusXcm'],
10+
hrmp: ['hrmp'],
11+
bridgeHub: ['bridgeHubPolkadot', 'bridgeHubKusama', 'bridgeHubPaseo'],
12+
13+
14+
assets: ['assets', 'statemine', 'statemint', 'assetHub', 'foreignAssets', 'assetManager'],
15+
balances: ['balances'],
16+
nfts: ['nfts', 'uniques'],
17+
18+
19+
identity: ['identity', 'people', 'identityServer'],
20+
governance: ['gov', 'governance', 'democracy', 'council', 'technicalCommittee', 'elections', 'phragmenElection'],
21+
collectives: ['collectives', 'alliance'],
22+
23+
24+
contracts: ['contracts'],
25+
evm: ['evm', 'ethereum', 'moonbeam', 'frontier'],
26+
27+
28+
staking: ['staking', 'nominationPools'],
29+
rewards: ['rewards', 'bounties', 'treasury'],
30+
31+
32+
33+
liquidStakingBifrost: ['slp', 'salp', 'liquidStaking', 'vtokenMinting', 'bancor'],
34+
35+
// Acala & Karura - Hub DeFi
36+
defiAcala: ['dex', 'loans', 'cdpTreasury', 'honzon', 'incentives', 'rewards'],
37+
liquidStakingAcala: ['homa'],
38+
stablecoinAcala: ['stableAsset', 'cdpEngine'],
39+
40+
41+
amm: ['amm', 'dex'],
42+
oracle: ['oracle', 'acalaOracle', 'band'],
43+
44+
45+
utility: ['utility'],
46+
system: ['system'],
47+
coretime: ['coretime', 'broker'],
48+
proxy: ['proxy'],
49+
multisig: ['multisig'],
50+
vesting: ['vesting'],
51+
scheduler: ['scheduler'],
52+
};
53+
54+
55+
export const findPallet = (api: ApiPromise, possibleNames: string[]): SubmittableExtrinsics<'promise'> | undefined => {
56+
for (const name of possibleNames) {
57+
if (api.tx[name]) {
58+
return api.tx[name];
59+
}
60+
}
61+
return undefined;
62+
};

0 commit comments

Comments
 (0)