1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (C) 2021 Mangata team
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::unnecessary_mut_passed)]
use codec::{Codec, Decode, Encode};
use frame_support::pallet_prelude::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::traits::{MaybeDisplay, MaybeFromStr};
use sp_std::vec::Vec;

#[derive(Eq, PartialEq, Encode, Decode, Default, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub struct RpcAssetMetadata<TokenId> {
	pub token_id: TokenId,
	pub decimals: u32,
	pub name: Vec<u8>,
	pub symbol: Vec<u8>,
}

sp_api::decl_runtime_apis! {
	pub trait XykApi<Balance, TokenId, AccountId> where
		Balance: Codec + MaybeDisplay + MaybeFromStr,
		TokenId: Codec + MaybeDisplay + MaybeFromStr,
		AccountId: Codec + MaybeDisplay + MaybeFromStr,{
		fn calculate_sell_price(
			input_reserve: Balance,
			output_reserve: Balance,
			sell_amount: Balance
		) -> Balance;
		fn calculate_buy_price(
			input_reserve: Balance,
			output_reserve: Balance,
			buy_amount: Balance
		) -> Balance;
		fn calculate_sell_price_id(
			sold_token_id: TokenId,
			bought_token_id: TokenId,
			sell_amount: Balance
		) -> Balance;
		fn calculate_buy_price_id(
			sold_token_id: TokenId,
			bought_token_id: TokenId,
			buy_amount: Balance
		) -> Balance;
		fn get_burn_amount(
			first_asset_id: TokenId,
			second_asset_id: TokenId,
			liquidity_asset_amount: Balance,
		) -> (Balance,Balance);
		fn get_max_instant_burn_amount(
			user: AccountId,
			liquidity_asset_id: TokenId,
		) -> Balance;
		fn get_max_instant_unreserve_amount(
			user: AccountId,
			liquidity_asset_id: TokenId,
		) -> Balance;
		fn calculate_rewards_amount(
			user: AccountId,
			liquidity_asset_id: TokenId,
		) -> Balance;
		fn calculate_balanced_sell_amount(
			total_amount: Balance,
			reserve_amount: Balance,
		) -> Balance;
		fn get_liq_tokens_for_trading(
		) -> Vec<TokenId>;
		fn is_buy_asset_lock_free(
			path: sp_std::vec::Vec<TokenId>,
			input_amount: Balance,
		) -> Option<bool>;
		fn is_sell_asset_lock_free(
			path: sp_std::vec::Vec<TokenId>,
			input_amount: Balance,
		) -> Option<bool>;
		fn get_tradeable_tokens() -> Vec<RpcAssetMetadata<TokenId>>;
	}
}