diff --git a/packages/mrl/src/getTransferData/getMoonChainData.ts b/packages/mrl/src/getTransferData/getMoonChainData.ts index 4b23cd78..752dd9f6 100644 --- a/packages/mrl/src/getTransferData/getMoonChainData.ts +++ b/packages/mrl/src/getTransferData/getMoonChainData.ts @@ -2,19 +2,14 @@ import { type MrlAssetRoute, getMoonChain } from '@moonbeam-network/xcm-config'; import { getBalance, getDestinationFee } from '@moonbeam-network/xcm-sdk'; import { Parachain } from '@moonbeam-network/xcm-types'; import { getMultilocationDerivedAddresses } from '@moonbeam-network/xcm-utils'; -import type { - DestinationTransferData, - MoonChainTransferData, -} from '../mrl.interfaces'; +import type { MoonChainTransferData } from '../mrl.interfaces'; interface GetMoonChainDataParams { - destinationData: DestinationTransferData; route: MrlAssetRoute; sourceAddress: string; } export async function getMoonChainData({ - destinationData, route, sourceAddress, }: GetMoonChainDataParams): Promise { @@ -25,18 +20,6 @@ export async function getMoonChainData({ } const moonChain = getMoonChain(route.source.chain); - // TODO is this used for something? do we need the balance? - // const asset = moonChain.getChainAsset(route.mrl.moonChain.asset); - // const isDestinationMoonChain = route.destination.chain.isEqual(moonChain); - - // TODO technically not correct - // if (isDestinationMoonChain) { - // return { - // balance: destinationData.balance, - // chain: destinationData.chain, - // fee: destinationData.fee, - // }; - // } const fee = await getDestinationFee({ address: sourceAddress, // TODO not correct @@ -48,7 +31,10 @@ export async function getMoonChainData({ let address = sourceAddress; - if (Parachain.is(route.source.chain)) { + if ( + Parachain.is(route.source.chain) && + !route.source.chain.isEqual(moonChain) + ) { const { address20 } = getMultilocationDerivedAddresses({ address: sourceAddress, paraId: route.source.chain.parachainId, @@ -66,8 +52,7 @@ export async function getMoonChainData({ }); return { - // TODO technically feeBalance - balance: feeBalance, + feeBalance, chain: moonChain, fee, }; diff --git a/packages/mrl/src/getTransferData/getTransferData.ts b/packages/mrl/src/getTransferData/getTransferData.ts index d15d5d5f..353fe407 100644 --- a/packages/mrl/src/getTransferData/getTransferData.ts +++ b/packages/mrl/src/getTransferData/getTransferData.ts @@ -67,7 +67,6 @@ export async function getTransferData({ }); const moonChainData = await getMoonChainData({ - destinationData, route, sourceAddress, }); diff --git a/packages/mrl/src/mrl.interfaces.ts b/packages/mrl/src/mrl.interfaces.ts index 60119009..ef4a89eb 100644 --- a/packages/mrl/src/mrl.interfaces.ts +++ b/packages/mrl/src/mrl.interfaces.ts @@ -38,7 +38,12 @@ export interface SourceTransferData extends SourceChainTransferData { export interface DestinationTransferData extends ChainTransferData {} -export type MoonChainTransferData = Omit; +export type MoonChainTransferData = Omit< + ChainTransferData, + 'min' | 'balance' +> & { + feeBalance: AssetAmount; +}; export interface ChainTransferData { chain: AnyChain; diff --git a/packages/sdk/src/services/polkadot/PolkadotService.ts b/packages/sdk/src/services/polkadot/PolkadotService.ts index 01b3ac46..8d55e4fb 100644 --- a/packages/sdk/src/services/polkadot/PolkadotService.ts +++ b/packages/sdk/src/services/polkadot/PolkadotService.ts @@ -94,29 +94,28 @@ export class PolkadotService { ): Promise { const extrinsic = this.getExtrinsic(config); + const isSigner = this.#isSigner(signer); + const signOptions = { + nonce: -1, + signer: isSigner ? signer : undefined, + withSignedTransaction: true, + }; + const hash = await new Promise((resolve, reject) => { extrinsic - .signAndSend( - this.#isSigner(signer) ? account : signer, - { - nonce: -1, - signer: this.#isSigner(signer) ? signer : undefined, - withSignedTransaction: true, - }, - (result) => { - if (result.isError || result.dispatchError) { - reject( - new Error( - result.dispatchError?.toString() || 'Transaction failed', - ), - ); - } - if (result.txHash) { - resolve(result.txHash.toString()); - } - statusCallback?.(result); - }, - ) + .signAndSend(isSigner ? account : signer, signOptions, (result) => { + if (result.isError || result.dispatchError) { + reject( + new Error( + result.dispatchError?.toString() || 'Transaction failed', + ), + ); + } + if (result.txHash) { + resolve(result.txHash.toString()); + } + statusCallback?.(result); + }) .catch(reject); });