From b27aa4800caab192a70140c45720f5ca36d9aa04 Mon Sep 17 00:00:00 2001 From: mmaurello <93129175+mmaurello@users.noreply.github.com> Date: Fri, 20 Dec 2024 18:43:14 +0100 Subject: [PATCH] Ethereum, moonbeam and Hydration configurations (#409) * Ethereum, moonbeam and Hydration configurations * remove unused vars * add routes to index file * moonbeam to ethereum configurations * remove peaq routes for now * xcm config adjustments and not throw error when amount is 0 in network fee and relayer fee --- .../src/contract/contracts/Xtokens/Xtokens.ts | 1 - packages/config/src/assets.ts | 6 + packages/config/src/chains.ts | 48 ++- packages/config/src/mrl-configs/ethereum.ts | 282 ++++++++++++++++++ packages/config/src/mrl-configs/hydration.ts | 221 ++++++++++++++ packages/config/src/mrl-configs/index.ts | 6 + packages/config/src/mrl-configs/moonbeam.ts | 213 +++++++++++++ packages/config/src/xcm-configs/moonriver.ts | 10 +- .../src/getTransferData/getMoonChainData.ts | 1 - .../mrl/src/getTransferData/getSourceData.ts | 5 +- .../src/services/wormhole/WormholeService.ts | 7 +- .../sdk/src/getTransferData/getSourceData.ts | 1 + .../getTransferData/getTransferData.utils.ts | 5 + 13 files changed, 796 insertions(+), 10 deletions(-) create mode 100644 packages/config/src/mrl-configs/ethereum.ts create mode 100644 packages/config/src/mrl-configs/hydration.ts create mode 100644 packages/config/src/mrl-configs/moonbeam.ts diff --git a/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts b/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts index 30fda2ac..f2285a62 100644 --- a/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts +++ b/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts @@ -117,7 +117,6 @@ type DestinationMultilocation = [ ), ]; -// TODO test if this is needed function getDestinationMultilocationForPrecompileDestination( address: string, destination: AnyParachain, diff --git a/packages/config/src/assets.ts b/packages/config/src/assets.ts index e6395c2f..06dc02cb 100644 --- a/packages/config/src/assets.ts +++ b/packages/config/src/assets.ts @@ -110,6 +110,11 @@ export const eqd = new Asset({ originSymbol: 'EQD', }); +export const eth = new Asset({ + key: 'eth', + originSymbol: 'ETH', +}); + export const fil = new Asset({ key: 'fil', originSymbol: 'FIL', @@ -428,6 +433,7 @@ export const assetsList: Asset[] = [ dot, eq, eqd, + eth, fil, ftm, ftmwh, diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 74370c8d..8f23cbba 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -30,6 +30,7 @@ import { dot, eq, eqd, + eth, fil, ftm, ftmwh, @@ -461,12 +462,53 @@ export const darwiniaCrab = new EvmParachain({ ws: ['wss://darwiniacrab-rpc.dwellir.com', 'wss://crab-rpc.darwinia.network'], }); +export const ethereum = new EvmChain({ + assets: [ + ChainAsset.fromAsset(eth, { + decimals: 18, + }), + ChainAsset.fromAsset(usdc, { + address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', + decimals: 6, + }), + ChainAsset.fromAsset(usdt, { + address: '0xdac17f958d2ee523a2206206994597c13d831ec7', + decimals: 6, + }), + ChainAsset.fromAsset(dai, { + address: '0x6b175474e89094c44da98b954eedeac495271d0f', + decimals: 18, + }), + ChainAsset.fromAsset(wbtc, { + address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', + decimals: 8, + }), + ChainAsset.fromAsset(glmr, { + address: '0x93d3696A9F879b331f40CB5059e37015423A3Bd0', + decimals: 18, + }), + ChainAsset.fromAsset(peaq, { + address: '0x6e642b4dfe787b8f101d1fb66c2ef56e2b4c6c52', + decimals: 18, + }), + ], + ecosystem: Ecosystem.Polkadot, + explorer: 'https://etherscan.io', + id: 1, + key: 'ethereum', + name: 'Ethereum', + nativeAsset: eth, + rpc: 'https://ethereum-rpc.publicnode.com', + wh: { + name: 'Ethereum', + }, +}); + export const fantomTestnet = new EvmChain({ assets: [ ChainAsset.fromAsset(ftm, { decimals: 18, }), - // TODO should be WGLMR ? ChainAsset.fromAsset(dev, { address: '0x41E3CFDFC255A4bF3C8D3560Bc8D3D9b5080338e', decimals: 18, @@ -1367,6 +1409,9 @@ export const moonbeam = new EvmParachain({ rpc: 'https://rpc.api.moonbeam.network', ss58Format: 1284, ws: ['wss://wss.api.moonbeam.network'], + wh: { + name: 'Moonbeam', + }, }); export const moonriver = new EvmParachain({ @@ -2262,6 +2307,7 @@ export const chainsList: AnyChain[] = [ crustShadow, darwinia, darwiniaCrab, + ethereum, fantomTestnet, hydration, hydrationAlphanet, diff --git a/packages/config/src/mrl-configs/ethereum.ts b/packages/config/src/mrl-configs/ethereum.ts new file mode 100644 index 00000000..0eeb4052 --- /dev/null +++ b/packages/config/src/mrl-configs/ethereum.ts @@ -0,0 +1,282 @@ +import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder'; +import { + dai, + eth, + glmr, + usdc, + usdcwh, + usdt, + usdtwh, + wbtc, + weth, +} from '../assets'; +import { ethereum, hydration, moonbeam } from '../chains'; +import { MrlChainRoutes } from '../types/MrlChainRoutes'; + +export const ethereumRoutes = new MrlChainRoutes({ + chain: ethereum, + routes: [ + /** + * Destination Hydration + */ + { + source: { + asset: usdc, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: usdc, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: usdcwh, + chain: hydration, + balance: BalanceBuilder().substrate().tokens().accounts(), + fee: { + asset: usdcwh, + amount: 0.004, + }, + }, + mrl: { + isAutomaticPossible: false, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: usdcwh, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: dai, + chain: hydration, + balance: BalanceBuilder().substrate().tokens().accounts(), + fee: { + asset: dai, + amount: 0.004, + }, + }, + mrl: { + isAutomaticPossible: false, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + /** + * Destination Moonbeam + */ + { + source: { + asset: eth, + balance: BalanceBuilder().evm().native(), + destinationFee: { + asset: eth, + balance: BalanceBuilder().evm().native(), + }, + }, + destination: { + asset: weth, + chain: moonbeam, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: weth, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: weth, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: usdc, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: usdc, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: usdcwh, + chain: moonbeam, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: usdcwh, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: usdcwh, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: usdt, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: usdt, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: usdtwh, + chain: moonbeam, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: usdtwh, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: usdtwh, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: dai, + chain: moonbeam, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: dai, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: wbtc, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: wbtc, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: wbtc, + chain: moonbeam, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: wbtc, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: wbtc, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: glmr, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: glmr, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: glmr, + chain: moonbeam, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: glmr, + balance: BalanceBuilder().substrate().system().account(), + fee: { + asset: glmr, + amount: 0.15, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + ], +}); diff --git a/packages/config/src/mrl-configs/hydration.ts b/packages/config/src/mrl-configs/hydration.ts new file mode 100644 index 00000000..13b6a32a --- /dev/null +++ b/packages/config/src/mrl-configs/hydration.ts @@ -0,0 +1,221 @@ +import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder'; +import { + dai, + eth, + glmr, + hdx, + usdc, + usdcwh, + usdt, + usdtwh, + wbtc, + weth, +} from '../assets'; +import { ethereum, hydration } from '../chains'; +import { MrlChainRoutes } from '../types/MrlChainRoutes'; + +export const hydrationRoutes = new MrlChainRoutes({ + chain: hydration, + routes: [ + { + source: { + asset: weth, + balance: BalanceBuilder().substrate().tokens().accounts(), + destinationFee: { + asset: weth, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + moonChainFee: { + asset: glmr, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + fee: { + asset: hdx, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + destination: { + asset: eth, + chain: ethereum, + balance: BalanceBuilder().evm().native(), + fee: { + asset: eth, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(), + moonChain: { + asset: weth, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.1, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: usdcwh, + balance: BalanceBuilder().substrate().tokens().accounts(), + destinationFee: { + asset: usdcwh, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + moonChainFee: { + asset: glmr, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + fee: { + asset: hdx, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + destination: { + asset: usdc, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: usdc, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(), + moonChain: { + asset: usdcwh, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.1, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: usdtwh, + balance: BalanceBuilder().substrate().tokens().accounts(), + destinationFee: { + asset: usdtwh, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + moonChainFee: { + asset: glmr, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + fee: { + asset: hdx, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + destination: { + asset: usdt, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: usdt, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(), + moonChain: { + asset: usdtwh, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.1, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: dai, + balance: BalanceBuilder().substrate().tokens().accounts(), + destinationFee: { + asset: dai, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + moonChainFee: { + asset: glmr, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + fee: { + asset: hdx, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + destination: { + asset: dai, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: dai, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(), + moonChain: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.1, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: wbtc, + balance: BalanceBuilder().substrate().tokens().accounts(), + destinationFee: { + asset: wbtc, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + moonChainFee: { + asset: glmr, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + fee: { + asset: hdx, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + destination: { + asset: wbtc, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: wbtc, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(), + moonChain: { + asset: wbtc, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0.1, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + ], +}); diff --git a/packages/config/src/mrl-configs/index.ts b/packages/config/src/mrl-configs/index.ts index cb3baec5..5d1cd179 100644 --- a/packages/config/src/mrl-configs/index.ts +++ b/packages/config/src/mrl-configs/index.ts @@ -1,14 +1,20 @@ import type { MrlChainRoutes } from '../types/MrlChainRoutes'; +import { ethereumRoutes } from './ethereum'; import { fantomTestnetRoutes } from './fantomTestnet'; +import { hydrationRoutes } from './hydration'; import { moonbaseAlphaRoutes } from './moonbaseAlpha'; import { moonbaseBetaRoutes } from './moonbaseBeta'; +import { moonbeamRoutes } from './moonbeam'; import { peaqAlphanetRoutes } from './peaqAlphanet'; import { peaqEvmAlphanetRoutes } from './peaqEvmAlphanet'; export const mrlRoutesList: MrlChainRoutes[] = [ + ethereumRoutes, + hydrationRoutes, fantomTestnetRoutes, moonbaseAlphaRoutes, moonbaseBetaRoutes, + moonbeamRoutes, peaqAlphanetRoutes, peaqEvmAlphanetRoutes, ]; diff --git a/packages/config/src/mrl-configs/moonbeam.ts b/packages/config/src/mrl-configs/moonbeam.ts new file mode 100644 index 00000000..3691ed73 --- /dev/null +++ b/packages/config/src/mrl-configs/moonbeam.ts @@ -0,0 +1,213 @@ +import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder'; +import { + dai, + eth, + glmr, + peaq, + usdc, + usdcwh, + usdt, + usdtwh, + wbtc, + weth, +} from '../assets'; +import { ethereum, moonbeam } from '../chains'; +import { MrlChainRoutes } from '../types/MrlChainRoutes'; + +export const moonbeamRoutes = new MrlChainRoutes({ + chain: moonbeam, + routes: [ + { + source: { + asset: weth, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: weth, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: eth, + chain: ethereum, + balance: BalanceBuilder().evm().native(), + fee: { + asset: eth, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: weth, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: peaq, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: peaq, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: peaq, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: peaq, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: false, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: peaq, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: usdcwh, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: usdcwh, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: usdc, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: usdc, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: usdcwh, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: usdtwh, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: usdtwh, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: usdt, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: usdt, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: usdtwh, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: dai, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: dai, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: dai, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + { + source: { + asset: wbtc, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: wbtc, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: wbtc, + chain: ethereum, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: wbtc, + amount: 0, + }, + }, + mrl: { + isAutomaticPossible: true, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: wbtc, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: glmr, + amount: 0, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, + ], +}); diff --git a/packages/config/src/xcm-configs/moonriver.ts b/packages/config/src/xcm-configs/moonriver.ts index 2c58b14f..7b9cb064 100644 --- a/packages/config/src/xcm-configs/moonriver.ts +++ b/packages/config/src/xcm-configs/moonriver.ts @@ -83,7 +83,7 @@ export const moonriverRoutes = new ChainRoutes({ destination: { asset: movr, chain: calamari, - balance: BalanceBuilder().substrate().system().account(), + balance: BalanceBuilder().substrate().assets().account(), fee: { amount: 0.001, asset: movr, @@ -144,7 +144,7 @@ export const moonriverRoutes = new ChainRoutes({ chain: khala, balance: BalanceBuilder().substrate().assets().account(), fee: { - amount: 0.0002, + amount: 0.001, asset: movr, }, }, @@ -683,7 +683,7 @@ export const moonriverRoutes = new ChainRoutes({ chain: bifrostKusama, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.0001, + amount: 0.1, asset: vbnc, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -707,7 +707,7 @@ export const moonriverRoutes = new ChainRoutes({ chain: bifrostKusama, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.0001, + amount: 0.001, asset: vksm, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -731,7 +731,7 @@ export const moonriverRoutes = new ChainRoutes({ chain: bifrostKusama, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.00000001, + amount: 0.1, asset: vmovr, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), diff --git a/packages/mrl/src/getTransferData/getMoonChainData.ts b/packages/mrl/src/getTransferData/getMoonChainData.ts index ed03836d..f333d39a 100644 --- a/packages/mrl/src/getTransferData/getMoonChainData.ts +++ b/packages/mrl/src/getTransferData/getMoonChainData.ts @@ -34,7 +34,6 @@ export async function getMoonChainData({ destinationAddress, }); - console.log('sourceAddress', sourceAddress); const fee = await getDestinationFee({ address: moonChainAddress, asset: route.source.asset, diff --git a/packages/mrl/src/getTransferData/getSourceData.ts b/packages/mrl/src/getTransferData/getSourceData.ts index 9c9c79bc..ec111dca 100644 --- a/packages/mrl/src/getTransferData/getSourceData.ts +++ b/packages/mrl/src/getTransferData/getSourceData.ts @@ -63,6 +63,7 @@ export async function getSourceData({ builder: route.source.balance, chain: source, }); + const feeBalance = route.source.fee ? await getBalance({ address: sourceAddress, @@ -87,6 +88,7 @@ export async function getSourceData({ }); const existentialDeposit = await getExistentialDeposit(source); + const min = await getAssetMin({ asset, builder: route.source.min, @@ -185,6 +187,7 @@ async function getFee({ if (ContractConfig.is(transfer)) { return getContractFee({ address: sourceAddress, + balance, chain: chain as EvmChain | EvmParachain, contract: transfer, destinationFee, @@ -248,7 +251,7 @@ async function getWormholeFee({ const fee = await wh.getFee(config); return AssetAmount.fromChainAsset(chain.getChainAsset(asset), { - amount: fee.relayFee ? fee.relayFee.amount + safetyAmount : 0n, + amount: fee?.relayFee ? fee.relayFee.amount + safetyAmount : 0n, }); } diff --git a/packages/mrl/src/services/wormhole/WormholeService.ts b/packages/mrl/src/services/wormhole/WormholeService.ts index 3eaac618..d9eac2e9 100644 --- a/packages/mrl/src/services/wormhole/WormholeService.ts +++ b/packages/mrl/src/services/wormhole/WormholeService.ts @@ -26,7 +26,12 @@ export class WormholeService { this.#wh = wormholeFactory(chain); } - async getFee(transfer: WormholeConfig): Promise { + async getFee(transfer: WormholeConfig): Promise { + const amount = transfer.args[1]; + if (amount === 0n) { + return undefined; + } + const xfer = await this.#wh[transfer.func](...transfer.args); return TokenTransfer.quoteTransfer( diff --git a/packages/sdk/src/getTransferData/getSourceData.ts b/packages/sdk/src/getTransferData/getSourceData.ts index f9b9647e..70acdfae 100644 --- a/packages/sdk/src/getTransferData/getSourceData.ts +++ b/packages/sdk/src/getTransferData/getSourceData.ts @@ -152,6 +152,7 @@ export async function getFee({ if (contract) { return getContractFee({ address: sourceAddress, + balance, chain: chain as EvmChain | EvmParachain, contract, destinationFee, diff --git a/packages/sdk/src/getTransferData/getTransferData.utils.ts b/packages/sdk/src/getTransferData/getTransferData.utils.ts index 12660347..b40fa118 100644 --- a/packages/sdk/src/getTransferData/getTransferData.utils.ts +++ b/packages/sdk/src/getTransferData/getTransferData.utils.ts @@ -307,6 +307,7 @@ export async function getExtrinsicFee({ export interface GetContractFeeParams { address: string; + balance: AssetAmount; chain: EvmChain | EvmParachain; contract: ContractConfig; destinationFee: AssetAmount; @@ -316,6 +317,7 @@ export interface GetContractFeeParams { export async function getContractFee({ address, + balance, chain, contract, destinationFee, @@ -323,6 +325,9 @@ export async function getContractFee({ feeConfig, }: GetContractFeeParams): Promise { try { + if (balance.amount === 0n) { + return feeBalance.copyWith({ amount: 0n }); + } const evm = EvmService.create(chain); const fee = await evm.getFee(address, contract); const extra = feeConfig?.extra