Skip to content

Commit

Permalink
Merge branch 'main' into riha/get-balance-by-chain-and-token
Browse files Browse the repository at this point in the history
  • Loading branch information
Rihyx authored Mar 20, 2024
2 parents b547687 + 3ade51f commit 72e4b37
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-tools-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moonbeam-network/xcm-utils': patch
---

Add MRL types to polkadot API
2 changes: 1 addition & 1 deletion examples/sdk-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "MIT",
"dependencies": {
"@moonbeam-network/xcm-config": "2.0.4",
"@moonbeam-network/xcm-sdk": "2.0.5",
"@moonbeam-network/xcm-sdk": "2.0.6",
"@moonbeam-network/xcm-utils": "2.0.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ export const moonbaseBeta = new EvmParachain({
parachainId: 888,
rpc: 'https://frag-moonbase-beta-rpc.g.moonbase.moonbeam.network',
ss58Format: 1287,
ws: 'wss://frag-moonbase-beta-rpc-ws.g.moonbase.moonbeam.network',
ws: 'wss://deo-moon-rpc-1-moonbase-beta-rpc-1.moonbase.ol-infra.network',
});

export const moonbeam = new EvmParachain({
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @moonbeam-network/xcm-sdk

## 2.0.6

### Patch Changes

- [#220](https://github.com/moonbeam-foundation/xcm-sdk/pull/220) [`bf0e917e64372b7a9bb7782ff8bc8ea69149bd36`](https://github.com/moonbeam-foundation/xcm-sdk/commit/bf0e917e64372b7a9bb7782ff8bc8ea69149bd36) Thanks [@mmaurello](https://github.com/mmaurello)! - Fix decimal fetching for HydraDX

## 2.0.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-sdk",
"version": "2.0.5",
"version": "2.0.6",
"description": "The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem",
"scripts": {
"build": "tsup",
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './getTransferData/getSourceData';
export * from './getTransferData/getTransferData.utils';
export * from './sdk';
export * from './sdk.interfaces';
4 changes: 2 additions & 2 deletions packages/sdk/src/polkadot/PolkadotService.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Bytes, Struct, u8 } from '@polkadot/types';
import { Bytes, Option, Struct, u8 } from '@polkadot/types';

export interface AssetMetadata extends Struct {
readonly name: Bytes;
readonly symbol: Bytes;
readonly decimals: u8;
readonly decimals: u8 | Option<u8>;
}
17 changes: 13 additions & 4 deletions packages/sdk/src/polkadot/PolkadotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ export class PolkadotService {

const data = (await fn(asset)) as AssetMetadata | Option<AssetMetadata>;
const unwrapped = 'unwrapOrDefault' in data ? data.unwrapOrDefault() : data;
const decimals =
'unwrapOrDefault' in unwrapped.decimals
? unwrapped.decimals.unwrapOrDefault()
: unwrapped.decimals;

return {
decimals: unwrapped.decimals.toNumber(),
decimals: decimals.toNumber(),
symbol: unwrapped.symbol.toString(),
};
}
Expand All @@ -138,12 +142,17 @@ export class PolkadotService {
async getAssetDecimals(asset: Asset): Promise<number> {
const metaId = this.chain.getMetadataAssetId(asset);

return (
const decimals =
this.chain.getAssetDecimals(asset) ||
(await this.getAssetDecimalsFromQuery(metaId)) ||
(await this.getAssetMeta(metaId))?.decimals ||
this.decimals
);
this.decimals; // TODO remove this and handle it separately only for native assets

if (!decimals) {
throw new Error(`No decimals found for asset ${asset.originSymbol}`);
}

return decimals;
}

async query(config: SubstrateQueryConfig): Promise<bigint> {
Expand Down
14 changes: 14 additions & 0 deletions packages/utils/src/polkadot/polkadot.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
import { typesBundle } from '@polkadot/apps-config';
import LRU from 'lru-cache';

export enum MRLTypes {
XcmVersionedMultiLocation = 'XcmVersionedMultiLocation',
XcmRoutingUserAction = 'XcmRoutingUserAction',
VersionedUserAction = 'VersionedUserAction',
}

const cache = new LRU<string, Promise<ApiPromise>>({
max: 20,
// eslint-disable-next-line sort-keys
Expand All @@ -20,6 +26,14 @@ export async function getPolkadotApi(ws: string): Promise<ApiPromise> {
ApiPromise.create({
noInitWarn: true,
provider: new WsProvider(ws),
types: {
[MRLTypes.XcmRoutingUserAction]: {
destination: MRLTypes.XcmVersionedMultiLocation,
},
[MRLTypes.VersionedUserAction]: {
_enum: { V1: MRLTypes.XcmRoutingUserAction },
},
},
typesBundle,
});

Expand Down

0 comments on commit 72e4b37

Please sign in to comment.