Skip to content

Commit

Permalink
feat: statemint routes for DOT (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Jun 6, 2023
1 parent 61a6d3f commit ea5701b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/adapters/polkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export const polkadotRoutersConfig: Omit<RouteConfigs, "from">[] = [
token: "DOT",
xcm: { fee: { token: "DOT", amount: "3549633" }, weightLimit: "Unlimited" },
},
{
to: "statemint",
token: "DOT",
xcm: {
fee: { token: "DOT", amount: "15800000" },
weightLimit: "Unlimited",
},
},
];

// TODO: should remove after kusama upgrade
Expand Down
52 changes: 46 additions & 6 deletions src/adapters/statemint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ import {
} from "../types";
import { validateAddress } from "../utils";

export const statemintRoutersConfig: Omit<RouteConfigs, "from">[] = [
{
to: "polkadot",
token: "DOT",
xcm: {
fee: { token: "DOT", amount: "421500000" },
weightLimit: "Unlimited",
},
},
];

export const statemineRoutersConfig: Omit<RouteConfigs, "from">[] = [
{
to: "kusama",
Expand Down Expand Up @@ -51,10 +62,14 @@ export const statemineRoutersConfig: Omit<RouteConfigs, "from">[] = [
},
];

export const statemineTokensConfig: Record<
export const statemintTokensConfig: Record<
string,
Record<string, BasicToken>
> = {
statemint: {
DOT: { name: "DOT", symbol: "DOT", decimals: 10, ed: "10000000000" },
USDT: { name: "USDT", symbol: "USDT", decimals: 6, ed: "1000" },
},
statemine: {
KSM: { name: "KSM", symbol: "KSM", decimals: 12, ed: "79999999" },
RMRK: { name: "RMRK", symbol: "RMRK", decimals: 10, ed: "100000000" },
Expand Down Expand Up @@ -172,7 +187,7 @@ class BaseStatemintAdapter extends BaseCrossChainAdapter {
this.balanceAdapter = new StatemintBalanceAdapter({
api,
chain,
tokens: statemineTokensConfig[chain],
tokens: statemintTokensConfig[chain],
});
}

Expand Down Expand Up @@ -226,6 +241,19 @@ class BaseStatemintAdapter extends BaseCrossChainAdapter {
);
}

private get isV0V1() {
try {
const keys = (this.api?.createType("XcmVersionedMultiLocation") as any)
.defKeys as string[];

return keys.includes("V0");
} catch (e) {
// ignore error
}

return false;
}

public createTx(
params: TransferParams
):
Expand All @@ -248,6 +276,8 @@ class BaseStatemintAdapter extends BaseCrossChainAdapter {
throw new TokenNotFound(token);
}

const isV0V1Support = this.isV0V1;

const dst = { interior: "Here", parents: 1 };
const acc = {
interior: { X1: { AccountId32: { id: accountId } } },
Expand All @@ -263,9 +293,9 @@ class BaseStatemintAdapter extends BaseCrossChainAdapter {
];

return this.api?.tx.polkadotXcm.limitedTeleportAssets(
{ V3: dst },
{ V3: acc },
{ V3: ass },
{ [isV0V1Support ? "V1" : "V3"]: dst },
{ [isV0V1Support ? "V1" : "V3"]: acc },
{ [isV0V1Support ? "V1" : "V3"]: ass },
0,
this.getDestWeight(token, to)?.toString()
);
Expand Down Expand Up @@ -312,12 +342,22 @@ class BaseStatemintAdapter extends BaseCrossChainAdapter {
}
}

export class StatemintAdapter extends BaseStatemintAdapter {
constructor() {
super(
chains.statemint,
statemintRoutersConfig,
statemintTokensConfig.statemint
);
}
}

export class StatemineAdapter extends BaseStatemintAdapter {
constructor() {
super(
chains.statemine,
statemineRoutersConfig,
statemineTokensConfig.statemine
statemintTokensConfig.statemine
);
}
}

0 comments on commit ea5701b

Please sign in to comment.