Skip to content

Commit

Permalink
PINK integration with Moonbeam (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello authored Mar 12, 2024
1 parent c194655 commit 7e24392
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-roses-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moonbeam-network/xcm-config': patch
---

PINK asset configuration
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
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',
];
}
6 changes: 6 additions & 0 deletions packages/config/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ export const pica = new Asset({
originSymbol: 'PICA',
});

export const pink = new Asset({
key: 'pink',
originSymbol: 'PINK',
});

export const ring = new Asset({
key: 'ring',
originSymbol: 'RING',
Expand Down Expand Up @@ -370,6 +375,7 @@ export const assetsList: Asset[] = [
pen,
pha,
pica,
pink,
ring,
rmrk,
sdn,
Expand Down
10 changes: 10 additions & 0 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
pen,
pha,
pica,
pink,
ring,
rmrk,
sdn,
Expand Down Expand Up @@ -919,6 +920,10 @@ export const moonbeam = new EvmParachain({
asset: ztg,
id: '150874409661081770150564009349448205842',
},
{
asset: pink,
id: '64174511183114006009298114091987195453',
},
],
ecosystem: Ecosystem.Polkadot,
genesisHash:
Expand Down Expand Up @@ -1291,6 +1296,11 @@ export const polkadotAssetHub = new Parachain({
id: 1337,
palletInstance: 50,
},
{
asset: pink,
id: 23,
palletInstance: 50,
},
],
ecosystem: Ecosystem.Polkadot,
genesisHash:
Expand Down
16 changes: 16 additions & 0 deletions packages/config/src/configs/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
para,
pen,
pha,
pink,
ring,
sub,
usdc,
Expand Down Expand Up @@ -483,6 +484,21 @@ export const moonbeamConfig = new ChainConfig({
balance: BalanceBuilder().substrate().system().account(),
},
}),
new AssetConfig({
asset: pink,
balance: BalanceBuilder().substrate().assets().account(),
contract: ContractBuilder().Xtokens().transferMultiCurrencies(),
destination: polkadotAssetHub,
destinationFee: {
amount: 0.7,
asset: usdt,
balance: BalanceBuilder().substrate().assets().account(),
},
fee: {
asset: glmr,
balance: BalanceBuilder().substrate().system().account(),
},
}),
new AssetConfig({
asset: hdx,
balance: BalanceBuilder().substrate().assets().account(),
Expand Down
Loading

0 comments on commit 7e24392

Please sign in to comment.