Skip to content

Commit

Permalink
Feat: add Phala <-> Interlay routes (#138)
Browse files Browse the repository at this point in the history
* feat: add phala <-> interlay routes

* chore: lint
  • Loading branch information
bvotteler authored Sep 4, 2024
1 parent 2bb269e commit fbd9c36
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/adapters/interlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ export const interlayRouteConfigs = createRouteConfigs("interlay", [
token: "IBTC",
xcm: { fee: { token: "IBTC", amount: "110" }, weightLimit: DEST_WEIGHT },
},
{
to: "phala",
token: "PHA",
xcm: { fee: { token: "PHA", amount: "65000000000" } },
},
{
to: "phala",
token: "INTR",
xcm: { fee: { token: "INTR", amount: "650000000" } },
},
{
to: "phala",
token: "IBTC",
xcm: { fee: { token: "IBTC", amount: "6500000" } },
},
{
to: "polkadot",
token: "DOT",
Expand Down Expand Up @@ -237,6 +252,13 @@ export const interlayTokensConfig: Record<
ed: "0",
toRaw: () => ({ ForeignAsset: 11 }),
},
PHA: {
name: "PHA",
symbol: "PHA",
decimals: 12,
ed: "10000000000",
toRaw: () => ({ ForeignAsset: 14 }),
},
},
kintsugi: {
KINT: {
Expand Down
65 changes: 64 additions & 1 deletion src/adapters/phala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ import {
getDestAccountInfo,
} from "../utils";

export const phalaRouteConfigs = createRouteConfigs("phala", [
{
to: "interlay",
token: "PHA",
xcm: {
fee: { token: "PHA", amount: "80000000000000" },
},
},
{
to: "interlay",
token: "IBTC",
xcm: {
fee: { token: "IBTC", amount: "70" },
},
},
{
to: "interlay",
token: "INTR",
xcm: {
fee: { token: "INTR", amount: "20000000" },
},
},
]);

export const khalaRouteConfigs = createRouteConfigs("khala", [
{
to: "karura",
Expand All @@ -41,6 +65,32 @@ export const khalaRouteConfigs = createRouteConfigs("khala", [
},
]);

export const phalaTokensConfig: Record<string, ExtendedToken> = {
PHA: {
name: "PHA",
symbol: "PHA",
decimals: 12,
ed: "10000000000",
toRaw: () => undefined,
},
IBTC: {
name: "IBTC",
symbol: "IBTC",
decimals: 8,
ed: "1000000",
toRaw: () =>
"0x0001000000000000000000000000000000000000000000000000000000000000",
},
INTR: {
name: "INTR",
symbol: "INTR",
decimals: 10,
ed: "100000000",
toRaw: () =>
"0x0002000000000000000000000000000000000000000000000000000000000000",
},
};

export const khalaTokensConfig: Record<string, ExtendedToken> = {
PHA: {
name: "PHA",
Expand All @@ -67,6 +117,11 @@ export const khalaTokensConfig: Record<string, ExtendedToken> = {
},
};

const tokensConfig: Record<string, Record<string, ExtendedToken>> = {
khala: khalaTokensConfig,
phala: phalaTokensConfig,
};

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const createBalanceStorages = (api: AnyApi) => {
return {
Expand Down Expand Up @@ -119,6 +174,8 @@ class PhalaBalanceAdapter extends BalanceAdapter {
const SUPPORTED_TOKENS: Record<string, number> = {
KAR: 1,
KUSD: 4,
INTR: 13,
IBTC: 14,
};
const tokenId = SUPPORTED_TOKENS[token];

Expand Down Expand Up @@ -155,7 +212,7 @@ class BasePhalaAdapter extends BaseCrossChainAdapter {
this.balanceAdapter = new PhalaBalanceAdapter({
chain: this.chain.id as ChainId,
api,
tokens: khalaTokensConfig,
tokens: tokensConfig[this.chain.id],
});
}

Expand Down Expand Up @@ -273,6 +330,12 @@ class BasePhalaAdapter extends BaseCrossChainAdapter {
}
}

export class PhalaAdapter extends BasePhalaAdapter {
constructor() {
super(chains.phala, phalaRouteConfigs, phalaTokensConfig);
}
}

export class KhalaAdapter extends BasePhalaAdapter {
constructor() {
super(chains.khala, khalaRouteConfigs, khalaTokensConfig);
Expand Down
7 changes: 7 additions & 0 deletions src/configs/chains/polkadot-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export const polkadotChains = {
paraChainId: 2012,
ss58Prefix: 172,
},
phala: {
display: "Phala",
type: "substrate",
icon: "https://resources.acala.network/_next/image?url=%2Fnetworks%2Fphala.png&w=96&q=75",
paraChainId: 2035,
ss58Prefix: 30,
},
moonbeam: {
display: "Moonbeam",
type: "ethereum",
Expand Down

0 comments on commit fbd9c36

Please sign in to comment.