Skip to content

Commit

Permalink
feat: add support to paseo
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala committed Jul 26, 2024
1 parent 35abaf6 commit f6609cd
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 2 deletions.
Binary file added .papi/metadata/pas.scale
Binary file not shown.
Binary file added .papi/metadata/pasAh.scale
Binary file not shown.
8 changes: 8 additions & 0 deletions .papi/polkadot-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"rocAh": {
"wsUrl": "wss://asset-hub-rococo-rpc.dwellir.com",
"metadata": ".papi/metadata/rocAh.scale"
},
"pas": {
"chain": "paseo",
"metadata": ".papi/metadata/pas.scale"
},
"pasAh": {
"chain": "paseo_asset_hub",
"metadata": ".papi/metadata/pasAh.scale"
}
}
}
6 changes: 5 additions & 1 deletion src/api/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import dot from "./dot"
import ksm from "./ksm"
import wnd from "./wnd"
import roc from "./roc"
import pas from "./pas"
import { AssetId, AssetInChain, ChainId } from "./types"

const assetsInChains = [...dot, ...ksm, ...wnd, ...roc]
const assetsInChains = [...dot, ...ksm, ...wnd, ...roc, ...pas]

export const chains = new Map<ChainId, Map<AssetId, AssetInChain>>()

Expand All @@ -20,6 +21,7 @@ export const ASSET_DECIMALS: Record<AssetId, number> = {
KSM: 12,
WND: 12,
ROC: 12,
PAS: 10,
}

export const CHAIN_NAMES: Record<ChainId, string> = {
Expand All @@ -31,4 +33,6 @@ export const CHAIN_NAMES: Record<ChainId, string> = {
wndAh: "Westend AssetHub",
roc: "Rococo RelayChain",
rocAh: "Rococo AssetHub",
pas: "Paseo RelayChain",
pasAh: "Paseo AssetHub",
}
3 changes: 3 additions & 0 deletions src/api/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ export { wndAhClient } from "./wndAh"

export { rocClient } from "./roc"
export { rocAhClient } from "./rocAh"

export { pasClient } from "./pas"
export { pasAhClient } from "./pasAh"
9 changes: 9 additions & 0 deletions src/api/clients/pas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createClient } from "polkadot-api"
import { getSmProvider } from "polkadot-api/sm-provider"
import { smoldot } from "./smoldot"

export const pasRelayChain = import("polkadot-api/chains/paseo").then(
({ chainSpec }) => smoldot.addChain({ chainSpec }),
)

export const pasClient = createClient(getSmProvider(pasRelayChain))
13 changes: 13 additions & 0 deletions src/api/clients/pasAh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createClient } from "polkadot-api"
import { getSmProvider } from "polkadot-api/sm-provider"
import { smoldot } from "./smoldot"
import { pasRelayChain } from "./pas"

const smoldotParaChain = Promise.all([
pasRelayChain,
import("polkadot-api/chains/paseo_asset_hub"),
]).then(([relayChain, { chainSpec }]) =>
smoldot.addChain({ chainSpec, potentialRelayChains: [relayChain] }),
)

export const pasAhClient = createClient(getSmProvider(smoldotParaChain))
19 changes: 19 additions & 0 deletions src/api/pas/ah.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { pasAh as descriptors } from "@polkadot-api/descriptors"
import { pasAhClient } from "@/api/clients"
import { AssetInChain } from "../types"
import { fromAssetHubToRelay, watchAccoutFreeBalance } from "../common"

const api = pasAhClient.getTypedApi(descriptors)

const chain = "pasAh"
const pas: AssetInChain = {
chain,
symbol: "PAS",
watchFreeBalance: watchAccoutFreeBalance(api),
teleport: {
pas: (...args) =>
api.tx.PolkadotXcm.limited_teleport_assets(fromAssetHubToRelay(...args)),
},
}

export default [pas]
4 changes: 4 additions & 0 deletions src/api/pas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import relay from "./relay"
import ah from "./ah"

export default [...relay, ...ah]
18 changes: 18 additions & 0 deletions src/api/pas/relay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { pas as descriptors } from "@polkadot-api/descriptors"
import { pasClient } from "@/api/clients"
import { AssetInChain } from "../types"
import { fromRelayToAssetHub, watchAccoutFreeBalance } from "../common"

const api = pasClient.getTypedApi(descriptors)

const pas: AssetInChain = {
chain: "pas",
symbol: "PAS",
watchFreeBalance: watchAccoutFreeBalance(api),
teleport: {
pasAh: (...args) =>
api.tx.XcmPallet.limited_teleport_assets(fromRelayToAssetHub(...args)),
},
}

export default [pas]
4 changes: 3 additions & 1 deletion src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export type ChainId =
| "ksmAh"
| "roc"
| "rocAh"
export type AssetId = "DOT" | "KSM" | "WND" | "ROC"
| "pas"
| "pasAh"
export type AssetId = "DOT" | "KSM" | "WND" | "ROC" | "PAS"

export type TeleportAsset = (
from: PolkadotSigner,
Expand Down

0 comments on commit f6609cd

Please sign in to comment.