Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AssetConversionApi #5694

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/api-augment/src/substrate/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import '@polkadot/api-base/types/calls';

import type { ApiTypes, AugmentedCall, DecoratedCallBase } from '@polkadot/api-base/types';
import type { Bytes, Null, Option, Result, Vec, u32 } from '@polkadot/types-codec';
import type { Bytes, Null, Option, Result, Vec, bool, u128, u32 } from '@polkadot/types-codec';
import type { AnyNumber, IMethod, ITuple } from '@polkadot/types-codec/types';
import type { MultiAssetId } from '@polkadot/types/interfaces/assetConversion';
import type { TAssetBalance } from '@polkadot/types/interfaces/assets';
import type { BabeEquivocationProof, BabeGenesisConfiguration, Epoch, OpaqueKeyOwnershipProof } from '@polkadot/types/interfaces/babe';
import type { CheckInherentsResult, InherentData } from '@polkadot/types/interfaces/blockbuilder';
Expand Down Expand Up @@ -43,6 +44,25 @@ declare module '@polkadot/api-base/types/calls' {
**/
[key: string]: DecoratedCallBase<ApiType>;
};
/** 0x8a8047a53a8277ec/1 */
assetConversionApi: {
/**
* Get pool reserves
**/
getReserves: AugmentedCall<ApiType, (asset1: MultiAssetId | { Native: any } | { Asset: any } | string | Uint8Array, asset2: MultiAssetId | { Native: any } | { Asset: any } | string | Uint8Array) => Observable<Option<ITuple<[Balance, Balance]>>>>;
/**
* Quote price: exact tokens for tokens
**/
quotePriceExactTokensForTokens: AugmentedCall<ApiType, (asset1: MultiAssetId | { Native: any } | { Asset: any } | string | Uint8Array, asset2: MultiAssetId | { Native: any } | { Asset: any } | string | Uint8Array, amount: u128 | AnyNumber | Uint8Array, include_fee: bool | boolean | Uint8Array) => Observable<Option<Balance>>>;
/**
* Quote price: tokens for exact tokens
**/
quotePriceTokensForExactTokens: AugmentedCall<ApiType, (asset1: MultiAssetId | { Native: any } | { Asset: any } | string | Uint8Array, asset2: MultiAssetId | { Native: any } | { Asset: any } | string | Uint8Array, amount: u128 | AnyNumber | Uint8Array, include_fee: bool | boolean | Uint8Array) => Observable<Option<Balance>>>;
/**
* Generic call
**/
[key: string]: DecoratedCallBase<ApiType>;
};
/** 0x8453b50b22293977/1 */
assetsApi: {
/**
Expand Down
2 changes: 2 additions & 0 deletions packages/types-augment/src/registry/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '@polkadot/types/types/registry';

import type { Data, StorageKey } from '@polkadot/types';
import type { BitVec, Bool, Bytes, F32, F64, I128, I16, I256, I32, I64, I8, ISize, Json, Null, OptionBool, Raw, Text, Type, U128, U16, U256, U32, U64, U8, USize, bool, f32, f64, i128, i16, i256, i32, i64, i8, isize, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types-codec';
import type { MultiAssetId } from '@polkadot/types/interfaces/assetConversion';
import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDestroyWitness, AssetDetails, AssetMetadata, TAssetBalance, TAssetDepositBalance } from '@polkadot/types/interfaces/assets';
import type { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations';
import type { RawAuraPreDigest } from '@polkadot/types/interfaces/aura';
Expand Down Expand Up @@ -684,6 +685,7 @@ declare module '@polkadot/types/types/registry' {
MultiAssetFilter: MultiAssetFilter;
MultiAssetFilterV1: MultiAssetFilterV1;
MultiAssetFilterV2: MultiAssetFilterV2;
MultiAssetId: MultiAssetId;
MultiAssets: MultiAssets;
MultiAssetsV1: MultiAssetsV1;
MultiAssetsV2: MultiAssetsV2;
Expand Down
22 changes: 22 additions & 0 deletions packages/types/src/interfaces/assetConversion/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2017-2023 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0

// order important in structs... :)
/* eslint-disable sort-keys */

import type { Definitions } from '../../types/index.js';

import { runtime } from './runtime.js';

export default {
rpc: {},
runtime,
types: {
MultiAssetId: {
_enum: {
Native: null,
Asset: 'AssetId'
}
}
}
} as Definitions;
4 changes: 4 additions & 0 deletions packages/types/src/interfaces/assetConversion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */

export * from './types.js';
72 changes: 72 additions & 0 deletions packages/types/src/interfaces/assetConversion/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2017-2023 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { DefinitionsCall } from '../../types/index.js';

export const runtime: DefinitionsCall = {
AssetConversionApi: [
{
methods: {
get_reserves: {
description: 'Get pool reserves',
params: [
{
name: 'asset1',
type: 'MultiAssetId'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsidorenko
I think, primary, we use asset-conversion on AssetHubs, so lets make them work at least,
so I would change it here to Box<XcmV3MultiLocation> (please, try it locally, should work),

and then lets solve: https://github.com/paritytech/cumulus/issues/2915
and then lets find solution how to dynamically support: MultiAssetId (substrate node) vs MultiLocation (asset-hub),
because this could require some dynamic loading or some switch for node kind (substrate -> MultiAssetId, asset-hubs -> MultiLocation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried, the Box<XcmV3MultiLocation> works well

},
{
name: 'asset2',
type: 'MultiAssetId'
}
],
type: 'Option<(Balance,Balance)>'
},
quote_price_exact_tokens_for_tokens: {
description: 'Quote price: exact tokens for tokens',
params: [
{
name: 'asset1',
type: 'MultiAssetId'
},
{
name: 'asset2',
type: 'MultiAssetId'
},
{
name: 'amount',
type: 'u128'
},
{
name: 'include_fee',
type: 'bool'
}
],
type: 'Option<(Balance)>'
},
quote_price_tokens_for_exact_tokens: {
description: 'Quote price: tokens for exact tokens',
params: [
{
name: 'asset1',
type: 'MultiAssetId'
},
{
name: 'asset2',
type: 'MultiAssetId'
},
{
name: 'amount',
type: 'u128'
},
{
name: 'include_fee',
type: 'bool'
}
],
type: 'Option<(Balance)>'
}
},
version: 1
}
]
};
15 changes: 15 additions & 0 deletions packages/types/src/interfaces/assetConversion/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */

import type { Enum } from '@polkadot/types-codec';
import type { AssetId } from '@polkadot/types/interfaces/runtime';

/** @name MultiAssetId */
export interface MultiAssetId extends Enum {
readonly isNative: boolean;
readonly isAsset: boolean;
readonly asAsset: AssetId;
readonly type: 'Native' | 'Asset';
}

export type PHANTOM_ASSETCONVERSION = 'assetConversion';
1 change: 1 addition & 0 deletions packages/types/src/interfaces/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export * from './essentials.js';

// substrate types
export { default as assetConversion } from './assetConversion/definitions.js';
export { default as assets } from './assets/definitions.js';
export { default as aura } from './aura/definitions.js';
export { default as authorship } from './authorship/definitions.js';
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/interfaces/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */

export * from './assetConversion/types.js';
export * from './assets/types.js';
export * from './attestations/types.js';
export * from './aura/types.js';
Expand Down