diff --git a/Cargo.lock b/Cargo.lock index 526afab5eb..acf75f305b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3559,6 +3559,7 @@ dependencies = [ "module-redeem-rpc-runtime-api", "module-refund-rpc-runtime-api", "module-replace-rpc-runtime-api", + "module-reward-rpc-runtime-api", "module-vault-registry-rpc-runtime-api", "pallet-transaction-payment-rpc", "parity-scale-codec", @@ -3631,6 +3632,7 @@ dependencies = [ "module-redeem-rpc", "module-refund-rpc", "module-replace-rpc", + "module-reward-rpc", "module-vault-registry-rpc", "pallet-transaction-payment-rpc", "sc-consensus-manual-seal", @@ -3676,6 +3678,7 @@ dependencies = [ "module-redeem-rpc-runtime-api", "module-refund-rpc-runtime-api", "module-replace-rpc-runtime-api", + "module-reward-rpc-runtime-api", "module-vault-registry-rpc-runtime-api", "nomination", "oracle", @@ -3812,6 +3815,7 @@ dependencies = [ "module-redeem-rpc-runtime-api", "module-refund-rpc-runtime-api", "module-replace-rpc-runtime-api", + "module-reward-rpc-runtime-api", "module-vault-registry-rpc-runtime-api", "nomination", "oracle", @@ -4166,6 +4170,7 @@ dependencies = [ "module-redeem-rpc-runtime-api", "module-refund-rpc-runtime-api", "module-replace-rpc-runtime-api", + "module-reward-rpc-runtime-api", "module-vault-registry-rpc-runtime-api", "nomination", "oracle", @@ -5530,6 +5535,29 @@ dependencies = [ "sp-std", ] +[[package]] +name = "module-reward-rpc" +version = "0.3.0" +dependencies = [ + "jsonrpsee", + "module-oracle-rpc-runtime-api", + "module-reward-rpc-runtime-api", + "parity-scale-codec", + "sp-api", + "sp-blockchain", + "sp-runtime", +] + +[[package]] +name = "module-reward-rpc-runtime-api" +version = "0.3.0" +dependencies = [ + "frame-support", + "module-oracle-rpc-runtime-api", + "parity-scale-codec", + "sp-api", +] + [[package]] name = "module-vault-registry-rpc" version = "0.3.0" @@ -12340,6 +12368,7 @@ dependencies = [ "module-redeem-rpc-runtime-api", "module-refund-rpc-runtime-api", "module-replace-rpc-runtime-api", + "module-reward-rpc-runtime-api", "module-vault-registry-rpc-runtime-api", "nomination", "oracle", @@ -12439,6 +12468,7 @@ dependencies = [ "module-redeem-rpc-runtime-api", "module-refund-rpc-runtime-api", "module-replace-rpc-runtime-api", + "module-reward-rpc-runtime-api", "module-vault-registry-rpc-runtime-api", "nomination", "oracle", diff --git a/crates/reward/rpc/Cargo.toml b/crates/reward/rpc/Cargo.toml new file mode 100644 index 0000000000..2c42512fd4 --- /dev/null +++ b/crates/reward/rpc/Cargo.toml @@ -0,0 +1,16 @@ +[package] +authors = ["Interlay Ltd"] +edition = "2021" +name = "module-reward-rpc" +version = '0.3.0' + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0" } +jsonrpsee = { version = "0.13.0", features = ["server", "macros"] } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" } +module-reward-rpc-runtime-api = { path = "runtime-api" } + +[dependencies.module-oracle-rpc-runtime-api] +path = '../../oracle/rpc/runtime-api' diff --git a/crates/reward/rpc/runtime-api/Cargo.toml b/crates/reward/rpc/runtime-api/Cargo.toml new file mode 100644 index 0000000000..a066814825 --- /dev/null +++ b/crates/reward/rpc/runtime-api/Cargo.toml @@ -0,0 +1,23 @@ +[package] +authors = ["Interlay Ltd"] +edition = "2021" +name = "module-reward-rpc-runtime-api" +version = '0.3.0' + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false } + +[dependencies.module-oracle-rpc-runtime-api] +default-features = false +path = '../../../oracle/rpc/runtime-api' + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "sp-api/std", + "module-oracle-rpc-runtime-api/std", +] diff --git a/crates/reward/rpc/runtime-api/src/lib.rs b/crates/reward/rpc/runtime-api/src/lib.rs new file mode 100644 index 0000000000..fe76818e7d --- /dev/null +++ b/crates/reward/rpc/runtime-api/src/lib.rs @@ -0,0 +1,22 @@ +//! Runtime API definition for the Reward Module. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::Codec; +use frame_support::dispatch::DispatchError; +use module_oracle_rpc_runtime_api::BalanceWrapper; + +sp_api::decl_runtime_apis! { + pub trait RewardApi where + AccountId: Codec, + VaultId: Codec, + CurrencyId: Codec, + Balance: Codec + { + /// Get a given user's rewards due + fn compute_escrow_reward(account_id: AccountId, currency_id: CurrencyId) -> Result, DispatchError>; + + /// Get a given vault's rewards due + fn compute_vault_reward(vault_id: VaultId, currency_id: CurrencyId) -> Result, DispatchError>; + } +} diff --git a/crates/reward/rpc/src/lib.rs b/crates/reward/rpc/src/lib.rs new file mode 100644 index 0000000000..22684beca8 --- /dev/null +++ b/crates/reward/rpc/src/lib.rs @@ -0,0 +1,117 @@ +//! RPC interface for the Reward Module. + +use codec::Codec; +use jsonrpsee::{ + core::{async_trait, Error as JsonRpseeError, RpcResult}, + proc_macros::rpc, + types::error::{CallError, ErrorCode, ErrorObject}, +}; +use module_oracle_rpc_runtime_api::BalanceWrapper; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_runtime::{ + generic::BlockId, + traits::{Block as BlockT, MaybeDisplay, MaybeFromStr}, + DispatchError, +}; +use std::sync::Arc; + +pub use module_reward_rpc_runtime_api::RewardApi as RewardRuntimeApi; + +#[rpc(client, server)] +pub trait RewardApi +where + Balance: Codec + MaybeDisplay + MaybeFromStr, + AccountId: Codec, + VaultId: Codec, + CurrencyId: Codec, +{ + #[method(name = "reward_computeEscrowReward")] + fn compute_escrow_reward( + &self, + account_id: AccountId, + currency_id: CurrencyId, + at: Option, + ) -> RpcResult>; + + #[method(name = "reward_computeVaultReward")] + fn compute_vault_reward( + &self, + vault_id: VaultId, + currency_id: CurrencyId, + at: Option, + ) -> RpcResult>; +} + +fn internal_err(message: T) -> JsonRpseeError { + JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( + ErrorCode::InternalError.code(), + message.to_string(), + None::<()>, + ))) +} + +/// A struct that implements the [`RewardApi`]. +pub struct Reward { + client: Arc, + _marker: std::marker::PhantomData, +} + +impl Reward { + /// Create new `Reward` with the given reference to the client. + pub fn new(client: Arc) -> Self { + Reward { + client, + _marker: Default::default(), + } + } +} + +fn handle_response(result: Result, E>, msg: String) -> RpcResult { + result + .map_err(|err| internal_err(format!("Runtime error: {:?}: {:?}", msg, err)))? + .map_err(|err| internal_err(format!("Execution error: {:?}: {:?}", msg, err))) +} + +#[async_trait] +impl + RewardApiServer<::Hash, AccountId, VaultId, CurrencyId, Balance> for Reward +where + Block: BlockT, + C: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, + C::Api: RewardRuntimeApi, + AccountId: Codec, + VaultId: Codec, + CurrencyId: Codec, + Balance: Codec + MaybeDisplay + MaybeFromStr, +{ + fn compute_escrow_reward( + &self, + account_id: AccountId, + currency_id: CurrencyId, + at: Option<::Hash>, + ) -> RpcResult> { + let api = self.client.runtime_api(); + let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + + handle_response( + api.compute_escrow_reward(&at, account_id, currency_id), + "Unable to obtain the current reward".into(), + ) + } + + fn compute_vault_reward( + &self, + vault_id: VaultId, + currency_id: CurrencyId, + at: Option<::Hash>, + ) -> RpcResult> { + let api = self.client.runtime_api(); + let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + + handle_response( + api.compute_vault_reward(&at, vault_id, currency_id), + "Unable to obtain the current reward".into(), + ) + } +} diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml index f9abc16ee0..c6306b383f 100644 --- a/parachain/Cargo.toml +++ b/parachain/Cargo.toml @@ -38,6 +38,7 @@ module-btc-relay-rpc-runtime-api = { path = "../crates/btc-relay/rpc/runtime-api module-oracle-rpc-runtime-api = { path = "../crates/oracle/rpc/runtime-api" } module-vault-registry-rpc-runtime-api = { path = "../crates/vault-registry/rpc/runtime-api" } module-escrow-rpc-runtime-api = { path = "../crates/escrow/rpc/runtime-api" } +module-reward-rpc-runtime-api = { path = "../crates/reward/rpc/runtime-api" } module-issue-rpc-runtime-api = { path = "../crates/issue/rpc/runtime-api" } module-redeem-rpc-runtime-api = { path = "../crates/redeem/rpc/runtime-api" } module-replace-rpc-runtime-api = { path = "../crates/replace/rpc/runtime-api" } diff --git a/parachain/runtime/interlay/Cargo.toml b/parachain/runtime/interlay/Cargo.toml index d73b4003be..2756fb5776 100644 --- a/parachain/runtime/interlay/Cargo.toml +++ b/parachain/runtime/interlay/Cargo.toml @@ -100,6 +100,7 @@ module-btc-relay-rpc-runtime-api = { path = "../../../crates/btc-relay/rpc/runti module-oracle-rpc-runtime-api = { path = "../../../crates/oracle/rpc/runtime-api", default-features = false } module-vault-registry-rpc-runtime-api = { path = "../../../crates/vault-registry/rpc/runtime-api", default-features = false } module-escrow-rpc-runtime-api = { path = "../../../crates/escrow/rpc/runtime-api", default-features = false } +module-reward-rpc-runtime-api = { path = "../../../crates/reward/rpc/runtime-api", default-features = false } module-issue-rpc-runtime-api = { path = "../../../crates/issue/rpc/runtime-api", default-features = false } module-redeem-rpc-runtime-api = { path = "../../../crates/redeem/rpc/runtime-api", default-features = false } module-replace-rpc-runtime-api = { path = "../../../crates/replace/rpc/runtime-api", default-features = false } @@ -213,6 +214,7 @@ std = [ "module-oracle-rpc-runtime-api/std", "module-vault-registry-rpc-runtime-api/std", "module-escrow-rpc-runtime-api/std", + "module-reward-rpc-runtime-api/std", "module-issue-rpc-runtime-api/std", "module-redeem-rpc-runtime-api/std", "module-replace-rpc-runtime-api/std", diff --git a/parachain/runtime/interlay/src/lib.rs b/parachain/runtime/interlay/src/lib.rs index 52dda71696..2c46f26d9c 100644 --- a/parachain/runtime/interlay/src/lib.rs +++ b/parachain/runtime/interlay/src/lib.rs @@ -1417,6 +1417,26 @@ impl_runtime_apis! { } } + impl module_reward_rpc_runtime_api::RewardApi< + Block, + AccountId, + VaultId, + CurrencyId, + Balance + > for Runtime { + fn compute_escrow_reward(account_id: AccountId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&account_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + + fn compute_vault_reward(vault_id: VaultId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&vault_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + } + impl module_issue_rpc_runtime_api::IssueApi< Block, AccountId, diff --git a/parachain/runtime/kintsugi/Cargo.toml b/parachain/runtime/kintsugi/Cargo.toml index ceb9271935..77db2b2140 100644 --- a/parachain/runtime/kintsugi/Cargo.toml +++ b/parachain/runtime/kintsugi/Cargo.toml @@ -100,6 +100,7 @@ module-btc-relay-rpc-runtime-api = { path = "../../../crates/btc-relay/rpc/runti module-oracle-rpc-runtime-api = { path = "../../../crates/oracle/rpc/runtime-api", default-features = false } module-vault-registry-rpc-runtime-api = { path = "../../../crates/vault-registry/rpc/runtime-api", default-features = false } module-escrow-rpc-runtime-api = { path = "../../../crates/escrow/rpc/runtime-api", default-features = false } +module-reward-rpc-runtime-api = { path = "../../../crates/reward/rpc/runtime-api", default-features = false } module-issue-rpc-runtime-api = { path = "../../../crates/issue/rpc/runtime-api", default-features = false } module-redeem-rpc-runtime-api = { path = "../../../crates/redeem/rpc/runtime-api", default-features = false } module-replace-rpc-runtime-api = { path = "../../../crates/replace/rpc/runtime-api", default-features = false } @@ -217,6 +218,7 @@ std = [ "module-oracle-rpc-runtime-api/std", "module-vault-registry-rpc-runtime-api/std", "module-escrow-rpc-runtime-api/std", + "module-reward-rpc-runtime-api/std", "module-issue-rpc-runtime-api/std", "module-redeem-rpc-runtime-api/std", "module-replace-rpc-runtime-api/std", diff --git a/parachain/runtime/kintsugi/src/lib.rs b/parachain/runtime/kintsugi/src/lib.rs index ace72a9e35..3ae9aa7782 100644 --- a/parachain/runtime/kintsugi/src/lib.rs +++ b/parachain/runtime/kintsugi/src/lib.rs @@ -1515,6 +1515,26 @@ impl_runtime_apis! { } } + impl module_reward_rpc_runtime_api::RewardApi< + Block, + AccountId, + VaultId, + CurrencyId, + Balance + > for Runtime { + fn compute_escrow_reward(account_id: AccountId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&account_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + + fn compute_vault_reward(vault_id: VaultId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&vault_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + } + impl module_issue_rpc_runtime_api::IssueApi< Block, AccountId, diff --git a/parachain/runtime/testnet-interlay/Cargo.toml b/parachain/runtime/testnet-interlay/Cargo.toml index a5db2d6eec..2d07120254 100644 --- a/parachain/runtime/testnet-interlay/Cargo.toml +++ b/parachain/runtime/testnet-interlay/Cargo.toml @@ -101,6 +101,7 @@ module-btc-relay-rpc-runtime-api = { path = "../../../crates/btc-relay/rpc/runti module-oracle-rpc-runtime-api = { path = "../../../crates/oracle/rpc/runtime-api", default-features = false } module-vault-registry-rpc-runtime-api = { path = "../../../crates/vault-registry/rpc/runtime-api", default-features = false } module-escrow-rpc-runtime-api = { path = "../../../crates/escrow/rpc/runtime-api", default-features = false } +module-reward-rpc-runtime-api = { path = "../../../crates/reward/rpc/runtime-api", default-features = false } module-issue-rpc-runtime-api = { path = "../../../crates/issue/rpc/runtime-api", default-features = false } module-redeem-rpc-runtime-api = { path = "../../../crates/redeem/rpc/runtime-api", default-features = false } module-replace-rpc-runtime-api = { path = "../../../crates/replace/rpc/runtime-api", default-features = false } @@ -218,6 +219,7 @@ std = [ "module-oracle-rpc-runtime-api/std", "module-vault-registry-rpc-runtime-api/std", "module-escrow-rpc-runtime-api/std", + "module-reward-rpc-runtime-api/std", "module-issue-rpc-runtime-api/std", "module-redeem-rpc-runtime-api/std", "module-replace-rpc-runtime-api/std", diff --git a/parachain/runtime/testnet-interlay/src/lib.rs b/parachain/runtime/testnet-interlay/src/lib.rs index 3642c7bd10..3d45aefab6 100644 --- a/parachain/runtime/testnet-interlay/src/lib.rs +++ b/parachain/runtime/testnet-interlay/src/lib.rs @@ -1389,6 +1389,27 @@ impl_runtime_apis! { } } + impl module_reward_rpc_runtime_api::RewardApi< + Block, + AccountId, + VaultId, + CurrencyId, + Balance + > for Runtime { + fn compute_escrow_reward(account_id: AccountId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&account_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + + fn compute_vault_reward(vault_id: VaultId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&vault_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + } + + impl module_issue_rpc_runtime_api::IssueApi< Block, AccountId, diff --git a/parachain/runtime/testnet-kintsugi/Cargo.toml b/parachain/runtime/testnet-kintsugi/Cargo.toml index e27cf4ae79..14c283c6b5 100644 --- a/parachain/runtime/testnet-kintsugi/Cargo.toml +++ b/parachain/runtime/testnet-kintsugi/Cargo.toml @@ -101,6 +101,7 @@ module-btc-relay-rpc-runtime-api = { path = "../../../crates/btc-relay/rpc/runti module-oracle-rpc-runtime-api = { path = "../../../crates/oracle/rpc/runtime-api", default-features = false } module-vault-registry-rpc-runtime-api = { path = "../../../crates/vault-registry/rpc/runtime-api", default-features = false } module-escrow-rpc-runtime-api = { path = "../../../crates/escrow/rpc/runtime-api", default-features = false } +module-reward-rpc-runtime-api = { path = "../../../crates/reward/rpc/runtime-api", default-features = false } module-issue-rpc-runtime-api = { path = "../../../crates/issue/rpc/runtime-api", default-features = false } module-redeem-rpc-runtime-api = { path = "../../../crates/redeem/rpc/runtime-api", default-features = false } module-replace-rpc-runtime-api = { path = "../../../crates/replace/rpc/runtime-api", default-features = false } @@ -218,6 +219,7 @@ std = [ "module-oracle-rpc-runtime-api/std", "module-vault-registry-rpc-runtime-api/std", "module-escrow-rpc-runtime-api/std", + "module-reward-rpc-runtime-api/std", "module-issue-rpc-runtime-api/std", "module-redeem-rpc-runtime-api/std", "module-replace-rpc-runtime-api/std", diff --git a/parachain/runtime/testnet-kintsugi/src/lib.rs b/parachain/runtime/testnet-kintsugi/src/lib.rs index 515ec422ea..5f82f5d6a2 100644 --- a/parachain/runtime/testnet-kintsugi/src/lib.rs +++ b/parachain/runtime/testnet-kintsugi/src/lib.rs @@ -1389,6 +1389,26 @@ impl_runtime_apis! { } } + impl module_reward_rpc_runtime_api::RewardApi< + Block, + AccountId, + VaultId, + CurrencyId, + Balance + > for Runtime { + fn compute_escrow_reward(account_id: AccountId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&account_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + + fn compute_vault_reward(vault_id: VaultId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&vault_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + } + impl module_issue_rpc_runtime_api::IssueApi< Block, AccountId, diff --git a/parachain/src/service.rs b/parachain/src/service.rs index 164d9e56da..ae97421e9f 100644 --- a/parachain/src/service.rs +++ b/parachain/src/service.rs @@ -98,7 +98,7 @@ pub trait RuntimeApiCollection: AccountId, H256, refund::RefundRequest, - > + > + module_reward_rpc_runtime_api::RewardApi, CurrencyId, Balance> where >::StateBackend: sp_api::StateBackend, { @@ -145,7 +145,7 @@ where AccountId, H256, refund::RefundRequest, - >, + > + module_reward_rpc_runtime_api::RewardApi, CurrencyId, Balance>, >::StateBackend: sp_api::StateBackend, { } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index bc9fedbdd4..27030d25c9 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -17,6 +17,7 @@ module-redeem-rpc = { path = "../crates/redeem/rpc" } module-replace-rpc = { path = "../crates/replace/rpc" } module-refund-rpc = { path = "../crates/refund/rpc" } module-escrow-rpc = { path = "../crates/escrow/rpc" } +module-reward-rpc = { path = "../crates/reward/rpc" } vault-registry = { path = "../crates/vault-registry" } primitives = { package = "interbtc-primitives", path = "../primitives" } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 4f923562c4..83d020cfe9 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -74,6 +74,7 @@ where ReplaceRequest, >, C::Api: module_escrow_rpc::EscrowRuntimeApi, + C::Api: module_reward_rpc::RewardRuntimeApi, CurrencyId, Balance>, C::Api: BlockBuilder, P: TransactionPool + 'static, { @@ -84,6 +85,7 @@ where use module_redeem_rpc::{Redeem, RedeemApiServer}; use module_refund_rpc::{Refund, RefundApiServer}; use module_replace_rpc::{Replace, ReplaceApiServer}; + use module_reward_rpc::{Reward, RewardApiServer}; use module_vault_registry_rpc::{VaultRegistry, VaultRegistryApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer}; @@ -116,6 +118,8 @@ where module.merge(Escrow::new(client.clone()).into_rpc())?; + module.merge(Reward::new(client.clone()).into_rpc())?; + module.merge(Issue::new(client.clone()).into_rpc())?; module.merge(Redeem::new(client.clone()).into_rpc())?; diff --git a/standalone/runtime/Cargo.toml b/standalone/runtime/Cargo.toml index f9be9fb00a..857fbb378d 100644 --- a/standalone/runtime/Cargo.toml +++ b/standalone/runtime/Cargo.toml @@ -81,6 +81,7 @@ module-btc-relay-rpc-runtime-api = { path = "../../crates/btc-relay/rpc/runtime- module-oracle-rpc-runtime-api = { path = "../../crates/oracle/rpc/runtime-api", default-features = false } module-vault-registry-rpc-runtime-api = { path = "../../crates/vault-registry/rpc/runtime-api", default-features = false } module-escrow-rpc-runtime-api = { path = "../../crates/escrow/rpc/runtime-api", default-features = false } +module-reward-rpc-runtime-api = { path = "../../crates/reward/rpc/runtime-api", default-features = false } module-issue-rpc-runtime-api = { path = "../../crates/issue/rpc/runtime-api", default-features = false } module-redeem-rpc-runtime-api = { path = "../../crates/redeem/rpc/runtime-api", default-features = false } module-replace-rpc-runtime-api = { path = "../../crates/replace/rpc/runtime-api", default-features = false } @@ -179,6 +180,7 @@ std = [ "module-oracle-rpc-runtime-api/std", "module-vault-registry-rpc-runtime-api/std", "module-escrow-rpc-runtime-api/std", + "module-reward-rpc-runtime-api/std", "module-issue-rpc-runtime-api/std", "module-redeem-rpc-runtime-api/std", "module-replace-rpc-runtime-api/std", diff --git a/standalone/runtime/src/lib.rs b/standalone/runtime/src/lib.rs index 46a6d232c3..7dbe8d2c66 100644 --- a/standalone/runtime/src/lib.rs +++ b/standalone/runtime/src/lib.rs @@ -1357,6 +1357,26 @@ impl_runtime_apis! { } } + impl module_reward_rpc_runtime_api::RewardApi< + Block, + AccountId, + VaultId, + CurrencyId, + Balance + > for Runtime { + fn compute_escrow_reward(account_id: AccountId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&account_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + + fn compute_vault_reward(vault_id: VaultId, currency_id: CurrencyId) -> Result, DispatchError> { + let amount = >::compute_reward(&vault_id, currency_id)?; + let balance = BalanceWrapper:: { amount }; + Ok(balance) + } + } + impl module_issue_rpc_runtime_api::IssueApi< Block, AccountId,