Skip to content

Commit

Permalink
Add family property to chain config (#157)
Browse files Browse the repository at this point in the history
* Add family property to chain config.

* docs(changeset): Add family property to chain config.
  • Loading branch information
imstar15 authored Feb 26, 2024
1 parent 95e828b commit 7c28827
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-yaks-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@oak-network/config": patch
---

Add family property to chain config.
6 changes: 5 additions & 1 deletion packages/config/src/chains/dev.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import BN from "bn.js";
import { Weight } from "./types/Weight";
import { createChain } from "./types/Chain";
import { ChainFamily, createChain } from "./types/Chain";
import { DevTokens } from "../tokens";

const shibuya = createChain({
assets: [{ asset: DevTokens.sby, isNative: true }],
endpoint: "ws://127.0.0.1:9948",
family: ChainFamily.astar,
isEthereum: true,
key: "shibuya",
name: "Shibuya",
Expand All @@ -24,6 +25,7 @@ const turingLocal = createChain({
{ asset: DevTokens.mgr, id: "1", isNative: false },
],
endpoint: "ws://127.0.0.1:9946",
family: ChainFamily.oak,
key: "turing-local",
name: "Turing Local",
relayChain: "local",
Expand All @@ -39,6 +41,7 @@ const mangataLocal = createChain({
{ asset: DevTokens.tur, isNative: false },
],
endpoint: "ws://127.0.0.1:9947",
family: ChainFamily.mangata,
key: "mangata-local",
name: "Mangata Local",
relayChain: "local",
Expand All @@ -59,6 +62,7 @@ const moonbaseLocal = createChain({
},
],
endpoint: "ws://127.0.0.1:9949",
family: ChainFamily.moonbeam,
isEthereum: true,
key: "moonbase-local",
name: "Moonbase Local",
Expand Down
6 changes: 5 additions & 1 deletion packages/config/src/chains/kusama.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import BN from "bn.js";
import { Weight } from "./types/Weight";
import { createChain } from "./types/Chain";
import { ChainFamily, createChain } from "./types/Chain";
import { KusamaTokens } from "../tokens";

const shiden = createChain({
assets: [{ asset: KusamaTokens.sdn, isNative: true }],
endpoint: "wss://shiden-rpc.dwellir.com",
family: ChainFamily.astar,
isEthereum: true,
key: "shiden",
name: "Shiden Network",
Expand All @@ -24,6 +25,7 @@ const turing = createChain({
{ asset: KusamaTokens.mgx, isNative: false }, // MGX is not registered on Turing yet
],
endpoint: "wss://rpc.turing.oak.tech",
family: ChainFamily.oak,
key: "turing",
name: "Turing Network",
relayChain: "kusama",
Expand All @@ -39,6 +41,7 @@ const mangata = createChain({
{ asset: KusamaTokens.xcTur, isNative: false },
],
endpoint: "wss://kusama-rpc.mangata.online",
family: ChainFamily.mangata,
key: "mangata",
name: "Mangata",
relayChain: "kusama",
Expand All @@ -59,6 +62,7 @@ const moonriver = createChain({
},
],
endpoint: "wss://wss.api.moonriver.moonbeam.network",
family: ChainFamily.moonbeam,
isEthereum: true,
key: "moonriver",
name: "Moonriver",
Expand Down
4 changes: 3 additions & 1 deletion packages/config/src/chains/moonbase.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import BN from "bn.js";
import { Weight } from "./types/Weight";
import { createChain } from "./types/Chain";
import { ChainFamily, createChain } from "./types/Chain";
import { MoonbaseTokens } from "../tokens";

const turingMoonbase = createChain({
assets: [{ asset: MoonbaseTokens.tur, isNative: true }],
endpoint: "ws://167.99.226.24:8846",
family: ChainFamily.oak,
key: "turing-moonbase",
name: "Moonbase Turing",
relayChain: "moonbase-alpha-relay",
Expand All @@ -26,6 +27,7 @@ const moonbaseAlpha = createChain({
},
],
endpoint: "wss://wss.api.moonbase.moonbeam.network",
family: ChainFamily.moonbeam,
isEthereum: true,
key: "moonbase-alpha",
name: "Moonbase Alpha",
Expand Down
5 changes: 4 additions & 1 deletion packages/config/src/chains/rococo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import BN from "bn.js";
import { Weight } from "./types/Weight";
import { createChain } from "./types/Chain";
import { ChainFamily, createChain } from "./types/Chain";
import { RococoTokens } from "../tokens";

const rocstar = createChain({
assets: [{ asset: RococoTokens.rstr, isNative: true }],
endpoint: "wss://rocstar.astar.network",
family: ChainFamily.astar,
isEthereum: true,
key: "rocstar",
name: "Rocstar",
Expand All @@ -22,6 +23,7 @@ const mangataRococo = createChain({
{ asset: RococoTokens.tur, id: "7", isNative: false },
],
endpoint: "wss://collator-01-ws-rococo.mangata.online",
family: ChainFamily.mangata,
key: "mangata-rococo",
name: "Mangata Rococo",
relayChain: "rococo",
Expand All @@ -37,6 +39,7 @@ const turingStaging = createChain({
{ asset: RococoTokens.rstr, id: "9", isNative: false },
],
endpoint: "wss://rpc.turing-staging.oak.tech",
family: ChainFamily.oak,
key: "turing-staging",
name: "Turing Staging",
relayChain: "rococo",
Expand Down
18 changes: 16 additions & 2 deletions packages/config/src/chains/types/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { Weight } from "./Weight";
import { RelayChainType } from "./RelayChainType";
import { XcmInstructionNetworkType } from "./XcmInstructionNetworkType";

enum ChainFamily {
oak = "oak",
moonbeam = "moonbeam",
astar = "astar",
mangata = "mangata",
}

interface XcmConfig {
instructionNetworkType?: XcmInstructionNetworkType;
instructionWeight: Weight;
Expand All @@ -22,6 +29,7 @@ interface ChainConstructorParams {
endpoint: string;
isEthereum?: boolean;
key: string;
family: ChainFamily;
name: string;
relayChain: RelayChainType;
xcm: XcmConfig;
Expand All @@ -36,6 +44,8 @@ class Chain {

key: string;

family: ChainFamily;

name: string | undefined;

paraId: number | undefined;
Expand All @@ -51,6 +61,7 @@ class Chain {
endpoint,
isEthereum = false, // Set default value to false
key,
family,
name,
relayChain,
xcm,
Expand All @@ -59,6 +70,7 @@ class Chain {
this.endpoint = endpoint;
this.isEthereum = isEthereum;
this.key = key;
this.family = family;
this.name = name;
this.relayChain = relayChain;
this.xcm = xcm;
Expand All @@ -70,14 +82,16 @@ function createChain(config: {
endpoint: string;
isEthereum?: boolean;
key: string;
family: ChainFamily;
name: string;
relayChain: RelayChainType;
xcm: XcmConfig;
}): Chain {
const { assets, endpoint, isEthereum, key, name, relayChain, xcm } = config;
const { assets, endpoint, isEthereum, key, family, name, relayChain, xcm } = config;
return new Chain({
assets: assets.map((asset) => new XToken(asset)),
endpoint,
family,
isEthereum,
key,
name,
Expand All @@ -86,6 +100,6 @@ function createChain(config: {
});
}

export { createChain };
export { ChainFamily, createChain };

export type { Chain, XcmConfig, ChainConstructorParams };

0 comments on commit 7c28827

Please sign in to comment.