-
Notifications
You must be signed in to change notification settings - Fork 19
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: integrate EMA Oracle #599
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
076e793
add EmaOracle to Basilisk runtime
apopiak c889078
update ema oracle to new liquidity type
apopiak 3b4fbf4
Merge branch 'master' of github.com:galacticcouncil/Basilisk-node int…
apopiak 93f6ea5
bump runtime version
apopiak e8d2dba
formatting
apopiak 23a5532
update oracle pallet to most recent version
apopiak fc11ff3
bump crate versions
apopiak 7e376bf
bump xyk LM benchmarking pallet version
apopiak af9bf56
reduce max unique oracle entries and adjust oracle periods
apopiak 411c17d
update warehouse dep
apopiak 09595b9
fix xyk LM compile errors in mocks
apopiak 9dac5e4
adjust integration test to expect hourly oracle instead of ten minutes
apopiak 785ef64
update ema-oracle to fix benchmarking issue
apopiak 95c4a5b
use ema-oracle pallet version with fixed get_entry benchmark
apopiak 10c6b51
add oracle weights file and use the contained weights
apopiak 30411fb
Merge branch 'master' of github.com:galacticcouncil/Basilisk-node int…
apopiak 54d2613
bump crate and spec versions
apopiak 628697f
bump xyk LM benchmarking crate
apopiak fae5cf3
update warehouse deps to new oracle impl and new AMMTransfer trait
apopiak 40d392d
run ci
mrq1911 93df908
Merge branch 'master' of github.com:galacticcouncil/Basilisk-node int…
apopiak 6f533ba
bump crate versions
apopiak 65d1327
Merge remote-tracking branch 'origin' into apopiak/oracle-integration
apopiak c9f308f
Merge branch 'master' of github.com:galacticcouncil/Basilisk-node int…
apopiak 645c281
adjust integration test
apopiak 781e60c
bump crate versions
apopiak b5c5c68
Merge branch 'master' into apopiak/oracle-integration
apopiak d72a5d2
Merge branch 'master' into apopiak/oracle-integration
mrq1911 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#![cfg(test)] | ||
|
||
use crate::kusama_test_net::*; | ||
|
||
use basilisk_runtime::{EmaOracle, RuntimeOrigin, XYK}; | ||
use frame_support::{ | ||
assert_ok, | ||
traits::{OnFinalize, OnInitialize}, | ||
}; | ||
use hydradx_traits::{AggregatedPriceOracle, OraclePeriod::*}; | ||
use pallet_ema_oracle::OracleError; | ||
use polkadot_primitives::v2::BlockNumber; | ||
use xcm_emulator::TestExt; | ||
|
||
pub fn basilisk_run_to_block(to: BlockNumber) { | ||
while basilisk_runtime::System::block_number() < to { | ||
let b = basilisk_runtime::System::block_number(); | ||
|
||
basilisk_runtime::System::on_finalize(b); | ||
basilisk_runtime::EmaOracle::on_finalize(b); | ||
|
||
basilisk_runtime::System::on_initialize(b + 1); | ||
basilisk_runtime::EmaOracle::on_initialize(b + 1); | ||
|
||
basilisk_runtime::System::set_block_number(b + 1); | ||
} | ||
} | ||
|
||
use pallet_xyk::SOURCE; | ||
|
||
#[test] | ||
fn xyk_trades_are_ingested_into_oracle() { | ||
TestNet::reset(); | ||
|
||
let asset_a = 1; | ||
let asset_b = 2; | ||
|
||
Basilisk::execute_with(|| { | ||
// arrange | ||
basilisk_run_to_block(2); | ||
|
||
assert_ok!(XYK::create_pool( | ||
RuntimeOrigin::signed(ALICE.into()), | ||
asset_a, | ||
100 * UNITS, | ||
asset_b, | ||
200 * UNITS, | ||
)); | ||
assert_ok!(XYK::sell( | ||
RuntimeOrigin::signed(ALICE.into()), | ||
asset_a, | ||
asset_b, | ||
5 * UNITS, | ||
UNITS, | ||
false, | ||
)); | ||
|
||
// act | ||
// will store the data received in the sell as oracle values | ||
basilisk_run_to_block(3); | ||
|
||
// assert | ||
let expected = ((105000000000000, 190504761904760).into(), 0); | ||
assert_eq!(EmaOracle::get_price(asset_a, asset_b, LastBlock, SOURCE), Ok(expected)); | ||
// ten minutes oracle not configured/supported | ||
assert_eq!( | ||
EmaOracle::get_price(asset_a, asset_b, TenMinutes, SOURCE), | ||
Err(OracleError::NotPresent) | ||
); | ||
assert_eq!(EmaOracle::get_price(asset_a, asset_b, Hour, SOURCE), Ok(expected)); | ||
assert_eq!(EmaOracle::get_price(asset_a, asset_b, Day, SOURCE), Ok(expected)); | ||
assert_eq!(EmaOracle::get_price(asset_a, asset_b, Week, SOURCE), Ok(expected)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// This file is part of Basilisk-node. | ||
|
||
// Copyright (C) 2020-2023 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. | ||
|
||
//! Autogenerated weights for pallet_ema_oracle | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
//! DATE: 2023-03-09, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] | ||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 | ||
|
||
// Executed Command: | ||
// target/release/basilisk | ||
// benchmark | ||
// pallet | ||
// --chain=dev | ||
// --steps=10 | ||
// --repeat=30 | ||
// --execution=wasm | ||
// --wasm-execution=compiled | ||
// --heap-pages=4096 | ||
// --template=.maintain/pallet-weight-template-no-back.hbs | ||
// --pallet=pallet_ema_oracle | ||
// --output=oracle.rs | ||
// --extrinsic=* | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
#![allow(clippy::unnecessary_cast)] | ||
|
||
use frame_support::{ | ||
traits::Get, | ||
weights::{constants::RocksDbWeight, Weight}, | ||
}; | ||
use sp_std::marker::PhantomData; | ||
|
||
use pallet_ema_oracle::weights::WeightInfo; | ||
|
||
pub struct BasiliskWeight<T>(PhantomData<T>); | ||
|
||
impl<T: frame_system::Config> WeightInfo for BasiliskWeight<T> { | ||
fn on_finalize_no_entry() -> Weight { | ||
Weight::from_ref_time(4_740_000).saturating_add(T::DbWeight::get().reads(1 as u64)) | ||
} | ||
fn on_finalize_multiple_tokens(b: u32) -> Weight { | ||
Weight::from_ref_time(19_041_000) // Standard Error: 53_000 | ||
.saturating_add(Weight::from_ref_time(43_566_000).saturating_mul(b as u64)) | ||
.saturating_add(T::DbWeight::get().reads(1 as u64)) | ||
.saturating_add(T::DbWeight::get().reads((4 as u64).saturating_mul(b as u64))) | ||
.saturating_add(T::DbWeight::get().writes(1 as u64)) | ||
.saturating_add(T::DbWeight::get().writes((4 as u64).saturating_mul(b as u64))) | ||
} | ||
fn on_trade_multiple_tokens(b: u32) -> Weight { | ||
Weight::from_ref_time(17_201_000) // Standard Error: 6_000 | ||
.saturating_add(Weight::from_ref_time(712_000).saturating_mul(b as u64)) | ||
.saturating_add(T::DbWeight::get().reads(1 as u64)) | ||
.saturating_add(T::DbWeight::get().writes(1 as u64)) | ||
} | ||
fn on_liquidity_changed_multiple_tokens(b: u32) -> Weight { | ||
Weight::from_ref_time(17_238_000) // Standard Error: 6_000 | ||
.saturating_add(Weight::from_ref_time(704_000).saturating_mul(b as u64)) | ||
.saturating_add(T::DbWeight::get().reads(1 as u64)) | ||
.saturating_add(T::DbWeight::get().writes(1 as u64)) | ||
} | ||
fn get_entry() -> Weight { | ||
Weight::from_ref_time(24_093_000).saturating_add(T::DbWeight::get().reads(2 as u64)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be xyk reweighted now with oracle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah