Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: price-oracle pallet #112

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
32ab7c9
pallet_price_oracle initial commit
Roznovjak Jul 15, 2021
98cd5ba
price-oracle initial implementation
Roznovjak Jul 22, 2021
7125c2c
price-oracle initial implementation
Roznovjak Jul 22, 2021
0c3d9c5
clippy and formatting
Roznovjak Jul 22, 2021
37ecf49
various adjustments
Roznovjak Aug 2, 2021
ca4cc34
Merge branch 'master' into feat/price_oracle
Roznovjak Aug 2, 2021
8bb43c1
ignore zero prices and move impl types to own file
Roznovjak Aug 4, 2021
13d64b3
Merge branch 'master' into feat/price_oracle
Roznovjak Aug 4, 2021
a5ca64e
remove unused config params
Roznovjak Aug 4, 2021
a7f09fe
Merge branch 'master' into feat/price_oracle
Roznovjak Aug 5, 2021
c7af9ce
initial price-oracle benchmarking
Roznovjak Aug 6, 2021
e9d4c62
update price-oracle benchmarking
Roznovjak Aug 8, 2021
e83579e
add new benchmarks and parameterize weight calculation of on_initialize
Roznovjak Aug 9, 2021
42f43e4
don't decrease the price over time and add new test and benchmark
Roznovjak Aug 11, 2021
1ef6039
comment errors, rename PriceEntry field names and perform checked div…
Roznovjak Aug 11, 2021
9d6f15f
rework benchmarking
Roznovjak Aug 13, 2021
a2da074
rework pricebuffer and average_price calculation
Roznovjak Aug 15, 2021
65f6311
Merge branch 'master' into feat/price_oracle
Roznovjak Aug 15, 2021
fdbad06
add comments
Roznovjak Aug 16, 2021
14e6f31
add num_of_assets storage
Roznovjak Aug 16, 2021
a38d737
remove useless if statement
Roznovjak Aug 18, 2021
6487d35
remove not necessary benchmarks
Roznovjak Aug 18, 2021
7ca20ef
add PoolRegistered event
Roznovjak Aug 19, 2021
5344652
fix event handling in tests
Roznovjak Aug 19, 2021
8de92c6
various improvements
Roznovjak Aug 20, 2021
c79c088
move price computation from on_initialize to on_finalize
Roznovjak Aug 24, 2021
d3d760b
change storage hasher
Roznovjak Aug 24, 2021
99cb4f8
update benchmark weights
Roznovjak Aug 25, 2021
105512e
Merge branch 'master' into feat/price_oracle
Roznovjak Aug 27, 2021
03d8f40
Merge branch 'master' into feat/price_oracle
Roznovjak Aug 31, 2021
b98cc86
add mising config param to mock
Roznovjak Aug 31, 2021
78080c8
Merge branch 'master' into feat/price_oracle
Roznovjak Sep 1, 2021
0cdf2e6
Merge branch 'master' into feat/price_oracle
Roznovjak Oct 12, 2021
7e5493e
merge master branch
Roznovjak Oct 12, 2021
12605ba
satisfy clippy
Roznovjak Oct 12, 2021
17f54ed
small improvements
Roznovjak Oct 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 70 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pallets/exchange/benchmarking/src/mock.rs
Expand Up @@ -28,8 +28,7 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup, Zero},
};

use pallet_xyk::AssetPairAccountIdFor;
use primitives::{fee, AssetId, Balance};
use primitives::{fee, AssetId, Balance, traits::AssetPairAccountIdFor};

pub type Amount = i128;
pub type AccountId = u64;
Expand Down Expand Up @@ -138,6 +137,7 @@ impl pallet_xyk::Config for Test {
type NativeAssetId = HDXAssetId;
type WeightInfo = ();
type GetExchangeFee = ExchangeFeeRate;
type AMMHandler = ();
}

