Skip to content

Commit

Permalink
move mrl config to MRL interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Jan 15, 2025
1 parent 65be59e commit 60713c3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
5 changes: 0 additions & 5 deletions packages/config/src/types/AssetRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface AssetRouteConstructorParams {
destination: DestinationConfig;
contract?: ContractConfigBuilder;
extrinsic?: ExtrinsicConfigBuilder;
mrl?: MrlConfig;
}

export interface SourceConfig {
Expand Down Expand Up @@ -75,20 +74,16 @@ export class AssetRoute {

readonly extrinsic?: ExtrinsicConfigBuilder;

readonly mrl?: MrlConfig;

constructor({
source,
destination,
contract,
extrinsic,
mrl,
}: AssetRouteConstructorParams) {
this.source = source;
this.destination = destination;
this.contract = contract;
this.extrinsic = extrinsic;
this.mrl = mrl;
}

getDestinationFeeAssetOnSource(): ChainAsset {
Expand Down
3 changes: 1 addition & 2 deletions packages/config/src/types/ChainRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ export class ChainRoutes {
constructor({ chain, routes }: ChainRoutesConstructorParams) {
this.chain = chain;
this.#routes = new Map(
routes.map(({ source, destination, contract, extrinsic, mrl }) => [
routes.map(({ source, destination, contract, extrinsic }) => [
`${source.asset.key}-${destination.chain.key}`,
new AssetRoute({
source: { ...source, chain },
destination,
contract,
extrinsic,
mrl,
}),
]),
);
Expand Down
6 changes: 5 additions & 1 deletion packages/config/src/types/MrlAssetRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import type { Asset } from '@moonbeam-network/xcm-types';
import {
AssetRoute,
type AssetRouteConstructorParams,
type MrlConfig,
type SourceConfig,
} from './AssetRoute';

export interface MrlAssetRouteConstructorParams
extends AssetRouteConstructorParams {
source: MrlSourceConfig;
mrl: MrlConfig;
}

export interface MrlSourceConfig extends SourceConfig {
Expand All @@ -19,6 +21,7 @@ export interface MrlSourceConfig extends SourceConfig {
}

export class MrlAssetRoute extends AssetRoute {
readonly mrl: MrlConfig;
readonly source: MrlSourceConfig;

constructor({
Expand All @@ -28,7 +31,8 @@ export class MrlAssetRoute extends AssetRoute {
extrinsic,
mrl,
}: MrlAssetRouteConstructorParams & { source: MrlSourceConfig }) {
super({ source, destination, contract, extrinsic, mrl });
super({ source, destination, contract, extrinsic });
this.mrl = mrl;
this.source = source;
}
}
19 changes: 19 additions & 0 deletions packages/config/src/types/MrlChainRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { AnyAsset, AnyChain } from '@moonbeam-network/xcm-types';
import { getKey } from '../config.utils';
import { ChainRoutes, type ChainRoutesConstructorParams } from './ChainRoutes';
import {
MrlAssetRoute,
Expand Down Expand Up @@ -37,4 +39,21 @@ export class MrlChainRoutes extends ChainRoutes {
getRoutes(): MrlAssetRoute[] {
return Array.from(this.#routes.values());
}

getAssetRoute(
asset: string | AnyAsset,
destination: string | AnyChain,
): MrlAssetRoute {
const assetKey = getKey(asset);
const destKey = getKey(destination);
const route = this.#routes.get(`${assetKey}-${destKey}`);

if (!route) {
throw new Error(
`AssetRoute for asset ${assetKey} and destination ${destKey} not found`,
);
}

return route;
}
}
9 changes: 7 additions & 2 deletions packages/mrl/src/mrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ConfigService, mrlRoutesMap } from '@moonbeam-network/xcm-config';
import {
ConfigService,
type MrlAssetRoute,
mrlRoutesMap,
} from '@moonbeam-network/xcm-config';
import type {
AnyAsset,
AnyChain,
Expand Down Expand Up @@ -39,6 +43,7 @@ export function Mrl(options?: MrlOptions) {
source,
destination,
});

return {
setIsAutomatic(isAutomatic: boolean) {
return {
Expand All @@ -50,7 +55,7 @@ export function Mrl(options?: MrlOptions) {
destinationAddress: string;
}) {
return getTransferData({
route,
route: route as MrlAssetRoute,
sourceAddress,
destinationAddress,
isAutomatic,
Expand Down

0 comments on commit 60713c3

Please sign in to comment.