Skip to content

Commit

Permalink
update mrl example
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Oct 15, 2024
1 parent 8f058ac commit 8cd1d05
Showing 1 changed file with 113 additions and 8 deletions.
121 changes: 113 additions & 8 deletions examples/mrl-simple/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}`);

Expand All @@ -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 });
}

0 comments on commit 8cd1d05

Please sign in to comment.