Skip to content

Commit

Permalink
Merge branch 'main' into mjm/mrl-types
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello authored Mar 20, 2024
2 parents f4e0363 + db146f4 commit 5fd6f17
Show file tree
Hide file tree
Showing 25 changed files with 595 additions and 255 deletions.
6 changes: 3 additions & 3 deletions examples/sdk-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"author": "",
"license": "MIT",
"dependencies": {
"@moonbeam-network/xcm-config": "2.0.2",
"@moonbeam-network/xcm-sdk": "2.0.2",
"@moonbeam-network/xcm-utils": "2.0.0"
"@moonbeam-network/xcm-config": "2.0.4",
"@moonbeam-network/xcm-sdk": "2.0.6",
"@moonbeam-network/xcm-utils": "2.0.1"
},
"devDependencies": {
"bun": "^1.0.21"
Expand Down
401 changes: 216 additions & 185 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@
"@changesets/cli": "^2.27.1",
"@slack/webhook": "^7.0.2",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"bun": "^1.0.21",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^5.1.3",
"ethers": "^6.11.0",
"glob": "^10.3.10",
"husky": "^9.0.10",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"turbo": "^1.12.3",
"typescript": "^5.3.3",
"tsup": "^8.0.2",
"turbo": "^1.12.5",
"typescript": "^5.4.2",
"viem": "^2.7.8"
},
"lint-staged": {
Expand Down
10 changes: 10 additions & 0 deletions packages/builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @moonbeam-network/xcm-builder

## 2.0.1

### Patch Changes

- [#214](https://github.com/moonbeam-foundation/xcm-sdk/pull/214) [`c5b5d890ddcbc199108328ff535e9a63e58becd4`](https://github.com/moonbeam-foundation/xcm-sdk/commit/c5b5d890ddcbc199108328ff535e9a63e58becd4) Thanks [@Rihyx](https://github.com/Rihyx)! - Update dev dependencies

- Updated dependencies [[`c5b5d890ddcbc199108328ff535e9a63e58becd4`](https://github.com/moonbeam-foundation/xcm-sdk/commit/c5b5d890ddcbc199108328ff535e9a63e58becd4)]:
- @moonbeam-network/xcm-types@2.0.1
- @moonbeam-network/xcm-utils@2.0.1

## 2.0.0

### Major Changes
Expand Down
11 changes: 11 additions & 0 deletions packages/builder/fixtures/builderParamsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export const buildParamsMock: ExtrinsicConfigBuilderPrams = {
source: alphanetAssetHubMock,
};

export const buildParamsSameAssetMock: ExtrinsicConfigBuilderPrams = {
address: '0xeF46c7649270C912704fB09B75097f6E32208b85',
amount: 99_000_000_000n,
asset: 'USDT',
destination: moonbaseAlphaMock,
fee: 5_000_000_000n,
feeAsset: 'USDT',
palletInstance: 10,
source: alphanetAssetHubMock,
};

export const buildParachainParamsMock: ExtrinsicConfigBuilderPrams = {
address: 'wd84XqsQ4LVzhmTBVd4s5ApGt9sBnnk8K7Q5PhBwwhxwqgm1u',
amount: 99_000_000_000n,
Expand Down
6 changes: 3 additions & 3 deletions 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.0.0",
"version": "2.0.1",
"description": "Moonbeam XCM builder",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -50,8 +50,8 @@
"types": "./build/index.d.ts",
"main": "./build/index.cjs",
"dependencies": {
"@moonbeam-network/xcm-types": "2.0.0",
"@moonbeam-network/xcm-utils": "2.0.0",
"@moonbeam-network/xcm-types": "2.0.1",
"@moonbeam-network/xcm-utils": "2.0.1",
"big.js": "^6.2.1",
"type-fest": "^3.8.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,29 @@ exports[`polkadotXcm limitedReserveTransferAssets parachain should get correct a
},
},
},
{
"fun": {
"Fungible": 5000000000n,
},
"id": {
"Concrete": {
"interior": {
"X2": [
{
"PalletInstance": 10,
},
{
"GeneralIndex": "RMRK",
},
],
},
"parents": 0,
},
},
},
],
},
0,
1,
"Unlimited",
]
`;
Expand Down Expand Up @@ -173,7 +193,89 @@ exports[`polkadotXcm limitedReserveTransferAssets x1 should get correct argument
]
`;

exports[`polkadotXcm limitedReserveTransferAssets x2 should be correct config 1`] = `
exports[`polkadotXcm limitedReserveTransferAssets x2 different assets should be correct config 1`] = `
ExtrinsicConfig {
"func": "limitedReserveTransferAssets",
"getArgs": [Function],
"module": "polkadotXcm",
"type": "Substrate",
}
`;

