From 5b4c2a1a022dc00111abcaa5e4ec91b93ec8708b Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Fri, 18 Oct 2024 15:29:56 +0200 Subject: [PATCH 1/8] add AGNG route from Fantom to Peaq --- .../config/src/mrl-configs/fantomTestnet.ts | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/config/src/mrl-configs/fantomTestnet.ts b/packages/config/src/mrl-configs/fantomTestnet.ts index 1f9f8739..c8c22ee1 100644 --- a/packages/config/src/mrl-configs/fantomTestnet.ts +++ b/packages/config/src/mrl-configs/fantomTestnet.ts @@ -1,5 +1,5 @@ import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder'; -import { dev, ftm, ftmwh } from '../assets'; +import { agng, dev, ftm, ftmwh } from '../assets'; import { fantomTestnet, moonbaseAlpha, @@ -42,6 +42,37 @@ export const fantomTestnetRoutes = new MrlChainRoutes({ }, }, }, + { + source: { + asset: agng, + balance: BalanceBuilder().evm().erc20(), + destinationFee: { + asset: agng, + balance: BalanceBuilder().evm().erc20(), + }, + }, + destination: { + asset: agng, + chain: peaqAlphanet, + balance: BalanceBuilder().substrate().system().account(), + fee: { + asset: agng, + amount: 1, + }, + }, + mrl: { + isAutomaticPossible: false, + transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(), + moonChain: { + asset: agng, + fee: { + asset: dev, + amount: 0.1, + balance: BalanceBuilder().substrate().system().account(), + }, + }, + }, + }, { source: { asset: ftm, From 458d6d8f5fb34c55ce67ec60654e709cdf77d4a9 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Thu, 24 Oct 2024 14:56:49 +0200 Subject: [PATCH 2/8] Add redeeming functionalities for Womrhole --- examples/mrl-simple/index.ts | 56 ++++++++++++++++--- .../builder/src/mrl/MrlBuilder.interfaces.ts | 9 +++ .../providers/wormhole/contract/Gmp/Gmp.ts | 28 ++++++++++ .../providers/wormhole/contract/Gmp/GmpAbi.ts | 15 +++++ .../providers/wormhole/contract/Gmp/index.ts | 1 + .../mrl/providers/wormhole/contract/index.ts | 3 +- .../providers/wormhole/wormhole/wormhole.ts | 4 +- .../mrl/src/getTransferData/getRedeemData.ts | 49 ++++++++++++++++ packages/mrl/src/mrl.interfaces.ts | 13 ++++- packages/mrl/src/mrl.ts | 10 ++++ .../src/services/wormhole/WormholeService.ts | 40 +++++++++++++ 11 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts create mode 100644 packages/builder/src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts create mode 100644 packages/builder/src/mrl/providers/wormhole/contract/Gmp/index.ts create mode 100644 packages/mrl/src/getTransferData/getRedeemData.ts diff --git a/examples/mrl-simple/index.ts b/examples/mrl-simple/index.ts index 8f32c373..251d9b7a 100644 --- a/examples/mrl-simple/index.ts +++ b/examples/mrl-simple/index.ts @@ -16,6 +16,7 @@ import { cryptoWaitReady } from '@polkadot/util-crypto'; import { http, type Address, createWalletClient } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { moonbaseAlpha as moonbaseAlphaViem } from 'viem/chains'; +import type { EvmSigner } from '../../packages/sdk/build'; // disable unnecessary warning logs console.warn = () => null; @@ -54,12 +55,46 @@ main() .finally(() => process.exit()); async function main() { - const isAutomatic = true; - // await fromFantomToPeaq(ftm, 0.011, isAutomatic); - // await fromFantomToMoonbase(ftm, 0.01, isAutomatic); + const isAutomatic = false; + + // await fromFantomToPeaq(agng, 10, isAutomatic); + // await fromFantomToMoonbase(dev, 1.23, isAutomatic); // await fromMoonbaseToFantom(ftmwh, 0.01, isAutomatic); - await fromPeaqToFantom(agng, 20, isAutomatic); + // await fromPeaqToFantom(ftmwh, 0.0121, isAutomatic); // await fromPeaqEvmToFantom(ftmwh, 1.5, isAutomatic); + + // await redeemInMoonbaseAlpha(); + await redeemInFantomTestnet(); +} + +async function redeemInMoonbaseAlpha() { + const tx = + '0x7c2771b74211420284c44116fe436003df31713a7ffefb034b2ce21ef3711cef'; + const walletClient = createWalletClient({ + account, + chain: moonbaseAlphaViem, + transport: http(), + }); + + const data = await Mrl().setTxHashToRedeem(tx).setRedeemChain(moonbaseAlpha); + console.log('data', data); + + await data.redeem(walletClient as EvmSigner); +} + +async function redeemInFantomTestnet() { + const tx = + '0xa0032ff270885f7278a42d4d974fceab9e4feb039263db35b09beafe57bd6683'; + const walletClient = createWalletClient({ + account, + chain: fantomTestnet.getViemChain(), + transport: http(), + }); + + const data = await Mrl().setTxHashToRedeem(tx).setRedeemChain(fantomTestnet); + console.log('data', data); + + await data.redeem(walletClient as EvmSigner); } async function fromFantomToPeaq( @@ -86,7 +121,7 @@ async function fromFantomToPeaq( await data.transfer(amount, isAutomatic, { polkadotSigner: pair, - evmSigner: walletClient, + evmSigner: walletClient as EvmSigner, }); } @@ -112,10 +147,11 @@ async function fromFantomToMoonbase( console.log(data); - await data.transfer(amount, isAutomatic, { + const hash = await data.transfer(amount, isAutomatic, { polkadotSigner: pair, - evmSigner: walletClient, + evmSigner: walletClient as EvmSigner, }); + console.log('hash', hash); } async function fromMoonbaseToFantom( @@ -141,7 +177,7 @@ async function fromMoonbaseToFantom( await data.transfer(amount, isAutomatic, { polkadotSigner: pair, - evmSigner: walletClient, + evmSigner: walletClient as EvmSigner, }); } @@ -188,5 +224,7 @@ async function fromPeaqEvmToFantom( console.log(data); - await data.transfer(amount, isAutomatic, { evmSigner: walletClient }); + await data.transfer(amount, isAutomatic, { + evmSigner: walletClient as EvmSigner, + }); } diff --git a/packages/builder/src/mrl/MrlBuilder.interfaces.ts b/packages/builder/src/mrl/MrlBuilder.interfaces.ts index 0e9456b9..a3c83f3f 100644 --- a/packages/builder/src/mrl/MrlBuilder.interfaces.ts +++ b/packages/builder/src/mrl/MrlBuilder.interfaces.ts @@ -15,6 +15,11 @@ export type MrlConfigBuilder = ConfigBuilder< MrlBuilderParams >; +export type MrlRedeemConfigBuilder = ConfigBuilder< + ContractConfig, + MrlRedeemBuilderParams +>; + export interface MrlBuilderParams extends BuilderParams { isAutomatic: boolean; moonApi: ApiPromise; @@ -24,6 +29,10 @@ export interface MrlBuilderParams extends BuilderParams { transact?: Transact; } +export interface MrlRedeemBuilderParams { + bytes?: Uint8Array; +} + export interface Transact { call: HexString; txWeight: { diff --git a/packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts new file mode 100644 index 00000000..e76f0a71 --- /dev/null +++ b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts @@ -0,0 +1,28 @@ +import type { Address } from 'viem'; +import { ContractConfig } from '../../../../../contract'; +import type { MrlRedeemConfigBuilder } from '../../../../MrlBuilder.interfaces'; +import { GMP_ABI } from './GmpAbi'; + +const module = 'GMP'; + +export const GMP_CONTRACT_ADDRESS = + '0x0000000000000000000000000000000000000816'; + +export function Gmp() { + return { + wormholeTransferERC20: (): MrlRedeemConfigBuilder => ({ + build: ({ bytes }) => { + const hex = + `0x${Buffer.from(bytes as Uint8Array).toString('hex')}` as Address; + + return new ContractConfig({ + address: GMP_CONTRACT_ADDRESS, + abi: GMP_ABI, + args: [hex], + func: 'wormholeTransferERC20', + module, + }); + }, + }), + }; +} diff --git a/packages/builder/src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts new file mode 100644 index 00000000..d6026468 --- /dev/null +++ b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts @@ -0,0 +1,15 @@ +export const GMP_ABI = [ + { + inputs: [ + { + internalType: 'bytes', + name: 'vaa', + type: 'bytes', + }, + ], + name: 'wormholeTransferERC20', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as const; diff --git a/packages/builder/src/mrl/providers/wormhole/contract/Gmp/index.ts b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/index.ts new file mode 100644 index 00000000..3e0209db --- /dev/null +++ b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/index.ts @@ -0,0 +1 @@ +export * from './Gmp'; diff --git a/packages/builder/src/mrl/providers/wormhole/contract/index.ts b/packages/builder/src/mrl/providers/wormhole/contract/index.ts index 478deb08..8209ddeb 100644 --- a/packages/builder/src/mrl/providers/wormhole/contract/index.ts +++ b/packages/builder/src/mrl/providers/wormhole/contract/index.ts @@ -1,7 +1,8 @@ import { Batch } from './Batch'; +import { Gmp } from './Gmp'; import { TokenBridge } from './TokenBridge'; import { TokenBridgeRelayer } from './TokenBridgeRelayer'; export function contract() { - return { Batch, TokenBridge, TokenBridgeRelayer }; + return { Batch, Gmp, TokenBridge, TokenBridgeRelayer }; } diff --git a/packages/builder/src/mrl/providers/wormhole/wormhole/wormhole.ts b/packages/builder/src/mrl/providers/wormhole/wormhole/wormhole.ts index 24960128..5dd16aa6 100644 --- a/packages/builder/src/mrl/providers/wormhole/wormhole/wormhole.ts +++ b/packages/builder/src/mrl/providers/wormhole/wormhole/wormhole.ts @@ -7,12 +7,10 @@ import type { MrlBuilderParams, MrlConfigBuilder, } from '../../../MrlBuilder.interfaces'; +import { GMP_CONTRACT_ADDRESS } from '../contract/Gmp'; import { WormholeConfig } from './WormholeConfig'; import { wormholeFactory } from './wormholeFactory'; -export const GMP_CONTRACT_ADDRESS = - '0x0000000000000000000000000000000000000816'; - export function wormhole() { return { tokenTransfer: (): MrlConfigBuilder => ({ diff --git a/packages/mrl/src/getTransferData/getRedeemData.ts b/packages/mrl/src/getTransferData/getRedeemData.ts new file mode 100644 index 00000000..3fe68776 --- /dev/null +++ b/packages/mrl/src/getTransferData/getRedeemData.ts @@ -0,0 +1,49 @@ +import { type ContractConfig, MrlBuilder } from '@moonbeam-network/xcm-builder'; +import { EvmService, type EvmSigner } from '@moonbeam-network/xcm-sdk'; +import type { EvmChain, EvmParachain } from '@moonbeam-network/xcm-types'; +import { WormholeService } from '../services/wormhole'; + +export interface GetRedeemDataParams { + txId: string; + chain: EvmChain | EvmParachain; +} + +export async function getRedeemData({ txId, chain }: GetRedeemDataParams) { + // TODO this is just for wormhole + const wh = WormholeService.create(chain); + + const vaa = await wh.getVaa(txId); + const tokenTransfer = await wh.getTokenTransfer(vaa, txId); + + const isXcm = vaa.payloadName === 'TransferWithPayload'; + + return { + vaa, + tokenTransfer, + async redeem(signer: EvmSigner) { + const isComplete = await wh.isComplete(vaa, tokenTransfer); + + if (isComplete) { + throw new Error('This transaction is already finalized in Wormhole'); + } + + if (isXcm) { + const bytes = await wh.getVaaBytes(vaa); + + const contract = MrlBuilder() + .wormhole() + .contract() + .Gmp() + .wormholeTransferERC20() + .build({ bytes }) as ContractConfig; + + const evm = EvmService.create(chain); + const hash = await evm.transfer(signer, contract); + + return hash; + } + + return await wh.completeTransfer(tokenTransfer, signer); + }, + }; +} diff --git a/packages/mrl/src/mrl.interfaces.ts b/packages/mrl/src/mrl.interfaces.ts index 9abe5060..a552d5ed 100644 --- a/packages/mrl/src/mrl.interfaces.ts +++ b/packages/mrl/src/mrl.interfaces.ts @@ -1,7 +1,11 @@ -import type { SourceChainTransferData } from '@moonbeam-network/xcm-sdk'; +import type { + EvmSigner, + SourceChainTransferData, +} 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 { TokenTransfer } from '@wormhole-foundation/sdk-connect'; import type { WalletClient } from 'viem'; export interface Signers { @@ -41,3 +45,10 @@ export interface ChainTransferData { fee: AssetAmount; min: AssetAmount; } + +// TODO this is just for Wormhole +export type RedeemData = { + vaa: TokenTransfer.VAA; + tokenTransfer: TokenTransfer; + transfer(signer: EvmSigner): Promise; +}; diff --git a/packages/mrl/src/mrl.ts b/packages/mrl/src/mrl.ts index 1c511e30..c9a44e8a 100644 --- a/packages/mrl/src/mrl.ts +++ b/packages/mrl/src/mrl.ts @@ -3,7 +3,10 @@ import type { AnyAsset, AnyChain, Ecosystem, + EvmChain, + EvmParachain, } from '@moonbeam-network/xcm-types'; +import { getRedeemData } from './getTransferData/getRedeemData'; import { getTransferData } from './getTransferData/getTransferData'; const DEFAULT_SERVICE = new ConfigService({ routes: mrlRoutesMap }); @@ -56,5 +59,12 @@ export function Mrl(options?: MrlOptions) { }, }; }, + setTxHashToRedeem(txId: string) { + return { + setRedeemChain(chain: EvmChain | EvmParachain) { + return getRedeemData({ txId, chain }); + }, + }; + }, }; } diff --git a/packages/mrl/src/services/wormhole/WormholeService.ts b/packages/mrl/src/services/wormhole/WormholeService.ts index 1d852096..3eaac618 100644 --- a/packages/mrl/src/services/wormhole/WormholeService.ts +++ b/packages/mrl/src/services/wormhole/WormholeService.ts @@ -45,4 +45,44 @@ export class WormholeService { return xfer.initiateTransfer(new WormholeWagmiSigner(this.chain, signer)); } + + async getVaa(txId: string) { + return await TokenTransfer.getTransferVaa(this.#wh, txId); + } + + async getVaaBytes(vaa: TokenTransfer.VAA) { + return ( + (await this.#wh.getVaaBytes({ + chain: vaa.emitterChain, + emitter: vaa.emitterAddress, + sequence: vaa.sequence, + })) || undefined + ); + } + + async getTokenTransfer(vaa: TokenTransfer.VAA, txId: string) { + return await TokenTransfer.from(this.#wh, { + chain: vaa.emitterChain, + txid: txId, + }); + } + + async isComplete(vaa: TokenTransfer.VAA, tokenTransfer: TokenTransfer) { + const isComplete = await TokenTransfer.isTransferComplete( + tokenTransfer.toChain, + vaa, + ); + return isComplete; + } + + async completeTransfer( + tokenTransfer: TokenTransfer, + signer: EvmSigner, + ): Promise { + const txIds = await tokenTransfer.completeTransfer( + new WormholeWagmiSigner(this.chain, signer), + ); + + return txIds[0]; + } } From 9d135c88fc2f810353c194de16b08a939a7b84df Mon Sep 17 00:00:00 2001 From: Richard Kenigs Date: Fri, 25 Oct 2024 15:53:35 +0200 Subject: [PATCH 3/8] imporve dev mode --- packages/builder/package.json | 2 +- packages/config/package.json | 2 +- packages/mrl/package.json | 2 +- packages/sdk/package.json | 2 +- packages/types/package.json | 2 +- packages/utils/package.json | 2 +- turbo.json | 3 ++- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/builder/package.json b/packages/builder/package.json index 14ba345c..3f5fe8a6 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam XCM builder", "scripts": { "build": "tsup", - "dev": "pnpm run build -- --watch", + "dev": "tsup --watch", "typecheck": "tsc --noEmit", "test": "vitest --run", "test:watch": "vitest", diff --git a/packages/config/package.json b/packages/config/package.json index 8d67c9e0..3753a617 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -4,7 +4,7 @@ "description": "All necessary configuration to transfer assets from Moonbeam, Moonriver, Moonbase to other parachains and back", "scripts": { "build": "tsup", - "dev": "pnpm run build -- --watch", + "dev": "tsup --watch", "typecheck": "tsc --noEmit", "test": "vitest --run", "test:watch": "vitest", diff --git a/packages/mrl/package.json b/packages/mrl/package.json index 3be6de5b..3a84588b 100644 --- a/packages/mrl/package.json +++ b/packages/mrl/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam Routed Liquidity", "scripts": { "build": "tsup", - "dev": "pnpm run build -- --watch", + "dev": "tsup --watch", "typecheck": "tsc --noEmit", "prepack": "prettier --write build/index.d.ts" }, diff --git a/packages/sdk/package.json b/packages/sdk/package.json index cfc54326..4c6e2328 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -4,7 +4,7 @@ "description": "The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem", "scripts": { "build": "tsup", - "dev": "pnpm run build -- --watch", + "dev": "tsup --watch", "typecheck": "tsc --noEmit", "test:acc": "vitest --run --testTimeout 300000 ./tests/acceptance", "prepack": "prettier --write build/index.d.ts" diff --git a/packages/types/package.json b/packages/types/package.json index 0988a403..522166fe 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam XCM Types", "scripts": { "build": "tsup", - "dev": "pnpm run build -- --watch", + "dev": "tsup --watch", "test": "vitest --run", "test:watch": "vitest", "test:update": "vitest -u", diff --git a/packages/utils/package.json b/packages/utils/package.json index 1e955efa..a655149d 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam XCM utilities", "scripts": { "build": "tsup", - "dev": "pnpm run build -- --watch", + "dev": "tsup --watch", "typecheck": "tsc --noEmit", "test": "vitest --run", "test:watch": "vitest", diff --git a/turbo.json b/turbo.json index 251e6da8..92657dd8 100644 --- a/turbo.json +++ b/turbo.json @@ -6,7 +6,8 @@ "dependsOn": ["^build"] }, "dev": { - "cache": false + "cache": false, + "persistent": true }, "link": { "cache": false From 10a6c384e999e2ecfcb9f44433e5122853d058a5 Mon Sep 17 00:00:00 2001 From: Richard Kenigs Date: Fri, 25 Oct 2024 16:03:21 +0200 Subject: [PATCH 4/8] try to fix dev --- turbo.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/turbo.json b/turbo.json index 92657dd8..9758cf35 100644 --- a/turbo.json +++ b/turbo.json @@ -6,6 +6,8 @@ "dependsOn": ["^build"] }, "dev": { + "outputs": ["build/**"], + "dependsOn": ["^build"], "cache": false, "persistent": true }, From 10fc344b7864317247e25bde442ff1384146928f Mon Sep 17 00:00:00 2001 From: mmaurello Date: Fri, 25 Oct 2024 16:23:26 +0200 Subject: [PATCH 5/8] Revert "try to fix dev" This reverts commit 10a6c384e999e2ecfcb9f44433e5122853d058a5. --- turbo.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/turbo.json b/turbo.json index 9758cf35..92657dd8 100644 --- a/turbo.json +++ b/turbo.json @@ -6,8 +6,6 @@ "dependsOn": ["^build"] }, "dev": { - "outputs": ["build/**"], - "dependsOn": ["^build"], "cache": false, "persistent": true }, From 5076e2297457d02d0826f8623a6f80265a68dcd6 Mon Sep 17 00:00:00 2001 From: mmaurello Date: Fri, 25 Oct 2024 16:23:31 +0200 Subject: [PATCH 6/8] Revert "imporve dev mode" This reverts commit 9d135c88fc2f810353c194de16b08a939a7b84df. --- packages/builder/package.json | 2 +- packages/config/package.json | 2 +- packages/mrl/package.json | 2 +- packages/sdk/package.json | 2 +- packages/types/package.json | 2 +- packages/utils/package.json | 2 +- turbo.json | 3 +-- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/builder/package.json b/packages/builder/package.json index 3f5fe8a6..14ba345c 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam XCM builder", "scripts": { "build": "tsup", - "dev": "tsup --watch", + "dev": "pnpm run build -- --watch", "typecheck": "tsc --noEmit", "test": "vitest --run", "test:watch": "vitest", diff --git a/packages/config/package.json b/packages/config/package.json index 3753a617..8d67c9e0 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -4,7 +4,7 @@ "description": "All necessary configuration to transfer assets from Moonbeam, Moonriver, Moonbase to other parachains and back", "scripts": { "build": "tsup", - "dev": "tsup --watch", + "dev": "pnpm run build -- --watch", "typecheck": "tsc --noEmit", "test": "vitest --run", "test:watch": "vitest", diff --git a/packages/mrl/package.json b/packages/mrl/package.json index 3a84588b..3be6de5b 100644 --- a/packages/mrl/package.json +++ b/packages/mrl/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam Routed Liquidity", "scripts": { "build": "tsup", - "dev": "tsup --watch", + "dev": "pnpm run build -- --watch", "typecheck": "tsc --noEmit", "prepack": "prettier --write build/index.d.ts" }, diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 4c6e2328..cfc54326 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -4,7 +4,7 @@ "description": "The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem", "scripts": { "build": "tsup", - "dev": "tsup --watch", + "dev": "pnpm run build -- --watch", "typecheck": "tsc --noEmit", "test:acc": "vitest --run --testTimeout 300000 ./tests/acceptance", "prepack": "prettier --write build/index.d.ts" diff --git a/packages/types/package.json b/packages/types/package.json index 522166fe..0988a403 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam XCM Types", "scripts": { "build": "tsup", - "dev": "tsup --watch", + "dev": "pnpm run build -- --watch", "test": "vitest --run", "test:watch": "vitest", "test:update": "vitest -u", diff --git a/packages/utils/package.json b/packages/utils/package.json index a655149d..1e955efa 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -4,7 +4,7 @@ "description": "Moonbeam XCM utilities", "scripts": { "build": "tsup", - "dev": "tsup --watch", + "dev": "pnpm run build -- --watch", "typecheck": "tsc --noEmit", "test": "vitest --run", "test:watch": "vitest", diff --git a/turbo.json b/turbo.json index 92657dd8..251e6da8 100644 --- a/turbo.json +++ b/turbo.json @@ -6,8 +6,7 @@ "dependsOn": ["^build"] }, "dev": { - "cache": false, - "persistent": true + "cache": false }, "link": { "cache": false From d6a870c2d321dcf8159b402658cc58a5425d02b9 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Tue, 29 Oct 2024 10:25:17 +0100 Subject: [PATCH 7/8] change u8 to hex calculation --- .../builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts index e76f0a71..9d2bf23e 100644 --- a/packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts +++ b/packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts @@ -1,4 +1,4 @@ -import type { Address } from 'viem'; +import { u8aToHex } from '@polkadot/util'; import { ContractConfig } from '../../../../../contract'; import type { MrlRedeemConfigBuilder } from '../../../../MrlBuilder.interfaces'; import { GMP_ABI } from './GmpAbi'; @@ -12,8 +12,7 @@ export function Gmp() { return { wormholeTransferERC20: (): MrlRedeemConfigBuilder => ({ build: ({ bytes }) => { - const hex = - `0x${Buffer.from(bytes as Uint8Array).toString('hex')}` as Address; + const hex = u8aToHex(bytes); return new ContractConfig({ address: GMP_CONTRACT_ADDRESS, From f1db70181b0e7efdb54e23b71764b5ade691a010 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Tue, 29 Oct 2024 10:45:13 +0100 Subject: [PATCH 8/8] change getRedeemdData builder --- examples/mrl-simple/index.ts | 14 +++++++------- packages/mrl/src/getTransferData/getRedeemData.ts | 4 ++-- packages/mrl/src/mrl.ts | 15 ++++++--------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/examples/mrl-simple/index.ts b/examples/mrl-simple/index.ts index 251d9b7a..e2881d52 100644 --- a/examples/mrl-simple/index.ts +++ b/examples/mrl-simple/index.ts @@ -63,27 +63,27 @@ async function main() { // await fromPeaqToFantom(ftmwh, 0.0121, isAutomatic); // await fromPeaqEvmToFantom(ftmwh, 1.5, isAutomatic); - // await redeemInMoonbaseAlpha(); - await redeemInFantomTestnet(); + await redeemInMoonbaseAlpha(); + // await redeemInFantomTestnet(); } async function redeemInMoonbaseAlpha() { - const tx = - '0x7c2771b74211420284c44116fe436003df31713a7ffefb034b2ce21ef3711cef'; + const txId = + '0x59e70ad73c57bce44cbb3e3308fc6a31d29ff0dcbb2957055b05025969545bed'; const walletClient = createWalletClient({ account, chain: moonbaseAlphaViem, transport: http(), }); - const data = await Mrl().setTxHashToRedeem(tx).setRedeemChain(moonbaseAlpha); + const data = await Mrl().getRedeemData({ txId, chain: moonbaseAlpha }); console.log('data', data); await data.redeem(walletClient as EvmSigner); } async function redeemInFantomTestnet() { - const tx = + const txId = '0xa0032ff270885f7278a42d4d974fceab9e4feb039263db35b09beafe57bd6683'; const walletClient = createWalletClient({ account, @@ -91,7 +91,7 @@ async function redeemInFantomTestnet() { transport: http(), }); - const data = await Mrl().setTxHashToRedeem(tx).setRedeemChain(fantomTestnet); + const data = await Mrl().getRedeemData({ txId, chain: fantomTestnet }); console.log('data', data); await data.redeem(walletClient as EvmSigner); diff --git a/packages/mrl/src/getTransferData/getRedeemData.ts b/packages/mrl/src/getTransferData/getRedeemData.ts index 3fe68776..04e5fd83 100644 --- a/packages/mrl/src/getTransferData/getRedeemData.ts +++ b/packages/mrl/src/getTransferData/getRedeemData.ts @@ -3,12 +3,12 @@ import { EvmService, type EvmSigner } from '@moonbeam-network/xcm-sdk'; import type { EvmChain, EvmParachain } from '@moonbeam-network/xcm-types'; import { WormholeService } from '../services/wormhole'; -export interface GetRedeemDataParams { +export interface WormholeRedeemParams { txId: string; chain: EvmChain | EvmParachain; } -export async function getRedeemData({ txId, chain }: GetRedeemDataParams) { +export async function getRedeemData({ txId, chain }: WormholeRedeemParams) { // TODO this is just for wormhole const wh = WormholeService.create(chain); diff --git a/packages/mrl/src/mrl.ts b/packages/mrl/src/mrl.ts index c9a44e8a..33c5c26e 100644 --- a/packages/mrl/src/mrl.ts +++ b/packages/mrl/src/mrl.ts @@ -3,10 +3,11 @@ import type { AnyAsset, AnyChain, Ecosystem, - EvmChain, - EvmParachain, } from '@moonbeam-network/xcm-types'; -import { getRedeemData } from './getTransferData/getRedeemData'; +import { + type WormholeRedeemParams, + getRedeemData, +} from './getTransferData/getRedeemData'; import { getTransferData } from './getTransferData/getTransferData'; const DEFAULT_SERVICE = new ConfigService({ routes: mrlRoutesMap }); @@ -59,12 +60,8 @@ export function Mrl(options?: MrlOptions) { }, }; }, - setTxHashToRedeem(txId: string) { - return { - setRedeemChain(chain: EvmChain | EvmParachain) { - return getRedeemData({ txId, chain }); - }, - }; + getRedeemData({ txId, chain }: WormholeRedeemParams) { + return getRedeemData({ txId, chain }); }, }; }