Skip to content

Commit

Permalink
Change Astar and Shiden pallet and remove Any input in network type (#…
Browse files Browse the repository at this point in the history
…166)

* change astar and shiden pallet and remove Any input in network type

* update snapshots and add changeset
  • Loading branch information
mmaurello authored Nov 14, 2023
1 parent df29a0b commit e4989bb
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 88 deletions.
7 changes: 7 additions & 0 deletions .changeset/healthy-forks-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moonbeam-network/xcm-builder': patch
'@moonbeam-network/xcm-config': patch
'@moonbeam-network/xcm-sdk': patch
---

Change Astar and Shiden pallet and fix Any keyword error
3 changes: 1 addition & 2 deletions packages/builder/src/extrinsic/ExtrinsicBuilder.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export function getExtrinsicArgumentVersion(
}

export function getExtrinsicAccount(address: string) {
const isEthAddress = address.length === 42;
const isEthAddress = address.length === 42 && address.startsWith('0x');

return isEthAddress
? {
AccountKey20: {
key: address,
network: 'Any',
},
}
: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ exports[`eqBalances transferXcm should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down Expand Up @@ -98,7 +97,6 @@ exports[`eqBalances xcmTransfer should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ exports[`polkadotXcm limitedReserveTransferAssets here should get correct argume
"X1": {
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
},
Expand Down Expand Up @@ -144,7 +143,6 @@ exports[`polkadotXcm limitedReserveTransferAssets x1 should get correct argument
"X1": {
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
},
Expand Down Expand Up @@ -202,7 +200,6 @@ exports[`polkadotXcm limitedReserveTransferAssets x2 should get correct argument
"X1": {
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
},
Expand Down Expand Up @@ -328,7 +325,6 @@ exports[`polkadotXcm limitedReserveWithdrawAssets x2 should get correct argument
"X1": {
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exports[`xTokens transfer should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down Expand Up @@ -128,7 +127,6 @@ exports[`xTokens transferMultiAsset x1 should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down Expand Up @@ -183,7 +181,6 @@ exports[`xTokens transferMultiAsset x2 should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down Expand Up @@ -271,7 +268,6 @@ exports[`xTokens transferMultiCurrencies x2 should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down
91 changes: 34 additions & 57 deletions packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ import {
ExtrinsicConfigBuilder,
XcmVersion,
} from '../../ExtrinsicBuilder.interfaces';
import {
getExtrinsicAccount,
getExtrinsicArgumentVersion,
} from '../../ExtrinsicBuilder.utils';
import { getExtrinsicArgumentVersion } from '../../ExtrinsicBuilder.utils';
import { ExtrinsicConfig } from '../../ExtrinsicConfig';
import { getWeight } from './xTokens.utils';
import { getDestination, getWeight } from './xTokens.utils';

const pallet = 'xTokens';

Expand All @@ -25,19 +22,7 @@ export function xTokens() {
return [
asset,
amount,
{
[version]: {
parents: 1,
interior: {
X2: [
{
Parachain: destination.parachainId,
},
getExtrinsicAccount(address),
],
},
},
},
getDestination(version, address, destination),
getWeight(source.weight, func),
];
},
Expand All @@ -47,6 +32,34 @@ export function xTokens() {
const funcName = 'transferMultiasset';

return {
here: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, destination }) =>
new ExtrinsicConfig({
module: pallet,
func: funcName,
getArgs: (func) => {
const version = getExtrinsicArgumentVersion(func, 1);

return [
{
[version]: {
id: {
Concrete: {
parents: 0,
interior: 'Here',
},
},
fun: {
Fungible: amount,
},
},
},
getDestination(version, address, destination),
'Unlimited',
];
},
}),
}),
X1: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, destination }) =>
new ExtrinsicConfig({
Expand All @@ -73,19 +86,7 @@ export function xTokens() {
},
},
},
{
[version]: {
parents: 1,
interior: {
X2: [
{
Parachain: destination.parachainId,
},
getExtrinsicAccount(address),
],
},
},
},
getDestination(version, address, destination),
'Unlimited',
];
},
Expand Down Expand Up @@ -122,19 +123,7 @@ export function xTokens() {
},
},
},
{
[version]: {
parents: 1,
interior: {
X2: [
{
Parachain: destination.parachainId,
},
getExtrinsicAccount(address),
],
},
},
},
getDestination(version, address, destination),
getWeight(source.weight, func),
];
},
Expand All @@ -153,19 +142,7 @@ export function xTokens() {
[feeAsset, fee],
],
1,
{
[XcmVersion.v3]: {
parents: 1,
interior: {
X2: [
{
Parachain: destination.parachainId,
},
getExtrinsicAccount(address),
],
},
},
},
getDestination(XcmVersion.v3, address, destination),
'Unlimited',
],
}),
Expand Down
24 changes: 24 additions & 0 deletions packages/builder/src/extrinsic/pallets/xTokens/xTokens.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AnyChain } from '@moonbeam-network/xcm-types';
import { SubmittableExtrinsicFunction } from '@polkadot/api/types';
import { XcmVersion } from '../../ExtrinsicBuilder.interfaces';
import { getExtrinsicAccount } from '../../ExtrinsicBuilder.utils';
import { XTokensWeightLimit } from './xTokens.interfaces';

