Skip to content

Commit

Permalink
fix parachain methods (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov authored Sep 6, 2023
1 parent 6f33de3 commit b9d3d04
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sora-substrate/api",
"version": "1.21.7",
"version": "1.21.8",
"license": "Apache-2.0",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
Expand All @@ -10,6 +10,6 @@
"dependencies": {
"@open-web3/orml-api-derive": "1.1.4",
"@polkadot/api": "9.14.2",
"@sora-substrate/types": "1.21.7"
"@sora-substrate/types": "1.21.8"
}
}
4 changes: 2 additions & 2 deletions packages/connection/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@sora-substrate/connection",
"version": "1.21.7",
"version": "1.21.8",
"license": "Apache-2.0",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sora-substrate/api": "1.21.7"
"@sora-substrate/api": "1.21.8"
}
}
4 changes: 2 additions & 2 deletions packages/liquidity-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@sora-substrate/liquidity-proxy",
"version": "1.21.7",
"version": "1.21.8",
"license": "Apache-2.0",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sora-substrate/math": "1.21.7"
"@sora-substrate/math": "1.21.8"
}
}
2 changes: 1 addition & 1 deletion packages/math/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sora-substrate/math",
"version": "1.21.7",
"version": "1.21.8",
"license": "Apache-2.0",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/type-definitions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sora-substrate/type-definitions",
"version": "1.21.7",
"version": "1.21.8",
"license": "Apache-2.0",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sora-substrate/types",
"version": "1.21.7",
"version": "1.21.8",
"license": "Apache-2.0",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
Expand All @@ -13,7 +13,7 @@
"@polkadot/api": "9.14.2",
"@polkadot/typegen": "9.14.2",
"@polkadot/types": "9.14.2",
"@sora-substrate/type-definitions": "1.21.7"
"@sora-substrate/type-definitions": "1.21.8"
},
"devDependencies": {
"@types/websocket": "^1.0.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/util/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sora-substrate/util",
"version": "1.21.7",
"version": "1.21.8",
"license": "Apache-2.0",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
Expand All @@ -9,11 +9,11 @@
},
"dependencies": {
"@polkadot/ui-keyring": "2.12.1",
"@sora-substrate/api": "1.21.7",
"@sora-substrate/connection": "1.21.7",
"@sora-substrate/liquidity-proxy": "1.21.7",
"@sora-substrate/math": "1.21.7",
"@sora-substrate/types": "1.21.7",
"@sora-substrate/api": "1.21.8",
"@sora-substrate/connection": "1.21.8",
"@sora-substrate/liquidity-proxy": "1.21.8",
"@sora-substrate/math": "1.21.8",
"@sora-substrate/types": "1.21.8",
"axios": "^0.21.1",
"crypto-js": "^4.0.0",
"lodash": "^4.17.15"
Expand Down
20 changes: 13 additions & 7 deletions packages/util/src/bridgeProxy/sub/parachain.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import type { ApiPromise } from '@polkadot/api';
import type { CodecString } from '@sora-substrate/math';
import type { u32, u128 } from '@polkadot/types';
import type { Option } from '@polkadot/types-codec';
import type { XcmV3MultiLocation } from '@polkadot/types/lookup';

export class SoraParachainApi {
public async getRelayChainBlockNumber(blockHash: string, api: ApiPromise): Promise<number> {
const apiInstanceAtBlock = await api.at(blockHash);
const blockNumber = await apiInstanceAtBlock.query.parachainSystem.lastRelayChainBlockNumber();
const blockNumber = (await apiInstanceAtBlock.query.parachainSystem.lastRelayChainBlockNumber()) as u32;

return Number(blockNumber.toString());
return blockNumber.toNumber();
}

public async getAssetMulilocation(assetId: string, api: ApiPromise) {
const multilocation = await api.query.xcmApp.assetIdToMultilocation(assetId);
public async getAssetMulilocation(assetId: string, api: ApiPromise): Promise<XcmV3MultiLocation | null> {
const multilocation = (await api.query.xcmApp.assetIdToMultilocation(assetId)) as Option<XcmV3MultiLocation>;

return multilocation;
return multilocation.isSome ? multilocation.unwrap() : null;
}

public async getAssetMinimumAmount(assetId: string, api: ApiPromise): Promise<CodecString> {
const multilocation = await this.getAssetMulilocation(assetId, api);
const amount = await api.query.xcmApp.assetMinimumAmount(multilocation);

return amount.toString();
if (!multilocation) return '0';

const amount = (await api.query.xcmApp.assetMinimumAmount(multilocation)) as Option<u128>;

return amount.isSome ? amount.unwrap().toString() : '0';
}
}

0 comments on commit b9d3d04

Please sign in to comment.