diff --git a/examples/mrl-simple/index.ts b/examples/mrl-simple/index.ts index 73e6901d..8f32c373 100644 --- a/examples/mrl-simple/index.ts +++ b/examples/mrl-simple/index.ts @@ -54,14 +54,25 @@ main() .finally(() => process.exit()); async function main() { - // await fromFantomToPeaq(ftm, 0.011); - // await fromFantomToMoonbase(ftm, 0.01); - // await fromMoonbaseToFantom(dev, 0.01); - // await fromPeaqToFantom(ftmwh, 0.1); - await fromPeaqEvmToFantom(ftmwh, 0.12); + const isAutomatic = true; + // await fromFantomToPeaq(ftm, 0.011, isAutomatic); + // await fromFantomToMoonbase(ftm, 0.01, isAutomatic); + // await fromMoonbaseToFantom(ftmwh, 0.01, isAutomatic); + await fromPeaqToFantom(agng, 20, isAutomatic); + // await fromPeaqEvmToFantom(ftmwh, 1.5, isAutomatic); } -async function fromFantomToPeaq(asset: Asset, amount: number) { +async function fromFantomToPeaq( + asset: Asset, + amount: number, + isAutomatic: boolean, +) { + const walletClient = createWalletClient({ + account, + chain: fantomTestnet.getViemChain(), + transport: http(), + }); + const data = await Mrl() .setSource(fantomTestnet) .setDestination(peaqAlphanet) @@ -73,13 +84,17 @@ async function fromFantomToPeaq(asset: Asset, amount: number) { console.log(data); - await data.transfer(amount, { + await data.transfer(amount, isAutomatic, { polkadotSigner: pair, evmSigner: walletClient, }); } -async function fromFantomToMoonbase(asset: Asset, amount: number) { +async function fromFantomToMoonbase( + asset: Asset, + amount: number, + isAutomatic: boolean, +) { const walletClient = createWalletClient({ account, chain: fantomTestnet.getViemChain(), @@ -89,7 +104,7 @@ async function fromFantomToMoonbase(asset: Asset, amount: number) { const data = await Mrl() .setSource(fantomTestnet) .setDestination(moonbaseAlpha) - .setAsset(dev) + .setAsset(asset) .setAddresses({ sourceAddress: account.address, destinationAddress: account.address, @@ -97,13 +112,17 @@ async function fromFantomToMoonbase(asset: Asset, amount: number) { console.log(data); - await data.transfer(0.5, { + await data.transfer(amount, isAutomatic, { polkadotSigner: pair, evmSigner: walletClient, }); } -async function fromMoonbaseToFantom(asset: Asset, amount: number) { +async function fromMoonbaseToFantom( + asset: Asset, + amount: number, + isAutomatic: boolean, +) { const walletClient = createWalletClient({ account, chain: moonbaseAlphaViem, @@ -120,13 +139,17 @@ async function fromMoonbaseToFantom(asset: Asset, amount: number) { console.log(data); - await data.transfer(amount, { + await data.transfer(amount, isAutomatic, { polkadotSigner: pair, evmSigner: walletClient, }); } -async function fromPeaqToFantom(asset: Asset, amount: number) { +async function fromPeaqToFantom( + asset: Asset, + amount: number, + isAutomatic: boolean, +) { const data = await Mrl() .setSource(peaqAlphanet) .setDestination(fantomTestnet) @@ -138,12 +161,16 @@ async function fromPeaqToFantom(asset: Asset, amount: number) { console.log(data); - await data.transfer(amount, { + await data.transfer(amount, isAutomatic, { polkadotSigner: pair, }); } -async function fromPeaqEvmToFantom(asset: Asset, amount: number) { +async function fromPeaqEvmToFantom( + asset: Asset, + amount: number, + isAutomatic: boolean, +) { const walletClient = createWalletClient({ account, chain: peaqEvmAlphanet.getViemChain(), @@ -161,5 +188,5 @@ async function fromPeaqEvmToFantom(asset: Asset, amount: number) { console.log(data); - await data.transfer(amount, { evmSigner: walletClient }); + await data.transfer(amount, isAutomatic, { evmSigner: walletClient }); } diff --git a/packages/config/src/mrl-configs/fantomTestnet.ts b/packages/config/src/mrl-configs/fantomTestnet.ts index fe6ceac8..1f9f8739 100644 --- a/packages/config/src/mrl-configs/fantomTestnet.ts +++ b/packages/config/src/mrl-configs/fantomTestnet.ts @@ -92,7 +92,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({ }, }, mrl: { - isAutomaticPossible: false, // TODO + isAutomaticPossible: true, transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), moonChain: { asset: ftmwh, diff --git a/packages/config/src/mrl-configs/moonbaseAlpha.ts b/packages/config/src/mrl-configs/moonbaseAlpha.ts index 7a03c035..9538185e 100644 --- a/packages/config/src/mrl-configs/moonbaseAlpha.ts +++ b/packages/config/src/mrl-configs/moonbaseAlpha.ts @@ -29,7 +29,7 @@ export const moonbaseAlphaRoutes = new MrlChainRoutes({ }, }, mrl: { - isAutomaticPossible: false, // TODO + isAutomaticPossible: true, transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), moonChain: { asset: ftmwh, diff --git a/packages/config/src/mrl-configs/peaqEvmAlphanet.ts b/packages/config/src/mrl-configs/peaqEvmAlphanet.ts index b778fd10..0d562e43 100644 --- a/packages/config/src/mrl-configs/peaqEvmAlphanet.ts +++ b/packages/config/src/mrl-configs/peaqEvmAlphanet.ts @@ -33,7 +33,7 @@ export const peaqEvmAlphanetRoutes = new MrlChainRoutes({ }, }, mrl: { - isAutomaticPossible: false, // TODO + isAutomaticPossible: true, transfer: MrlBuilder() .wormhole() .contract() diff --git a/packages/mrl/src/getTransferData/getSourceData.ts b/packages/mrl/src/getTransferData/getSourceData.ts index 2f53318e..0b732ef9 100644 --- a/packages/mrl/src/getTransferData/getSourceData.ts +++ b/packages/mrl/src/getTransferData/getSourceData.ts @@ -94,6 +94,7 @@ export async function getSourceData({ asset: balance, destinationAddress, feeAsset: feeBalance, + isAutomatic: route.mrl.isAutomaticPossible, route, sourceAddress, }); @@ -113,6 +114,7 @@ export async function getSourceData({ transfer, asset: balance, feeAsset: feeBalance, + isAutomatic: route.mrl.isAutomaticPossible, destinationAddress, route, sourceAddress, @@ -128,6 +130,7 @@ export async function getSourceData({ return { balance, chain: source, + destinationFee, destinationFeeBalance, moonChainFeeBalance, existentialDeposit, @@ -202,6 +205,7 @@ export async function getRelayerFee({ chain, destinationAddress, feeAsset, + isAutomatic, route, sourceAddress, transfer, @@ -215,6 +219,7 @@ export async function getRelayerFee({ asset, destinationAddress, feeAsset, + isAutomatic, route, sourceAddress, }); diff --git a/packages/mrl/src/getTransferData/getTransferData.ts b/packages/mrl/src/getTransferData/getTransferData.ts index fd281b36..07050069 100644 --- a/packages/mrl/src/getTransferData/getTransferData.ts +++ b/packages/mrl/src/getTransferData/getTransferData.ts @@ -103,6 +103,7 @@ export async function getTransferData({ source: sourceData, async transfer( amount, + isAutomatic, { evmSigner, polkadotSigner }: Partial, ): Promise { const source = route.source.chain; @@ -122,6 +123,7 @@ export async function getTransferData({ asset, destinationAddress, feeAsset, + isAutomatic, route, sourceAddress, }); diff --git a/packages/mrl/src/getTransferData/getTransferData.utils.ts b/packages/mrl/src/getTransferData/getTransferData.utils.ts index f96da7cf..184c9f1e 100644 --- a/packages/mrl/src/getTransferData/getTransferData.utils.ts +++ b/packages/mrl/src/getTransferData/getTransferData.utils.ts @@ -100,6 +100,7 @@ export interface BuildTransferParams { asset: AssetAmount; destinationAddress: string; feeAsset: AssetAmount; + isAutomatic: boolean; route: AssetRoute; sourceAddress: string; } @@ -111,6 +112,11 @@ export async function buildTransfer(params: BuildTransferParams) { `MrlConfigBuilder is not defined for source chain ${route.source.chain.name} and asset ${route.source.asset.originSymbol}`, ); } + if (params.isAutomatic && !route.mrl.isAutomaticPossible) { + throw new Error( + `Route from source chain ${route.source.chain.name} and asset ${route.source.asset.originSymbol} does not allow the automatic option`, + ); + } const builderParams = await getMrlBuilderParams(params); return route.mrl.transfer.build({ @@ -125,6 +131,7 @@ export async function getMrlBuilderParams({ asset, destinationAddress, feeAsset, + isAutomatic, route, sourceAddress, }: BuildTransferParams): Promise { @@ -151,7 +158,7 @@ export async function getMrlBuilderParams({ destinationAddress, destinationApi, fee: feeAsset, - isAutomatic: route.mrl.isAutomaticPossible, + isAutomatic, moonApi, moonAsset: moonChain.nativeAsset, moonChain, diff --git a/packages/mrl/src/mrl.interfaces.ts b/packages/mrl/src/mrl.interfaces.ts index 4413a283..9abe5060 100644 --- a/packages/mrl/src/mrl.interfaces.ts +++ b/packages/mrl/src/mrl.interfaces.ts @@ -18,6 +18,7 @@ export interface TransferData { source: SourceTransferData; transfer( amount: bigint | number | string, + isAutomatic: boolean, signers: Signers, ): Promise; } diff --git a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap index 63e0857b..4dcde56a 100644 --- a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap +++ b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap @@ -473,6 +473,71 @@ exports[`sdk > getParachainBalances > on 'Moonbase Alpha' for address: '0x4E8214 ] `; +exports[`sdk > getParachainBalances > on 'Moonbase Beta' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = ` +[ + _AssetAmount { + "address": undefined, + "amount": 100000000000000000n, + "decimals": 18, + "ids": { + "balanceId": "198801030527939140930753142903035039136", + "id": { + "ForeignAsset": "198801030527939140930753142903035039136", + }, + }, + "key": "ftmwh", + "min": undefined, + "originSymbol": "FTM.wh", + "symbol": undefined, + }, + _AssetAmount { + "address": undefined, + "amount": 0n, + "decimals": 6, + "ids": { + "balanceId": "319794858556516669238969276945382613133", + "id": { + "ForeignAsset": "319794858556516669238969276945382613133", + }, + }, + "key": "usdcwh", + "min": undefined, + "originSymbol": "USDC.Wh", + "symbol": undefined, + }, + _AssetAmount { + "address": undefined, + "amount": 1100000000000000000n, + "decimals": 18, + "ids": { + "balanceId": "85534404031760856987006367174489651085", + "id": { + "ForeignAsset": "85534404031760856987006367174489651085", + }, + }, + "key": "alan", + "min": undefined, + "originSymbol": "ALAN", + "symbol": undefined, + }, + _AssetAmount { + "address": undefined, + "amount": 1100000000000000000n, + "decimals": 18, + "ids": { + "balanceId": "222902676330054289648817870329963141953", + "id": { + "ForeignAsset": "222902676330054289648817870329963141953", + }, + }, + "key": "dev", + "min": undefined, + "originSymbol": "DEV", + "symbol": undefined, + }, +] +`; + exports[`sdk > getParachainBalances > on 'Moonbeam' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = ` [ _AssetAmount { @@ -788,9 +853,12 @@ exports[`sdk > getParachainBalances > on 'Moonbeam' for address: '0x4E82143Af671 "symbol": undefined, }, _AssetAmount { - "address": "0xFfFffFFF18898CB5Fe1E88E668152B4f4052A947", + "address": "0xFfffffFfB3229c8E7657eABEA704d5e75246e544", "amount": 0n, "decimals": 12, + "ids": { + "id": "238111524681612888331172110363070489924", + }, "key": "neuro", "min": undefined, "originSymbol": "NEURO", diff --git a/packages/sdk/tests/acceptance/sdk.test.ts b/packages/sdk/tests/acceptance/sdk.test.ts index 4302b793..ed6eeef0 100644 --- a/packages/sdk/tests/acceptance/sdk.test.ts +++ b/packages/sdk/tests/acceptance/sdk.test.ts @@ -31,10 +31,10 @@ const config: { chain: AnyParachain; address: string }[] = [ { chain: centrifuge, address: substrateAddress }, { chain: hydrationAlphanet, address: hydrationAddress }, { chain: hydrationAlphanet, address: substrateAddress }, - // { - // chain: moonbaseBeta, - // address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e84405e', - // }, + { + chain: moonbaseBeta, + address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e84405e', + }, { chain: moonbaseAlpha, address: moonEvmAddress }, { chain: peaqEvmAlphanet, address: moonEvmAddress }, { chain: peaqAlphanet, address: substrateAddress },