diff --git a/node/service/src/chain_spec/asgard.rs b/node/service/src/chain_spec/asgard.rs index c00a5de310..6c77f707a9 100644 --- a/node/service/src/chain_spec/asgard.rs +++ b/node/service/src/chain_spec/asgard.rs @@ -197,6 +197,7 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig { get_account_id_from_seed::("Dave//stash"), get_account_id_from_seed::("Eve//stash"), get_account_id_from_seed::("Ferdie//stash"), + whitelisted_caller(), // Benchmarking whitelist_account ]; let balances = endowed_accounts .iter() @@ -215,7 +216,8 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig { .flat_map(|x| { vec![ (x.clone(), CurrencyId::Stable(TokenSymbol::AUSD), ENDOWMENT * 10_000), - (x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT), + (x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::VSToken(TokenSymbol::DOT), ENDOWMENT * 4_000_000), (x.clone(), CurrencyId::Token(TokenSymbol::ETH), ENDOWMENT), (x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT), ] diff --git a/pallets/bancor/rpc/src/lib.rs b/pallets/bancor/rpc/src/lib.rs index 1060b300a4..1cb3063270 100644 --- a/pallets/bancor/rpc/src/lib.rs +++ b/pallets/bancor/rpc/src/lib.rs @@ -25,132 +25,145 @@ use sp_blockchain::HeaderBackend; use sp_core::Bytes; use sp_rpc::number::NumberOrHex; use sp_runtime::{ - generic::BlockId, - traits::{Block as BlockT, Zero}, - SaturatedConversion, + generic::BlockId, + traits::{Block as BlockT, Zero}, + SaturatedConversion, }; use std::marker::PhantomData; use std::sync::Arc; #[derive(Clone, Debug)] pub struct BancorStruct { - client: Arc, - _marker: PhantomData, + client: Arc, + _marker: PhantomData, } impl BancorStruct { - pub fn new(client: Arc) -> Self { - Self { - client, - _marker: PhantomData, - } - } + pub fn new(client: Arc) -> Self { + Self { client, _marker: PhantomData } + } } #[rpc] pub trait BancorRpcApi { - #[rpc(name = "bancor_getBancorTokenAmountOut")] - fn get_bancor_token_amount_out( - &self, - token_id: CurrencyId, - vstoken_amount: Balance, - at: Option, - ) -> JsonRpcResult; - - #[rpc(name = "bancor_getBancorVstokenAmountOut")] - fn get_bancor_vstoken_amount_out( - &self, - token_id: CurrencyId, - token_amount: Balance, - at: Option, - ) -> JsonRpcResult; + #[rpc(name = "bancor_getBancorTokenAmountOut")] + fn get_bancor_token_amount_out( + &self, + token_id: CurrencyId, + vstoken_amount: Balance, + at: Option, + ) -> JsonRpcResult; + + #[rpc(name = "bancor_getBancorVstokenAmountOut")] + fn get_bancor_vstoken_amount_out( + &self, + token_id: CurrencyId, + token_amount: Balance, + at: Option, + ) -> JsonRpcResult; + + #[rpc(name = "bancor_getInstantVstokenPrice")] + fn get_instant_vstoken_price( + &self, + currency_id: CurrencyId, + at: Option, + ) -> JsonRpcResult; + + #[rpc(name = "bancor_getInstantTokenPrice")] + fn get_instant_token_price( + &self, + currency_id: CurrencyId, + at: Option, + ) -> JsonRpcResult; } /// Error type of this RPC api. pub enum Error { - /// The transaction was not decodable. - DecodeError, - /// The call to runtime failed. - RuntimeError, + /// The transaction was not decodable. + DecodeError, + /// The call to runtime failed. + RuntimeError, } impl From for i64 { - fn from(e: Error) -> i64 { - match e { - Error::RuntimeError => 1, - Error::DecodeError => 2, - } - } + fn from(e: Error) -> i64 { + match e { + Error::RuntimeError => 1, + Error::DecodeError => 2, + } + } } impl BancorRpcApi<::Hash, CurrencyId, Balance> - for BancorStruct + for BancorStruct where - Block: BlockT, - C: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, - C::Api: BancorRuntimeApi, - CurrencyId: Codec, - Balance: Codec + std::fmt::Display + std::ops::Add + sp_runtime::traits::Zero, + Block: BlockT, + C: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, + C::Api: BancorRuntimeApi, + CurrencyId: Codec, + Balance: Codec + std::fmt::Display + std::ops::Add + sp_runtime::traits::Zero, { - fn get_bancor_token_amount_out( - &self, - token_id: CurrencyId, - vstoken_amount: Balance, - at: Option, - ) -> JsonRpcResult{ + fn get_bancor_token_amount_out( + &self, + token_id: CurrencyId, + vstoken_amount: Balance, + at: Option, + ) -> JsonRpcResult { let api = self.client.runtime_api(); let at = BlockId::::hash(at.unwrap_or_else(|| self.client.info().best_hash)); - api.get_bancor_token_amount_out(&at, token_id, vstoken_amount).map_err(|e| RpcError { - code: ErrorCode::InternalError, - message: "Failed to get bancor token amount out.".to_owned(), - data: Some(format!("{:?}", e).into()), - }) - } - - fn get_bancor_vstoken_amount_out( - &self, - token_id: CurrencyId, - token_amount: Balance, - at: Option, - ) -> JsonRpcResult{ + api.get_bancor_token_amount_out(&at, token_id, vstoken_amount) + .map_err(|e| RpcError { + code: ErrorCode::InternalError, + message: "Failed to get bancor token amount out.".to_owned(), + data: Some(format!("{:?}", e).into()), + }) + } + + fn get_bancor_vstoken_amount_out( + &self, + token_id: CurrencyId, + token_amount: Balance, + at: Option, + ) -> JsonRpcResult { let api = self.client.runtime_api(); let at = BlockId::::hash(at.unwrap_or_else(|| self.client.info().best_hash)); - api.get_bancor_vstoken_amount_out(&at, token_id, token_amount).map_err(|e| RpcError { - code: ErrorCode::InternalError, - message: "Failed to get bancor vstoken amount out.".to_owned(), - data: Some(format!("{:?}", e).into()), - }) - } - - fn get_instant_vstoken_price( - &self, - currency_id: CurrencyId, - at: Option, - ) -> JsonRpcResult{ + api.get_bancor_vstoken_amount_out(&at, token_id, token_amount) + .map_err(|e| RpcError { + code: ErrorCode::InternalError, + message: "Failed to get bancor vstoken amount out.".to_owned(), + data: Some(format!("{:?}", e).into()), + }) + } + + fn get_instant_vstoken_price( + &self, + currency_id: CurrencyId, + at: Option, + ) -> JsonRpcResult { let api = self.client.runtime_api(); let at = BlockId::::hash(at.unwrap_or_else(|| self.client.info().best_hash)); - api.get_instant_vstoken_price(&at, currency_id).map_err(|e| RpcError { + api.get_instant_vstoken_price(&at, currency_id).map_err(|e| RpcError { code: ErrorCode::InternalError, message: "Failed to get bancor instant vstoken price.".to_owned(), data: Some(format!("{:?}", e).into()), }) - } + } - fn get_instant_token_price( - &self, - currency_id: CurrencyId, - at: Option, - ) -> JsonRpcResult{ + fn get_instant_token_price( + &self, + currency_id: CurrencyId, + at: Option, + ) -> JsonRpcResult { let api = self.client.runtime_api(); let at = BlockId::::hash(at.unwrap_or_else(|| self.client.info().best_hash)); - api.get_instant_token_price(&at, currency_id).map_err(|e| RpcError { + api.get_instant_token_price(&at, currency_id).map_err(|e| RpcError { code: ErrorCode::InternalError, message: "Failed to get bancor instant token price.".to_owned(), data: Some(format!("{:?}", e).into()), }) - } + } } diff --git a/runtime/asgard/src/weights/bifrost_bancor.rs b/runtime/asgard/src/weights/bifrost_bancor.rs index cbfc8d80b9..e5415b5baa 100644 --- a/runtime/asgard/src/weights/bifrost_bancor.rs +++ b/runtime/asgard/src/weights/bifrost_bancor.rs @@ -19,16 +19,16 @@ //! Autogenerated weights for bifrost_bancor //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-03, STEPS: `[50, ]`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 +//! DATE: 2021-08-04, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: // target/release/bifrost // benchmark -// --chain=asgard-dev +// --chain=asgard-local // --steps=50 -// --repeat=1 -// --pallet=bifrost-bancor +// --repeat=20 +// --pallet=bifrost_bancor // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -46,21 +46,21 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_bancor::WeightInfo for WeightInfo { fn add_token_to_pool() -> Weight { - (64_732_000 as Weight) + (61_646_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn exchange_for_token() -> Weight { - (94_428_000 as Weight) + (90_360_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn exchange_for_vstoken() -> Weight { - (82_786_000 as Weight) + (79_159_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn on_initialize() -> Weight { - (22_914_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) + (22_252_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) } } diff --git a/runtime/asgard/src/weights/bifrost_salp.rs b/runtime/asgard/src/weights/bifrost_salp.rs index 4f95249a7f..798704af6f 100644 --- a/runtime/asgard/src/weights/bifrost_salp.rs +++ b/runtime/asgard/src/weights/bifrost_salp.rs @@ -19,13 +19,13 @@ //! Autogenerated weights for bifrost_salp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-07-30, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 +//! DATE: 2021-08-04, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: // target/release/bifrost // benchmark -// --chain=asgard-dev +// --chain=asgard-local // --steps=50 // --repeat=20 // --pallet=bifrost_salp @@ -46,19 +46,19 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { - (60_294_000 as Weight) + (57_287_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn contribute() -> Weight { - (63_079_000 as Weight) + (59_913_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn on_finalize(n: u32) -> Weight { - (8_753_000 as Weight) - // Standard Error: 0 - .saturating_add((214_000 as Weight).saturating_mul(n as Weight)) + (9_072_000 as Weight) + // Standard Error: 2_000 + .saturating_add((219_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } diff --git a/runtime/dev/Cargo.toml b/runtime/dev/Cargo.toml index 9814900128..3d566d14b2 100644 --- a/runtime/dev/Cargo.toml +++ b/runtime/dev/Cargo.toml @@ -187,4 +187,5 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "bifrost-salp/runtime-benchmarks", + "bifrost-bancor/runtime-benchmarks", ] diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 193a7e3c28..3a5e9d91d2 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -1490,6 +1490,7 @@ impl_runtime_apis! { let mut batches = Vec::::new(); let params = (&config, &whitelist); add_benchmark!(params, batches, bifrost_salp, Salp); + add_benchmark!(params, batches, bifrost_bancor, Bancor); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/scripts/run_all_benches.sh b/scripts/run_all_benches.sh index f07313254f..526dc1d828 100755 --- a/scripts/run_all_benches.sh +++ b/scripts/run_all_benches.sh @@ -9,11 +9,11 @@ runtimes=( # cargo build --locked --release for runtime in "${runtimes[@]}"; do - cargo run --release --features="runtime-benchmarks,with-${runtime}-runtime" --locked benchmark --chain "${runtime}-dev" --execution=wasm --wasm-execution=compiled --pallet "*" --extrinsic "*" --repeat 0 | sed -r -e 's/Pallet: "([a-z_:]+)".*/\1/' | uniq | grep -v frame_system > "${runtime}_pallets" + cargo run --release --features="runtime-benchmarks,with-${runtime}-runtime" --locked benchmark --chain "${runtime}-local" --execution=wasm --wasm-execution=compiled --pallet "*" --extrinsic "*" --repeat 0 | sed -r -e 's/Pallet: "([a-z_:]+)".*/\1/' | uniq | grep -v frame_system > "${runtime}_pallets" while read -r line; do pallet="$(echo "$line" | cut -d' ' -f1)"; echo "Runtime: $runtime. Pallet: $pallet"; - cargo run --release --features="runtime-benchmarks,with-${runtime}-runtime" -- benchmark --chain="${runtime}-dev" --steps=50 --repeat=20 --pallet="$pallet" --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./HEADER-GPL3 --output="./runtime/${runtime}/src/weights/${pallet/::/_}.rs" + cargo run --release --features="runtime-benchmarks,with-${runtime}-runtime" -- benchmark --chain="${runtime}-local" --steps=50 --repeat=20 --pallet="$pallet" --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./HEADER-GPL3 --output="./runtime/${runtime}/src/weights/${pallet/::/_}.rs" done < "${runtime}_pallets" rm "${runtime}_pallets" done \ No newline at end of file