Skip to content

Commit

Permalink
add moonbase to fantom routes and fix configuration accordingly to co…
Browse files Browse the repository at this point in the history
…nsider moonChain as source
  • Loading branch information
mmaurello committed Oct 1, 2024
1 parent b46e429 commit 64f32e5
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 19 deletions.
17 changes: 10 additions & 7 deletions packages/builder/src/mrl/providers/wormhole/wormhole/wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function wormhole() {
sourceAddress,
}) => {
const isNativeAsset = asset.isSame(source.nativeAsset);
const isDestinationMoonChain = destination.isEqual(moonChain);
const isSourceOrDestinationMoonChain =
destination.isEqual(moonChain) || source.isEqual(moonChain);
const tokenAddress = isNativeAsset ? 'native' : asset.address;

if (!tokenAddress) {
Expand All @@ -35,25 +36,27 @@ export function wormhole() {

const wh = wormholeFactory(source);
const whSource = wh.getChain(source.getWormholeName());
const whMoonChain = wh.getChain(moonChain.getWormholeName());
const whDestination = wh.getChain(destination.getWormholeName());
const whAsset = Wormhole.tokenId(whSource.chain, tokenAddress);
const whSourceAddress = Wormhole.chainAddress(
whSource.chain,
sourceAddress,
);
const whMoonChainAddress = Wormhole.chainAddress(
whMoonChain.chain,
isDestinationMoonChain ? destinationAddress : GMP_CONTRACT_ADDRESS,
const whDestinationAddress = Wormhole.chainAddress(
whDestination.chain,
isSourceOrDestinationMoonChain
? destinationAddress
: GMP_CONTRACT_ADDRESS,
);

return new WormholeConfig({
args: [
whAsset,
asset.amount,
whSourceAddress,
whMoonChainAddress,
whDestinationAddress,
isAutomatic,
isDestinationMoonChain
isSourceOrDestinationMoonChain
? undefined
: getPayload({ destination, destinationAddress, moonApi }),
],
Expand Down
6 changes: 5 additions & 1 deletion packages/config/src/mrl-configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { ChainRoutes } from '../types/ChainRoutes';
import { fantomTestnetRoutes } from './fantomTestnet';
import { moonbaseAlphaRoutes } from './moonbaseAlpha';

export const mrlRoutesList: ChainRoutes[] = [fantomTestnetRoutes];
export const mrlRoutesList: ChainRoutes[] = [
fantomTestnetRoutes,
moonbaseAlphaRoutes,
];

export const mrlRoutesMap = new Map<string, ChainRoutes>(
mrlRoutesList.map((config) => [config.chain.key, config]),
Expand Down
72 changes: 72 additions & 0 deletions packages/config/src/mrl-configs/moonbaseAlpha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder';
import { dev, ftm, ftmwh } from '../assets';
import { fantomTestnet, moonbaseAlpha } from '../chains';
import { ChainRoutes } from '../types/ChainRoutes';

export const moonbaseAlphaRoutes = new ChainRoutes({
chain: moonbaseAlpha,
routes: [
{
source: {
asset: ftmwh,
balance: BalanceBuilder().evm().erc20(),
destinationFee: {
asset: ftmwh,
balance: BalanceBuilder().evm().erc20(),
},
},
destination: {
asset: ftm,
chain: fantomTestnet,
balance: BalanceBuilder().evm().native(),
fee: {
asset: ftm,
amount: 0,
},
},
mrl: {
isAutomatic: true,
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
moonChain: {
asset: ftmwh,
fee: {
asset: dev,
amount: 0.1, // TODO not really, it would be the source fee as source is moonChain
balance: BalanceBuilder().substrate().system().account(),
},
},
},
},
{
source: {
asset: dev,
balance: BalanceBuilder().substrate().system().account(),
destinationFee: {
asset: dev,
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: dev,
chain: fantomTestnet,
balance: BalanceBuilder().evm().erc20(),
fee: {
asset: dev,
amount: 0,
},
},
mrl: {
isAutomatic: true,
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
moonChain: {
asset: dev,
fee: {
asset: dev,
amount: 0.1,
balance: BalanceBuilder().substrate().system().account(),
},
},
},
},
],
});
3 changes: 2 additions & 1 deletion packages/mrl/src/getTransferData/getMoonChainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function getMoonChainData({

const moonChain = getMoonChain(route.source.chain);
const asset = moonChain.getChainAsset(route.mrl.moonChain.asset);
const feeAsset = moonChain.getChainAsset(route.mrl.moonChain.fee.asset);
const isDestinationMoonChain = route.destination.chain.isEqual(moonChain);

if (isDestinationMoonChain) {
Expand All @@ -37,7 +38,7 @@ export async function getMoonChainData({
}

const fee = await getDestinationFee({
asset,
asset: feeAsset,
chain: moonChain,
fee: route.mrl.moonChain.fee.amount,
});
Expand Down
27 changes: 17 additions & 10 deletions packages/mrl/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
type ExtrinsicConfig,
WormholeConfig,
} from '@moonbeam-network/xcm-builder';
import type { AssetRoute, FeeConfig } from '@moonbeam-network/xcm-config';
import {
type AssetRoute,
type FeeConfig,
dev,
} from '@moonbeam-network/xcm-config';
import {
type SourceChainTransferData,
getAssetMin,
Expand All @@ -14,12 +18,12 @@ import {
getExtrinsicFee,
getMax,
} from '@moonbeam-network/xcm-sdk';
import type {
AnyChain,
AnyParachain,
import {
type AnyChain,
type AnyParachain,
AssetAmount,
EvmChain,
EvmParachain,
type EvmChain,
type EvmParachain,
} from '@moonbeam-network/xcm-types';
import { WormholeService } from '../services/wormhole';
import { buildTransfer } from './getTransferData.utils';
Expand Down Expand Up @@ -137,11 +141,14 @@ export async function getFee({
const wh = WormholeService.create(chain as EvmChain | EvmParachain);
const fee = await wh.getFee(transfer);

console.log('fee', fee);
// TODO technically this is not the fee on source chain, it's relayer fee
// source fee should be the fee paid to send the message in polkadot to eth or to sign the transaction in eth to polkadot
console.log('fee in getFee', fee);

// TODO: finish
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
return {} as any;
return AssetAmount.fromChainAsset(chain.getChainAsset(dev), {
// TODO not dev
amount: fee.relayFee?.amount || 0n,
});
}

if (ContractConfig.is(transfer)) {
Expand Down

0 comments on commit 64f32e5

Please sign in to comment.