Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STINK integration with Moonbeam #266

Merged
merged 7 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/healthy-carrots-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
---

STINK integration with Moonbeam
24 changes: 18 additions & 6 deletions packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable sort-keys */
import { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces';
import { ExtrinsicConfig } from '../../ExtrinsicConfig';
import { getPolkadotXcmExtrinsicArgs } from './polkadotXcm.util';
import {
getPolkadotXcmExtrinsicArgs,
shouldFeeAssetPrecedeAsset,
} from './polkadotXcm.util';

const pallet = 'polkadotXcm';

Expand Down Expand Up @@ -73,7 +76,7 @@ export function polkadotXcm() {
getArgs: (extrinsicFunction) => {
const isAssetDifferent =
!!params.feeAsset && params.asset !== params.feeAsset;
const asset = [
const assets = [
{
id: {
Concrete: {
Expand All @@ -96,8 +99,11 @@ export function polkadotXcm() {
},
];

const shouldFeeAssetPrecede =
shouldFeeAssetPrecedeAsset(params);

if (isAssetDifferent) {
asset.push({
const feeAsset = {
id: {
Concrete: {
parents: 0,
Expand All @@ -116,14 +122,20 @@ export function polkadotXcm() {
fun: {
Fungible: params.fee,
},
});
};

if (shouldFeeAssetPrecede) {
assets.unshift(feeAsset);
} else {
assets.push(feeAsset);
}
}

return getPolkadotXcmExtrinsicArgs({
...params,
func: extrinsicFunction,
asset,
feeIndex: isAssetDifferent ? 1 : 0,
asset: assets,
feeIndex: isAssetDifferent && !shouldFeeAssetPrecede ? 1 : 0,
});
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ export function getPolkadotXcmExtrinsicArgs({
'Unlimited',
];
}

export function shouldFeeAssetPrecedeAsset({
asset,
feeAsset,
}: ExtrinsicConfigBuilderPrams): boolean {
const assetIdNumber = Number(asset);
const feeAssetIdNumber = Number(feeAsset);

if (Number.isNaN(assetIdNumber) || Number.isNaN(feeAssetIdNumber)) {
return false;
}

return assetIdNumber > feeAssetIdNumber;
}
6 changes: 6 additions & 0 deletions packages/config/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ export const soon = new Asset({
originSymbol: 'SOON',
});

export const stink = new Asset({
key: 'stink',
originSymbol: 'STINK',
});

export const sub = new Asset({
key: 'sub',
originSymbol: 'SUB',
Expand Down Expand Up @@ -421,6 +426,7 @@ export const assetsList: Asset[] = [
rmrk,
sdn,
soon,
stink,
sub,
teer,
tnkr,
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 @@ -55,6 +55,7 @@ import {
ring,
rmrk,
sdn,
stink,
sub,
teer,
tnkr,
Expand Down Expand Up @@ -1062,6 +1063,10 @@ export const moonbeam = new EvmParachain({
asset: pink,
id: '64174511183114006009298114091987195453',
},
{
asset: stink,
id: '112679793397406599376365943185137098326',
},
],
ecosystem: Ecosystem.Polkadot,
genesisHash:
Expand Down Expand Up @@ -1685,6 +1690,11 @@ export const polkadotAssetHub = new Parachain({
id: 23,
palletInstance: 50,
},
{
asset: stink,
id: 42069,
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 @@ -26,6 +26,7 @@ import {
pha,
pink,
ring,
stink,
sub,
usdc,
usdcwh,
Expand Down Expand Up @@ -519,6 +520,21 @@ export const moonbeamConfig = new ChainConfig({
balance: BalanceBuilder().substrate().system().account(),
},
}),
new AssetConfig({
asset: stink,
balance: BalanceBuilder().substrate().assets().account(),
contract: ContractBuilder().Xtokens().transferMultiCurrencies(),
destination: polkadotAssetHub,
destinationFee: {
amount: 0.2,
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
22 changes: 21 additions & 1 deletion packages/config/src/configs/polkadotAssetHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ExtrinsicBuilder,
FeeBuilder,
} from '@moonbeam-network/xcm-builder';
import { ded, dot, pink, usdc, usdt } from '../assets';
import { ded, dot, pink, stink, usdc, usdt } from '../assets';
import { moonbeam, polkadotAssetHub } from '../chains';
import { AssetConfig } from '../types/AssetConfig';
import { ChainConfig } from '../types/ChainConfig';
Expand Down Expand Up @@ -93,6 +93,26 @@ export const polkadotAssetHubConfig = new ChainConfig({
},
min: AssetMinBuilder().assets().asset(),
}),
new AssetConfig({
asset: stink,
balance: BalanceBuilder().substrate().assets().account(),
destination: moonbeam,
destinationFee: {
amount: 0.03,
asset: usdt,
balance: BalanceBuilder().substrate().assets().account(),
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.limitedReserveTransferAssets()
.X2(),
fee: {
asset: dot,
balance: BalanceBuilder().substrate().system().account(),
xcmDeliveryFeeAmount,
},
min: AssetMinBuilder().assets().asset(),
}),
],
chain: polkadotAssetHub,
});
Loading