Skip to content

Commit

Permalink
Merge branch 'mjm/sovereign-account-balances' of github.com:moonbeam-…
Browse files Browse the repository at this point in the history
…foundation/xcm-sdk into mjm/dot-asset-hub
  • Loading branch information
mmaurello committed Sep 23, 2024
2 parents 9baa2f4 + 8ee36af commit 5ce2d6b
Show file tree
Hide file tree
Showing 24 changed files with 193 additions and 108 deletions.
37 changes: 29 additions & 8 deletions examples/sdk-simple/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
/* eslint-disable import/no-extraneous-dependencies */
import { dot, moonbeam, polkadot } from '@moonbeam-network/xcm-config';
import { Sdk, TransferData } from '@moonbeam-network/xcm-sdk';
import { EvmSigner, Sdk, TransferData } from '@moonbeam-network/xcm-sdk';
import { Keyring } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';
import { ethers } from 'ethers';
import { setTimeout } from 'node:timers/promises';

import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { moonbeam as moonbeamViem } from 'viem/chains';
// Moonbeam Signer ===========================================================

const moonbeamPrivateKey = '';
const provider = new ethers.WebSocketProvider(moonbeam.ws, {
const moonbeamPrivateKey = '0x...';
const provider = new ethers.WebSocketProvider(moonbeam.ws[0], {
chainId: moonbeam.id,
name: moonbeam.name,
});
const evmSigner = new ethers.Wallet(moonbeamPrivateKey, provider);

// Using ethers
// *****WARNING: IN THE UPCOMING VERSION OF THIS SDK, ethers SUPPORT WILL BE REMOVED, PLEASE SWITCH TO viem WHEN POSSIBLE
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const ethersSigner = new ethers.Wallet(moonbeamPrivateKey, provider);

// Using viem
const account = privateKeyToAccount(moonbeamPrivateKey);
const viemSigner = createWalletClient({
account,
chain: moonbeamViem,
transport: http('https://rpc.api.moonbeam.network'),
});

// ethers
// const evmSigner: EvmSigner = ethersSigner
// const address = ethersSigner.address
// viem
const evmSigner: EvmSigner = viemSigner;
const { address } = account;

// Polkadot Signer ===========================================================

Expand Down Expand Up @@ -65,7 +86,7 @@ export async function fromPolkadot() {
console.log('\nTransfer from Polkadot to Moonbeam\n');

const data = await Sdk().getTransferData({
destinationAddress: evmSigner.address,
destinationAddress: address,
destinationKeyOrChain: moonbeam,
keyOrAsset: dot,
polkadotSigner: pair,
Expand Down Expand Up @@ -93,7 +114,7 @@ export async function fromMoonbeam() {
.asset(dot)
.source(moonbeam)
.destination(polkadot)
.accounts(evmSigner.address, pair.address, {
.accounts(address, pair.address, {
evmSigner,
});

Expand All @@ -114,7 +135,7 @@ async function main() {
console.warn = () => null;
console.clear();

console.log(`\nMoonbeam address: ${evmSigner.address}.`);
console.log(`\nMoonbeam address: ${address}.`);
console.log(`Polkadot address: ${pair.address}.`);

await fromPolkadot();
Expand Down
4 changes: 2 additions & 2 deletions examples/sdk-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"author": "",
"license": "MIT",
"dependencies": {
"@moonbeam-network/xcm-config": "2.5.9",
"@moonbeam-network/xcm-sdk": "2.5.10",
"@moonbeam-network/xcm-config": "2.5.12",
"@moonbeam-network/xcm-sdk": "2.5.14",
"@moonbeam-network/xcm-utils": "2.1.7"
},
"devDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @moonbeam-network/xcm-builder

## 2.4.7

### Patch Changes

- [#345](https://github.com/moonbeam-foundation/xcm-sdk/pull/345) [`6fe69b2`](https://github.com/moonbeam-foundation/xcm-sdk/commit/6fe69b230b4d44c717d9ec7ff73bbc6282b1385e) Thanks [@mmaurello](https://github.com/mmaurello)! - Add transferAssetsUsingTypeAndThen function to xcmPallet and implement it to relay chains

## 2.4.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-builder",
"version": "2.4.6",
"version": "2.4.7",
"description": "Moonbeam XCM builder",
"scripts": {
"build": "tsup",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum XcmVersion {
v1 = 'V1',
v2 = 'V2',
v3 = 'V3',
v4 = 'V4',
}

export type Parents = 0 | 1;
71 changes: 71 additions & 0 deletions packages/builder/src/extrinsic/pallets/xcmPallet/xcmPallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import {
ExtrinsicConfigBuilder,
Parents,
XcmVersion,
} from '../../ExtrinsicBuilder.interfaces';
import { getExtrinsicAccount } from '../../ExtrinsicBuilder.utils';
import { ExtrinsicConfig } from '../../ExtrinsicConfig';
import { getPolkadotXcmExtrinsicArgs } from '../polkadotXcm/polkadotXcm.util';

Expand Down Expand Up @@ -42,5 +44,74 @@ export function xcmPallet() {
}),
};
},
transferAssetsUsingTypeAndThen: () => {
const func = 'transferAssetsUsingTypeAndThen';

return {
here: (): ExtrinsicConfigBuilder => ({
build: (params) =>
new ExtrinsicConfig({
module: pallet,
func,
getArgs: () => {
const version = XcmVersion.v4;
return [
{
[version]: {
parents: 0,
interior: {
X1: [
{
Parachain: params.destination.parachainId,
},
],
},
},
},
{
[version]: [
{
id: {
parents: 0,
interior: 'Here',
},
fun: {
Fungible: params.amount,
},
},
],
},
'LocalReserve',
{
[version]: {
parents: 0,
interior: 'Here',
},
},
'LocalReserve',
{
[version]: [
{
DepositAsset: {
assets: {
Wild: { AllCounted: 1 },
},
beneficiary: {
parents: 0,
interior: {
X1: [getExtrinsicAccount(params.address)],
},
},
},
},
],
},
'Unlimited',
];
},
}),
}),
};
},
};
}
21 changes: 21 additions & 0 deletions packages/config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# @moonbeam-network/xcm-config

## 2.5.12

### Patch Changes

- [#345](https://github.com/moonbeam-foundation/xcm-sdk/pull/345) [`6fe69b2`](https://github.com/moonbeam-foundation/xcm-sdk/commit/6fe69b230b4d44c717d9ec7ff73bbc6282b1385e) Thanks [@mmaurello](https://github.com/mmaurello)! - Add transferAssetsUsingTypeAndThen function to xcmPallet and implement it to relay chains

- Updated dependencies [[`6fe69b2`](https://github.com/moonbeam-foundation/xcm-sdk/commit/6fe69b230b4d44c717d9ec7ff73bbc6282b1385e)]:
- @moonbeam-network/xcm-builder@2.4.7

## 2.5.11

### Patch Changes

- [#342](https://github.com/moonbeam-foundation/xcm-sdk/pull/342) [`8add299`](https://github.com/moonbeam-foundation/xcm-sdk/commit/8add299dc2edc34a8812c8f846ac314c03caa6d7) Thanks [@mmaurello](https://github.com/mmaurello)! - Remove Litmus configuration

## 2.5.10

### Patch Changes

- [#340](https://github.com/moonbeam-foundation/xcm-sdk/pull/340) [`8747171`](https://github.com/moonbeam-foundation/xcm-sdk/commit/87471713dfda8345a0cbc902fc3d8b28a5e78cee) Thanks [@mmaurello](https://github.com/mmaurello)! - Increase GLMR sent along for fees

## 2.5.9

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-config",
"version": "2.5.9",
"version": "2.5.12",
"description": "All necessary configuration to transfer assets from Moonbeam, Moonriver, Moonbase to other parachains and back",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -49,7 +49,7 @@
"types": "./build/index.d.ts",
"main": "./build/index.cjs",
"dependencies": {
"@moonbeam-network/xcm-builder": "2.4.6",
"@moonbeam-network/xcm-builder": "2.4.7",
"@moonbeam-network/xcm-types": "2.3.4"
},
"peerDependencies": {
Expand Down
18 changes: 0 additions & 18 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,23 +677,6 @@ export const kusamaAssetHub = new Parachain({
],
});

export const litmus = new Parachain({
assetsData: [
{
asset: lit,
id: 'SelfReserve',
},
],
ecosystem: Ecosystem.Kusama,
genesisHash:
'0xda5831fbc8570e3c6336d0d72b8c08f8738beefec812df21ef2afc2982ede09c',
key: 'litmus',
name: 'Litmus',
parachainId: 2106,
ss58Format: 131,
ws: ['wss://rpc.litmus-parachain.litentry.io'],
});

export const mangataKusama = new Parachain({
assetsData: [
{
Expand Down Expand Up @@ -1952,7 +1935,6 @@ export const chainsList: AnyChain[] = [
khala,
kintsugi,
kusama,
litmus,
mangataKusama,
mantaParachain,
moonbaseAlpha,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/configs/alphanetRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const alphanetRelayConfig = new ChainConfig({
},
extrinsic: ExtrinsicBuilder()
.xcmPallet()
.limitedReserveTransferAssets(0)
.transferAssetsUsingTypeAndThen()
.here(),
}),
],
Expand Down
10 changes: 5 additions & 5 deletions packages/config/src/configs/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const hydrationConfig = new ChainConfig({
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: moonbeam,
destinationFee: {
amount: 0.04,
amount: 0.08,
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
Expand All @@ -52,7 +52,7 @@ export const hydrationConfig = new ChainConfig({
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: moonbeam,
destinationFee: {
amount: 0.04,
amount: 0.08,
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
Expand All @@ -67,7 +67,7 @@ export const hydrationConfig = new ChainConfig({
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: moonbeam,
destinationFee: {
amount: 0.04,
amount: 0.08,
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
Expand All @@ -82,7 +82,7 @@ export const hydrationConfig = new ChainConfig({
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: moonbeam,
destinationFee: {
amount: 0.04,
amount: 0.08,
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
Expand All @@ -97,7 +97,7 @@ export const hydrationConfig = new ChainConfig({
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: moonbeam,
destinationFee: {
amount: 0.04,
amount: 0.08,
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
Expand Down
2 changes: 0 additions & 2 deletions packages/config/src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { khalaConfig } from './khala';
import { kintsugiConfig } from './kintsugi';
import { kusamaConfig } from './kusama';
import { kusamaAssetHubConfig } from './kusamaAssetHub';
import { litmusConfig } from './litmus';
import { mangataKusamaConfig } from './mangataKusama';
import { mantaParachainConfig } from './mantaParachain';
import { moonbaseAlphaConfig } from './moonbaseAlpha';
Expand Down Expand Up @@ -70,7 +69,6 @@ export const chainsConfigList: ChainConfig[] = [
khalaConfig,
kintsugiConfig,
kusamaConfig,
litmusConfig,
mangataKusamaConfig,
mantaParachainConfig,
moonbaseAlphaConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/configs/kusama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const kusamaConfig = new ChainConfig({
},
extrinsic: ExtrinsicBuilder()
.xcmPallet()
.limitedReserveTransferAssets(0)
.transferAssetsUsingTypeAndThen()
.here(),
fee: {
asset: ksm,
Expand Down
Loading

0 comments on commit 5ce2d6b

Please sign in to comment.