Skip to content

Commit

Permalink
fix external utils (cfg upgrade 6.0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Dec 11, 2024
1 parent 3f7c98c commit 6b1d713
Showing 1 changed file with 58 additions and 15 deletions.
73 changes: 58 additions & 15 deletions packages/apps/src/utils/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,61 @@ const defaultExternals = [
'31337', // WUD
];

export function readExternal(isTestnet: boolean) {
const config = ExternalAssetCursor.deref();

if (config) {
const key = isTestnet ? 'testnet' : 'mainnet';
return config.state.tokens[key];
}
return undefined;
}

export function configureExternal(
isTestnet: boolean,
configService: HydrationConfigService,
) {
readExternal(isTestnet)?.forEach((ext) => {
if (ext.origin === 1000 && !defaultExternals.includes(ext.id)) {
const assetData = buildAssetData(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);
}
});
}

export function readExternal(isTestnet: boolean) {
const config = ExternalAssetCursor.deref();
function toHubAsset(external: ExternalAsset): ChainAssetData {
const { decimals, id, origin, symbol } = external;
const key = symbol.toLowerCase();
const asset = new Asset({
key: [key, origin, id].join('_'),
originSymbol: symbol,
});

if (config) {
const key = isTestnet ? 'testnet' : 'mainnet';
return config.state.tokens[key];
}
return undefined;
return {
asset: asset,
decimals: decimals,
id: id,
xcmLocation: {
parents: 0,
interior: {
X2: [
{
PalletInstance: 50,
},
{
GeneralIndex: id,
},
],
},
},
} as ChainAssetData;
}

export function buildAssetData(external: ExternalAsset): 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('_'),
Expand All @@ -45,9 +74,23 @@ export function buildAssetData(external: ExternalAsset): ChainAssetData {

return {
asset: asset,
balanceId: internalId,
decimals: decimals,
id: id,
palletInstance: 50,
id: internalId,
xcmLocation: {
parents: 1,
interior: {
X3: [
{
Parachain: origin,
},
{
PalletInstance: 50,
},
{
GeneralIndex: id,
},
],
},
},
} as ChainAssetData;
}

0 comments on commit 6b1d713

Please sign in to comment.