Skip to content

Commit

Permalink
Different assets on source and destination to support MRL
Browse files Browse the repository at this point in the history
  • Loading branch information
ekenigs committed Sep 13, 2024
1 parent 41a42b3 commit f3d30ce
Show file tree
Hide file tree
Showing 63 changed files with 510 additions and 272 deletions.
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"aseed",
"astar",
"ausd",
"axlusdc",
"biomejs",
"bncs",
"composablenodes",
Expand Down Expand Up @@ -90,14 +91,14 @@
"xfer",
"xtokens"
],
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint",
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnPaste": false,
"editor.formatOnType": false,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"typescript.preferences.importModuleSpecifier": "relative",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.eslint": "explicit"
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
}
}
10 changes: 4 additions & 6 deletions examples/mrl-simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Mrl } from '@moonbeam-network/mrl';
import {
fantomTestnet,
ftmwh,
moonbeam,
peaqChain,
polkadot,
peaqAlphanet,
} from '@moonbeam-network/xcm-config';
import { Keyring } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';
Expand All @@ -28,7 +26,7 @@ if (!EVM_PRIVATE_KEY || !POLKADOT_PRIVATE_KEY) {
const account = privateKeyToAccount(EVM_PRIVATE_KEY as Address);
const walletClient = createWalletClient({
account,
chain: moonbeam.getViemChain(),
chain: fantomTestnet.getViemChain(),
transport: http(),
});

Expand All @@ -38,7 +36,7 @@ console.log(`\nEVM address: ${account.address}`);

await cryptoWaitReady();
const keyring = new Keyring({
ss58Format: polkadot.ss58Format,
ss58Format: peaqAlphanet.ss58Format,
type: 'sr25519',
});
const pair = keyring.createFromUri(POLKADOT_PRIVATE_KEY);
Expand All @@ -55,7 +53,7 @@ main()
async function main() {
const data = await Mrl()
.setSource(fantomTestnet)
.setDestination(peaqChain)
.setDestination(peaqAlphanet)
.setAsset(ftmwh)
.setAddresses({
sourceAddress: account.address,
Expand Down
3 changes: 2 additions & 1 deletion packages/config/src/ConfigService/ConfigService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ describe('config service', () => {
chain: hydration,
routes: [
{
asset: glmr,
source: {
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
destination: {
asset: glmr,
chain: moonbeam,
balance: BalanceBuilder().substrate().tokens().accounts(),
fee: {
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/ConfigService/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ConfigService {
.filter((routes) => routes.chain.ecosystem === ecosystem)
.map((routes) => routes.getRoutes())
.flat(2)
.map((route) => route.asset),
.map((route) => route.source.asset),
),
).sort((a, b) => a.key.localeCompare(b.key));
}
Expand Down
6 changes: 4 additions & 2 deletions packages/config/src/mrl-configs/fantomTestnet.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder';
import { dev, ftmwh } from '../assets';
import { dev, ftm, ftmwh } from '../assets';
import { fantomTestnet, peaqAlphanet } from '../chains';
import { ChainRoutes } from '../types/ChainRoutes';

export const fantomTestnetRoutes = new ChainRoutes({
chain: fantomTestnet,
routes: [
{
asset: ftmwh,
source: {
asset: ftm,
balance: BalanceBuilder().evm().native(),
destinationFee: {
asset: ftm,
balance: BalanceBuilder().evm().native(),
},
},
destination: {
asset: ftmwh,
chain: peaqAlphanet,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
Expand Down
7 changes: 2 additions & 5 deletions packages/config/src/types/AssetRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
import type { AnyChain, Asset, SetOptional } from '@moonbeam-network/xcm-types';

export interface AssetRouteConstructorParams {
asset: Asset;
source: SourceConfig;
destination: DestinationConfig;
contract?: ContractConfigBuilder;
Expand All @@ -18,10 +17,12 @@ export interface AssetRouteConstructorParams {
}

export interface SourceConfig {
asset: Asset;
chain: AnyChain;
balance: BalanceConfigBuilder;
fee?: FeeConfig;
destinationFee?: {
asset?: Asset;
balance: BalanceConfigBuilder;
};
min?: AssetMinConfigBuilder;
Expand Down Expand Up @@ -55,8 +56,6 @@ export interface MoonChainFeeConfig extends FeeConfig {
}

export class AssetRoute {
readonly asset: Asset;

readonly source: SourceConfig;

readonly destination: DestinationConfig;
Expand All @@ -68,14 +67,12 @@ export class AssetRoute {
readonly mrl?: MrlConfig;

constructor({
asset,
source,
destination,
contract,
extrinsic,
mrl,
}: AssetRouteConstructorParams) {
this.asset = asset;
this.source = source;
this.destination = destination;
this.contract = contract;
Expand Down
12 changes: 6 additions & 6 deletions packages/config/src/types/ChainRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export class ChainRoutes {
constructor({ chain, routes }: ChainRoutesConstructorParams) {
this.chain = chain;
this.#routes = new Map(
routes.map(({ asset, source, destination, contract, extrinsic }) => [
`${asset.key}-${destination.chain.key}`,
routes.map(({ source, destination, contract, extrinsic, mrl }) => [
`${source.asset.key}-${destination.chain.key}`,
new AssetRoute({
asset,
source: { ...source, chain },
destination,
contract,
extrinsic,
mrl,
}),
]),
);
Expand All @@ -43,7 +43,7 @@ export class ChainRoutes {
getAssetRoutes(keyOrAsset: string | AnyAsset): AssetRoute[] {
const key = getKey(keyOrAsset);

return this.getRoutes().filter((cfg) => cfg.asset.key === key);
return this.getRoutes().filter((route) => route.source.asset.key === key);
}

getAssetDestinations(keyOrAsset: string | AnyAsset): AnyChain[] {
Expand All @@ -56,8 +56,8 @@ export class ChainRoutes {
const key = getKey(keyOrChain);

return this.getRoutes()
.filter((cfg) => cfg.destination.chain.key === key)
.map((cfg) => cfg.asset);
.filter((route) => route.destination.chain.key === key)
.map((route) => route.source.asset);
}

getAssetRoute(
Expand Down
12 changes: 8 additions & 4 deletions packages/config/src/xcm-configs/acala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ export const acalaRoutes = new ChainRoutes({
chain: acala,
routes: [
{
asset: aca,
source: {
asset: aca,
balance: BalanceBuilder().substrate().system().account(),
destinationFee: {
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: aca,
chain: moonbeam,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
Expand All @@ -30,8 +31,8 @@ export const acalaRoutes = new ChainRoutes({
extrinsic: ExtrinsicBuilder().xTokens().transfer(),
},
{
asset: aseed,
source: {
asset: aseed,
balance: BalanceBuilder().substrate().tokens().accounts(),
fee: {
asset: aca,
Expand All @@ -43,6 +44,7 @@ export const acalaRoutes = new ChainRoutes({
},
},
destination: {
asset: aseed,
chain: moonbeam,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
Expand All @@ -53,8 +55,8 @@ export const acalaRoutes = new ChainRoutes({
extrinsic: ExtrinsicBuilder().xTokens().transfer(),
},
{
asset: glmr,
source: {
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
fee: {
asset: aca,
Expand All @@ -66,6 +68,7 @@ export const acalaRoutes = new ChainRoutes({
},
},
destination: {
asset: glmr,
chain: moonbeam,
balance: BalanceBuilder().substrate().system().account(),
fee: {
Expand All @@ -76,8 +79,8 @@ export const acalaRoutes = new ChainRoutes({
extrinsic: ExtrinsicBuilder().xTokens().transfer(),
},
{
asset: ldot,
source: {
asset: ldot,
balance: BalanceBuilder().substrate().tokens().accounts(),
fee: {
asset: aca,
Expand All @@ -89,6 +92,7 @@ export const acalaRoutes = new ChainRoutes({
},
},
destination: {
asset: ldot,
chain: moonbeam,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
Expand Down
3 changes: 2 additions & 1 deletion packages/config/src/xcm-configs/alphanetAssetHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const alphanetAssetHubRoutes = new ChainRoutes({
chain: alphanetAssetHub,
routes: [
{
asset: tt1,
source: {
asset: tt1,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
asset: unit,
Expand All @@ -25,6 +25,7 @@ export const alphanetAssetHubRoutes = new ChainRoutes({
},
},
destination: {
asset: tt1,
chain: moonbaseAlpha,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
Expand Down
3 changes: 2 additions & 1 deletion packages/config/src/xcm-configs/alphanetRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export const alphanetRelayRoutes = new ChainRoutes({
chain: alphanetRelay,
routes: [
{
asset: unit,
source: {
asset: unit,
balance: BalanceBuilder().substrate().system().account(),
destinationFee: {
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: unit,
chain: moonbaseAlpha,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
Expand Down
6 changes: 4 additions & 2 deletions packages/config/src/xcm-configs/astar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export const astarRoutes = new ChainRoutes({
chain: astar,
routes: [
{
asset: astr,
source: {
asset: astr,
balance: BalanceBuilder().substrate().system().account(),
destinationFee: {
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: astr,
chain: moonbeam,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
Expand All @@ -32,8 +33,8 @@ export const astarRoutes = new ChainRoutes({
.here(),
},
{
asset: glmr,
source: {
asset: glmr,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
asset: astr,
Expand All @@ -44,6 +45,7 @@ export const astarRoutes = new ChainRoutes({
},
},
destination: {
asset: glmr,
chain: moonbeam,
balance: BalanceBuilder().substrate().system().account(),
fee: {
Expand Down
Loading

0 comments on commit f3d30ce

Please sign in to comment.