diff --git a/.changeset/healthy-carrots-teach.md b/.changeset/healthy-carrots-teach.md new file mode 100644 index 00000000..3e905670 --- /dev/null +++ b/.changeset/healthy-carrots-teach.md @@ -0,0 +1,7 @@ +--- +'@moonbeam-network/xcm-builder': patch +'@moonbeam-network/xcm-config': patch +'@moonbeam-network/xcm-sdk': patch +--- + +STINK integration with Moonbeam diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts index 34b4d36e..62c6ecfc 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts @@ -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'; @@ -73,7 +76,7 @@ export function polkadotXcm() { getArgs: (extrinsicFunction) => { const isAssetDifferent = !!params.feeAsset && params.asset !== params.feeAsset; - const asset = [ + const assets = [ { id: { Concrete: { @@ -96,8 +99,11 @@ export function polkadotXcm() { }, ]; + const shouldFeeAssetPrecede = + shouldFeeAssetPrecedeAsset(params); + if (isAssetDifferent) { - asset.push({ + const feeAsset = { id: { Concrete: { parents: 0, @@ -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, }); }, }), diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts index e5ebea18..044fc1c1 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts @@ -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; +} diff --git a/packages/config/src/assets.ts b/packages/config/src/assets.ts index e2967242..9d2fc1a6 100644 --- a/packages/config/src/assets.ts +++ b/packages/config/src/assets.ts @@ -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', @@ -421,6 +426,7 @@ export const assetsList: Asset[] = [ rmrk, sdn, soon, + stink, sub, teer, tnkr, diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 27cf7ad3..6ee03ae0 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -55,6 +55,7 @@ import { ring, rmrk, sdn, + stink, sub, teer, tnkr, @@ -1062,6 +1063,10 @@ export const moonbeam = new EvmParachain({ asset: pink, id: '64174511183114006009298114091987195453', }, + { + asset: stink, + id: '112679793397406599376365943185137098326', + }, ], ecosystem: Ecosystem.Polkadot, genesisHash: @@ -1685,6 +1690,11 @@ export const polkadotAssetHub = new Parachain({ id: 23, palletInstance: 50, }, + { + asset: stink, + id: 42069, + palletInstance: 50, + }, ], ecosystem: Ecosystem.Polkadot, genesisHash: diff --git a/packages/config/src/configs/moonbeam.ts b/packages/config/src/configs/moonbeam.ts index fb9e5ccb..06a47137 100644 --- a/packages/config/src/configs/moonbeam.ts +++ b/packages/config/src/configs/moonbeam.ts @@ -26,6 +26,7 @@ import { pha, pink, ring, + stink, sub, usdc, usdcwh, @@ -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(), diff --git a/packages/config/src/configs/polkadotAssetHub.ts b/packages/config/src/configs/polkadotAssetHub.ts index 2afe08fa..ecedd597 100644 --- a/packages/config/src/configs/polkadotAssetHub.ts +++ b/packages/config/src/configs/polkadotAssetHub.ts @@ -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'; @@ -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, });