exports[`polkadotXcm limitedReserveTransferAssets x2 different assets should get correct arguments 1`] = `
[
{
"V1": {
"interior": {
"X1": {
"Parachain": 1000,
},
},
"parents": 1,
},
},
{
"V1": {
"interior": {
"X1": {
"AccountKey20": {
"key": "0xeF46c7649270C912704fB09B75097f6E32208b85",
},
},
},
"parents": 0,
},
},
{
"V1": [
{
"fun": {
"Fungible": 99000000000n,
},
"id": {
"Concrete": {
"interior": {
"X2": [
{
"PalletInstance": 10,
},
{
"GeneralIndex": "USDT",
},
],
},
"parents": 0,
},
},
},
{
"fun": {
"Fungible": 5000000000n,
},
"id": {
"Concrete": {
"interior": {
"X2": [
{
"PalletInstance": 10,
},
{
"GeneralIndex": "RMRK",
},
],
},
"parents": 0,
},
},
},
],
},
1,
"Unlimited",
]
`;

exports[`polkadotXcm limitedReserveTransferAssets x2 the same asset should be correct config 1`] = `
ExtrinsicConfig {
"func": "limitedReserveTransferAssets",
"getArgs": [Function],
Expand All @@ -182,7 +284,7 @@ ExtrinsicConfig {
}
`;

exports[`polkadotXcm limitedReserveTransferAssets x2 should get correct arguments 1`] = `
exports[`polkadotXcm limitedReserveTransferAssets x2 the same asset should get correct arguments 1`] = `
[
{
"V1": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
buildParachainParamsMock,
buildParamsMock,
buildParamsSameAssetMock,
} from '../../../../fixtures';
import { polkadotXcm } from './polkadotXcm';

Expand Down Expand Up @@ -37,17 +38,34 @@ describe('polkadotXcm', () => {
});

describe('x2', () => {
const extrinsic = polkadotXcm()
.limitedReserveTransferAssets()
.X2()
.build(buildParamsMock);

it('should be correct config', () => {
expect(extrinsic).toMatchSnapshot();
describe('the same asset', () => {
const extrinsic = polkadotXcm()
.limitedReserveTransferAssets()
.X2()
.build(buildParamsSameAssetMock);

it('should be correct config', () => {
expect(extrinsic).toMatchSnapshot();
});

it('should get correct arguments', () => {
expect(extrinsic.getArgs()).toMatchSnapshot();
});
});

it('should get correct arguments', () => {
expect(extrinsic.getArgs()).toMatchSnapshot();
describe('different assets', () => {
const extrinsic = polkadotXcm()
.limitedReserveTransferAssets()
.X2()
.build(buildParamsMock);

it('should be correct config', () => {
expect(extrinsic).toMatchSnapshot();
});

it('should get correct arguments', () => {
expect(extrinsic.getArgs()).toMatchSnapshot();
});
});
});

Expand Down
75 changes: 52 additions & 23 deletions packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,62 @@ export function polkadotXcm() {
new ExtrinsicConfig({
module: pallet,
func,
getArgs: (extrinsicFunction) =>
getPolkadotXcmExtrinsicArgs({
...params,
func: extrinsicFunction,
asset: [
{
id: {
Concrete: {
parents: 0,
interior: {
X2: [
{
PalletInstance: params.palletInstance,
},
{
GeneralIndex: params.asset,
},
],
},
getArgs: (extrinsicFunction) => {
const isAssetDifferent =
!!params.feeAsset && params.asset !== params.feeAsset;
const asset = [
{
id: {
Concrete: {
parents: 0,
interior: {
X2: [
{
PalletInstance: params.palletInstance,
},
{
GeneralIndex: params.asset,
},
],
},
},
fun: {
Fungible: params.amount,
},
fun: {
Fungible: params.amount,
},
},
];

if (isAssetDifferent) {
asset.push({
id: {
Concrete: {
parents: 0,
interior: {
X2: [
{
PalletInstance: params.palletInstance,
},
{
GeneralIndex: params.feeAsset,
},
],
},
},
},
],
}),
fun: {
Fungible: params.fee,
},
});
}

return getPolkadotXcmExtrinsicArgs({
...params,
func: extrinsicFunction,
asset,
feeIndex: isAssetDifferent ? 1 : 0,
});
},
}),
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface GetExtrinsicParams extends ExtrinsicConfigBuilderPrams {
asset: any;
func?: SubmittableExtrinsicFunction<'promise'>;
parents?: Parents;
feeIndex?: number;
}

export function getPolkadotXcmExtrinsicArgs({
Expand All @@ -21,6 +22,7 @@ export function getPolkadotXcmExtrinsicArgs({
destination,
func,
parents = 1,
feeIndex = 0,
}: GetExtrinsicParams): any[] {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const version = getExtrinsicArgumentVersion(func);
Expand All @@ -47,7 +49,7 @@ export function getPolkadotXcmExtrinsicArgs({
{
[version]: asset,
},
0,
feeIndex,
'Unlimited',
];
}
Loading

0 comments on commit 5fd6f17

Please sign in to comment.