Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .papi/descriptors/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-autogenerated.13566815344429969239",
"version": "0.1.0-autogenerated.9525622409029835453",
"name": "@polkadot-api/descriptors",
"files": [
"dist"
Expand Down
Binary file added .papi/metadata/ksmEnc.scale
Binary file not shown.
Binary file modified .papi/metadata/passet.scale
Binary file not shown.
8 changes: 7 additions & 1 deletion .papi/polkadot-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@
"wsUrl": "wss://testnet-passet-hub.polkadot.io",
"metadata": ".papi/metadata/passet.scale",
"genesis": "0xfd974cf9eaf028f5e44b9fdd1949ab039c6cf9cc54449b0b60d71b042e79aeb6",
"codeHash": "0x87d8a4f006f8d55b05a81e32c8594acabb4f95dbeae1b724edc9ecf2289dc7af"
"codeHash": "0x3e088e61b3cb51e74c67cb3634a699109bf3ded14fbd35ed731968d0aa82a441"
},
"ksmEnc": {
"wsUrl": "wss://kusama.api.encointer.org",
"metadata": ".papi/metadata/ksmEnc.scale",
"genesis": "0x7dd99936c1e9e6d1ce7d90eb6f33bea8393b4bf87677d675aa63c9cb3e8c5b5b",
"codeHash": "0x6a1faad9888624da0ec673c6e992312bf6f7bf40ef95d796ee072a3367f87021"
}
}
}
1 change: 1 addition & 0 deletions src/api/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const CHAIN_NAMES: Record<ChainId, string> = {
dotAh: "Polkadot AssetHub",
ksm: "Kusama RelayChain",
ksmAh: "Kusama AssetHub",
ksmEnc: "Kusama Encointer",
wnd: "Westend RelayChain",
wndAh: "Westend AssetHub",
pas: "Paseo RelayChain",
Expand Down
1 change: 1 addition & 0 deletions src/api/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { dotAhClient } from "./dotAh"

export { ksmClient } from "./ksm"
export { ksmAhClient } from "./ksmAh"
export { ksmEncClient } from "./ksmEnc"

export { wndClient } from "./wnd"
export { wndAhClient } from "./wndAh"
Expand Down
13 changes: 13 additions & 0 deletions src/api/clients/ksmEnc.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 { ksmRelayChain } from "./ksm"

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

export const ksmEncClient = createClient(getSmProvider(smoldotParaChain))
45 changes: 45 additions & 0 deletions src/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const fromRelayToAssetHub = (
to?: SS58String,
) => fromRelayToParachain(1000, from, amount, to)

export const fromRelayToEncointer = (
from: PolkadotSigner,
amount: bigint,
to?: SS58String,
) => fromRelayToParachain(1001, from, amount, to)

export const fromRelayToParachain = (
paraId: number,
from: PolkadotSigner,
Expand Down Expand Up @@ -75,6 +81,27 @@ export const fromAssetHubToRelay = (
weight_limit: XcmV3WeightLimit.Unlimited(),
})

export const fromEncointerToRelay = (
from: PolkadotSigner,
amount: bigint,
to?: SS58String,
) => ({
dest: {
type: "V3" as const,
value: {
parents: 1,
interior: {
type: "Here" as const,
value: undefined,
},
},
},
beneficiary: getBeneficiary(to ?? from.publicKey),
assets: getNativeAsset(1, amount),
fee_asset_item: 0,
weight_limit: XcmV3WeightLimit.Unlimited(),
})

export const fromAssetHubToForeign = (
network: XcmV5NetworkId,
parachainId: number,
Expand All @@ -95,6 +122,24 @@ export const fromAssetHubToForeign = (
weight_limit: XcmV3WeightLimit.Unlimited(),
})

export const fromSystemToSibling = (
parachainId: number,
assets: XcmVersionedAssets,
from: PolkadotSigner,
to?: SS58String,
) => ({
dest: XcmVersionedLocation.V4({
parents: 1,
interior: XcmV3Junctions.X1(
XcmV3Junction.Parachain(parachainId),
),
}),
beneficiary: getBeneficiary(to ?? from.publicKey),
assets,
fee_asset_item: 0,
weight_limit: XcmV3WeightLimit.Unlimited(),
})

type GenericApi = TypedApi<typeof dotAh>

export const watchAccoutFreeBalance = (api: {
Expand Down
11 changes: 10 additions & 1 deletion src/api/ksm/ah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ksmAhClient } from "@/api/clients"
import { AssetInChain } from "../types"
import {
fromAssetHubToForeign,
fromAssetHubToRelay,
fromAssetHubToRelay, fromSystemToSibling,
getNativeAsset,
watchAccoutFreeBalance,
watchForeingAssetAccoutFreeBalance,
Expand All @@ -24,6 +24,15 @@ const ksm: AssetInChain = {
teleport: {
ksm: (...args) =>
api.tx.PolkadotXcm.transfer_assets(fromAssetHubToRelay(...args)),
ksmEnc: (from, amount, to) =>
api.tx.PolkadotXcm.limited_teleport_assets(
fromSystemToSibling(
1001,
getNativeAsset(1, amount),
from,
to,
),
),
dotAh: (from, amount, to) =>
api.tx.PolkadotXcm.transfer_assets(
fromAssetHubToForeign(
Expand Down
34 changes: 34 additions & 0 deletions src/api/ksm/enc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
ksmEnc,
} from "@polkadot-api/descriptors"
import { ksmEncClient } from "@/api/clients"
import { AssetInChain } from "../types"
import {
fromSystemToSibling,
fromEncointerToRelay,
getNativeAsset,
watchAccoutFreeBalance,
} from "../common"

const api = ksmEncClient.getTypedApi(ksmEnc)

const ksm: AssetInChain = {
chain: "ksmEnc",
symbol: "KSM",
watchFreeBalance: watchAccoutFreeBalance(api),
teleport: {
ksm: (...args) =>
api.tx.PolkadotXcm.limited_teleport_assets(fromEncointerToRelay(...args)),
ksmAh: (from, amount, to) =>
api.tx.PolkadotXcm.limited_teleport_assets(
fromSystemToSibling(
1000,
getNativeAsset(1, amount),
from,
to,
),
),
},
}

export default [ksm]
3 changes: 2 additions & 1 deletion src/api/ksm/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import relay from "./relay"
import ah from "./ah"
import enc from "./enc"

export default [...relay, ...ah]
export default [...relay, ...ah, ...enc]
4 changes: 3 additions & 1 deletion src/api/ksm/relay.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ksm as descriptors } from "@polkadot-api/descriptors"
import { ksmClient } from "@/api/clients"
import { AssetInChain } from "../types"
import { fromRelayToAssetHub, watchAccoutFreeBalance } from "../common"
import { fromRelayToAssetHub, fromRelayToEncointer, watchAccoutFreeBalance } from "../common"

const api = ksmClient.getTypedApi(descriptors)

Expand All @@ -12,6 +12,8 @@ const ksm: AssetInChain = {
teleport: {
ksmAh: (...args) =>
api.tx.XcmPallet.transfer_assets(fromRelayToAssetHub(...args)),
ksmEnc: (...args) =>
api.tx.XcmPallet.transfer_assets(fromRelayToEncointer(...args)),
},
}

Expand Down
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type ChainId =
| "wndAh"
| "ksm"
| "ksmAh"
| "ksmEnc"
| "pas"
| "pasAh"
| "passet"
Expand Down