/**
Expand Down Expand Up @@ -27,3 +30,24 @@ export function getWeight(

return weight;
}

export function getDestination(
version: XcmVersion,
address: string,
destination: AnyChain,
) {
return {
[version]: {
parents: 1,
// eslint-disable-next-line sort-keys
interior: {
X2: [
{
Parachain: destination.parachainId,
},
getExtrinsicAccount(address),
],
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ exports[`xTransfer transfer here should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down Expand Up @@ -139,7 +138,6 @@ exports[`xTransfer transfer x2 should get correct arguments 1`] = `
{
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ exports[`xcmPallet limitedReserveTransferAssets should get correct arguments 1`]
"X1": {
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
"network": "Any",
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export const astar = new Parachain({
{
asset: glmr,
id: 18446744073709551619n,
palletInstance: 10,
},
// NOTE: no meta for native token
{
Expand Down Expand Up @@ -1242,7 +1241,6 @@ export const shiden = new Parachain({
{
asset: movr,
id: 18446744073709551620n,
palletInstance: 10,
},
// NOTE: no meta for native token
{
Expand All @@ -1257,7 +1255,7 @@ export const shiden = new Parachain({
name: 'Shiden',
parachainId: 2007,
ss58Format: 5,
ws: 'wss://rpc.shiden.astar.network',
ws: 'wss://shiden-rpc.dwellir.com',
});

export const turing = new Parachain({
Expand Down
9 changes: 3 additions & 6 deletions packages/config/src/configs/astar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const astarConfig = new ChainConfig({
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.limitedReserveTransferAssets()
.xTokens()
.transferMultiAsset(astar.parachainId)
.here(),
}),
new AssetConfig({
Expand All @@ -33,10 +33,7 @@ export const astarConfig = new ChainConfig({
asset: glmr,
balance: BalanceBuilder().substrate().assets().account(),
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.limitedReserveTransferAssets()
.X2(),
extrinsic: ExtrinsicBuilder().xTokens().transfer(),
fee: {
asset: astr,
balance: BalanceBuilder().substrate().system().account(),
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/configs/khala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const khalaConfig = new ChainConfig({
balance: BalanceBuilder().substrate().assets().account(),
destination: moonriver,
destinationFee: {
amount: 0.0001,
amount: 0.001,
asset: movr,
balance: BalanceBuilder().substrate().assets().account(),
},
Expand Down
9 changes: 3 additions & 6 deletions packages/config/src/configs/shiden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const shidenConfig = new ChainConfig({
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.limitedReserveTransferAssets()
.xTokens()
.transferMultiAsset(shiden.parachainId)
.here(),
}),
new AssetConfig({
Expand All @@ -33,10 +33,7 @@ export const shidenConfig = new ChainConfig({
asset: movr,
balance: BalanceBuilder().substrate().assets().account(),
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.limitedReserveWithdrawAssets()
.X2(),
extrinsic: ExtrinsicBuilder().xTokens().transfer(),
fee: {
asset: sdn,
balance: BalanceBuilder().substrate().system().account(),
Expand Down

0 comments on commit e4989bb

Please sign in to comment.