Skip to content

Commit

Permalink
-wip- adjustments after integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Nov 22, 2024
1 parent 29c1a67 commit 09cc138
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
20 changes: 5 additions & 15 deletions examples/sdk-simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,24 @@ console.log(`Substrate address: ${pair.address}`);

export function logBalances(data: TransferData): void {
console.log(
`Balance on ${data.source.chain.name} ${data.source.balance.toDecimal()} ${
data.source.balance.symbol
}`,
`Balance on ${data.source.chain.name} ${data.source.balance.toDecimal()} ${data.source.balance.getSymbol()}`,
);
console.log(
`Balance on ${
data.destination.chain.name
} ${data.destination.balance.toDecimal()} ${
data.destination.balance.symbol
}`,
} ${data.destination.balance.toDecimal()} ${data.destination.balance.getSymbol()}`,
);
}

export function logTxDetails(data: TransferData): void {
console.log(
`\nYou can send min: ${data.min.toDecimal()} ${
data.min.symbol
} and max: ${data.max.toDecimal()} ${data.max.symbol} from ${
`\nYou can send min: ${data.min.toDecimal()} ${data.min.getSymbol()} and max: ${data.max.toDecimal()} ${data.max.getSymbol()} from ${
data.source.chain.name
} to ${
data.destination.chain.name
}. You will pay ${data.source.fee.toDecimal()} ${
data.source.fee.symbol
} fee on ${
}. You will pay ${data.source.fee.toDecimal()} ${data.source.fee.getSymbol()} fee on ${
data.source.chain.name
} and ${data.destination.fee.toDecimal()} ${
data.destination.fee.symbol
} fee on ${data.destination.chain.name}.`,
} and ${data.destination.fee.toDecimal()} ${data.destination.fee.getSymbol()} fee on ${data.destination.chain.name}.`,
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/mrl-configs/fantomTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({
balance: BalanceBuilder().evm().erc20(),
fee: {
asset: ftmwh,
amount: 0,
amount: 0.01,
},
},
mrl: {
Expand Down Expand Up @@ -150,7 +150,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({
balance: BalanceBuilder().substrate().system().account(),
fee: {
asset: dev,
amount: 0,
amount: 0.01,
},
},
mrl: {
Expand Down
27 changes: 15 additions & 12 deletions packages/mrl/src/getTransferData/getMoonChainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ export async function getMoonChainData({
}

const moonChain = getMoonChain(route.source.chain);
const asset = moonChain.getChainAsset(route.mrl.moonChain.asset);
const isDestinationMoonChain = route.destination.chain.isEqual(moonChain);
// 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);

if (isDestinationMoonChain) {
return {
balance: destinationData.balance,
chain: destinationData.chain,
fee: destinationData.fee,
};
}
// 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 @@ -56,15 +58,16 @@ export async function getMoonChainData({
address = address20;
}

const balance = await getBalance({
const feeBalance = await getBalance({
address,
asset,
asset: moonChain.getChainAsset(route.mrl.moonChain.fee.asset),
builder: route.mrl.moonChain.fee.balance,
chain: moonChain,
});

return {
balance,
// TODO technically feeBalance
balance: feeBalance,
chain: moonChain,
fee,
};
Expand Down
5 changes: 4 additions & 1 deletion packages/mrl/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type EvmChain,
type EvmParachain,
} from '@moonbeam-network/xcm-types';
import { toBigInt } from '@moonbeam-network/xcm-utils';
import type { SourceTransferData } from '../mrl.interfaces';
import { WormholeService } from '../services/wormhole';
import {
Expand Down Expand Up @@ -239,11 +240,13 @@ async function getWormholeFee({
config,
}: GetWormholeFeeParams): Promise<AssetAmount | undefined> {
if (WormholeConfig.is(config)) {
const safetyAmount = toBigInt(0.000001, asset.decimals);

const wh = WormholeService.create(chain as EvmChain | EvmParachain);
const fee = await wh.getFee(config);

return AssetAmount.fromChainAsset(chain.getChainAsset(asset), {
amount: fee.relayFee?.amount || 0n,
amount: fee.relayFee ? fee.relayFee.amount + safetyAmount : 0n,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/mrl/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './mrl';
export * from './mrl.interfaces';

0 comments on commit 09cc138

Please sign in to comment.