From 8cd1d05dff7cad8bd7a020aef28f70d103d42528 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Tue, 15 Oct 2024 12:19:22 +0200 Subject: [PATCH] update mrl example --- examples/mrl-simple/index.ts | 121 ++++++++++++++++++++++++++++++++--- 1 file changed, 113 insertions(+), 8 deletions(-) diff --git a/examples/mrl-simple/index.ts b/examples/mrl-simple/index.ts index 7d8a5571..e06e64fb 100644 --- a/examples/mrl-simple/index.ts +++ b/examples/mrl-simple/index.ts @@ -1,9 +1,21 @@ import { Mrl } from '@moonbeam-network/mrl'; -import { fantomTestnet, ftm, peaqAlphanet } from '@moonbeam-network/xcm-config'; +import { + agng, + dev, + fantomTestnet, + ftm, + ftmwh, + moonbaseAlpha, + moonbaseBeta, + peaqAlphanet, + peaqEvmAlphanet, +} from '@moonbeam-network/xcm-config'; +import type { Asset } from '@moonbeam-network/xcm-types'; import { Keyring } from '@polkadot/api'; -import { cryptoWaitReady } from '@polkadot/util-crypto'; +import { cryptoWaitReady, mnemonicToMiniSecret } from '@polkadot/util-crypto'; import { http, type Address, createWalletClient } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; +import { moonbaseAlpha as moonbaseAlphaViem } from 'viem/chains'; // disable unnecessary warning logs console.warn = () => null; @@ -20,11 +32,6 @@ if (!EVM_PRIVATE_KEY || !POLKADOT_PRIVATE_KEY) { // EVM Signer =========================================================== const account = privateKeyToAccount(EVM_PRIVATE_KEY as Address); -const walletClient = createWalletClient({ - account, - chain: fantomTestnet.getViemChain(), - transport: http(), -}); console.log(`\nEVM address: ${account.address}`); @@ -47,14 +54,112 @@ main() .finally(() => process.exit()); async function main() { + // await fromFantomToPeaq(ftm, 0.011); + // await fromFantomToMoonbase(ftm, 0.01); + // await fromMoonbaseToFantom(ftmwh, 0.01); + // await fromPeaqToFantom(agng, 1); + await fromPeaqEvmToFantom(ftmwh, 0.01); +} + +async function fromFantomToPeaq(asset: Asset, amount: number) { const data = await Mrl() .setSource(fantomTestnet) .setDestination(peaqAlphanet) - .setAsset(ftm) + .setAsset(asset) .setAddresses({ sourceAddress: account.address, destinationAddress: pair.address, }); console.log(data); + + await data.transfer(amount, { + polkadotSigner: pair, + evmSigner: walletClient, + }); +} + +async function fromFantomToMoonbase(asset: Asset, amount: number) { + const walletClient = createWalletClient({ + account, + chain: fantomTestnet.getViemChain(), + transport: http(), + }); + + const data = await Mrl() + .setSource(fantomTestnet) + .setDestination(moonbaseAlpha) + .setAsset(dev) + .setAddresses({ + sourceAddress: account.address, + destinationAddress: account.address, + }); + + console.log(data); + + await data.transfer(0.5, { + polkadotSigner: pair, + evmSigner: walletClient, + }); +} + +async function fromMoonbaseToFantom(asset: Asset, amount: number) { + const walletClient = createWalletClient({ + account, + chain: moonbaseAlphaViem, + transport: http(), + }); + const data = await Mrl() + .setSource(moonbaseAlpha) + .setDestination(fantomTestnet) + .setAsset(asset) + .setAddresses({ + sourceAddress: account.address, + destinationAddress: account.address, + }); + + console.log(data); + + await data.transfer(amount, { + polkadotSigner: pair, + evmSigner: walletClient, + }); +} + +async function fromPeaqToFantom(asset: Asset, amount: number) { + const data = await Mrl() + .setSource(peaqAlphanet) + .setDestination(fantomTestnet) + .setAsset(asset) + .setAddresses({ + sourceAddress: pair.address, + destinationAddress: account.address, + }); + + console.log(data); + + await data.transfer(amount, { + polkadotSigner: pair, + }); +} + +async function fromPeaqEvmToFantom(asset: Asset, amount: number) { + const walletClient = createWalletClient({ + account, + chain: peaqEvmAlphanet.getViemChain(), + transport: http(), + }); + + const data = await Mrl() + .setSource(peaqEvmAlphanet) + .setDestination(fantomTestnet) + .setAsset(asset) + .setAddresses({ + sourceAddress: account.address, + destinationAddress: account.address, + }); + + console.log(data); + + await data.transfer(amount, { evmSigner: walletClient }); }