Skip to content

Commit

Permalink
Merge pull request #113 from bvotteler/feat-add-bifrost-polkadot-vdot
Browse files Browse the repository at this point in the history
Feat: add bifrost polkadot vdot
  • Loading branch information
bvotteler authored Sep 15, 2023
2 parents 88a09d8 + a6d2696 commit 327a072
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/xcm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
--parachain=configs/hydradx.yml \
--parachain=configs/acala.yml \
--parachain=configs/parallel.yml \
--parachain=configs/bifrost-polkadot.yml \
&> log.txt &
echo "Waiting for log to show chopsticks is ready..."
tail -f log.txt | grep -q "Connected parachains"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interlay/bridge",
"version": "0.3.16",
"version": "0.4.0",
"description": "polkawallet bridge sdk",
"main": "build/index.js",
"typings": "build/index.d.ts",
Expand Down
16 changes: 8 additions & 8 deletions scripts/interlay-chopsticks-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { StatemintAdapter } from "../src/adapters/statemint";
import { HydraAdapter } from "../src/adapters/hydradx";
import { AcalaAdapter } from "../src/adapters/acala";
import { ParallelAdapter } from "../src/adapters/parallel";
import { BifrostPolkadotAdapter } from "../src/adapters/bifrost";
import { BaseCrossChainAdapter } from "../src/base-chain-adapter";
import { RouterTestCase, runTestCasesAndExit } from "./chopsticks-test";

Expand All @@ -22,16 +23,15 @@ async function main(): Promise<void> {
// .github/workflows/xcm-tests.yml
// reminder: parachains get ports in oder of arguments, starting with 8000 and incremented for each following one;
// relaychain gets its port last after all parachains.
interlay: { adapter: new InterlayAdapter(), endpoints: ['ws://127.0.0.1:8000'] },
statemint: { adapter: new StatemintAdapter(), endpoints: ['ws://127.0.0.1:8001'] },
hydra: { adapter: new HydraAdapter(), endpoints: ['ws://127.0.0.1:8002'] },
acala: { adapter: new AcalaAdapter(), endpoints: ['ws://127.0.0.1:8003'] },
interlay: { adapter: new InterlayAdapter(), endpoints: ['ws://127.0.0.1:8000'] },
statemint: { adapter: new StatemintAdapter(), endpoints: ['ws://127.0.0.1:8001'] },
hydra: { adapter: new HydraAdapter(), endpoints: ['ws://127.0.0.1:8002'] },
acala: { adapter: new AcalaAdapter(), endpoints: ['ws://127.0.0.1:8003'] },
// disable astar - rpc currently is too fragile for use in recurring tests
// astar: { adapter: new AstarAdapter(), endpoints: ['ws://127.0.0.1:8004'] },
// parallel: { adapter: new ParallelAdapter(), endpoints: ['ws://127.0.0.1:8005'] },
// polkadot: { adapter: new PolkadotAdapter(), endpoints: ['ws://127.0.0.1:8006'] },
parallel: { adapter: new ParallelAdapter(), endpoints: ['ws://127.0.0.1:8004'] },
polkadot: { adapter: new PolkadotAdapter(), endpoints: ['ws://127.0.0.1:8005'] },
parallel: { adapter: new ParallelAdapter(), endpoints: ['ws://127.0.0.1:8004'] },
bifrost_polkadot: { adapter: new BifrostPolkadotAdapter(), endpoints: ['ws://127.0.0.1:8005']},
polkadot: { adapter: new PolkadotAdapter(), endpoints: ['ws://127.0.0.1:8006'] },
};

