Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest HydraDX / Basilisk #69

Merged
merged 14 commits into from
Jul 3, 2023
Merged
7 changes: 7 additions & 0 deletions src/adapters/acala/acala-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export const acalaRouteConfigs = createRouteConfigs("acala", [
fee: { token: "DAI", amount: "2926334210356268" },
},
},
{
to: "hydradx",
token: "DOT",
xcm: {
fee: { token: "DOT", amount: "491129243" },
},
},
{
to: "hydradx",
token: "WETH",
Expand Down
17 changes: 16 additions & 1 deletion src/adapters/acala/karura-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const karuraRouteConfigs = createRouteConfigs("karura", [
to: "statemine",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "1000" },
fee: { token: "USDT", amount: "1183" },
},
},
{
Expand Down Expand Up @@ -324,13 +324,27 @@ export const karuraRouteConfigs = createRouteConfigs("karura", [
fee: { token: "BSX", amount: "22000000000000" },
},
},
{
to: "basilisk",
token: "KSM",
xcm: {
fee: { token: "KSM", amount: "359882060" },
},
},
{
to: "basilisk",
token: "KUSD",
xcm: {
fee: { token: "KUSD", amount: "3150402683" },
},
},
{
to: "basilisk",
token: "aUSD",
nohaapav marked this conversation as resolved.
Show resolved Hide resolved
xcm: {
fee: { token: "aUSD", amount: "3150402683" },
},
},
{
to: "basilisk",
token: "DAI",
Expand Down Expand Up @@ -397,6 +411,7 @@ export const karuraRouteConfigs = createRouteConfigs("karura", [
export const karuraTokensConfig: Record<string, BasicToken> = {
KAR: { name: "KAR", symbol: "KAR", decimals: 12, ed: "100000000000" },
KUSD: { name: "KUSD", symbol: "KUSD", decimals: 12, ed: "10000000000" },
aUSD: { name: "aUSD", symbol: "aUSD", decimals: 12, ed: "10000000000" },
LKSM: { name: "LKSM", symbol: "LKSM", decimals: 12, ed: "500000000" },
SDN: { name: "SDN", symbol: "SDN", decimals: 18, ed: "10000000000000000" },
BNC: { name: "BNC", symbol: "BNC", decimals: 12, ed: "8000000000" },
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/hydradx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Bridge } from '../bridge';
import { ApiPromise, WsProvider } from '@polkadot/api';
import { FixedPointNumber } from '@acala-network/sdk-core';
import { HydraAdapter } from './hydradx';
import { HydraDxAdapter } from './hydradx';
import { AcalaAdapter } from './acala';

describe.skip('hydradx adapter should work', () => {
Expand All @@ -11,7 +11,7 @@ describe.skip('hydradx adapter should work', () => {
let bridge: Bridge;

beforeAll(async () => {
const hydradx = new HydraAdapter();
const hydradx = new HydraDxAdapter();
const acala = new AcalaAdapter();

const hydradxApi = new ApiPromise({ provider: new WsProvider('wss://hydradx.api.onfinality.io/public-ws') });
Expand Down
208 changes: 189 additions & 19 deletions src/adapters/hydradx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ import { ISubmittableResult } from "@polkadot/types/types";
import { BalanceAdapter, BalanceAdapterConfigs } from "../balance-adapter";
import { BaseCrossChainAdapter } from "../base-chain-adapter";
import { ChainId, chains } from "../configs";
import { ApiNotFound } from "../errors";
import { BalanceData, ExtendedToken, TransferParams } from "../types";
import { createRouteConfigs } from "../utils";
import { ApiNotFound, TokenNotFound } from "../errors";
import { isChainEqual } from "../utils/is-chain-equal";
import { checkMessageVersionIsV3 } from "../utils/check-message-version";
import {
createXTokensAssetsParam,
createXTokensDestParam,
createRouteConfigs,
} from "../utils";

import { SUPPORTED_TOKENS as STATEMINE_SUPPORTED_TOKENS } from "./statemint";

export const basiliskRouteConfigs = createRouteConfigs("basilisk", [
{
to: "kusama",
token: "KSM",
xcm: {
fee: { token: "KSM", amount: "11523248" },
fee: { token: "KSM", amount: "104571640" },
},
},
{
Expand All @@ -35,6 +43,13 @@ export const basiliskRouteConfigs = createRouteConfigs("basilisk", [
fee: { token: "KUSD", amount: "5060238106" },
},
},
{
to: "karura",
token: "aUSD",
nohaapav marked this conversation as resolved.
Show resolved Hide resolved
xcm: {
fee: { token: "aUSD", amount: "5060238106" },
},
},
{
to: "karura",
token: "KSM",
Expand Down Expand Up @@ -70,6 +85,27 @@ export const basiliskRouteConfigs = createRouteConfigs("basilisk", [
fee: { token: "WBTC", amount: "2" },
},
},
{
to: "statemine",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "1183" },
},
},
{
to: "tinkernet",
token: "TNKR",
xcm: {
fee: { token: "TNKR", amount: "9270203240" },
},
},
{
to: "robonomics",
token: "XRT",
xcm: {
fee: { token: "XRT", amount: "4632" },
},
},
]);

export const basiliskTokensConfig: Record<string, ExtendedToken> = {
Expand All @@ -87,13 +123,41 @@ export const basiliskTokensConfig: Record<string, ExtendedToken> = {
ed: "10000000000",
toRaw: () => 2,
},
aUSD: {
nohaapav marked this conversation as resolved.
Show resolved Hide resolved
name: "aUSD",
symbol: "aUSD",
decimals: 12,
ed: "10000000000",
toRaw: () => 2,
},
KSM: {
name: "KSM",
symbol: "KSM",
decimals: 12,
ed: "100000000",
toRaw: () => 1,
},
USDT: {
name: "USDT",
symbol: "USDT",
decimals: 6,
ed: "10000",
toRaw: () => 14,
},
TNKR: {
name: "TNKR",
symbol: "TNKR",
decimals: 12,
ed: "1000000000",
toRaw: () => 6,
},
XRT: {
name: "XRT",
symbol: "XRT",
decimals: 9,
ed: "1683502",
toRaw: () => 16,
},
DAI: {
name: "DAI",
symbol: "DAI",
Expand Down Expand Up @@ -124,12 +188,28 @@ export const basiliskTokensConfig: Record<string, ExtendedToken> = {
},
};

export const hydraRouteConfigs = createRouteConfigs("hydradx", [
const DEST_WEIGHT = "5000000000";

export const hydradxRoutersConfig = createRouteConfigs("hydradx", [
{
to: "polkadot",
token: "DOT",
xcm: {
fee: { token: "DOT", amount: "469417452" },
},
},
{
to: "acala",
token: "DAI",
xcm: {
fee: { token: "DAI", amount: "808240000000000" },
fee: { token: "DAI", amount: "926960000000000" },
},
},
{
to: "acala",
token: "DOT",
xcm: {
fee: { token: "DOT", amount: "471820453" },
},
},
{
Expand All @@ -146,15 +226,41 @@ export const hydraRouteConfigs = createRouteConfigs("hydradx", [
fee: { token: "WBTC", amount: "4" },
},
},
{
to: "interlay",
token: "IBTC",
xcm: { fee: { token: "IBTC", amount: "62" } },
},
{
to: "statemint",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "700000" },
},
},
{
to: "zeitgeist",
token: "ZTG",
xcm: {
fee: { token: "ZTG", amount: "93000000" },
},
},
{
to: "astar",
token: "ASTR",
xcm: {
fee: { token: "ASTR", amount: "4041465440000000" },
},
},
]);

export const hydraTokensConfig: Record<string, ExtendedToken> = {
DAI: {
name: "DAI",
symbol: "DAI",
decimals: 18,
ed: "10000000000",
toRaw: () => 2,
export const hydradxTokensConfig: Record<string, ExtendedToken> = {
HDX: {
name: "HDX",
symbol: "HDX",
decimals: 12,
ed: "1000000000000",
toRaw: () => 0,
},
WETH: {
name: "WETH",
Expand All @@ -163,12 +269,48 @@ export const hydraTokensConfig: Record<string, ExtendedToken> = {
ed: "7000000000000",
toRaw: () => 4,
},
WBTC: {
name: "WBTC",
symbol: "WBTC",
WBTC: { name: "WBTC", symbol: "WBTC", decimals: 8, ed: "44", toRaw: () => 3 },
IBTC: {
name: "IBTC",
symbol: "IBTC",
decimals: 8,
ed: "44",
toRaw: () => 3,
ed: "36",
toRaw: () => 11,
},
DOT: {
name: "DOT",
symbol: "DOT",
decimals: 10,
ed: "17540000",
toRaw: () => 5,
},
DAI: {
name: "DAI",
symbol: "DAI",
decimals: 18,
ed: "10000000000000000",
toRaw: () => 2,
},
USDT: {
name: "USDT",
symbol: "USDT",
decimals: 6,
ed: "10000",
toRaw: () => 10,
},
ZTG: {
name: "ZTG",
symbol: "ZTG",
decimals: 10,
ed: "1204151916",
toRaw: () => 12,
},
ASTR: {
name: "ASTR",
symbol: "ASTR",
decimals: 18,
ed: "147058823529412000",
toRaw: () => 9,
},
};

Expand Down Expand Up @@ -311,6 +453,34 @@ class BaseHydradxAdapter extends BaseCrossChainAdapter {
):
| SubmittableExtrinsic<"promise", ISubmittableResult>
| SubmittableExtrinsic<"rxjs", ISubmittableResult> {
if (!this.api) throw new ApiNotFound(this.chain.id);

const { amount, to, token, address } = params;
const toChain = chains[to];
const isV3 = checkMessageVersionIsV3(this.api);

// For statemine & statemint
if (
isChainEqual(toChain, "statemine") ||
isChainEqual(toChain, "statemint")
) {
const assetId = STATEMINE_SUPPORTED_TOKENS[token];
const accountId = this.api?.createType("AccountId32", address).toHex();
const destWeight = isV3 ? "Unlimited" : DEST_WEIGHT;

if (assetId === undefined) throw new TokenNotFound(token);
return this.api.tx.xTokens.transferMultiasset(
createXTokensAssetsParam(
this.api,
toChain.paraChainId,
assetId,
amount.toChainData()
),
createXTokensDestParam(this.api, toChain.paraChainId, accountId) as any,
destWeight
);
}

return this.createXTokensTx(params);
}
}
Expand All @@ -321,8 +491,8 @@ export class BasiliskAdapter extends BaseHydradxAdapter {
}
}

export class HydraAdapter extends BaseHydradxAdapter {
export class HydraDxAdapter extends BaseHydradxAdapter {
constructor() {
super(chains.hydradx, hydraRouteConfigs, hydraTokensConfig);
super(chains.hydradx, hydradxRoutersConfig, hydradxTokensConfig);
}
}
Loading