Skip to content

Commit

Permalink
fixes in getMoonChainData
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Nov 27, 2024
1 parent 870da01 commit 01c84c5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 44 deletions.
27 changes: 6 additions & 21 deletions packages/mrl/src/getTransferData/getMoonChainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MoonChainTransferData> {
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -66,8 +52,7 @@ export async function getMoonChainData({
});

return {
// TODO technically feeBalance
balance: feeBalance,
feeBalance,
chain: moonChain,
fee,
};
Expand Down
1 change: 0 additions & 1 deletion packages/mrl/src/getTransferData/getTransferData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export async function getTransferData({
});

const moonChainData = await getMoonChainData({
destinationData,
route,
sourceAddress,
});
Expand Down
7 changes: 6 additions & 1 deletion packages/mrl/src/mrl.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export interface SourceTransferData extends SourceChainTransferData {

export interface DestinationTransferData extends ChainTransferData {}

export type MoonChainTransferData = Omit<ChainTransferData, 'min'>;
export type MoonChainTransferData = Omit<
ChainTransferData,
'min' | 'balance'
> & {
feeBalance: AssetAmount;
};

export interface ChainTransferData {
chain: AnyChain;
Expand Down
41 changes: 20 additions & 21 deletions packages/sdk/src/services/polkadot/PolkadotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,28 @@ export class PolkadotService {
): Promise<string> {
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<string>((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);
});

Expand Down

0 comments on commit 01c84c5

Please sign in to comment.