Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion node/service/src/chain_spec/asgard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
whitelisted_caller(), // Benchmarking whitelist_account
];
let balances = endowed_accounts
.iter()
Expand All @@ -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),
]
Expand Down
177 changes: 95 additions & 82 deletions pallets/bancor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C, Block> {
client: Arc<C>,
_marker: PhantomData<Block>,
client: Arc<C>,
_marker: PhantomData<Block>,
}

impl<C, Block> BancorStruct<C, Block> {
pub fn new(client: Arc<C>) -> Self {
Self {
client,
_marker: PhantomData,
}
}
pub fn new(client: Arc<C>) -> Self {
Self { client, _marker: PhantomData }
}
}

#[rpc]
pub trait BancorRpcApi<BlockHash, CurrencyId, Balance> {
#[rpc(name = "bancor_getBancorTokenAmountOut")]
fn get_bancor_token_amount_out(
&self,
token_id: CurrencyId,
vstoken_amount: Balance,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;

#[rpc(name = "bancor_getBancorVstokenAmountOut")]
fn get_bancor_vstoken_amount_out(
&self,
token_id: CurrencyId,
token_amount: Balance,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;
#[rpc(name = "bancor_getBancorTokenAmountOut")]
fn get_bancor_token_amount_out(
&self,
token_id: CurrencyId,
vstoken_amount: Balance,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;

#[rpc(name = "bancor_getBancorVstokenAmountOut")]
fn get_bancor_vstoken_amount_out(
&self,
token_id: CurrencyId,
token_amount: Balance,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;

#[rpc(name = "bancor_getInstantVstokenPrice")]
fn get_instant_vstoken_price(
&self,
currency_id: CurrencyId,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;

#[rpc(name = "bancor_getInstantTokenPrice")]
fn get_instant_token_price(
&self,
currency_id: CurrencyId,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;
}

/// 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<Error> 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<C, Block, CurrencyId, Balance> BancorRpcApi<<Block as BlockT>::Hash, CurrencyId, Balance>
for BancorStruct<C, Block>
for BancorStruct<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: BancorRuntimeApi<Block, CurrencyId, Balance>,
CurrencyId: Codec,
Balance: Codec + std::fmt::Display + std::ops::Add<Output = Balance> + sp_runtime::traits::Zero,
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: BancorRuntimeApi<Block, CurrencyId, Balance>,
CurrencyId: Codec,
Balance: Codec + std::fmt::Display + std::ops::Add<Output = Balance> + sp_runtime::traits::Zero,
{
fn get_bancor_token_amount_out(
&self,
token_id: CurrencyId,
vstoken_amount: Balance,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>{
fn get_bancor_token_amount_out(
&self,
token_id: CurrencyId,
vstoken_amount: Balance,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance> {
let api = self.client.runtime_api();
let at = BlockId::<Block>::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<BlockHash>,
) -> JsonRpcResult<Balance>{
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<BlockHash>,
) -> JsonRpcResult<Balance> {
let api = self.client.runtime_api();
let at = BlockId::<Block>::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<BlockHash>,
) -> JsonRpcResult<Balance>{
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<BlockHash>,
) -> JsonRpcResult<Balance> {
let api = self.client.runtime_api();
let at = BlockId::<Block>::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<BlockHash>,
) -> JsonRpcResult<Balance>{
fn get_instant_token_price(
&self,
currency_id: CurrencyId,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance> {
let api = self.client.runtime_api();
let at = BlockId::<Block>::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()),
})
}
}
}
18 changes: 9 additions & 9 deletions runtime/asgard/src/weights/bifrost_bancor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,21 +46,21 @@ use sp_std::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_bancor::WeightInfo for WeightInfo<T> {
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))
}
}
16 changes: 8 additions & 8 deletions runtime/asgard/src/weights/bifrost_salp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,19 +46,19 @@ use sp_std::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_salp::WeightInfo for WeightInfo<T> {
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))
}
Expand Down
1 change: 1 addition & 0 deletions runtime/dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,5 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"bifrost-salp/runtime-benchmarks",
"bifrost-bancor/runtime-benchmarks",
]
1 change: 1 addition & 0 deletions runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::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)
Expand Down
4 changes: 2 additions & 2 deletions scripts/run_all_benches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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