From c1bb63bb29535ade50a55e7d04b730744f0cd155 Mon Sep 17 00:00:00 2001 From: zktony Date: Wed, 13 Dec 2023 12:17:19 +0530 Subject: [PATCH 1/8] Added swap --- Cargo.lock | 28 ++++++++ Cargo.toml | 2 + nodes/mainnet/Cargo.toml | 2 + nodes/mainnet/src/node_rpc.rs | 7 +- rpc/swap/Cargo.toml | 26 ++++++++ rpc/swap/src/lib.rs | 119 ++++++++++++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 rpc/swap/Cargo.toml create mode 100644 rpc/swap/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 0159e58b0..eb21f6d0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8266,6 +8266,7 @@ dependencies = [ "itertools 0.10.5", "jsonrpsee", "node-polkadex-runtime", + "pallet-asset-conversion", "pallet-asset-conversion-tx-payment", "pallet-im-online", "pallet-ocex-lmp", @@ -8325,6 +8326,7 @@ dependencies = [ "structopt", "substrate-build-script-utils 5.0.0", "substrate-frame-rpc-system", + "swap-rpc", "tempfile", "thea", "try-runtime-cli", @@ -13878,6 +13880,32 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" +[[package]] +name = "swap-rpc" +version = "5.4.1" +dependencies = [ + "hash-db", + "jsonrpsee", + "orderbook-primitives", + "pallet-asset-conversion", + "parity-scale-codec", + "parking_lot 0.12.1", + "polkadex-primitives", + "sc-rpc", + "sc-rpc-api", + "serde", + "serde_json", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-offchain", + "sp-rpc", + "sp-runtime", + "sp-trie", + "tokio", + "trie-db", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/Cargo.toml b/Cargo.toml index 7d65144ba..c1f5655ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ members = [ "runtimes/mainnet", "runtimes/parachain", "rpc/assets", + "rpc/swap", "rpc/assets/runtime-api", "pallets/pdex-migration", "pallets/ocex", @@ -69,6 +70,7 @@ default-members = [ "pallets/thea-executor", "pallets/rewards/rpc", "pallets/rewards/rpc/runtime-api", + "rpc/swap" ] [workspace.dependencies] diff --git a/nodes/mainnet/Cargo.toml b/nodes/mainnet/Cargo.toml index 38a70d2ab..1e9a51aeb 100644 --- a/nodes/mainnet/Cargo.toml +++ b/nodes/mainnet/Cargo.toml @@ -34,6 +34,7 @@ polkadex-client = { path = "../../client" } thea = { path = "../../pallets/thea" } pallet-ocex-lmp = { path = "../../pallets/ocex" } +swap-rpc = { path = "../../rpc/swap" } # Substrate dependencies frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } @@ -80,6 +81,7 @@ sc-statement-store = { git = "https://github.com/paritytech/polkadot-sdk", branc sp-statement-store = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sc-network-statement = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } pallet-asset-conversion-tx-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } +pallet-asset-conversion = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } #Primitives polkadex-primitives = { path = "../../primitives/polkadex" } sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } diff --git a/nodes/mainnet/src/node_rpc.rs b/nodes/mainnet/src/node_rpc.rs index fc5086a10..13dc39b6b 100644 --- a/nodes/mainnet/src/node_rpc.rs +++ b/nodes/mainnet/src/node_rpc.rs @@ -37,7 +37,7 @@ use pallet_rewards_rpc::PolkadexRewardsRpc; use grandpa::{ FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState, }; -use polkadex_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index}; +use polkadex_primitives::{AccountId, AssetId, Balance, Block, BlockNumber, Hash, Index}; use rpc_assets::{PolkadexAssetHandlerRpc, PolkadexAssetHandlerRpcApiServer}; use sc_client_api::{AuxStore, BlockchainEvents}; use sc_consensus_babe::BabeWorkerHandle; @@ -48,6 +48,8 @@ pub use sc_rpc_api::DenyUnsafe; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; +use swap_rpc::PolkadexSwapRpc; +use swap_rpc::PolkadexSwapRpcApiServer; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use sp_consensus::SelectChain; use sp_consensus_babe::BabeApi; @@ -122,6 +124,7 @@ where C::Api: rpc_assets::PolkadexAssetHandlerRuntimeApi, C::Api: pallet_rewards_rpc::PolkadexRewardsRuntimeApi, C::Api: pallet_ocex_rpc::PolkadexOcexRuntimeApi, + C::Api: pallet_asset_conversion::AssetConversionApi, C: BlockchainEvents, { use pallet_ocex_rpc::PolkadexOcexRpcApiServer; @@ -177,7 +180,7 @@ where SyncState::new(chain_spec, client.clone(), shared_authority_set, babe_worker_handle)? .into_rpc(), )?; - + io.merge(PolkadexSwapRpc::new(client.clone()).into_rpc())?; // io.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?; io.merge(PolkadexAssetHandlerRpc::new(client.clone()).into_rpc())?; io.merge(PolkadexRewardsRpc::new(client.clone()).into_rpc())?; diff --git a/rpc/swap/Cargo.toml b/rpc/swap/Cargo.toml new file mode 100644 index 000000000..e3d78afae --- /dev/null +++ b/rpc/swap/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "swap-rpc" +version = "5.4.1" +edition = "2021" + +[dependencies] +tokio = { workspace = true } +serde = { workspace = true, default-features = true } +parity-scale-codec = { workspace = true, features = ["derive"] } +jsonrpsee = { workspace = true, features = ["client-core", "server", "macros"] } +sp-rpc = { workspace = true } +sp-blockchain = { workspace = true } +sp-api = { workspace = true } +sp-runtime = { workspace = true } +sp-core = { workspace = true } +orderbook-primitives = { path = "../../primitives/orderbook" } +serde_json = { workspace = true, default-features = true } +polkadex-primitives = { workspace = true } +sc-rpc-api = { workspace = true, default-features = true } +sc-rpc = { workspace = true, default-features = true } +sp-offchain = { workspace = true, default-features = true } +parking_lot = { workspace = true } +pallet-asset-conversion = { workspace = true, default-features = true } +hash-db = { workspace = true } +trie-db = { workspace = true } +sp-trie = { workspace = true } \ No newline at end of file diff --git a/rpc/swap/src/lib.rs b/rpc/swap/src/lib.rs new file mode 100644 index 000000000..40bd2e1d2 --- /dev/null +++ b/rpc/swap/src/lib.rs @@ -0,0 +1,119 @@ +// This file is part of Polkadex. +// +// Copyright (c) 2023 Polkadex oü. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program 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. +// +// This program 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. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! This crate provides an RPC methods for OCEX pallet - balances state and onchain/offchain +//! recovery data. + +use jsonrpsee::{ + core::{async_trait, Error as JsonRpseeError, RpcResult}, + proc_macros::rpc, + tracing::log, + types::error::{CallError, ErrorObject}, +}; +use parity_scale_codec::{Codec, Decode}; +use polkadex_primitives::AssetId; +use sc_rpc_api::DenyUnsafe; +use sp_api::{ApiExt, ProvideRuntimeApi}; +use sp_blockchain::HeaderBackend; +use sp_core::offchain::{storage::OffchainDb, OffchainDbExt, OffchainStorage}; +use sp_runtime::traits::Block as BlockT; +use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter}; +use std::sync::Arc; +pub use pallet_asset_conversion::AssetConversionApi; + +const RUNTIME_ERROR: i32 = 1; +const RETRIES: u8 = 3; + +#[rpc(client, server)] +pub trait PolkadexSwapRpcApi { + #[method(name = "tx_quotePriceExactTokensForTokens")] + async fn quote_price_exact_tokens_for_tokens(&self, at: Option, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult>; + + #[method(name = "tx_quotePriceTokensForExactTokens")] + async fn quote_price_tokens_for_exact_tokens(&self, at: Option, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult>; +} + +/// A structure that represents the Polkadex OCEX pallet RPC, which allows querying +/// individual balances and recovery state data. +/// +/// # Type Parameters +/// +/// * `Client`: The client API used to interact with the Substrate runtime. +/// * `Block`: The block type of the Substrate. +pub struct PolkadexSwapRpc { + /// An `Arc` reference to the client API for accessing runtime functionality. + client: Arc, + /// A marker for the `Block` type parameter, used to ensure the struct + /// is covariant with respect to the block type. + _marker: std::marker::PhantomData, +} + +impl PolkadexSwapRpc { + pub fn new(client: Arc) -> Self { + Self { + client, + _marker: Default::default(), + } + } +} + +#[async_trait] +impl +PolkadexSwapRpcApiServer<::Hash> +for PolkadexSwapRpc + where + Block: BlockT, + Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend, + Client::Api: pallet_asset_conversion::AssetConversionApi< + Block, + u128, + u128, + AssetId>, +{ + + async fn quote_price_exact_tokens_for_tokens(&self, at: Option<::Hash>, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult> { + let mut api = self.client.runtime_api(); + let at = match at { + Some(at) => at, + None => self.client.info().best_hash, + }; + let runtime_api_result = api + .quote_price_exact_tokens_for_tokens(at, asset_id1, asset_id2, amount, include_fee) + .map_err(runtime_error_into_rpc_err)?; + Ok(runtime_api_result) + } + + async fn quote_price_tokens_for_exact_tokens(&self, at: Option<::Hash>, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult> { + let mut api = self.client.runtime_api(); + let at = match at { + Some(at) => at, + None => self.client.info().best_hash, + }; + let runtime_api_result = api + .quote_price_tokens_for_exact_tokens(at, asset_id1, asset_id2, amount, include_fee) + .map_err(runtime_error_into_rpc_err)?; + Ok(runtime_api_result) + } +} + +/// Converts a runtime trap into an RPC error. +fn runtime_error_into_rpc_err(err: impl std::fmt::Debug) -> JsonRpseeError { + log::error!(target:"ocex","runtime rpc error: {:?} ",err); + CallError::Custom(ErrorObject::owned(RUNTIME_ERROR, "Runtime error", Some(format!("{err:?}")))) + .into() +} \ No newline at end of file From 3e5538f461bc139b030affacd50b0e0169d8aeaa Mon Sep 17 00:00:00 2001 From: zktony Date: Thu, 14 Dec 2023 00:52:30 +0530 Subject: [PATCH 2/8] Fixed formatting issues --- Cargo.toml | 2 +- nodes/mainnet/src/node_rpc.rs | 3 +- rpc/swap/Cargo.toml | 2 +- rpc/swap/src/lib.rs | 65 ++++++++++++++++++++++------------- 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c1f5655ad..62ceb599e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ default-members = [ "pallets/thea-executor", "pallets/rewards/rpc", "pallets/rewards/rpc/runtime-api", - "rpc/swap" + "rpc/swap", ] [workspace.dependencies] diff --git a/nodes/mainnet/src/node_rpc.rs b/nodes/mainnet/src/node_rpc.rs index 13dc39b6b..a42c52a94 100644 --- a/nodes/mainnet/src/node_rpc.rs +++ b/nodes/mainnet/src/node_rpc.rs @@ -48,13 +48,12 @@ pub use sc_rpc_api::DenyUnsafe; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; -use swap_rpc::PolkadexSwapRpc; -use swap_rpc::PolkadexSwapRpcApiServer; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use sp_consensus::SelectChain; use sp_consensus_babe::BabeApi; use sp_keystore::KeystorePtr; use std::sync::Arc; +use swap_rpc::{PolkadexSwapRpc, PolkadexSwapRpcApiServer}; /// Extra dependencies for BABE. pub struct BabeDeps { diff --git a/rpc/swap/Cargo.toml b/rpc/swap/Cargo.toml index e3d78afae..5bf34c662 100644 --- a/rpc/swap/Cargo.toml +++ b/rpc/swap/Cargo.toml @@ -23,4 +23,4 @@ parking_lot = { workspace = true } pallet-asset-conversion = { workspace = true, default-features = true } hash-db = { workspace = true } trie-db = { workspace = true } -sp-trie = { workspace = true } \ No newline at end of file +sp-trie = { workspace = true } diff --git a/rpc/swap/src/lib.rs b/rpc/swap/src/lib.rs index 40bd2e1d2..8d0fd268a 100644 --- a/rpc/swap/src/lib.rs +++ b/rpc/swap/src/lib.rs @@ -25,6 +25,8 @@ use jsonrpsee::{ tracing::log, types::error::{CallError, ErrorObject}, }; +pub use pallet_asset_conversion::AssetConversionApi; +use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter}; use parity_scale_codec::{Codec, Decode}; use polkadex_primitives::AssetId; use sc_rpc_api::DenyUnsafe; @@ -32,9 +34,7 @@ use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_blockchain::HeaderBackend; use sp_core::offchain::{storage::OffchainDb, OffchainDbExt, OffchainStorage}; use sp_runtime::traits::Block as BlockT; -use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter}; use std::sync::Arc; -pub use pallet_asset_conversion::AssetConversionApi; const RUNTIME_ERROR: i32 = 1; const RETRIES: u8 = 3; @@ -42,10 +42,24 @@ const RETRIES: u8 = 3; #[rpc(client, server)] pub trait PolkadexSwapRpcApi { #[method(name = "tx_quotePriceExactTokensForTokens")] - async fn quote_price_exact_tokens_for_tokens(&self, at: Option, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult>; + async fn quote_price_exact_tokens_for_tokens( + &self, + at: Option, + asset_id1: AssetId, + asset_id2: AssetId, + amount: u128, + include_fee: bool, + ) -> RpcResult>; #[method(name = "tx_quotePriceTokensForExactTokens")] - async fn quote_price_tokens_for_exact_tokens(&self, at: Option, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult>; + async fn quote_price_tokens_for_exact_tokens( + &self, + at: Option, + asset_id1: AssetId, + asset_id2: AssetId, + amount: u128, + include_fee: bool, + ) -> RpcResult>; } /// A structure that represents the Polkadex OCEX pallet RPC, which allows querying @@ -65,28 +79,26 @@ pub struct PolkadexSwapRpc { impl PolkadexSwapRpc { pub fn new(client: Arc) -> Self { - Self { - client, - _marker: Default::default(), - } + Self { client, _marker: Default::default() } } } #[async_trait] -impl -PolkadexSwapRpcApiServer<::Hash> -for PolkadexSwapRpc - where - Block: BlockT, - Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend, - Client::Api: pallet_asset_conversion::AssetConversionApi< - Block, - u128, - u128, - AssetId>, +impl PolkadexSwapRpcApiServer<::Hash> + for PolkadexSwapRpc +where + Block: BlockT, + Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend, + Client::Api: pallet_asset_conversion::AssetConversionApi, { - - async fn quote_price_exact_tokens_for_tokens(&self, at: Option<::Hash>, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult> { + async fn quote_price_exact_tokens_for_tokens( + &self, + at: Option<::Hash>, + asset_id1: AssetId, + asset_id2: AssetId, + amount: u128, + include_fee: bool, + ) -> RpcResult> { let mut api = self.client.runtime_api(); let at = match at { Some(at) => at, @@ -98,7 +110,14 @@ for PolkadexSwapRpc Ok(runtime_api_result) } - async fn quote_price_tokens_for_exact_tokens(&self, at: Option<::Hash>, asset_id1: AssetId, asset_id2: AssetId, amount: u128, include_fee: bool) -> RpcResult> { + async fn quote_price_tokens_for_exact_tokens( + &self, + at: Option<::Hash>, + asset_id1: AssetId, + asset_id2: AssetId, + amount: u128, + include_fee: bool, + ) -> RpcResult> { let mut api = self.client.runtime_api(); let at = match at { Some(at) => at, @@ -116,4 +135,4 @@ fn runtime_error_into_rpc_err(err: impl std::fmt::Debug) -> JsonRpseeError { log::error!(target:"ocex","runtime rpc error: {:?} ",err); CallError::Custom(ErrorObject::owned(RUNTIME_ERROR, "Runtime error", Some(format!("{err:?}")))) .into() -} \ No newline at end of file +} From 77cd28f3012d30dd92be472df7fac0684783092f Mon Sep 17 00:00:00 2001 From: zktony Date: Thu, 14 Dec 2023 13:07:16 +0530 Subject: [PATCH 3/8] Fixed chenks --- rpc/swap/src/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/rpc/swap/src/lib.rs b/rpc/swap/src/lib.rs index 8d0fd268a..4f8b07328 100644 --- a/rpc/swap/src/lib.rs +++ b/rpc/swap/src/lib.rs @@ -26,18 +26,13 @@ use jsonrpsee::{ types::error::{CallError, ErrorObject}, }; pub use pallet_asset_conversion::AssetConversionApi; -use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter}; -use parity_scale_codec::{Codec, Decode}; use polkadex_primitives::AssetId; -use sc_rpc_api::DenyUnsafe; -use sp_api::{ApiExt, ProvideRuntimeApi}; +use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; -use sp_core::offchain::{storage::OffchainDb, OffchainDbExt, OffchainStorage}; use sp_runtime::traits::Block as BlockT; use std::sync::Arc; const RUNTIME_ERROR: i32 = 1; -const RETRIES: u8 = 3; #[rpc(client, server)] pub trait PolkadexSwapRpcApi { @@ -99,7 +94,7 @@ where amount: u128, include_fee: bool, ) -> RpcResult> { - let mut api = self.client.runtime_api(); + let api = self.client.runtime_api(); let at = match at { Some(at) => at, None => self.client.info().best_hash, @@ -118,7 +113,7 @@ where amount: u128, include_fee: bool, ) -> RpcResult> { - let mut api = self.client.runtime_api(); + let api = self.client.runtime_api(); let at = match at { Some(at) => at, None => self.client.info().best_hash, From 8ab69088d6b5824e40ce431088e6e392f37027f4 Mon Sep 17 00:00:00 2001 From: zktony Date: Fri, 15 Dec 2023 09:57:00 +0530 Subject: [PATCH 4/8] Fixed warnings --- pallets/liquidity/src/benchmarking.rs | 4 ++-- pallets/rewards/src/benchmarking.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/liquidity/src/benchmarking.rs b/pallets/liquidity/src/benchmarking.rs index 00f1d08b8..7b01f760b 100644 --- a/pallets/liquidity/src/benchmarking.rs +++ b/pallets/liquidity/src/benchmarking.rs @@ -68,7 +68,7 @@ benchmarks! { call.dispatch_bypass_filter(origin.clone())?; //existential deposit - T::NativeCurrency::deposit_creating( + let _ = T::NativeCurrency::deposit_creating( &main_account.clone(), (10 * UNIT_BALANCE).saturated_into(), ); @@ -104,7 +104,7 @@ benchmarks! { call.dispatch_bypass_filter(origin.clone())?; //existential deposit - T::NativeCurrency::deposit_creating( + let _ = T::NativeCurrency::deposit_creating( &main_account.clone(), (10 * UNIT_BALANCE).saturated_into(), ); diff --git a/pallets/rewards/src/benchmarking.rs b/pallets/rewards/src/benchmarking.rs index e2db5c658..5a7d8c7d5 100644 --- a/pallets/rewards/src/benchmarking.rs +++ b/pallets/rewards/src/benchmarking.rs @@ -75,13 +75,13 @@ benchmarks! { let pallet_id_account = pallet_rewards::::get_pallet_account(); //set balance for pallet account - T::NativeCurrency::deposit_creating( + let _ = T::NativeCurrency::deposit_creating( &pallet_id_account, (10000000 * UNIT_BALANCE).saturated_into(), ); //set existential balance for alice - T::NativeCurrency::deposit_creating( + let _ = T::NativeCurrency::deposit_creating( &alice_account, (10000000 * UNIT_BALANCE).saturated_into(), ); @@ -111,13 +111,13 @@ benchmarks! { let pallet_id_account = pallet_rewards::::get_pallet_account(); //set balance for pallet account - T::NativeCurrency::deposit_creating( + let _ = T::NativeCurrency::deposit_creating( &pallet_id_account, (10000000 * UNIT_BALANCE).saturated_into(), ); //set existential balance for alice - T::NativeCurrency::deposit_creating( + let _ = T::NativeCurrency::deposit_creating( &alice_account, (10000000 * UNIT_BALANCE).saturated_into(), ); From 890cfb81b2d5371f6992e1095759dcf4d42d05cd Mon Sep 17 00:00:00 2001 From: zktony Date: Fri, 15 Dec 2023 23:50:18 +0530 Subject: [PATCH 5/8] Updated rpc end points --- rpc/swap/src/lib.rs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/rpc/swap/src/lib.rs b/rpc/swap/src/lib.rs index 4f8b07328..c166fec04 100644 --- a/rpc/swap/src/lib.rs +++ b/rpc/swap/src/lib.rs @@ -39,9 +39,8 @@ pub trait PolkadexSwapRpcApi { #[method(name = "tx_quotePriceExactTokensForTokens")] async fn quote_price_exact_tokens_for_tokens( &self, - at: Option, - asset_id1: AssetId, - asset_id2: AssetId, + asset_id1: String, + asset_id2: String, amount: u128, include_fee: bool, ) -> RpcResult>; @@ -49,9 +48,8 @@ pub trait PolkadexSwapRpcApi { #[method(name = "tx_quotePriceTokensForExactTokens")] async fn quote_price_tokens_for_exact_tokens( &self, - at: Option, - asset_id1: AssetId, - asset_id2: AssetId, + asset_id1: String, + asset_id2: String, amount: u128, include_fee: bool, ) -> RpcResult>; @@ -88,17 +86,15 @@ where { async fn quote_price_exact_tokens_for_tokens( &self, - at: Option<::Hash>, - asset_id1: AssetId, - asset_id2: AssetId, + asset_id1: String, + asset_id2: String, amount: u128, include_fee: bool, ) -> RpcResult> { let api = self.client.runtime_api(); - let at = match at { - Some(at) => at, - None => self.client.info().best_hash, - }; + let at = self.client.info().best_hash; + let asset_id1: AssetId = AssetId::try_from(asset_id1).map_err(runtime_error_into_rpc_err)?; + let asset_id2: AssetId = AssetId::try_from(asset_id2).map_err(runtime_error_into_rpc_err)?; let runtime_api_result = api .quote_price_exact_tokens_for_tokens(at, asset_id1, asset_id2, amount, include_fee) .map_err(runtime_error_into_rpc_err)?; @@ -107,17 +103,15 @@ where async fn quote_price_tokens_for_exact_tokens( &self, - at: Option<::Hash>, - asset_id1: AssetId, - asset_id2: AssetId, + asset_id1: String, + asset_id2: String, amount: u128, include_fee: bool, ) -> RpcResult> { let api = self.client.runtime_api(); - let at = match at { - Some(at) => at, - None => self.client.info().best_hash, - }; + let at = self.client.info().best_hash; + let asset_id1: AssetId = AssetId::try_from(asset_id1).map_err(runtime_error_into_rpc_err)?; + let asset_id2: AssetId = AssetId::try_from(asset_id2).map_err(runtime_error_into_rpc_err)?; let runtime_api_result = api .quote_price_tokens_for_exact_tokens(at, asset_id1, asset_id2, amount, include_fee) .map_err(runtime_error_into_rpc_err)?; From 973d921fa9edce27d013d7864340c487505e4f13 Mon Sep 17 00:00:00 2001 From: zktony Date: Sat, 16 Dec 2023 00:21:13 +0530 Subject: [PATCH 6/8] fixed formatting --- rpc/swap/src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rpc/swap/src/lib.rs b/rpc/swap/src/lib.rs index c166fec04..c0c976dcd 100644 --- a/rpc/swap/src/lib.rs +++ b/rpc/swap/src/lib.rs @@ -93,8 +93,10 @@ where ) -> RpcResult> { let api = self.client.runtime_api(); let at = self.client.info().best_hash; - let asset_id1: AssetId = AssetId::try_from(asset_id1).map_err(runtime_error_into_rpc_err)?; - let asset_id2: AssetId = AssetId::try_from(asset_id2).map_err(runtime_error_into_rpc_err)?; + let asset_id1: AssetId = + AssetId::try_from(asset_id1).map_err(runtime_error_into_rpc_err)?; + let asset_id2: AssetId = + AssetId::try_from(asset_id2).map_err(runtime_error_into_rpc_err)?; let runtime_api_result = api .quote_price_exact_tokens_for_tokens(at, asset_id1, asset_id2, amount, include_fee) .map_err(runtime_error_into_rpc_err)?; @@ -110,8 +112,10 @@ where ) -> RpcResult> { let api = self.client.runtime_api(); let at = self.client.info().best_hash; - let asset_id1: AssetId = AssetId::try_from(asset_id1).map_err(runtime_error_into_rpc_err)?; - let asset_id2: AssetId = AssetId::try_from(asset_id2).map_err(runtime_error_into_rpc_err)?; + let asset_id1: AssetId = + AssetId::try_from(asset_id1).map_err(runtime_error_into_rpc_err)?; + let asset_id2: AssetId = + AssetId::try_from(asset_id2).map_err(runtime_error_into_rpc_err)?; let runtime_api_result = api .quote_price_tokens_for_exact_tokens(at, asset_id1, asset_id2, amount, include_fee) .map_err(runtime_error_into_rpc_err)?; From f7d040e813170f82d38daf4ef46974b056cecb7f Mon Sep 17 00:00:00 2001 From: Gautham Date: Wed, 20 Dec 2023 11:40:38 +0530 Subject: [PATCH 7/8] Increment spec version and decrement transaction_version as hotfix for ledger --- runtimes/mainnet/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtimes/mainnet/src/lib.rs b/runtimes/mainnet/src/lib.rs index 748118f5b..bf6c56ec4 100644 --- a/runtimes/mainnet/src/lib.rs +++ b/runtimes/mainnet/src/lib.rs @@ -122,10 +122,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 315, + spec_version: 316, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 3, + transaction_version: 2, state_version: 0, }; From 5f0f7305b83963cae99e90c7ba2fdf5459502655 Mon Sep 17 00:00:00 2001 From: gautham Date: Wed, 20 Dec 2023 18:20:47 +0530 Subject: [PATCH 8/8] Fix clippy --- pallets/ocex/src/validator.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/ocex/src/validator.rs b/pallets/ocex/src/validator.rs index 07c41795c..f37e1810b 100644 --- a/pallets/ocex/src/validator.rs +++ b/pallets/ocex/src/validator.rs @@ -249,10 +249,11 @@ impl Pallet { /// Checks if another worker is already running or not pub fn check_worker_status() -> Result { let s_info = StorageValueRef::persistent(&WORKER_STATUS); - match s_info.get::().map_err(|err| { + let handle_err = |err| { log::error!(target:"ocex","Error while loading worker status: {:?}",err); "Unable to load worker status" - })? { + }; + match s_info.get::().map_err(handle_err)? { Some(true) => { // Another worker is online, so exit log::info!(target:"ocex", "Another worker is online, so exit");