const filterCases: Partial<RouterTestCase>[] = [
Expand Down
4 changes: 2 additions & 2 deletions scripts/kintsugi-chopsticks-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* tslint:disable:no-unused-variable */
import { KaruraAdapter } from "../src/adapters/acala";
import { BifrostAdapter } from "../src/adapters/bifrost";
import { BifrostKusamaAdapter } from "../src/adapters/bifrost";
import { KintsugiAdapter } from "../src/adapters/interlay";
import { HeikoAdapter } from "../src/adapters/parallel";
import { KusamaAdapter } from "../src/adapters/polkadot";
Expand All @@ -26,7 +26,7 @@ async function main(): Promise<void> {
statemine: { adapter: new StatemineAdapter(), endpoints: ['ws://127.0.0.1:8001'] },
karura: { adapter: new KaruraAdapter(), endpoints: ['ws://127.0.0.1:8002'] },
heiko: { adapter: new HeikoAdapter(), endpoints: ['ws://127.0.0.1:8003'] },
bifrost: { adapter: new BifrostAdapter(), endpoints: ['ws://127.0.0.1:8004'] },
bifrost: { adapter: new BifrostKusamaAdapter(), endpoints: ['ws://127.0.0.1:8004'] },
kusama: { adapter: new KusamaAdapter(), endpoints: ['ws://127.0.0.1:8005'] },
};

Expand Down
67 changes: 59 additions & 8 deletions src/adapters/bifrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { xTokensHelper } from "../utils/xtokens-helper";

const DEST_WEIGHT = "Unlimited";

export const bifrostRoutersConfig: Omit<CrossChainRouterConfigs, "from">[] = [
export const bifrostKusamaRoutersConfig: Omit<
CrossChainRouterConfigs,
"from"
>[] = [
{
to: "kintsugi",
token: "VKSM",
Expand All @@ -31,14 +34,43 @@ export const bifrostRoutersConfig: Omit<CrossChainRouterConfigs, "from">[] = [
},
];

export const bifrostTokensConfig: Record<string, BasicToken> = {
export const bifrostPolkadotRoutersConfig: Omit<
CrossChainRouterConfigs,
"from"
>[] = [
{
to: "interlay",
token: "VDOT",
xcm: {
// taken from transaction: fees were 18_012_501. Add 10x margin
fee: { token: "VDOT", amount: "180125010" },
weightLimit: DEST_WEIGHT,
},
},
];

export const bifrostKusamaTokensConfig: Record<string, BasicToken> = {
VKSM: { name: "VKSM", symbol: "VKSM", decimals: 12, ed: "100000000" },
};

const SUPPORTED_TOKENS: Record<string, unknown> = {
export const bifrostPolkadotTokensConfig: Record<string, BasicToken> = {
VDOT: { name: "VDOT", symbol: "VDOT", decimals: 10, ed: "1000000" },
};

const SUPPORTED_KUSAMA_TOKENS: Record<string, unknown> = {
VKSM: { VToken: "KSM" },
};

const SUPPORTED_POLKADOT_TOKENS: Record<string, unknown> = {
VDOT: { VToken2: 0 },
};

const getSupportedTokens = (chainname: string): Record<string, unknown> => {
return chainname === "bifrost_polkadot"
? SUPPORTED_POLKADOT_TOKENS
: SUPPORTED_KUSAMA_TOKENS;
};

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const createBalanceStorages = (api: AnyApi) => {
return {
Expand Down Expand Up @@ -85,7 +117,7 @@ class BifrostBalanceAdapter extends BalanceAdapter {
);
}

const tokenId = SUPPORTED_TOKENS[token];
const tokenId = getSupportedTokens(this.chain)[token];

if (tokenId === undefined) {
throw new CurrencyNotFound(token);
Expand Down Expand Up @@ -117,10 +149,15 @@ class BaseBifrostAdapter extends BaseCrossChainAdapter {

await api.isReady;

const tokensConfig =
this.chain.id === "bifrost_polkadot"
? bifrostPolkadotTokensConfig
: bifrostKusamaTokensConfig;

this.balanceAdapter = new BifrostBalanceAdapter({
chain: this.chain.id as ChainName,
api,
tokens: bifrostTokensConfig,
tokens: tokensConfig,
});
}

Expand Down Expand Up @@ -188,7 +225,7 @@ class BaseBifrostAdapter extends BaseCrossChainAdapter {

const accountId = this.api.createType("AccountId32", address).toHex();

const tokenId = SUPPORTED_TOKENS[token];
const tokenId = getSupportedTokens(this.chain.id)[token];

if (tokenId === undefined) {
throw new CurrencyNotFound(token);
Expand All @@ -207,8 +244,22 @@ class BaseBifrostAdapter extends BaseCrossChainAdapter {
}
}

export class BifrostAdapter extends BaseBifrostAdapter {
export class BifrostKusamaAdapter extends BaseBifrostAdapter {
constructor() {
super(chains.bifrost, bifrostRoutersConfig, bifrostTokensConfig);
super(
chains.bifrost,
bifrostKusamaRoutersConfig,
bifrostKusamaTokensConfig
);
}
}

export class BifrostPolkadotAdapter extends BaseBifrostAdapter {
constructor() {
super(
chains.bifrost_polkadot,
bifrostPolkadotRoutersConfig,
bifrostPolkadotTokensConfig
);
}
}
4 changes: 2 additions & 2 deletions src/adapters/interlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StatemineAdapter, StatemintAdapter } from "./statemint";
import { AcalaAdapter, KaruraAdapter } from "./acala";
import { HeikoAdapter, ParallelAdapter } from "./parallel";
import { buildTestTxWithConfigData } from "../utils/shared-spec-methods";
import { BifrostAdapter } from "./bifrost";
import { BifrostKusamaAdapter } from "./bifrost";
import { HydraAdapter } from "./hydradx";
import { AstarAdapter } from "./astar";

Expand Down Expand Up @@ -79,7 +79,7 @@ describe.skip("interlay-adapter should work", () => {
const kintsugi = new KintsugiAdapter();
const karura = new KaruraAdapter();
const heiko = new HeikoAdapter();
const bifrost = new BifrostAdapter();
const bifrost = new BifrostKusamaAdapter();
const statemine = new StatemineAdapter();
const kusama = new KusamaAdapter();

Expand Down
11 changes: 11 additions & 0 deletions src/adapters/interlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ export const interlayRoutersConfig: Omit<CrossChainRouterConfigs, "from">[] = [
weightLimit: DEST_WEIGHT,
},
},
{
to: "bifrost_polkadot",
token: "VDOT",
xcm: {
// from actual transaction: fee = 703. Add 10x margin
fee: { token: "VDOT", amount: "7030" },
weightLimit: DEST_WEIGHT,
},
},
];

export const kintsugiRoutersConfig: Omit<CrossChainRouterConfigs, "from">[] = [
Expand Down Expand Up @@ -182,6 +191,7 @@ export const interlayTokensConfig: Record<
IBTC: { name: "IBTC", symbol: "IBTC", decimals: 8, ed: "0" },
INTR: { name: "INTR", symbol: "INTR", decimals: 10, ed: "0" },
USDT: { name: "USDT", symbol: "USDT", decimals: 6, ed: "0" },
VDOT: { name: "VDOT", symbol: "VDOT", decimals: 10, ed: "0" },
},
kintsugi: {
KBTC: { name: "KBTC", symbol: "KBTC", decimals: 8, ed: "0" },
Expand All @@ -207,6 +217,7 @@ const INTERLAY_SUPPORTED_TOKENS: Record<string, unknown> = {
IBTC: { Token: "IBTC" },
INTR: { Token: "INTR" },
USDT: { ForeignAsset: 2 },
VDOT: { ForeignAsset: 3 },
};

const getSupportedTokens = (chainname: string): Record<string, unknown> => {
Expand Down
10 changes: 10 additions & 0 deletions src/api-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ export class ApiProvider {
prodParasPolkadotCommon.find((e) => e.info === "PolkadotAssetHub")
?.providers || {}
).filter((e) => e.startsWith("wss://"));
} else if (chain === "bifrost_polkadot" || chain === "bifrost") {
const chainInfoName = "bifrost";
const haystack =
chain === "bifrost_polkadot"
? prodParasPolkadot
: prodParasKusama;

nodes = Object.values(
haystack.find((e) => e.info === chainInfoName)?.providers || {}
).filter((e) => e.startsWith("wss://"));
} else {
const chainInfo = chain === "hydra" ? "hydradx" : chain;
nodes = Object.values(
Expand Down
11 changes: 7 additions & 4 deletions src/bridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { KusamaAdapter, PolkadotAdapter } from "./adapters/polkadot";
import { StatemineAdapter, StatemintAdapter } from "./adapters/statemint";
import { HeikoAdapter, ParallelAdapter } from "./adapters/parallel";
import { AcalaAdapter, KaruraAdapter } from "./adapters/acala";
import { BifrostAdapter } from "./adapters/bifrost";
import { BifrostKusamaAdapter, BifrostPolkadotAdapter } from "./adapters/bifrost";
import { HydraAdapter } from "./adapters/hydradx";
import { AstarAdapter } from "./adapters/astar";

Expand All @@ -29,7 +29,8 @@ describe.skip("Bridge sdk usage", () => {
statemint: new StatemintAdapter(),
statemine: new StatemineAdapter(),
heiko: new HeikoAdapter(),
bifrost: new BifrostAdapter(),
bifrost_polkadot: new BifrostPolkadotAdapter(),
bifrost: new BifrostKusamaAdapter(),
hydra: new HydraAdapter(),
parallel: new ParallelAdapter(),
astar: new AstarAdapter(),
Expand Down Expand Up @@ -178,7 +179,7 @@ describe.skip("Bridge sdk usage", () => {
// printBidirectionalTxs("kintsugi", "karura", "KBTC");
// printBidirectionalTxs("kintsugi", "karura", "LKSM");
// printBidirectionalTxs("kintsugi", "bifrost", "VKSM");
printBidirectionalTxs("kusama", "statemine", "KSM");
// printBidirectionalTxs("kusama", "statemine", "KSM");

// interlay
// printBidirectionalTxs("interlay", "polkadot", "DOT");
Expand All @@ -191,7 +192,8 @@ describe.skip("Bridge sdk usage", () => {
// printBidirectionalTxs("interlay", "parallel", "IBTC");
// printBidirectionalTxs("interlay", "astar", "INTR");
// printBidirectionalTxs("interlay", "astar", "IBTC");
printBidirectionalTxs("polkadot", "statemint", "DOT");
printBidirectionalTxs("interlay", "bifrost_polkadot", "VDOT");
// printBidirectionalTxs("polkadot", "statemint", "DOT");
});

test("5. getNativeToken should work", () => {
Expand All @@ -209,6 +211,7 @@ describe.skip("Bridge sdk usage", () => {
["acala", "ACA"],
["hydra", "HDX"],
["parallel", "PARA"],
["bifrost_polkadot", "BNC"],
["statemint", "DOT"],
];

Expand Down
8 changes: 8 additions & 0 deletions src/configs/chains/polkadot-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export const polkadotChains = {
paraChainId: 2006,
ss58Prefix: 5,
},
bifrost_polkadot: {
id: "bifrost_polkadot",
display: "Bifrost",
type: typeSubstrate,
icon: "https://resources.acala.network/_next/image?url=%2Fnetworks%2Fbifrost.png&w=96&q=75",
paraChainId: 2030,
ss58Prefix: 6,
},
interlay: {
id: "interlay",
display: "Interlay",
Expand Down

0 comments on commit 327a072

Please sign in to comment.