Skip to content

Commit

Permalink
feat: statemint/e --> asset hub (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpdunne authored Mar 11, 2024
1 parent 2b927cf commit 578dc2f
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 126 deletions.
6 changes: 3 additions & 3 deletions src/adapters/acala/acala-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,21 @@ export const acalaRouteConfigs = createRouteConfigs("acala", [
},
},
{
to: "statemint",
to: "assetHubPolkadot",
token: "USDT",
xcm: {
fee: { token: "DOT", amount: "160000000" },
},
},
{
to: "statemint",
to: "assetHubPolkadot",
token: "USDC",
xcm: {
fee: { token: "DOT", amount: "100000000" },
},
},
{
to: "statemint",
to: "assetHubPolkadot",
token: "PINK",
xcm: {
fee: { token: "DOT", amount: "100000000" },
Expand Down
14 changes: 7 additions & 7 deletions src/adapters/acala/acala.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Bridge } from "../../bridge";
import { KaruraAdapter } from "./acala";
import { KusamaAdapter } from "../polkadot";
import { MoonriverAdapter } from "../moonbeam";
import { StatemineAdapter } from "../statemint";
import { AssetHubKusamaAdapter } from "../assethub";
import { SubmittableExtrinsic } from "@polkadot/api/types";
import { ISubmittableResult } from "@polkadot/types/types";
import { ApiPromise, WsProvider } from "@polkadot/api";
Expand Down Expand Up @@ -35,18 +35,18 @@ describe.skip("acala-adapter", () => {
const karura = new KaruraAdapter();
const kusama = new KusamaAdapter();
const moonriver = new MoonriverAdapter();
const statemine = new StatemineAdapter();
const assetHubKusama = new AssetHubKusamaAdapter();

const karuraApi = new ApiPromise({ provider: new WsProvider('wss://karura.api.onfinality.io/public-ws') });
const kusmaApi = new ApiPromise({ provider: new WsProvider('wss://kusama.api.onfinality.io/public-ws') });
const statemineApi = new ApiPromise({ provider: new WsProvider('wss://statemine-rpc.dwellir.com') });
const assetHubApi = new ApiPromise({ provider: new WsProvider('wss://statemine-rpc.dwellir.com') });

await karura.init(karuraApi);
await kusama.init(kusmaApi);
await statemine.init(statemineApi);
await assetHubKusama.init(assetHubApi);

bridge = new Bridge({
adapters: [karura, kusama, moonriver, statemine],
adapters: [karura, kusama, moonriver, assetHubKusama],
});
});

Expand Down Expand Up @@ -149,7 +149,7 @@ describe.skip("acala-adapter", () => {
}
});

test('transfer from karura to statemine should be ok', (done) => {
test('transfer from karura to asset hub should be ok', (done) => {
try {

const adapter = bridge.findAdapter('karura');
Expand All @@ -164,7 +164,7 @@ describe.skip("acala-adapter", () => {

const amount = new FixedPointNumber(1, rmrk.decimals);
const tx = adapter.createTx({
to: 'statemine',
to: 'assetHubKusama',
token: 'RMRK',
amount,
address
Expand Down
19 changes: 11 additions & 8 deletions src/adapters/acala/acala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { ChainId, chains } from "../../configs";
import { ApiNotFound, InvalidAddress, TokenNotFound } from "../../errors";
import { BalanceData, ExtendedToken, TransferParams } from "../../types";
import { isChainEqual } from "../../utils/is-chain-equal";
import { statemineTokensConfig, statemintTokensConfig } from "../statemint";
import {
assetHubKusamaTokensConfig,
assetHubPolkadotTokensConfig,
} from "../assethub";
import {
createXTokensAssetsParam,
createXTokensDestParam,
Expand Down Expand Up @@ -154,8 +157,8 @@ class BaseAcalaAdapter extends BaseCrossChainAdapter {
throw new InvalidAddress(address);
}

if (isChainEqual(toChain, "statemint")) {
const tokenData = statemintTokensConfig[token];
if (isChainEqual(toChain, "assetHubPolkadot")) {
const tokenData = assetHubPolkadotTokensConfig[token];

if (!token) throw new TokenNotFound(token);

Expand Down Expand Up @@ -184,11 +187,11 @@ class BaseAcalaAdapter extends BaseCrossChainAdapter {
);
}

// for statemine
if (isChainEqual(toChain, "statemine")) {
const tokenData: ExtendedToken = isChainEqual(toChain, "statemine")
? statemineTokensConfig[token]
: statemintTokensConfig[token];
// for asset hub
if (isChainEqual(toChain, "assetHubKusama")) {
const tokenData: ExtendedToken = isChainEqual(toChain, "assetHubKusama")
? assetHubKusamaTokensConfig[token]
: assetHubPolkadotTokensConfig[token];

if (!token) throw new TokenNotFound(token);

Expand Down
6 changes: 3 additions & 3 deletions src/adapters/acala/karura-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ export const karuraRouteConfigs = createRouteConfigs("karura", [
},
},
{
to: "statemine",
to: "assetHubKusama",
token: "RMRK",
xcm: {
fee: { token: "RMRK", amount: "100000" },
},
},
{
to: "statemine",
to: "assetHubKusama",
token: "ARIS",
xcm: {
fee: { token: "KSM", amount: "16000000000" },
},
},
{
to: "statemine",
to: "assetHubKusama",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "1183" },
Expand Down
163 changes: 87 additions & 76 deletions src/adapters/statemint.ts → src/adapters/assethub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,82 +18,85 @@ import {
getDestAccountInfo,
} from "../utils";

export const statemintRouteConfigs = createRouteConfigs("statemint", [
{
to: "polkadot",
token: "DOT",
xcm: {
fee: { token: "DOT", amount: "421500000" },
weightLimit: "Unlimited",
export const assetHubPolkadotRouteConfigs = createRouteConfigs(
"assetHubPolkadot",
[
{
to: "polkadot",
token: "DOT",
xcm: {
fee: { token: "DOT", amount: "421500000" },
weightLimit: "Unlimited",
},
},
},
{
to: "hydradx",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "2200" },
weightLimit: "Unlimited",
{
to: "hydradx",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "2200" },
weightLimit: "Unlimited",
},
},
},
{
to: "acala",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
{
to: "acala",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
},
},
},
{
to: "acala",
token: "USDC",
xcm: {
fee: { token: "USDC", amount: "803" },
weightLimit: "Unlimited",
{
to: "acala",
token: "USDC",
xcm: {
fee: { token: "USDC", amount: "803" },
weightLimit: "Unlimited",
},
},
},
{
to: "acala",
token: "PINK",
xcm: {
fee: { token: "PINK", amount: "80370000" },
weightLimit: "Unlimited",
{
to: "acala",
token: "PINK",
xcm: {
fee: { token: "PINK", amount: "80370000" },
weightLimit: "Unlimited",
},
},
},
{
to: "astar",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
{
to: "astar",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
},
},
},
{
to: "interlay",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
{
to: "interlay",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
},
},
},
{
to: "moonbeam",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
{
to: "moonbeam",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
},
},
},
{
to: "parallel",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
{
to: "parallel",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "808" },
weightLimit: "Unlimited",
},
},
},
]);
]
);

export const statemineRouteConfigs = createRouteConfigs("statemine", [
export const assetHubKusamaRouteConfigs = createRouteConfigs("assetHubKusama", [
{
to: "kusama",
token: "KSM",
Expand Down Expand Up @@ -125,7 +128,7 @@ export const statemineRouteConfigs = createRouteConfigs("statemine", [
},
]);

export const statemintTokensConfig: Record<string, ExtendedToken> = {
export const assetHubPolkadotTokensConfig: Record<string, ExtendedToken> = {
DOT: {
name: "DOT",
symbol: "DOT",
Expand Down Expand Up @@ -156,7 +159,7 @@ export const statemintTokensConfig: Record<string, ExtendedToken> = {
},
};

export const statemineTokensConfig: Record<string, ExtendedToken> = {
export const assetHubKusamaTokensConfig: Record<string, ExtendedToken> = {
KSM: {
name: "KSM",
symbol: "KSM",
Expand Down Expand Up @@ -217,7 +220,7 @@ const createBalanceStorages = (api: AnyApi) => {
};
};

class StatemintBalanceAdapter extends BalanceAdapter {
class AssetHubBalanceAdapter extends BalanceAdapter {
private storages: ReturnType<typeof createBalanceStorages>;

constructor({ api, chain, tokens }: BalanceAdapterConfigs) {
Expand Down Expand Up @@ -275,8 +278,8 @@ class StatemintBalanceAdapter extends BalanceAdapter {
}
}

class BaseStatemintAdapter extends BaseCrossChainAdapter {
private balanceAdapter?: StatemintBalanceAdapter;
class BaseAssetHubAdapter extends BaseCrossChainAdapter {
private balanceAdapter?: AssetHubBalanceAdapter;

public async init(api: AnyApi) {
this.api = api;
Expand All @@ -285,7 +288,7 @@ class BaseStatemintAdapter extends BaseCrossChainAdapter {

const chain = this.chain.id as ChainId;

this.balanceAdapter = new StatemintBalanceAdapter({
this.balanceAdapter = new AssetHubBalanceAdapter({
api,
chain,
tokens: this.tokens,
Expand Down Expand Up @@ -438,14 +441,22 @@ class BaseStatemintAdapter extends BaseCrossChainAdapter {
}
}

export class StatemintAdapter extends BaseStatemintAdapter {
export class AssetHubPolkadotAdapter extends BaseAssetHubAdapter {
constructor() {
super(chains.statemint, statemintRouteConfigs, statemintTokensConfig);
super(
chains.assetHubPolkadot,
assetHubPolkadotRouteConfigs,
assetHubPolkadotTokensConfig
);
}
}

export class StatemineAdapter extends BaseStatemintAdapter {
export class AssetHubKusamaAdapter extends BaseAssetHubAdapter {
constructor() {
super(chains.statemine, statemineRouteConfigs, statemineTokensConfig);
super(
chains.assetHubKusama,
assetHubKusamaRouteConfigs,
assetHubKusamaTokensConfig
);
}
}
2 changes: 1 addition & 1 deletion src/adapters/astar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const astarRouteConfigs = createRouteConfigs("astar", [
},
},
{
to: "statemint",
to: "assetHubPolkadot",
token: "USDT",
xcm: {
fee: { token: "USDT", amount: "44306118000000000" },
Expand Down
Loading

0 comments on commit 578dc2f

Please sign in to comment.