Skip to content

Commit

Permalink
merge v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Sep 30, 2024
2 parents d2a060e + b46e429 commit f04a877
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 138 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"teer",
"tinkernet",
"tnkr",
"tokenbridge",
"usdc",
"usdcwh",
"usdt",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"@polkadot/util": "^13.0.2",
"@polkadot/util-crypto": "^13.0.2",
"@wormhole-foundation/sdk-connect": "^0.10.7",
"@wormhole-foundation/sdk-evm": "^0.10.7"
"@wormhole-foundation/sdk-evm": "^0.10.7",
"@wormhole-foundation/sdk-evm-tokenbridge": "^0.10.7"
},
"devDependencies": {
"@biomejs/biome": "^1.9.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ export const fantomTestnet = new EvmChain({
ChainAsset.fromAsset(ftm, {
decimals: 18,
}),
// TODO should be WGLMR
ChainAsset.fromAsset(dev, {
address: '0x41E3CFDFC255A4bF3C8D3560Bc8D3D9b5080338e',
decimals: 18,
}),
],
ecosystem: Ecosystem.AlphanetRelay,
explorer: 'https://testnet.ftmscan.com',
Expand Down
73 changes: 69 additions & 4 deletions packages/config/src/mrl-configs/fantomTestnet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder';
import { dev, ftm, ftmwh } from '../assets';
import { fantomTestnet, peaqAlphanet } from '../chains';
import { fantomTestnet, moonbaseAlpha, peaqAlphanet } from '../chains';
import { ChainRoutes } from '../types/ChainRoutes';

export const fantomTestnetRoutes = new ChainRoutes({
Expand All @@ -24,13 +24,78 @@ export const fantomTestnetRoutes = new ChainRoutes({
amount: 0.01,
},
},
mrl: {
isAutomatic: false, // TODO should be isAutomaticPossible
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
moonChain: {
asset: ftmwh,
fee: {
asset: dev,
amount: 0.1,
balance: BalanceBuilder().substrate().system().account(),
},
},
},
},
{
source: {
asset: ftm,
balance: BalanceBuilder().evm().native(),
destinationFee: {
asset: ftm,
balance: BalanceBuilder().evm().native(),
},
},
destination: {
asset: ftmwh,
chain: moonbaseAlpha,
balance: BalanceBuilder().evm().erc20(),
fee: {
asset: ftmwh,
amount: 0,
},
},
mrl: {
isAutomatic: false,
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
moonChain: {
asset: ftmwh,
fee: {
asset: dev,
amount: 0.1,
balance: BalanceBuilder().substrate().system().account(),
},
},
},
},
{
source: {
asset: dev,
balance: BalanceBuilder().evm().erc20(),
destinationFee: {
asset: dev,
balance: BalanceBuilder().evm().erc20(),
},
},
destination: {
asset: dev,
chain: moonbaseAlpha,
balance: BalanceBuilder().substrate().system().account(),
fee: {
asset: dev,
amount: 0,
},
},
mrl: {
isAutomatic: false,
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
moonChainFee: {
moonChain: {
asset: dev,
amount: 0.1,
balance: BalanceBuilder().substrate().system().account(),
fee: {
asset: dev,
amount: 0.1,
balance: BalanceBuilder().substrate().system().account(),
},
},
},
},
Expand Down
7 changes: 6 additions & 1 deletion packages/config/src/types/AssetRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ export interface FeeConfig {
export interface MrlConfig {
isAutomatic: boolean;
transfer: MrlConfigBuilder;
moonChainFee: MoonChainFeeConfig;
moonChain: MoonChainConfig;
}

export interface DestinationFeeConfig
extends SetOptional<FeeConfig, 'balance'> {
amount: number | FeeConfigBuilder;
}

export interface MoonChainConfig {
asset: Asset;
fee: MoonChainFeeConfig;
}

export interface MoonChainFeeConfig extends FeeConfig {
amount: number | FeeConfigBuilder;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/mrl/src/getTransferData/getMoonChainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function getMoonChainData({
}

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

if (isDestinationMoonChain) {
Expand All @@ -40,7 +40,7 @@ export async function getMoonChainData({
address: sourceAddress, // TODO not correct
asset: route.destination.fee.asset,
chain: moonChain,
fee: route.mrl.moonChainFee.amount,
fee: route.mrl.moonChain.fee.amount,
transferAsset: route.source.asset,
});

Expand All @@ -59,7 +59,7 @@ export async function getMoonChainData({
const balance = await getBalance({
address,
asset,
builder: route.mrl.moonChainFee.balance,
builder: route.mrl.moonChain.fee.balance,
chain: moonChain,
});

Expand Down
3 changes: 1 addition & 2 deletions packages/mrl/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export async function getSourceData({
}

const source = route.source.chain;
const destination = route.destination.chain;
const asset = source.getChainAsset(route.source.asset);
const feeAsset = route.source.fee
? source.getChainAsset(route.source.fee.asset)
Expand All @@ -71,7 +70,7 @@ export async function getSourceData({
sourceAddress,
});

const existentialDeposit = await getExistentialDeposit(destination);
const existentialDeposit = await getExistentialDeposit(source);
const min = await getAssetMin({
asset,
builder: route.source.min,
Expand Down
1 change: 1 addition & 0 deletions packages/mrl/src/services/wormhole/WormholeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type WormholeConfig,
wormholeFactory,
} from '@moonbeam-network/xcm-builder';
import '@wormhole-foundation/sdk-evm-tokenbridge';
import type { EvmSigner } from '@moonbeam-network/xcm-sdk';
import type { EvmChain, EvmParachain } from '@moonbeam-network/xcm-types';
import {
Expand Down
Loading

0 comments on commit f04a877

Please sign in to comment.