impl pallet_exchange::Config for Test {
Expand Down
4 changes: 2 additions & 2 deletions pallets/exchange/src/mock.rs
Expand Up @@ -30,8 +30,7 @@ use sp_runtime::{
use pallet_xyk as xyk;

use frame_support::traits::GenesisBuild;
use pallet_xyk::AssetPairAccountIdFor;
use primitives::{fee, AssetId, Balance};
use primitives::{fee, AssetId, Balance, traits::AssetPairAccountIdFor};

pub type Amount = i128;
pub type AccountId = u64;
Expand Down Expand Up @@ -144,6 +143,7 @@ impl xyk::Config for Test {
type NativeAssetId = HDXAssetId;
type WeightInfo = ();
type GetExchangeFee = ExchangeFeeRate;
type AMMHandler = ();
}

impl Config for Test {
Expand Down
17 changes: 17 additions & 0 deletions pallets/lbp/src/benchmarking.rs
@@ -1,3 +1,20 @@
// This file is part of Basilisk-node.

// Copyright (C) 2020-2021 Intergalactic, Limited (GIB).
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg(feature = "runtime-benchmarks")]

use super::*;
Expand Down
27 changes: 20 additions & 7 deletions pallets/lbp/src/lib.rs
@@ -1,3 +1,20 @@
// This file is part of Basilisk-node.

// Copyright (C) 2020-2021 Intergalactic, Limited (GIB).
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::unused_unit)]
#![allow(clippy::upper_case_acronyms)]
Expand All @@ -19,7 +36,7 @@ use frame_support::{
use frame_system::ensure_signed;
use hydra_dx_math::lbp::Weight as LBPWeight;
use orml_traits::{MultiCurrency, MultiCurrencyExtended, MultiReservableCurrency};
use primitives::traits::{AMMTransfer, AMM};
use primitives::traits::{AMMTransfer, AMM, AssetPairAccountIdFor};
use primitives::{
asset::AssetPair,
fee::{Fee, WithFee},
Expand Down Expand Up @@ -172,7 +189,7 @@ pub mod pallet {
type LBPWeightFunction: LBPWeightCalculation<Self::BlockNumber>;

/// Mapping of asset pairs to unique pool identities
type AssetPairPoolId: AssetPairPoolIdFor<AssetId, PoolId<Self>>;
type AssetPairPoolId: AssetPairAccountIdFor<AssetId, PoolId<Self>>;

/// Weight information for the extrinsics
type WeightInfo: WeightInfo;
Expand Down Expand Up @@ -926,13 +943,9 @@ impl<T: Config> Pallet<T> {
}
}

pub trait AssetPairPoolIdFor<AssetId: Sized, PoolId: Sized> {
fn from_assets(asset_a: AssetId, asset_b: AssetId) -> PoolId;
}

pub struct AssetPairPoolId<T: Config>(PhantomData<T>);

impl<T: Config> AssetPairPoolIdFor<AssetId, PoolId<T>> for AssetPairPoolId<T>
impl<T: Config> AssetPairAccountIdFor<AssetId, PoolId<T>> for AssetPairPoolId<T>
where
PoolId<T>: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
Expand Down
23 changes: 20 additions & 3 deletions pallets/lbp/src/mock.rs
@@ -1,10 +1,27 @@
// This file is part of Basilisk-node.

// Copyright (C) 2020-2021 Intergalactic, Limited (GIB).
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate as lbp;
use crate::{AssetPairPoolIdFor, Config};
use crate::Config;
use frame_support::parameter_types;
use frame_support::traits::GenesisBuild;
use frame_system;
use orml_traits::parameter_type_with_key;
use primitives::{AssetId, Balance, CORE_ASSET_ID};
use primitives::{AssetId, Balance, CORE_ASSET_ID, traits::AssetPairAccountIdFor};
use sp_core::H256;
use sp_runtime::{
testing::Header,
Expand Down Expand Up @@ -93,7 +110,7 @@ impl orml_tokens::Config for Test {

pub struct AssetPairPoolIdTest();

impl AssetPairPoolIdFor<AssetId, u64> for AssetPairPoolIdTest {
impl AssetPairAccountIdFor<AssetId, u64> for AssetPairPoolIdTest {
fn from_assets(asset_a: AssetId, asset_b: AssetId) -> u64 {
let mut a = asset_a as u128;
let mut b = asset_b as u128;
Expand Down