Skip to content

Commit

Permalink
Merge pull request #912 from moonbeam-foundation/eshaben/2900-polkado…
Browse files Browse the repository at this point in the history
…t-sdk-v1.7.2

Changes related to polkadot-sdk v.1.7.2 and XCM v4
  • Loading branch information
eshaben committed May 10, 2024
2 parents bcb9fc7 + 29d3f72 commit 733a267
Show file tree
Hide file tree
Showing 99 changed files with 1,032 additions and 1,276 deletions.
31 changes: 0 additions & 31 deletions .snippets/code/builders/interoperability/mrl/batch-extrinsics.js

This file was deleted.

@@ -1,25 +1,20 @@
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
import { ApiPromise, WsProvider } from '@polkadot/api';
import { ethers } from 'ethers';
import batchABI from './abi/Batch.js';
import erc20ABI from './abi/ERC20.js';
import tokenRelayerABI from './abi/TokenRelayer.js';

// Input data
// ...
const localXC20Address = 'INSERT_LOCAL_XC20_ADDRESS';
const transferAmount = 'INSERT_AMOUNT_TO_TRANSFER';
const xLabsRelayer = '0x9563a59c15842a6f322b10f69d1dd88b41f2e97b';
const batchPrecompile = '0x0000000000000000000000000000000000000808';
const destinationChainId = 'INSERT_DESTINATION_CHAIN_ID';
const computedOriginAccount = 'INSERT_COMPUTED_ORIGIN_ADDRESS';
// The recipient address on the destination chain needs to be formatted in 32 bytes
// You'll pad the address to the left with zeroes. Add the destination address below
// without the 0x
const destinationAddress =
'0x000000000000000000000000' + 'INSERT_DESTINATION_ADDRESS';

// Transfer multiassets parameters
// ...

// Create contract instances
const batchInterface = new ethers.Interface(batchABI);
const localXC20Interface = new ethers.Interface(erc20ABI);
Expand All @@ -29,13 +24,13 @@ const tokenRelayer = new ethers.Contract(
new ethers.JsonRpcProvider('https://rpc.api.moonbase.moonbeam.network')
);

// Get the encoded call data for the approve transaction
// Get the encoded calldata for the approve transaction
const approve = localXC20Interface.encodeFunctionData('approve', [
xLabsRelayer, // Spender
transferAmount, // Amount
]);

// Get the encoded call data for the transferTokensWithRelay transaction.
// Get the encoded calldata for the transferTokensWithRelay transaction.
// Use wrapAndTransferEthWithRelay if the token is GLMR
const transferTokensWithRelay = tokenRelayer.interface.encodeFunctionData(
'transferTokensWithRelay',
Expand All @@ -49,39 +44,35 @@ const transferTokensWithRelay = tokenRelayer.interface.encodeFunctionData(
]
);

