Skip to content

Commit

Permalink
fix externals config
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Dec 11, 2024
1 parent 67b5290 commit f65c72d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 14 deletions.
58 changes: 51 additions & 7 deletions examples/xcm-transfer/src/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ export function configureExternal(
) {
external.forEach((ext) => {
if (ext.origin === 1000 && !defaultExternals.includes(ext.id)) {
const assetData = toAssetData(ext);
console.log('💀 Registering ' + assetData.asset.key);
configService.addExternalHubRoute(assetData);
const hubAsset = toHubAsset(ext);
const parachainAsset = toParachainAsset(ext);

console.log('💀 Registering ' + hubAsset.asset.key);
configService.addExternalHubRoute(hubAsset, parachainAsset);
}
});
}

function toAssetData(external: ExternalAsset): ChainAssetData {
const { decimals, id, internalId, origin, symbol } = external;
function toHubAsset(external: ExternalAsset): ChainAssetData {
const { decimals, id, origin, symbol } = external;
const key = symbol.toLowerCase();
const asset = new Asset({
key: [key, origin, id].join('_'),
Expand All @@ -106,9 +108,51 @@ function toAssetData(external: ExternalAsset): ChainAssetData {

return {
asset: asset,
balanceId: internalId,
decimals: decimals,
id: id,
palletInstance: 50,
xcmLocation: {
parents: 0,
interior: {
X2: [
{
PalletInstance: 50,
},
{
GeneralIndex: id,
},
],
},
},
} as ChainAssetData;
}

function toParachainAsset(external: ExternalAsset): ChainAssetData {
const { decimals, id, internalId, origin, symbol } = external;
const key = symbol.toLowerCase();
const asset = new Asset({
key: [key, origin, id].join('_'),
originSymbol: symbol,
});

return {
asset: asset,
decimals: decimals,
id: internalId,
xcmLocation: {
parents: 1,
interior: {
X3: [
{
Parachain: origin,
},
{
PalletInstance: 50,
},
{
GeneralIndex: id,
},
],
},
},
} as ChainAssetData;
}
18 changes: 11 additions & 7 deletions packages/xcm-cfg/src/configs/HydrationConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import { toHydrationExtTemplate } from './polkadot/assethub/templates';
import { toHubExtTemplate } from './polkadot/hydration/templates';

export class HydrationConfigService extends ConfigService {
addExternalHubRoute(external: ChainAssetData) {
addExternalHubRoute(
hubAsset: ChainAssetData,
parachainAsset: ChainAssetData
) {
const { asset } = hubAsset;

const assethub = this.getChain('assethub');
const hydration = this.getChain('hydration');
const { balanceId, ...base } = external;

assethub.updateAsset(base);
hydration.updateAsset(external);
assethub.updateAsset(hubAsset);
hydration.updateAsset(parachainAsset);

this.updateAsset(external.asset);
this.updateChainRoute(assethub, toHydrationExtTemplate(external.asset));
this.updateChainRoute(hydration, toHubExtTemplate(external.asset));
this.updateAsset(asset);
this.updateChainRoute(assethub, toHydrationExtTemplate(asset));
this.updateChainRoute(hydration, toHubExtTemplate(asset));
}
}

0 comments on commit f65c72d

Please sign in to comment.