From a52c6e2728285853e2b7ef3a08501efd5055077d Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 15 Sep 2023 09:39:40 +0200 Subject: [PATCH 1/7] feat: add bifrost polkadot adapter and route definitions for vdot transfers (cherry picked from commit 99364aa587aac1d154f23a8adebd078f7cc6fd53) --- src/adapters/bifrost.ts | 62 +++++++++++++++++++++++---- src/adapters/interlay.spec.ts | 4 +- src/adapters/interlay.ts | 11 +++++ src/api-provider.ts | 10 +++++ src/bridge.spec.ts | 11 +++-- src/configs/chains/polkadot-chains.ts | 8 ++++ 6 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/adapters/bifrost.ts b/src/adapters/bifrost.ts index 03267f17..c6ab5123 100644 --- a/src/adapters/bifrost.ts +++ b/src/adapters/bifrost.ts @@ -19,7 +19,10 @@ import { xTokensHelper } from "../utils/xtokens-helper"; const DEST_WEIGHT = "Unlimited"; -export const bifrostRoutersConfig: Omit[] = [ +export const bifrostKusamaRoutersConfig: Omit< + CrossChainRouterConfigs, + "from" +>[] = [ { to: "kintsugi", token: "VKSM", @@ -31,14 +34,43 @@ export const bifrostRoutersConfig: Omit[] = [ }, ]; -export const bifrostTokensConfig: Record = { +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 = { VKSM: { name: "VKSM", symbol: "VKSM", decimals: 12, ed: "100000000" }, }; -const SUPPORTED_TOKENS: Record = { +export const bifrostPolkadotTokensConfig: Record = { + VDOT: { name: "VDOT", symbol: "VDOT", decimals: 10, ed: "1000000" }, +}; + +const SUPPORTED_KUSAMA_TOKENS: Record = { VKSM: { VToken: "KSM" }, }; +const SUPPORTED_POLKADOT_TOKENS: Record = { + VDOT: { VToken2: 0 }, +}; + +const getSupportedTokens = (chainname: string): Record => { + 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 { @@ -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); @@ -120,7 +152,7 @@ class BaseBifrostAdapter extends BaseCrossChainAdapter { this.balanceAdapter = new BifrostBalanceAdapter({ chain: this.chain.id as ChainName, api, - tokens: bifrostTokensConfig, + tokens: bifrostKusamaTokensConfig, }); } @@ -188,7 +220,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); @@ -207,8 +239,22 @@ class BaseBifrostAdapter extends BaseCrossChainAdapter { } } -export class BifrostAdapter extends BaseBifrostAdapter { +export class BifrostKusamaAdapter extends BaseBifrostAdapter { + constructor() { + super( + chains.bifrost, + bifrostKusamaRoutersConfig, + bifrostKusamaTokensConfig + ); + } +} + +export class BifrostPolkadotAdapter extends BaseBifrostAdapter { constructor() { - super(chains.bifrost, bifrostRoutersConfig, bifrostTokensConfig); + super( + chains.bifrost_polkadot, + bifrostPolkadotRoutersConfig, + bifrostPolkadotTokensConfig + ); } } diff --git a/src/adapters/interlay.spec.ts b/src/adapters/interlay.spec.ts index 71145c93..e0eaf2e5 100644 --- a/src/adapters/interlay.spec.ts +++ b/src/adapters/interlay.spec.ts @@ -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"; @@ -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(); diff --git a/src/adapters/interlay.ts b/src/adapters/interlay.ts index 652c6102..0227591b 100644 --- a/src/adapters/interlay.ts +++ b/src/adapters/interlay.ts @@ -97,6 +97,15 @@ export const interlayRoutersConfig: Omit[] = [ 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[] = [ @@ -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" }, @@ -207,6 +217,7 @@ const INTERLAY_SUPPORTED_TOKENS: Record = { IBTC: { Token: "IBTC" }, INTR: { Token: "INTR" }, USDT: { ForeignAsset: 2 }, + VDOT: { ForeignAsset: 3 }, }; const getSupportedTokens = (chainname: string): Record => { diff --git a/src/api-provider.ts b/src/api-provider.ts index eb6c446f..4e9ee7a2 100644 --- a/src/api-provider.ts +++ b/src/api-provider.ts @@ -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( diff --git a/src/bridge.spec.ts b/src/bridge.spec.ts index 4c2726ea..5e957385 100644 --- a/src/bridge.spec.ts +++ b/src/bridge.spec.ts @@ -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"; @@ -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(), @@ -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"); @@ -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", () => { @@ -209,6 +211,7 @@ describe.skip("Bridge sdk usage", () => { ["acala", "ACA"], ["hydra", "HDX"], ["parallel", "PARA"], + ["bifrost_polkadot", "BNC"], ["statemint", "DOT"], ]; diff --git a/src/configs/chains/polkadot-chains.ts b/src/configs/chains/polkadot-chains.ts index 61efbe0e..36447747 100644 --- a/src/configs/chains/polkadot-chains.ts +++ b/src/configs/chains/polkadot-chains.ts @@ -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", From 4c0f8731190e0d44f04cf0e462e252df4aab2325 Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 15 Sep 2023 10:06:40 +0200 Subject: [PATCH 2/7] fix: broken adapter name in chopsticks tests (cherry picked from commit 0bbc5f910ff131d034d4c013076c2c7ae018b2b4) --- scripts/kintsugi-chopsticks-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/kintsugi-chopsticks-test.ts b/scripts/kintsugi-chopsticks-test.ts index 615a2f5c..3b2f3e07 100644 --- a/scripts/kintsugi-chopsticks-test.ts +++ b/scripts/kintsugi-chopsticks-test.ts @@ -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"; @@ -26,7 +26,7 @@ async function main(): Promise { 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'] }, }; From 6481bfca2b89720c34179c14a6924911e22ffa70 Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 15 Sep 2023 09:40:42 +0200 Subject: [PATCH 3/7] test: add chopsticks tests for interlay <-> bifrost_polkadot vdot transfers (cherry picked from commit 253f722158e83887543eddf8bfff1ad21983f4eb) --- .github/workflows/xcm-tests.yml | 2 ++ scripts/interlay-chopsticks-test.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/xcm-tests.yml b/.github/workflows/xcm-tests.yml index c72dad74..dd02c095 100644 --- a/.github/workflows/xcm-tests.yml +++ b/.github/workflows/xcm-tests.yml @@ -6,6 +6,7 @@ on: push: branches: - master + - temp-polkadot-9-vdot-version pull_request: branches: - master @@ -88,6 +89,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" diff --git a/scripts/interlay-chopsticks-test.ts b/scripts/interlay-chopsticks-test.ts index e9d78901..1c6d295a 100644 --- a/scripts/interlay-chopsticks-test.ts +++ b/scripts/interlay-chopsticks-test.ts @@ -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"; @@ -22,16 +23,15 @@ async function main(): Promise { // .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: { adapter: new BifrostPolkadotAdapter(), endpoints: ['ws://127.0.0.1:8005']}, + polkadot: { adapter: new PolkadotAdapter(), endpoints: ['ws://127.0.0.1:8006'] }, }; const filterCases: Partial[] = [ From 8fdbbbc0d6f9b38923ad04ab845eae05e4b8c668 Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 15 Sep 2023 10:03:23 +0200 Subject: [PATCH 4/7] test: fix bifrost chain name in interlay chopsticks tests (cherry picked from commit 75cc8ee72bb953aa085afdd239829c02f2440ee6) --- scripts/interlay-chopsticks-test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/interlay-chopsticks-test.ts b/scripts/interlay-chopsticks-test.ts index 1c6d295a..e40f9a2c 100644 --- a/scripts/interlay-chopsticks-test.ts +++ b/scripts/interlay-chopsticks-test.ts @@ -23,15 +23,15 @@ async function main(): Promise { // .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:8004'] }, - bifrost: { adapter: new BifrostPolkadotAdapter(), 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'] }, + 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[] = [ From 218717dab60cf8c8e159965fac4ede8623eecb55 Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 15 Sep 2023 10:17:16 +0200 Subject: [PATCH 5/7] fix: incorrect tokens config used in balance adapter for bifrost polkadot (cherry picked from commit f62ce12eeaeef3f8388c4d1745dd4a1778b67a40) --- src/adapters/bifrost.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/adapters/bifrost.ts b/src/adapters/bifrost.ts index c6ab5123..8d2f5cd7 100644 --- a/src/adapters/bifrost.ts +++ b/src/adapters/bifrost.ts @@ -149,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: bifrostKusamaTokensConfig, + tokens: tokensConfig, }); } From fa53fc2fd9449f1e5dc4acc5a0e75691f57a9120 Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 15 Sep 2023 10:39:58 +0200 Subject: [PATCH 6/7] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f2c42510..9bc17318 100644 --- a/package.json +++ b/package.json @@ -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", From a6d2696b39c83b0718076596b53934ce6ce8ca5a Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 15 Sep 2023 10:40:45 +0200 Subject: [PATCH 7/7] chore: revert github action trigger when pushing to temp branch --- .github/workflows/xcm-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/xcm-tests.yml b/.github/workflows/xcm-tests.yml index dd02c095..9f88256b 100644 --- a/.github/workflows/xcm-tests.yml +++ b/.github/workflows/xcm-tests.yml @@ -6,7 +6,6 @@ on: push: branches: - master - - temp-polkadot-9-vdot-version pull_request: branches: - master