Skip to content

Commit

Permalink
Remove externalId & origin from Asset, use location instead
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Nov 27, 2024
1 parent 52a77d4 commit 84d3a30
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Requirements

- [Node.js](https://nodejs.org/) (**version 18 or higher**)
- [Node.js](https://nodejs.org/) (**version 20 or higher**)

## Local development

Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Collection of SDK(s) crafted to ease Hydration & Basilisk chains integration.

## Project Structure

| Package | Version | Changelog | Description |
|:----------------------|:--------------------|:-----------------------|:-----------------------|
| [`@galacticcouncil/sdk`](./packages/sdk) | [![version](https://img.shields.io/npm/v/@galacticcouncil/sdk.svg)](https://www.npmjs.com/package/@galacticcouncil/sdk) | [changelog](./packages/sdk/CHANGELOG.md) | Trade router & pool utilities
| [`@galacticcouncil/xcm-core`](./packages/xcm-core) | [![version](https://img.shields.io/npm/v/@galacticcouncil/xcm-core.svg)](https://www.npmjs.com/package/@galacticcouncil/xcm-core) | [changelog](./packages/xcm-core/CHANGELOG.md) | Cross-chain definitions & types
| [`@galacticcouncil/xcm-cfg`](./packages/xcm-cfg) | [![version](https://img.shields.io/npm/v/@galacticcouncil/xcm-cfg.svg)](https://www.npmjs.com/package/@galacticcouncil/xcm-cfg) | [changelog](./packages/xcm-cfg/CHANGELOG.md) | Cross-chain routes & configs
| [`@galacticcouncil/xcm-sdk`](./packages/xcm-sdk) | [![version](https://img.shields.io/npm/v/@galacticcouncil/xcm-sdk.svg)](https://www.npmjs.com/package/@galacticcouncil/xcm-sdk) | [changelog](./packages/xcm-sdk/CHANGELOG.md) | Cross-chain transfer sdk
| [`@galacticcouncil/math-ema`](./packages/math-ema) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-ema.svg)](https://www.npmjs.com/package/@galacticcouncil/math-ema) | [changelog](./packages/math-ema/CHANGELOG.md) | EMA math
| [`@galacticcouncil/math-lbp`](./packages/math-lbp) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-lbp.svg)](https://www.npmjs.com/package/@galacticcouncil/math-lbp) | [changelog](./packages/math-lbp/CHANGELOG.md) | LBP math
| [`@galacticcouncil/math-liquidity-mining`](./packages/math-liquidity-mining) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-liquidity-mining.svg)](https://www.npmjs.com/package/@galacticcouncil/math-liquidity-mining) | [changelog](./packages/math-liquidity-mining/CHANGELOG.md) | Liquidity mining math
| [`@galacticcouncil/math-omnipool`](./packages/math-omnipool) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-omnipool.svg)](https://www.npmjs.com/package/@galacticcouncil/math-omnipool) | [changelog](./packages/math-omnipool/CHANGELOG.md) | Omnipool math
| [`@galacticcouncil/math-stableswap`](./packages/math-stableswap) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-stableswap.svg)](https://www.npmjs.com/package/@galacticcouncil/math-stableswap) | [changelog](./packages/math-stableswap/CHANGELOG.md) | Stableswap math
| [`@galacticcouncil/math-staking`](./packages/math-staking) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-staking.svg)](https://www.npmjs.com/package/@galacticcouncil/math-staking) | [changelog](./packages/math-staking/CHANGELOG.md) | Staking math
| [`@galacticcouncil/math-xyk`](./packages/math-xyk) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-xyk.svg)](https://www.npmjs.com/package/@galacticcouncil/math-xyk) | [changelog](./packages/math-xyk/CHANGELOG.md) | XYK math
| Package | Version | Changelog | Description |
| :--------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------- | :------------------------------ |
| [`@galacticcouncil/sdk`](./packages/sdk) | [![version](https://img.shields.io/npm/v/@galacticcouncil/sdk.svg)](https://www.npmjs.com/package/@galacticcouncil/sdk) | [changelog](./packages/sdk/CHANGELOG.md) | Trade router & pool utilities |
| [`@galacticcouncil/xcm-core`](./packages/xcm-core) | [![version](https://img.shields.io/npm/v/@galacticcouncil/xcm-core.svg)](https://www.npmjs.com/package/@galacticcouncil/xcm-core) | [changelog](./packages/xcm-core/CHANGELOG.md) | Cross-chain definitions & types |
| [`@galacticcouncil/xcm-cfg`](./packages/xcm-cfg) | [![version](https://img.shields.io/npm/v/@galacticcouncil/xcm-cfg.svg)](https://www.npmjs.com/package/@galacticcouncil/xcm-cfg) | [changelog](./packages/xcm-cfg/CHANGELOG.md) | Cross-chain route configs |
| [`@galacticcouncil/xcm-sdk`](./packages/xcm-sdk) | [![version](https://img.shields.io/npm/v/@galacticcouncil/xcm-sdk.svg)](https://www.npmjs.com/package/@galacticcouncil/xcm-sdk) | [changelog](./packages/xcm-sdk/CHANGELOG.md) | Cross-chain transfer sdk |
| [`@galacticcouncil/math-ema`](./packages/math-ema) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-ema.svg)](https://www.npmjs.com/package/@galacticcouncil/math-ema) | [changelog](./packages/math-ema/CHANGELOG.md) | EMA math |
| [`@galacticcouncil/math-lbp`](./packages/math-lbp) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-lbp.svg)](https://www.npmjs.com/package/@galacticcouncil/math-lbp) | [changelog](./packages/math-lbp/CHANGELOG.md) | LBP math |
| [`@galacticcouncil/math-liquidity-mining`](./packages/math-liquidity-mining) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-liquidity-mining.svg)](https://www.npmjs.com/package/@galacticcouncil/math-liquidity-mining) | [changelog](./packages/math-liquidity-mining/CHANGELOG.md) | Liquidity mining math |
| [`@galacticcouncil/math-omnipool`](./packages/math-omnipool) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-omnipool.svg)](https://www.npmjs.com/package/@galacticcouncil/math-omnipool) | [changelog](./packages/math-omnipool/CHANGELOG.md) | Omnipool math |
| [`@galacticcouncil/math-stableswap`](./packages/math-stableswap) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-stableswap.svg)](https://www.npmjs.com/package/@galacticcouncil/math-stableswap) | [changelog](./packages/math-stableswap/CHANGELOG.md) | Stableswap math |
| [`@galacticcouncil/math-staking`](./packages/math-staking) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-staking.svg)](https://www.npmjs.com/package/@galacticcouncil/math-staking) | [changelog](./packages/math-staking/CHANGELOG.md) | Staking math |
| [`@galacticcouncil/math-xyk`](./packages/math-xyk) | [![version](https://img.shields.io/npm/v/@galacticcouncil/math-xyk.svg)](https://www.npmjs.com/package/@galacticcouncil/math-xyk) | [changelog](./packages/math-xyk/CHANGELOG.md) | XYK math |

## Contributing

Expand All @@ -29,6 +29,7 @@ Everything about building, setting up development environment & releasing can be
In case of unexpected sdk behaviour, please create well-written issue [here](https://github.com/galacticcouncil/sdk/issues/new). It makes it easier to find & fix the problem accordingly.

## Legal

<pre>
This file is part of https://github.com/galacticcouncil/*

Expand Down Expand Up @@ -58,4 +59,5 @@ This file is part of https://github.com/galacticcouncil/*
$$ $$$$$ $$$$$ $$ $$$$
$$$
</pre>

For more details read [LICENSE.md](LICENSE.md)
10 changes: 5 additions & 5 deletions examples/xcm-transfer/src/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ export function configureExternal(
) {
external.forEach((ext) => {
if (ext.origin === 1000 && !defaultExternals.includes(ext.id)) {
const assetData = toAssetData(ext, '_ah_');
console.log('Registering ' + assetData.asset.key);
const assetData = toAssetData(ext);
console.log('💀 Registering ' + assetData.asset.key);
configService.addExternalHubRoute(assetData);
}
});
}

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

Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/api/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ export class Router {
type: t.type,
isSufficient: t.isSufficient,
existentialDeposit: t.existentialDeposit,
origin: t.origin,
meta: t.meta,
externalId: t.externalId,
isWhiteListed: t.isWhiteListed,
} as Asset;
})
Expand Down
21 changes: 1 addition & 20 deletions packages/sdk/src/client/AssetClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Option, StorageKey } from '@polkadot/types';
import { ApiPromise } from '@polkadot/api';
import { SYSTEM_ASSET_ID } from '../consts';
import { Asset, AssetMetadata, Bond, ExternalAsset } from '../types';
import { findNestedKey } from '../utils/json';

import { PolkadotApiClient } from './PolkadotApi';

Expand Down Expand Up @@ -149,8 +148,6 @@ export class AssetClient extends PolkadotApiClient {

const { name, assetType, isSufficient, existentialDeposit } = details;
const { symbol, decimals } = metadata.get(tokenKey) ?? {};
const origin = this.parseLocation('parachain', location);
const pendulumId = 2094;
return {
id: tokenKey,
name: name.toHuman(),
Expand All @@ -159,11 +156,7 @@ export class AssetClient extends PolkadotApiClient {
icon: symbol,
type: assetType.toHuman(),
isSufficient: isSufficient ? isSufficient.toHuman() : true,
origin,
externalId: this.parseLocation(
pendulumId === origin ? 'generalKey' : 'generalIndex',
location
),
location: location?.toJSON(),
existentialDeposit: existentialDeposit.toString(),
} as Asset;
}
Expand Down Expand Up @@ -345,16 +338,4 @@ export class AssetClient extends PolkadotApiClient {
const type = details.assetType.toString();
return this.SUPPORTED_TYPES.includes(type);
}

private parseLocation(
key: string,
location?: HydradxRuntimeXcmAssetLocation
): any | undefined {
if (location) {
const entry = findNestedKey(location.toJSON(), key);
return entry && entry[key];
} else {
return undefined;
}
}
}
3 changes: 1 addition & 2 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ export interface Asset extends AssetMetadata {
type: string;
existentialDeposit: string;
isSufficient: boolean;
origin?: number;
externalId?: number;
location?: any;
meta?: Record<string, string>;
isWhiteListed?: boolean;
}
Expand Down

0 comments on commit 84d3a30

Please sign in to comment.