From 09cc138191a3462044b2e092bf72cf6173b3e7e4 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Fri, 22 Nov 2024 16:00:21 +0100 Subject: [PATCH 1/7] -wip- adjustments after integration --- examples/sdk-simple/index.ts | 20 ++++---------- .../config/src/mrl-configs/fantomTestnet.ts | 4 +-- .../src/getTransferData/getMoonChainData.ts | 27 ++++++++++--------- .../mrl/src/getTransferData/getSourceData.ts | 5 +++- packages/mrl/src/index.ts | 1 + 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/examples/sdk-simple/index.ts b/examples/sdk-simple/index.ts index e2e1ee2c..32bcb54b 100644 --- a/examples/sdk-simple/index.ts +++ b/examples/sdk-simple/index.ts @@ -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}.`, ); } diff --git a/packages/config/src/mrl-configs/fantomTestnet.ts b/packages/config/src/mrl-configs/fantomTestnet.ts index c8c22ee1..14ffb23c 100644 --- a/packages/config/src/mrl-configs/fantomTestnet.ts +++ b/packages/config/src/mrl-configs/fantomTestnet.ts @@ -119,7 +119,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({ balance: BalanceBuilder().evm().erc20(), fee: { asset: ftmwh, - amount: 0, + amount: 0.01, }, }, mrl: { @@ -150,7 +150,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({ balance: BalanceBuilder().substrate().system().account(), fee: { asset: dev, - amount: 0, + amount: 0.01, }, }, mrl: { diff --git a/packages/mrl/src/getTransferData/getMoonChainData.ts b/packages/mrl/src/getTransferData/getMoonChainData.ts index 98c47eb1..36f4a907 100644 --- a/packages/mrl/src/getTransferData/getMoonChainData.ts +++ b/packages/mrl/src/getTransferData/getMoonChainData.ts @@ -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 @@ -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, }; diff --git a/packages/mrl/src/getTransferData/getSourceData.ts b/packages/mrl/src/getTransferData/getSourceData.ts index 0b732ef9..b27615e0 100644 --- a/packages/mrl/src/getTransferData/getSourceData.ts +++ b/packages/mrl/src/getTransferData/getSourceData.ts @@ -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 { @@ -239,11 +240,13 @@ async function getWormholeFee({ config, }: GetWormholeFeeParams): Promise { 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, }); } diff --git a/packages/mrl/src/index.ts b/packages/mrl/src/index.ts index a5b48e19..d4eb4a1e 100644 --- a/packages/mrl/src/index.ts +++ b/packages/mrl/src/index.ts @@ -1 +1,2 @@ export * from './mrl'; +export * from './mrl.interfaces'; From 599a0fb91f49ad292a6b3436876a96b4a86aa55c Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Mon, 25 Nov 2024 16:10:05 +0100 Subject: [PATCH 2/7] add setIsAutomatic data initializer and exclude relayer fee from min if not automatic --- .../config/src/mrl-configs/fantomTestnet.ts | 4 +-- .../src/getTransferData/getTransferData.ts | 3 ++ .../getTransferData/getTransferData.utils.ts | 9 ++++-- packages/mrl/src/mrl.ts | 30 +++++++++++-------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/packages/config/src/mrl-configs/fantomTestnet.ts b/packages/config/src/mrl-configs/fantomTestnet.ts index 14ffb23c..c8c22ee1 100644 --- a/packages/config/src/mrl-configs/fantomTestnet.ts +++ b/packages/config/src/mrl-configs/fantomTestnet.ts @@ -119,7 +119,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({ balance: BalanceBuilder().evm().erc20(), fee: { asset: ftmwh, - amount: 0.01, + amount: 0, }, }, mrl: { @@ -150,7 +150,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({ balance: BalanceBuilder().substrate().system().account(), fee: { asset: dev, - amount: 0.01, + amount: 0, }, }, mrl: { diff --git a/packages/mrl/src/getTransferData/getTransferData.ts b/packages/mrl/src/getTransferData/getTransferData.ts index 088a2935..af2975aa 100644 --- a/packages/mrl/src/getTransferData/getTransferData.ts +++ b/packages/mrl/src/getTransferData/getTransferData.ts @@ -32,12 +32,14 @@ interface GetTransferDataParams { route: MrlAssetRoute; sourceAddress: string; destinationAddress: string; + isAutomatic: boolean; } export async function getTransferData({ route, sourceAddress, destinationAddress, + isAutomatic, }: GetTransferDataParams): Promise { if (!route.mrl) { throw new Error( @@ -98,6 +100,7 @@ export async function getTransferData({ destinationData, moonChainData, sourceData, + isAutomatic, }), moonChain: moonChainData, source: sourceData, diff --git a/packages/mrl/src/getTransferData/getTransferData.utils.ts b/packages/mrl/src/getTransferData/getTransferData.utils.ts index d9223a44..23bfafd7 100644 --- a/packages/mrl/src/getTransferData/getTransferData.utils.ts +++ b/packages/mrl/src/getTransferData/getTransferData.utils.ts @@ -46,6 +46,7 @@ interface DataParams { destinationData: DestinationChainTransferData; moonChainData: MoonChainTransferData; sourceData: SourceTransferData; + isAutomatic?: boolean; } export function getMoonChainFeeValueOnSource({ @@ -74,6 +75,7 @@ export function getMrlMin({ destinationData, moonChainData, sourceData, + isAutomatic, }: DataParams): AssetAmount { const minInDestination = getMin(destinationData); const min = AssetAmount.fromChainAsset( @@ -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()), diff --git a/packages/mrl/src/mrl.ts b/packages/mrl/src/mrl.ts index 33c5c26e..43f1b8a0 100644 --- a/packages/mrl/src/mrl.ts +++ b/packages/mrl/src/mrl.ts @@ -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, + }); + }, + }; }, }; }, From 870da01dc45089faaf391693bed0e9bad122e718 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Tue, 26 Nov 2024 17:00:37 +0100 Subject: [PATCH 3/7] add statusCallback param --- .../src/getTransferData/getTransferData.ts | 2 + packages/mrl/src/mrl.interfaces.ts | 3 +- .../src/services/polkadot/PolkadotService.ts | 37 ++++++++++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/packages/mrl/src/getTransferData/getTransferData.ts b/packages/mrl/src/getTransferData/getTransferData.ts index af2975aa..d15d5d5f 100644 --- a/packages/mrl/src/getTransferData/getTransferData.ts +++ b/packages/mrl/src/getTransferData/getTransferData.ts @@ -108,6 +108,7 @@ export async function getTransferData({ amount, isAutomatic, { evmSigner, polkadotSigner }: Partial, + statusCallback, ): Promise { const source = route.source.chain; @@ -155,6 +156,7 @@ export async function getTransferData({ sourceAddress, transfer, polkadotSigner, + statusCallback, ); return [hash]; diff --git a/packages/mrl/src/mrl.interfaces.ts b/packages/mrl/src/mrl.interfaces.ts index a552d5ed..60119009 100644 --- a/packages/mrl/src/mrl.interfaces.ts +++ b/packages/mrl/src/mrl.interfaces.ts @@ -4,7 +4,7 @@ import type { } from '@moonbeam-network/xcm-sdk'; import type { AnyChain, AssetAmount } from '@moonbeam-network/xcm-types'; import type { Signer } from '@polkadot/api/types'; -import type { IKeyringPair } from '@polkadot/types/types'; +import type { IKeyringPair, ISubmittableResult } from '@polkadot/types/types'; import type { TokenTransfer } from '@wormhole-foundation/sdk-connect'; import type { WalletClient } from 'viem'; @@ -24,6 +24,7 @@ export interface TransferData { amount: bigint | number | string, isAutomatic: boolean, signers: Signers, + statusCallback?: (params: ISubmittableResult) => void, ): Promise; } diff --git a/packages/sdk/src/services/polkadot/PolkadotService.ts b/packages/sdk/src/services/polkadot/PolkadotService.ts index 9d8de27b..01b3ac46 100644 --- a/packages/sdk/src/services/polkadot/PolkadotService.ts +++ b/packages/sdk/src/services/polkadot/PolkadotService.ts @@ -90,18 +90,37 @@ export class PolkadotService { account: string, config: ExtrinsicConfig, signer: PolkadotSigner | IKeyringPair, + statusCallback?: (params: ISubmittableResult) => void, ): Promise { const extrinsic = this.getExtrinsic(config); - const hash = await extrinsic.signAndSend( - this.#isSigner(signer) ? account : signer, - { - nonce: -1, - signer: this.#isSigner(signer) ? signer : undefined, - withSignedTransaction: true, - }, - ); - return hash.toString(); + 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); + }, + ) + .catch(reject); + }); + + return hash; } #isSigner(signer: PolkadotSigner | IKeyringPair): signer is PolkadotSigner { From 01c84c5967db890427d7c3b16965789a10592b1d Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Wed, 27 Nov 2024 11:38:14 +0100 Subject: [PATCH 4/7] fixes in getMoonChainData --- .../src/getTransferData/getMoonChainData.ts | 27 +++--------- .../src/getTransferData/getTransferData.ts | 1 - packages/mrl/src/mrl.interfaces.ts | 7 +++- .../src/services/polkadot/PolkadotService.ts | 41 +++++++++---------- 4 files changed, 32 insertions(+), 44 deletions(-) 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); }); From 1ee1a58af804d0d488f5df591b2f307d89fbe415 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Thu, 28 Nov 2024 15:36:37 +0100 Subject: [PATCH 5/7] adjust configs --- .../config/src/mrl-configs/fantomTestnet.ts | 33 +++++++++++++++++++ .../config/src/mrl-configs/peaqAlphanet.ts | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/config/src/mrl-configs/fantomTestnet.ts b/packages/config/src/mrl-configs/fantomTestnet.ts index c8c22ee1..8ec0679b 100644 --- a/packages/config/src/mrl-configs/fantomTestnet.ts +++ b/packages/config/src/mrl-configs/fantomTestnet.ts @@ -5,6 +5,8 @@ import { moonbaseAlpha, moonbaseBeta, peaqAlphanet, + peaqEvm, + peaqEvmAlphanet, } from '../chains'; import { MrlChainRoutes } from '../types/MrlChainRoutes'; @@ -42,6 +44,37 @@ export const fantomTestnetRoutes = new MrlChainRoutes({ }, }, }, + { + source: { + asset: ftm, + balance: BalanceBuilder().evm().native(), + destinationFee: { + asset: ftm, + balance: BalanceBuilder().evm().native(), + }, + }, + destination: { + asset: ftmwh, + chain: peaqEvmAlphanet, + balance: BalanceBuilder().evm().erc20(), + fee: { + asset: ftmwh, + amount: 0.01, + }, + }, + mrl: { + isAutomaticPossible: false, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: ftmwh, + fee: { + asset: dev, + amount: 0.1, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, { source: { asset: agng, diff --git a/packages/config/src/mrl-configs/peaqAlphanet.ts b/packages/config/src/mrl-configs/peaqAlphanet.ts index a9bd5dc7..d076e6f8 100644 --- a/packages/config/src/mrl-configs/peaqAlphanet.ts +++ b/packages/config/src/mrl-configs/peaqAlphanet.ts @@ -61,7 +61,7 @@ export const peaqAlphanetRoutes = new MrlChainRoutes({ destination: { asset: agng, chain: fantomTestnet, - balance: BalanceBuilder().evm().native(), + balance: BalanceBuilder().evm().erc20(), fee: { asset: agng, amount: 0.2, From 5be0a0c0c48b2d25e45c6e8e2c39a9a151e2e34f Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Fri, 29 Nov 2024 14:05:21 +0100 Subject: [PATCH 6/7] more adjustments --- packages/config/src/chains.ts | 5 +++++ packages/config/src/mrl-configs/fantomTestnet.ts | 1 - packages/mrl/src/getTransferData/getSourceData.ts | 6 ++++-- packages/mrl/src/getTransferData/getTransferData.ts | 6 ++++-- .../mrl/src/getTransferData/getTransferData.utils.ts | 9 +++------ packages/mrl/src/mrl.interfaces.ts | 1 + 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 2762c568..3c341536 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -962,6 +962,7 @@ export const moonbaseAlpha = new EvmParachain({ }), ], ecosystem: Ecosystem.AlphanetRelay, + explorer: 'https://moonbase.moonscan.io', genesisHash: '0x91bc6e169807aaa54802737e1c504b2577d4fafedd5a02c10293b1cd60e39527', id: 1287, @@ -1014,6 +1015,9 @@ export const moonbaseBeta = new EvmParachain({ }), ], ecosystem: Ecosystem.AlphanetRelay, + explorer: getPolkadotAppsUrl( + 'wss://moonbase-beta.api.moonbase.moonbeam.network', + ), genesisHash: '0xeebb5d05763801e54d6a7a60a4b7998ac125c4d050dcec418dd07ea959a54464', id: 1282, @@ -1347,6 +1351,7 @@ export const moonbeam = new EvmParachain({ }), ], ecosystem: Ecosystem.Polkadot, + explorer: 'https://moonbeam.moonscan.io', genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', id: 1284, diff --git a/packages/config/src/mrl-configs/fantomTestnet.ts b/packages/config/src/mrl-configs/fantomTestnet.ts index 8ec0679b..3059b96c 100644 --- a/packages/config/src/mrl-configs/fantomTestnet.ts +++ b/packages/config/src/mrl-configs/fantomTestnet.ts @@ -5,7 +5,6 @@ import { moonbaseAlpha, moonbaseBeta, peaqAlphanet, - peaqEvm, peaqEvmAlphanet, } from '../chains'; import { MrlChainRoutes } from '../types/MrlChainRoutes'; diff --git a/packages/mrl/src/getTransferData/getSourceData.ts b/packages/mrl/src/getTransferData/getSourceData.ts index 4b693352..9c9c79bc 100644 --- a/packages/mrl/src/getTransferData/getSourceData.ts +++ b/packages/mrl/src/getTransferData/getSourceData.ts @@ -31,6 +31,7 @@ import { } from './getTransferData.utils'; interface GetSourceDataParams { + isAutomatic: boolean; route: MrlAssetRoute; destinationAddress: string; destinationFee: AssetAmount; @@ -38,6 +39,7 @@ interface GetSourceDataParams { } export async function getSourceData({ + isAutomatic, route, destinationAddress, destinationFee, @@ -95,7 +97,7 @@ export async function getSourceData({ asset: balance, destinationAddress, feeAsset: feeBalance, - isAutomatic: route.mrl.isAutomaticPossible, + isAutomatic, route, sourceAddress, }); @@ -115,7 +117,7 @@ export async function getSourceData({ transfer, asset: balance, feeAsset: feeBalance, - isAutomatic: route.mrl.isAutomaticPossible, + isAutomatic, destinationAddress, route, sourceAddress, diff --git a/packages/mrl/src/getTransferData/getTransferData.ts b/packages/mrl/src/getTransferData/getTransferData.ts index 353fe407..fb675777 100644 --- a/packages/mrl/src/getTransferData/getTransferData.ts +++ b/packages/mrl/src/getTransferData/getTransferData.ts @@ -60,6 +60,7 @@ export async function getTransferData({ }); const sourceData = await getSourceData({ + isAutomatic: route.mrl.isAutomaticPossible && isAutomatic, route, destinationAddress, destinationFee, @@ -88,18 +89,19 @@ export async function getTransferData({ .minus( isSameAssetPayingDestinationFee ? destinationFee.toBig() : Big(0), ) - .minus(fee); + .minus(fee) + .minus(sourceData.relayerFee?.toBig() || Big(0)); return sourceData.balance.copyWith({ amount: result.lt(0) ? 0n : BigInt(result.toFixed()), }); }, + isAutomaticPossible: route.mrl.isAutomaticPossible, max: sourceData.max, min: getMrlMin({ destinationData, moonChainData, sourceData, - isAutomatic, }), moonChain: moonChainData, source: sourceData, diff --git a/packages/mrl/src/getTransferData/getTransferData.utils.ts b/packages/mrl/src/getTransferData/getTransferData.utils.ts index 23bfafd7..d9223a44 100644 --- a/packages/mrl/src/getTransferData/getTransferData.utils.ts +++ b/packages/mrl/src/getTransferData/getTransferData.utils.ts @@ -46,7 +46,6 @@ interface DataParams { destinationData: DestinationChainTransferData; moonChainData: MoonChainTransferData; sourceData: SourceTransferData; - isAutomatic?: boolean; } export function getMoonChainFeeValueOnSource({ @@ -75,7 +74,6 @@ export function getMrlMin({ destinationData, moonChainData, sourceData, - isAutomatic, }: DataParams): AssetAmount { const minInDestination = getMin(destinationData); const min = AssetAmount.fromChainAsset( @@ -89,10 +87,9 @@ export function getMrlMin({ moonChainData, sourceData, }); - const relayerFee = - sourceData.relayerFee?.amount && isAutomatic - ? sourceData.relayerFee.toBig() - : Big(0); + const relayerFee = sourceData.relayerFee?.amount + ? sourceData.relayerFee.toBig() + : Big(0); return min.copyWith({ amount: BigInt(min.toBig().add(moonChainFee).add(relayerFee).toFixed()), diff --git a/packages/mrl/src/mrl.interfaces.ts b/packages/mrl/src/mrl.interfaces.ts index ef4a89eb..ac80beb0 100644 --- a/packages/mrl/src/mrl.interfaces.ts +++ b/packages/mrl/src/mrl.interfaces.ts @@ -16,6 +16,7 @@ export interface Signers { export interface TransferData { destination: DestinationTransferData; getEstimate(amount: number | string): AssetAmount; + isAutomaticPossible: boolean; max: AssetAmount; min: AssetAmount; moonChain: MoonChainTransferData; From 68f2b45f594ff79b8849fe08d871eaeaae729c18 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Mon, 2 Dec 2024 10:24:06 +0100 Subject: [PATCH 7/7] change fantom rpc endpoint --- packages/config/src/chains.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 3c341536..9e0ad8dd 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -480,7 +480,7 @@ export const fantomTestnet = new EvmChain({ key: 'fantom-testnet', name: 'Fantom Testnet', nativeAsset: ftm, - rpc: 'https://rpc.testnet.fantom.network', + rpc: 'https://fantom-testnet-rpc.publicnode.com', wh: { name: 'Fantom', },