Skip to content

Commit

Permalink
remove provider enum and apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Oct 7, 2024
1 parent fa221e7 commit 7109206
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 45 deletions.
4 changes: 0 additions & 4 deletions packages/builder/src/mrl/MrlBuilder.constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
export const BATCH_CONTRACT_ADDRESS =
'0x0000000000000000000000000000000000000808';

export enum Provider {
WORMHOLE = 'Wormhole',
}
12 changes: 4 additions & 8 deletions packages/builder/src/mrl/MrlBuilder.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ import type { HexString } from '@polkadot/util/types';
import type { BuilderPrams, ConfigBuilder } from '../builder.interfaces';
import type { ContractConfig } from '../contract';
import type { ExtrinsicConfig } from '../extrinsic';
import type { Provider } from './MrlBuilder.constants';
import type { WormholeConfig } from './providers/wormhole/wormhole';

export interface MrlConfigBuilder
extends ConfigBuilder<
ContractConfig | ExtrinsicConfig | WormholeConfig,
MrlBuilderParams
> {
provider: Provider;
}
export type MrlConfigBuilder = ConfigBuilder<
ContractConfig | ExtrinsicConfig | WormholeConfig,
MrlBuilderParams
>;

export interface MrlBuilderParams extends BuilderPrams<AnyChain> {
isAutomatic: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { convertAddressTo32Bytes } from '@moonbeam-network/xcm-utils';
import type { Address } from 'viem';
import { ContractConfig } from '../../../../../contract';
import { Provider } from '../../../../MrlBuilder.constants';
import type { MrlConfigBuilder } from '../../../../MrlBuilder.interfaces';
import { wormholeFactory } from '../../wormhole';
import { TOKEN_BRIDGE_ABI } from './TokenBridgeAbi';
Expand All @@ -11,7 +10,6 @@ const module = 'TokenBridge';
export function TokenBridge() {
return {
transferTokens: (): MrlConfigBuilder => ({
provider: Provider.WORMHOLE,
build: ({ asset, destination, destinationAddress, moonChain }) => {
const wh = wormholeFactory(moonChain);
const whDestination = wh.getChain(destination.getWormholeName()).config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { convertAddressTo32Bytes } from '@moonbeam-network/xcm-utils';
import type { Address } from 'viem';
import { ContractConfig } from '../../../../../contract';
import { Provider } from '../../../../MrlBuilder.constants';
import type { MrlConfigBuilder } from '../../../../MrlBuilder.interfaces';
import { wormholeFactory } from '../../wormhole';
import { TOKEN_BRIDGE_RELAYER_ABI } from './TokenBridgeRelayerAbi';
Expand All @@ -11,7 +10,6 @@ const module = 'TokenBridgeRelayer';
export function TokenBridgeRelayer() {
return {
transferTokensWithRelay: (): MrlConfigBuilder => ({
provider: Provider.WORMHOLE,
build: ({ asset, destination, destinationAddress, moonChain }) => {
const wh = wormholeFactory(moonChain);
const whDestination = wh.getChain(destination.getWormholeName()).config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ import { type Address, encodeFunctionData } from 'viem';
import { ERC20_ABI } from '../../../../../balance/Erc20Abi';
import type { ContractConfig } from '../../../../../types/evm/ContractConfig';
import { ExtrinsicConfig } from '../../../../../types/substrate/ExtrinsicConfig';
import {
BATCH_CONTRACT_ADDRESS,
Provider,
} from '../../../../MrlBuilder.constants';
import { BATCH_CONTRACT_ADDRESS } from '../../../../MrlBuilder.constants';
import type { MrlConfigBuilder } from '../../../../MrlBuilder.interfaces';
import { contract as ContractBuilder } from '../../contract';
import { BATCH_CONTRACT_ABI } from './BatchContractAbi';

export function ethereumXcm() {
return {
transact: (): MrlConfigBuilder => ({
provider: Provider.WORMHOLE,
build: (params) => {
const { asset, isAutomatic, moonChain, moonGasLimit } = params;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { type AnyParachain, AssetAmount } from '@moonbeam-network/xcm-types';
import { getMultilocationDerivedAddresses } from '@moonbeam-network/xcm-utils';
import { ExtrinsicBuilder } from '../../../../../extrinsic/ExtrinsicBuilder';
import { ExtrinsicConfig } from '../../../../../types/substrate/ExtrinsicConfig';
import { Provider } from '../../../../MrlBuilder.constants';
import type { MrlConfigBuilder } from '../../../../MrlBuilder.interfaces';

// TODO: Can we move them somewhere?
Expand All @@ -12,7 +11,6 @@ const CROSS_CHAIN_FEE = 100_000_000_000_000_000n;
export function polkadotXcm() {
return {
send: (): MrlConfigBuilder => ({
provider: Provider.WORMHOLE,
build: ({
asset,
destination,
Expand Down
10 changes: 6 additions & 4 deletions packages/builder/src/mrl/providers/wormhole/wormhole/wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { getMultilocationDerivedAddresses } from '@moonbeam-network/xcm-utils';
import { evmToAddress } from '@polkadot/util-crypto/address';
import { Wormhole } from '@wormhole-foundation/sdk-connect';
import { getExtrinsicAccount } from '../../../../extrinsic/ExtrinsicBuilder.utils';
import { Provider } from '../../../MrlBuilder.constants';
import type {
MrlBuilderParams,
MrlConfigBuilder,
} from '../../../MrlBuilder.interfaces';
import { WormholeConfig, type WormholeFunctionArgs } from './WormholeConfig';
import { WormholeConfig } from './WormholeConfig';
import { wormholeFactory } from './wormholeFactory';

export const GMP_CONTRACT_ADDRESS =
Expand All @@ -17,7 +16,6 @@ export const GMP_CONTRACT_ADDRESS =
export function wormhole() {
return {
tokenTransfer: (): MrlConfigBuilder => ({
provider: Provider.WORMHOLE,
build: ({
asset,
destination,
Expand All @@ -31,7 +29,11 @@ export function wormhole() {
const isNativeAsset = asset.isSame(source.nativeAsset);
const isDestinationMoonChain = destination.isEqual(moonChain);
const isDestinationEvmChain = EvmChain.is(destination);
const tokenAddress = isNativeAsset ? 'native' : asset.address;
const tokenAddress = isNativeAsset
? 'native'
: isDestinationEvmChain
? moonChain.getChainAsset(asset).address
: asset.address;

const { address20: computedOriginAccount } =
getMultilocationDerivedAddresses({
Expand Down
4 changes: 4 additions & 0 deletions packages/config/src/mrl-configs/moonbaseAlpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const moonbaseAlphaRoutes = new ChainRoutes({
asset: ftmwh,
balance: BalanceBuilder().evm().erc20(),
},
fee: {
asset: dev,
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: ftm,
Expand Down
32 changes: 14 additions & 18 deletions packages/mrl/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ContractConfig,
type ExtrinsicConfig,
MrlBuilder,
Provider,
WormholeConfig,
} from '@moonbeam-network/xcm-builder';
import type { AssetRoute, FeeConfig } from '@moonbeam-network/xcm-config';
Expand Down Expand Up @@ -202,25 +201,22 @@ export async function getRelayFee({
return getWormholeFee({ asset, chain, config: transfer });
}

if (route?.mrl?.transfer.provider === Provider.WORMHOLE) {
const builderParams = await getMrlBuilderParams({
asset,
destinationAddress,
destinationFee,
route,
sourceAddress,
});

const wormholeConfig = MrlBuilder()
.wormhole()
.wormhole()
.tokenTransfer()
.build(builderParams);
// TODO this is only valid for Wormhole Provider
const builderParams = await getMrlBuilderParams({
asset,
destinationAddress,
destinationFee,
route,
sourceAddress,
});

return getWormholeFee({ asset, chain, config: wormholeConfig });
}
const wormholeConfig = MrlBuilder()
.wormhole()
.wormhole()
.tokenTransfer()
.build(builderParams);

return;
return getWormholeFee({ asset, chain, config: wormholeConfig });
}

async function getWormholeFee({
Expand Down

0 comments on commit 7109206

Please sign in to comment.