From bf0e917e64372b7a9bb7782ff8bc8ea69149bd36 Mon Sep 17 00:00:00 2001 From: mmaurello <93129175+mmaurello@users.noreply.github.com> Date: Wed, 20 Mar 2024 02:03:48 +1300 Subject: [PATCH 1/3] fix Hydra decimals as Options (#220) * fix Hydra decimals as Options * add changeset --- .changeset/rare-bikes-return.md | 5 +++++ .../src/polkadot/PolkadotService.interfaces.ts | 4 ++-- packages/sdk/src/polkadot/PolkadotService.ts | 17 +++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 .changeset/rare-bikes-return.md diff --git a/.changeset/rare-bikes-return.md b/.changeset/rare-bikes-return.md new file mode 100644 index 00000000..e5288dd2 --- /dev/null +++ b/.changeset/rare-bikes-return.md @@ -0,0 +1,5 @@ +--- +'@moonbeam-network/xcm-sdk': patch +--- + +Fix decimal fetching for HydraDX diff --git a/packages/sdk/src/polkadot/PolkadotService.interfaces.ts b/packages/sdk/src/polkadot/PolkadotService.interfaces.ts index f8d5044f..d0e24a1a 100644 --- a/packages/sdk/src/polkadot/PolkadotService.interfaces.ts +++ b/packages/sdk/src/polkadot/PolkadotService.interfaces.ts @@ -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; } diff --git a/packages/sdk/src/polkadot/PolkadotService.ts b/packages/sdk/src/polkadot/PolkadotService.ts index 837f5846..7a1ba476 100644 --- a/packages/sdk/src/polkadot/PolkadotService.ts +++ b/packages/sdk/src/polkadot/PolkadotService.ts @@ -125,9 +125,13 @@ export class PolkadotService { const data = (await fn(asset)) as AssetMetadata | Option; 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(), }; } @@ -149,12 +153,17 @@ export class PolkadotService { async getAssetDecimals(asset: Asset): Promise { 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 { From db146f4c7b2e3018eae91bfb5b80bb8c02861c91 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 20 Mar 2024 02:05:14 +1300 Subject: [PATCH 2/3] Version Packages (#221) Co-authored-by: github-actions[bot] --- .changeset/rare-bikes-return.md | 5 ----- examples/sdk-simple/package.json | 2 +- package-lock.json | 4 ++-- packages/sdk/CHANGELOG.md | 6 ++++++ packages/sdk/package.json | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 .changeset/rare-bikes-return.md diff --git a/.changeset/rare-bikes-return.md b/.changeset/rare-bikes-return.md deleted file mode 100644 index e5288dd2..00000000 --- a/.changeset/rare-bikes-return.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@moonbeam-network/xcm-sdk': patch ---- - -Fix decimal fetching for HydraDX diff --git a/examples/sdk-simple/package.json b/examples/sdk-simple/package.json index 903bc026..78b56341 100644 --- a/examples/sdk-simple/package.json +++ b/examples/sdk-simple/package.json @@ -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": { diff --git a/package-lock.json b/package-lock.json index 6864b04f..480cf20f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,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": { @@ -17300,7 +17300,7 @@ }, "packages/sdk": { "name": "@moonbeam-network/xcm-sdk", - "version": "2.0.5", + "version": "2.0.6", "license": "MIT", "dependencies": { "@moonbeam-network/xcm-builder": "2.0.1", diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index baeed761..026e8963 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -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 diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 21fe625d..09df3836 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -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", From 3ade51ff0ef5acc4a6f84391159d3652cd6ee792 Mon Sep 17 00:00:00 2001 From: mmaurello <93129175+mmaurello@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:10:29 +1300 Subject: [PATCH 3/3] MRL types (#211) * add mrl types to polkadot api * add changeset * update moonbase beta endpoint * export getTransferData.utils functions --- .changeset/new-tools-move.md | 5 +++++ packages/config/src/chains.ts | 2 +- packages/sdk/src/index.ts | 1 + packages/utils/src/polkadot/polkadot.api.ts | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changeset/new-tools-move.md diff --git a/.changeset/new-tools-move.md b/.changeset/new-tools-move.md new file mode 100644 index 00000000..78f246a5 --- /dev/null +++ b/.changeset/new-tools-move.md @@ -0,0 +1,5 @@ +--- +'@moonbeam-network/xcm-utils': patch +--- + +Add MRL types to polkadot API diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index fa22819e..1fe2110c 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -762,7 +762,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({ diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index dc5a19e6..3908c1f7 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -1,3 +1,4 @@ export * from './getTransferData/getSourceData'; +export * from './getTransferData/getTransferData.utils'; export * from './sdk'; export * from './sdk.interfaces'; diff --git a/packages/utils/src/polkadot/polkadot.api.ts b/packages/utils/src/polkadot/polkadot.api.ts index 10a3894e..062244fb 100644 --- a/packages/utils/src/polkadot/polkadot.api.ts +++ b/packages/utils/src/polkadot/polkadot.api.ts @@ -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>({ max: 20, // eslint-disable-next-line sort-keys @@ -20,6 +26,14 @@ export async function getPolkadotApi(ws: string): Promise { ApiPromise.create({ noInitWarn: true, provider: new WsProvider(ws), + types: { + [MRLTypes.XcmRoutingUserAction]: { + destination: MRLTypes.XcmVersionedMultiLocation, + }, + [MRLTypes.VersionedUserAction]: { + _enum: { V1: MRLTypes.XcmRoutingUserAction }, + }, + }, typesBundle, });