const batchAll = batchInterface.encodeFunctionData('batchAll', [
const encodedBatchAllCall = batchInterface.encodeFunctionData('batchAll', [
[localXC20Address, xLabsRelayer], // Addresses to call
[0, 0], // Value to send for each call
[approve, transferTokensWithRelay], // Call data for each call
[], // Gas limit for each call
]);

const sendBatchTx = async () => {
// Create origin chain API provider
// ...

export const getTransactCall = async () => {
// Create Moonbeam API provider
const moonbeamProvider = new WsProvider(
'wss://wss.api.moonbase.moonbeam.network'
);
const moonbeamAPI = await ApiPromise.create({ provider: moonbeamProvider });

// Create the transferMultiasset extrinsic
// ...

// Create the ethereumXCM extrinsic that uses the Batch Precompile
// Create the extrinsic for the remote EVM call
const transact = moonbeamAPI.tx.ethereumXcm.transact({
V2: {
gasLimit: 350000n,
action: {
Call: batchPrecompile,
Call: '0x0000000000000000000000000000000000000808',
},
value: 0n,
input: batchAll,
input: encodedBatchAllCall,
},
});

// Additional code goes here
};
const txWeight = (await transact.paymentInfo(computedOriginAccount)).weight;

moonbeamAPI.disconnect();

sendBatchTx();
return { transact, txWeight };
};
@@ -1,26 +1,31 @@
// Rest of script
// ...
import { ApiPromise, WsProvider } from '@polkadot/api';
import { getTransactCall } from './build-batch-evm-call.js';

const sendBatchTx = async () => {
// Rest of sendBatchTx logic
// ...
const originChainProviderWsURL = 'INSERT_ORIGIN_CHAIN_WSS_URL';
const computedOriginAccount = 'INSERT_COMPUTED_ORIGIN_ADDRESS';

const txWeight = (await transact.paymentInfo(multilocationDerivativeAccount))
.weight;

const sendXCM = originChainAPI.tx.polkadotXcm.send(
{ V3: { parents: 1, interior: { X1: { Parachain: 1000 } } } },
export const getPolkadotXcmCall = async () => {
// Create origin chain API provider
const originChainProvider = new WsProvider(originChainProviderWsURL);
const originChainAPI = await ApiPromise.create({
provider: originChainProvider,
});

// Get the weight required to execute the Transact calldata
const { transact, txWeight } = await getTransactCall();

// Create the extrinsic for the remote EVM call
const sendXcm = originChainAPI.tx.polkadotXcm.send(
{ V4: { parents: 1, interior: { X1: [{ Parachain: 1000 }] } } },
{
V3: [
V4: [
{
// Withdraw DEV asset (0.06) from the target account
WithdrawAsset: [
{
id: {
Concrete: {
parents: 0,
interior: { X1: { PalletInstance: 3 } },
},
parents: 0,
interior: { X1: [{ PalletInstance: 3 }] },
},
fun: { Fungible: 60000000000000000n },
},
Expand All @@ -31,10 +36,8 @@ const sendBatchTx = async () => {
BuyExecution: {
fees: {
id: {
Concrete: {
parents: 0,
interior: { X1: { PalletInstance: 3 } },
},
parents: 0,
interior: { X1: [{ PalletInstance: 3 }] },
},
fun: { Fungible: 60000000000000000n },
},
Expand Down Expand Up @@ -63,14 +66,14 @@ const sendBatchTx = async () => {
beneficiary: {
parents: 0,
interior: {
X1: { AccountKey20: { key: multilocationDerivativeAccount } },
X1: [{ AccountKey20: { key: computedOriginAccount } }],
},
},
},
},
],
}
);
}

sendBatchTx();
return sendXcm;
};
@@ -1,27 +1,23 @@
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
import { ethers } from 'ethers';
import { ApiPromise, WsProvider } from '@polkadot/api';

// Input data
const originChainProviderWsURL = 'INSERT_ORIGIN_CHAIN_WSS_URL';
const multilocationDerivativeAccount =
'INSERT_MULTILOCATION_DERIVATIVE_ADDRESS';
const computedOriginAccount = 'INSERT_COMPUTED_ORIGIN_ADDRESS';
const localXC20Address = 'INSERT_LOCAL_XC20_ADDRESS';
const transferAmount = 'INSERT_AMOUNT_TO_TRANSFER';

// Transfer multiassets parameters
const assets = {
V3: [
V4: [
{
// xcDEV
id: {
Concrete: {
parents: 1,
interior: {
X2: [
{ Parachain: 1000 }, // Parachain ID
{ PalletInstance: 3 }, // Index of the Balances Pallet
],
},
parents: 1,
interior: {
X2: [
{ Parachain: 1000 }, // Parachain ID
{ PalletInstance: 3 }, // Index of the Balances Pallet
],
},
},
fun: {
Expand All @@ -31,19 +27,17 @@ const assets = {
{
// Local XC-20 token
id: {
Concrete: {
parents: 1,
interior: {
X3: [
{ Parachain: 1000 }, // Parachain ID
{ PalletInstance: 48 }, // Index of the ERC-20 XCM Bridge Pallet
{
AccountKey20: {
key: localXC20Address,
},
parents: 1,
interior: {
X3: [
{ Parachain: 1000 }, // Parachain ID
{ PalletInstance: 48 }, // Index of the ERC-20 XCM Bridge Pallet
{
AccountKey20: {
key: localXC20Address,
},
],
},
},
],
},
},
fun: {
Expand All @@ -54,22 +48,24 @@ const assets = {
};
const feeItem = 0;
const destination = {
V3: {
V4: {
parents: 1,
interior: {
X2: [
{ Parachain: 1000 },
{ AccountKey20: { key: multilocationDerivativeAccount } },
{ AccountKey20: { key: computedOriginAccount } },
],
},
},
};
const weightLimit = 'Unlimited';

const sendBatchTx = async () => {
export const getTransferMultiassetsCall = async () => {
// Create origin chain API provider
const originChainProvider = new WsProvider(originChainProviderWsURL);
const originChainAPI = await ApiPromise.create({ provider: originChainProvider });
const originChainAPI = await ApiPromise.create({
provider: originChainProvider,
});

// Create the transferMultiasset extrinsic
const transferMultiassets = originChainAPI.tx.xTokens.transferMultiassets(
Expand All @@ -79,7 +75,7 @@ const sendBatchTx = async () => {
weightLimit
);

// Additional code goes here
};
originChainAPI.disconnect();

sendBatchTx();
return transferMultiassets;
};

0 comments on commit 733a267

Please sign in to comment.