Skip to content

Commit

Permalink
add setIsAutomatic data initializer and exclude relayer fee from min …
Browse files Browse the repository at this point in the history
…if not automatic
  • Loading branch information
mmaurello committed Nov 25, 2024
1 parent 58be9a5 commit 599a0fb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
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.01,
amount: 0,
},
},
mrl: {
Expand Down Expand Up @@ -150,7 +150,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({
balance: BalanceBuilder().substrate().system().account(),
fee: {
asset: dev,
amount: 0.01,
amount: 0,
},
},
mrl: {
Expand Down
3 changes: 3 additions & 0 deletions packages/mrl/src/getTransferData/getTransferData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ interface GetTransferDataParams {
route: MrlAssetRoute;
sourceAddress: string;
destinationAddress: string;
isAutomatic: boolean;
}

export async function getTransferData({
route,
sourceAddress,
destinationAddress,
isAutomatic,
}: GetTransferDataParams): Promise<TransferData> {
if (!route.mrl) {
throw new Error(
Expand Down Expand Up @@ -98,6 +100,7 @@ export async function getTransferData({
destinationData,
moonChainData,
sourceData,
isAutomatic,
}),
moonChain: moonChainData,
source: sourceData,
Expand Down
9 changes: 6 additions & 3 deletions packages/mrl/src/getTransferData/getTransferData.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface DataParams {
destinationData: DestinationChainTransferData;
moonChainData: MoonChainTransferData;
sourceData: SourceTransferData;
isAutomatic?: boolean;
}

export function getMoonChainFeeValueOnSource({
Expand Down Expand Up @@ -74,6 +75,7 @@ export function getMrlMin({
destinationData,
moonChainData,
sourceData,
isAutomatic,
}: DataParams): AssetAmount {
const minInDestination = getMin(destinationData);
const min = AssetAmount.fromChainAsset(
Expand All @@ -87,9 +89,10 @@ export function getMrlMin({
moonChainData,
sourceData,
});
const relayerFee = sourceData.relayerFee?.amount
? sourceData.relayerFee.toBig()
: Big(0);
const relayerFee =
sourceData.relayerFee?.amount && isAutomatic
? sourceData.relayerFee.toBig()
: Big(0);

return min.copyWith({
amount: BigInt(min.toBig().add(moonChainFee).add(relayerFee).toFixed()),
Expand Down
30 changes: 17 additions & 13 deletions packages/mrl/src/mrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,24 @@ export function Mrl(options?: MrlOptions) {
source,
destination,
});

return {
setAddresses({
sourceAddress,
destinationAddress,
}: {
sourceAddress: string;
destinationAddress: string;
}) {
return getTransferData({
route,
sourceAddress,
destinationAddress,
});
setIsAutomatic(isAutomatic: boolean) {
return {
setAddresses({
sourceAddress,
destinationAddress,
}: {
sourceAddress: string;
destinationAddress: string;
}) {
return getTransferData({
route,
sourceAddress,
destinationAddress,
isAutomatic,
});
},
};
},
};
},
Expand Down

0 comments on commit 599a0fb

Please sign in to comment.