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
// Copyright 2021 Centrifuge Foundation (centrifuge.io).
//
// This file is part of the Centrifuge chain project.
// Centrifuge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version (see http://www.gnu.org/licenses).
// Centrifuge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

use cfg_types::pools::PoolNav;
use pallet_pool_system::{
	tranches::{TrancheIndex, TrancheLoc, TrancheSolution},
	EpochSolution,
};
use parity_scale_codec::Codec;
use sp_api::decl_runtime_apis;
use sp_runtime::traits::Get;
use sp_std::vec::Vec;

decl_runtime_apis! {
	/// Runtime for pallet-pool-system.
	///
	/// Note: The runtime api is pallet specific, while the RPC methods
	///       are more focused on domain-specific logic
	pub trait PoolsApi<PoolId, TrancheId, Balance, Currency, BalanceRatio, MaxTranches>
	where
		PoolId: Codec,
		TrancheId: Codec,
		Balance: Codec,
		Currency: Codec,
		BalanceRatio: Codec,
		MaxTranches: Codec + Get<u32>,
	{
		fn currency(pool_id: PoolId) -> Option<Currency>;

		fn inspect_epoch_solution(pool_id: PoolId, solution: Vec<TrancheSolution>) -> Option<EpochSolution<Balance, MaxTranches>>;

		fn tranche_token_price(pool_id: PoolId, tranche: TrancheLoc<TrancheId>) -> Option<BalanceRatio>;

		fn tranche_token_prices(pool_id: PoolId) -> Option<Vec<BalanceRatio>>;

		fn tranche_ids(pool_id: PoolId) -> Option<Vec<TrancheId>>;

		fn tranche_id(pool_id: PoolId, tranche_index: TrancheIndex) -> Option<TrancheId>;

		fn tranche_currency(pool_id: PoolId, tranche_loc: TrancheLoc<TrancheId>) -> Option<Currency>;

		fn nav(pool_id: PoolId) -> Option<PoolNav<Balance>>;
	}
}