Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
518b9a9
update polkadot ver from 0.9.13 to 0.9.24
Jul 12, 2022
af2b0f8
fix some missing arg in fn when update polkadot version
Jul 12, 2022
bc47b4e
Added some misssing paramater for new config
Jul 13, 2022
64e25b9
Add missing contructer paramater
Jul 13, 2022
f7977ce
Update package chainlink-feed and some basic error
baopnpt Jul 14, 2022
00ccef5
update success price feed and local treasury pallets
Jul 15, 2022
7d54db5
update orm-pallets to polkadot-v0.9.24
Jul 15, 2022
3f3fa91
update success assetindex and saft registry
Jul 15, 2022
a9694e4
basic fix commmitee
Jul 15, 2022
d09e542
set default features false for integration test runtime
Jul 18, 2022
21e04a0
add dummy random for all pallet
Jul 18, 2022
210b91a
commit before change branch import
Jul 19, 2022
da127bd
basic bug fix for dev runtime after upgrade polkadot version
Jul 21, 2022
337dab1
fix pint, shot runtime
Jul 21, 2022
6be184a
fix some bug in node runtime
Aug 1, 2022
fcbb810
fix node runtime -done
Aug 2, 2022
c589a6b
fix all except integration test
Aug 2, 2022
b96f4df
fix all except patched lib
Aug 2, 2022
ba89d93
fix all runtime
Aug 2, 2022
71074b1
feat: add orml oracle
Aug 16, 2022
293e799
feat: add orml oracle
Aug 17, 2022
7cca3a2
update: remove chainlink
Aug 18, 2022
546eb60
Fix some unit test
Aug 26, 2022
fac7298
Fix compile error all test case
Aug 27, 2022
7ddee6c
Fix compile error all test case
Aug 27, 2022
4dff652
Merge pull request #1 from sotatek-dev/test-case-fix
Aug 27, 2022
84fb54b
Fix some panic config
Aug 28, 2022
b670b99
Merge pull request #2 from sotatek-dev/test-case-fix
Aug 28, 2022
03376ad
update interfration test
Aug 29, 2022
6b06174
update interfration test
Aug 29, 2022
05055e3
Fix integration test case
Sotatek-ThinhNguyen2 Aug 29, 2022
321071d
Merge branch 'develop' into price-feed-orml-oracle
Aug 29, 2022
3fc53b7
upgrade PINT to 0.9.26
Sotatek-ThinhNguyen2 Aug 30, 2022
122bc38
update interfration test
Aug 30, 2022
dfa2b7d
update interfration test
Aug 31, 2022
f8f65b9
enable dev runtime only for faster build
Sep 5, 2022
d62e286
use boundvec with limit 320 instead of vec for committeeOrigin, remot…
Sep 5, 2022
a0ff3dd
fix test case after upgrade
Sep 5, 2022
d9c0c8e
update intergration test
Sep 6, 2022
7f082b7
Merge pull request #4 from sotatek-dev/price-feed-orml-oracle
Sep 6, 2022
d5dd25d
merge unittest from develop
Sep 7, 2022
90e7b8b
upgrade xcm-emulator to 9.26
Sep 7, 2022
4ef9b2d
Merge pull request #5 from sotatek-dev/fix-origin-max-encode-len
Sep 7, 2022
4d78ed8
Enable mock for price-feed
Sep 7, 2022
6f51e74
Remote all chainlink test, add 2 unittest for new price feed
Sep 7, 2022
b92f61d
Merge pull request #6 from sotatek-dev/add-price-feed-test
Sep 7, 2022
ac0d7a2
Remote unused patch
Sep 8, 2022
acb9218
Fix pint shot genesis
Sep 9, 2022
08b88cb
Merge pull request #7 from sotatek-dev/fix-pint-feature-genesis
Sep 9, 2022
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
Prev Previous commit
Next Next commit
update: remove chainlink
  • Loading branch information
SotaTek-TungNguyen2 committed Aug 22, 2022
commit 7cca3a2ee2865a843ff837eedfa39f80f7b15095
6 changes: 1 addition & 5 deletions node/src/chain_spec/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@ fn pint_testnet_genesis(
balances: BalancesConfig { balances: vec![(root_key.clone(), 1 << 60)] },
treasury: Default::default(),
committee: CommitteeConfig { council_members: council_members.clone(), ..Default::default() },
chainlink_feed: ChainlinkFeedConfig {
feeds: Default::default(),
pallet_admin: Some(root_key.clone()),
feed_creators: council_members,
},
sudo: SudoConfig { key: Some(root_key) },
general_council: Default::default(),
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
invulnerables: initial_authorities.iter().cloned().map(|(acc, _)| acc).collect(),
Expand Down
6 changes: 1 addition & 5 deletions node/src/chain_spec/pint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ fn pint_testnet_genesis(
balances: BalancesConfig { balances: vec![(root_key.clone(), 1 << 60)] },
treasury: Default::default(),
committee: CommitteeConfig { council_members: council_members.clone(), ..Default::default() },
chainlink_feed: ChainlinkFeedConfig {
feeds: Default::default(),
pallet_admin: Some(root_key.clone()),
feed_creators: council_members,
},
sudo: SudoConfig { key: Some(root_key) },
general_council: Default::default(),
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
invulnerables: initial_authorities.iter().cloned().map(|(acc, _)| acc).collect(),
Expand Down
6 changes: 1 addition & 5 deletions node/src/chain_spec/shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,8 @@ fn pint_testnet_genesis(
balances: BalancesConfig { balances: vec![(root_key.clone(), 1 << 60)] },
treasury: Default::default(),
committee: CommitteeConfig { council_members: council_members.clone(), ..Default::default() },
chainlink_feed: ChainlinkFeedConfig {
feeds: Default::default(),
pallet_admin: Some(root_key.clone()),
feed_creators: council_members,
},
sudo: SudoConfig { key: Some(root_key) },
general_council: Default::default(),
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
invulnerables: initial_authorities.iter().cloned().map(|(acc, _)| acc).collect(),
Expand Down
3 changes: 0 additions & 3 deletions pallets/asset-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ xcm = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.2
xcm-executor = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.24', default-features = false }

# PINT dependencies
pallet-chainlink-feed = { git = 'https://github.com/Sotatek-BaoHoang2/chainlink-polkadot', branch = 'polkadot-v0.9.24', default-features = false }
pallet-price-feed = { path = "../price-feed", default-features = false }
primitives = { path = "../../primitives/primitives", default-features = false }

Expand Down Expand Up @@ -64,13 +63,11 @@ std = [

'orml-traits/std',
'orml-tokens/std',
'pallet-chainlink-feed/std'
]
runtime-benchmarks = [
'frame-benchmarking',
'frame-support/runtime-benchmarks',
'pallet-price-feed/runtime-benchmarks',
# 'pallet-chainlink-feed/runtime-benchmarks',
'primitives/runtime-benchmarks',
]

Expand Down
3 changes: 0 additions & 3 deletions pallets/price-feed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ frame-system = { git = 'https://github.com/paritytech/substrate', branch = 'polk
frame-benchmarking = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.24', default-features = false, optional = true }

# PINT dependencies
pallet-chainlink-feed = { git = 'https://github.com/Sotatek-BaoHoang2/chainlink-polkadot', branch = 'polkadot-v0.9.24', default-features = false }
primitives = { path = "../../primitives/primitives", default-features = false }
orml-oracle = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch = 'polkadot-v0.9.24', default-features = false }
orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch = 'polkadot-v0.9.24', default-features = false }
Expand All @@ -42,7 +41,6 @@ std = [
'scale-info/std',
'frame-support/std',
'frame-system/std',
'pallet-chainlink-feed/std',
'primitives/std',
'sp-core/std',
'sp-io/std',
Expand All @@ -52,7 +50,6 @@ std = [
runtime-benchmarks = [
'frame-benchmarking',
'frame-support/runtime-benchmarks',
'pallet-chainlink-feed/runtime-benchmarks',
'primitives/runtime-benchmarks',
]

Expand Down
206 changes: 27 additions & 179 deletions pallets/price-feed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ pub mod pallet {
traits::{Get, Time},
};
use frame_system::pallet_prelude::*;
use pallet_chainlink_feed::{FeedInterface, FeedOracle, RoundData};
use orml_oracle::{DataProvider};
use primitives::traits::MaybeAssetIdConvert;
use orml_traits::{DataProvider};
pub use primitives::{AssetPricePair, Price};
pub use primitives::traits::{MaybeAssetIdConvert};

pub type FeedIdFor<T> = <T as pallet_chainlink_feed::Config>::FeedId;
pub type MomentOf<T> = <<T as Config>::Time as Time>::Moment;
pub type FeedValueFor<T> = <T as pallet_chainlink_feed::Config>::Value;
pub type TimestampedFeedValue<T> = TimestampedValue<(FeedValueFor<T>, u8), MomentOf<T>>;

/// Provides access to all the price feeds
/// This is used to determine the equivalent amount of PINT for assets
Expand All @@ -75,7 +71,7 @@ pub mod pallet {
/// means of the asset pair `(base / quote)`. (e.g. DOT/PINT)
#[pallet::config]
pub trait Config:
frame_system::Config + pallet_chainlink_feed::Config + MaybeAssetIdConvert<u8, Self::AssetId>
frame_system::Config + MaybeAssetIdConvert<u8, Self::AssetId>
{
/// The origin that is allowed to insert asset -> feed mappings
type AdminOrigin: EnsureOrigin<Self::Origin>;
Expand All @@ -94,116 +90,44 @@ pub mod pallet {

/// The weight for this pallet's extrinsics.
type WeightInfo: WeightInfo;

type DataProvider: DataProvider<Self::AssetId, Price>;
}

#[pallet::pallet]
#[pallet::without_storage_info]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

/// Store a mapping (AssetId) -> FeedId for all active assets
#[pallet::storage]
#[pallet::getter(fn asset_feed)]
pub type AssetFeeds<T: Config> = StorageMap<_, Blake2_128Concat, T::AssetId, FeedIdFor<T>, OptionQuery>;

#[pallet::storage]
#[pallet::getter(fn latest_answer_timestamp)]
/// Stores the timestamp of the latest answer of each feed (feed) ->
/// Timestamp
pub type LatestAnswerTimestamp<T: Config> = StorageMap<_, Twox64Concat, FeedIdFor<T>, MomentOf<T>, ValueQuery>;

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config>
where
<T as pallet_chainlink_feed::Config>::FeedId: MaybeSerializeDeserialize,
{
/// The mappings to insert at genesis
pub asset_feeds: Vec<(T::AssetId, FeedIdFor<T>)>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T>
where
<T as pallet_chainlink_feed::Config>::FeedId: MaybeSerializeDeserialize,
{
fn default() -> Self {
Self { asset_feeds: Default::default() }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T>
where
<T as pallet_chainlink_feed::Config>::FeedId: MaybeSerializeDeserialize,
{
fn build(&self) {
for (asset, feed) in &self.asset_feeds {
AssetFeeds::<T>::insert(asset.clone(), *feed)
}
}
}

#[cfg(feature = "std")]
impl<T: Config> GenesisConfig<T>
where
<T as pallet_chainlink_feed::Config>::FeedId: MaybeSerializeDeserialize,
{
/// Direct implementation of `GenesisBuild::build_storage`.
///
/// Kept in order not to break dependency.
pub fn build_storage(&self) -> Result<frame_support::sp_runtime::Storage, String> {
<Self as GenesisBuild<T>>::build_storage(self)
}

/// Direct implementation of `GenesisBuild::assimilate_storage`.
///
/// Kept in order not to break dependency.
pub fn assimilate_storage(&self, storage: &mut frame_support::sp_runtime::Storage) -> Result<(), String> {
<Self as GenesisBuild<T>>::assimilate_storage(self, storage)
}
}
// #[cfg(feature = "std")]
// impl<T: Config> GenesisConfig<T>
// where
// <T as pallet_chainlink_feed::Config>::FeedId: MaybeSerializeDeserialize,
// {
// /// Direct implementation of `GenesisBuild::build_storage`.
// ///
// /// Kept in order not to break dependency.
// pub fn build_storage(&self) -> Result<frame_support::sp_runtime::Storage, String> {
// <Self as GenesisBuild<T>>::build_storage(self)
// }

// /// Direct implementation of `GenesisBuild::assimilate_storage`.
// ///
// /// Kept in order not to break dependency.
// pub fn assimilate_storage(&self, storage: &mut frame_support::sp_runtime::Storage) -> Result<(), String> {
// <Self as GenesisBuild<T>>::assimilate_storage(self, storage)
// }
// }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A new assetId -> feedId mapping was inserted
/// \[AssetId, NewFeedId, OldFeedId\]
UpdateAssetPriceFeed(T::AssetId, FeedIdFor<T>, Option<FeedIdFor<T>>),
/// An assetId -> feedId was removed
/// \[AssetId, FeedId\]
RemoveAssetPriceFeed(T::AssetId, FeedIdFor<T>),
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Maps the given asset to an existing price feed.
/// If the asset was already mapped to a price feed this will update the mapping
///
/// Callable by the governance committee.
#[pallet::weight(<T as Config>::WeightInfo::map_asset_price_feed())]
pub fn map_asset_price_feed(
origin: OriginFor<T>,
asset_id: T::AssetId,
feed_id: FeedIdFor<T>,
) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
let old_feed_id = AssetFeeds::<T>::mutate(&asset_id, |maybe_feed_id| maybe_feed_id.replace(feed_id));
Self::deposit_event(Event::UpdateAssetPriceFeed(asset_id, feed_id, old_feed_id));
Ok(())
}

/// Removes the the `asset` -> `feed` mapping if it exists.
/// This is a noop if the asset is not tracked.
///
/// Callable by the governance committee.
#[pallet::weight(<T as Config>::WeightInfo::unmap_asset_price_feed())]
pub fn unmap_asset_price_feed(origin: OriginFor<T>, asset_id: T::AssetId) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
if let Some(feed_id) = AssetFeeds::<T>::take(&asset_id) {
Self::deposit_event(Event::RemoveAssetPriceFeed(asset_id, feed_id));
}
Ok(())
}
//
}

#[pallet::error]
Expand All @@ -218,45 +142,15 @@ pub mod pallet {
ExceededAccuracy,
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}

impl<T: Config> Pallet<T> {
/// Returns the corresponding identifier for the asset's price feed
/// according to the internal mapping
pub fn asset_feed_id(asset_id: &T::AssetId) -> Option<FeedIdFor<T>> {
AssetFeeds::<T>::get(asset_id)
}

/// Returns the latest value in the feed together with the feed's
/// decimals (the feed's precision) or an error if no feed was found for the given
/// or the feed doesn't contain any valid round yet.
pub fn latest_valid_value(feed_id: FeedIdFor<T>) -> Result<(FeedValueFor<T>, u8), DispatchError> {
let feed = pallet_chainlink_feed::Pallet::<T>::feed(feed_id).ok_or(Error::<T>::AssetPriceFeedNotFound)?;
ensure!(feed.first_valid_round().is_some(), Error::<T>::InvalidFeedValue);
Ok((feed.latest_data().answer, feed.decimals()))
}

/// Same as `latest_value` but with the time the answer was emitted
pub fn latest_timestamped_value(feed_id: FeedIdFor<T>) -> Result<TimestampedFeedValue<T>, DispatchError> {
let moment = LatestAnswerTimestamp::<T>::get(&feed_id);
let value = Self::latest_valid_value(feed_id)?;
Ok(TimestampedValue { value, moment })
}
}

impl<T: Config> PriceFeed<T::AssetId> for Pallet<T>
where
FeedValueFor<T>: FixedPointOperand,
{
impl<T: Config> PriceFeed<T::AssetId> for Pallet<T> {
fn get_price(base: T::AssetId) -> Result<Price, DispatchError> {
// let feed = Self::asset_feed_id(&base).ok_or(Error::<T>::AssetPriceFeedNotFound)?;

// let (value, precision) = Self::latest_valid_value(feed)?;
// let multiplier = 10u128.checked_pow(precision.into()).ok_or(Error::<T>::ExceededAccuracy)?;

// Price::checked_from_rational(value, multiplier).ok_or_else(|| Error::<T>::ExceededAccuracy.into())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

DataProvider::<T::AssetId, Price>::get(&base).ok_or_else(|| Error::<T>::ExceededAccuracy.into())
T::DataProvider::get(&base).ok_or_else(|| Error::<T>::ExceededAccuracy.into())
}

fn get_relative_price_pair(
Expand All @@ -270,52 +164,6 @@ pub mod pallet {
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<T: Config> PriceFeedBenchmarks<T::AccountId, T::AssetId> for Pallet<T> {
fn create_feed(
caller: <T as frame_system::Config>::AccountId,
asset_id: T::AssetId,
) -> DispatchResultWithPostInfo {
use frame_benchmarking::vec;

pallet_chainlink_feed::Pallet::<T>::set_feed_creator(
<frame_system::Origin<T>>::Signed(pallet_chainlink_feed::Pallet::<T>::pallet_admin()).into(),
caller.clone(),
)?;

pallet_chainlink_feed::Pallet::<T>::create_feed(
<frame_system::Origin<T>>::Signed(caller.clone()).into(),
100u32.into(),
Zero::zero(),
(1u8.into(), 100u8.into()),
1u8.into(),
0u8,
vec![1; T::StringLimit::get() as usize],
Zero::zero(),
vec![(caller.clone(), caller.clone())],
None,
None,
)?;

let feed_id = <pallet_chainlink_feed::FeedCounter<T>>::get() - 1.into();
AssetFeeds::<T>::insert(&asset_id, feed_id);
pallet_chainlink_feed::Pallet::<T>::submit(
<frame_system::Origin<T>>::Signed(caller.clone()).into(),
feed_id,
1_u32.into(),
1.into(),
)?;

Ok(().into())
}
}

impl<T: Config> pallet_chainlink_feed::traits::OnAnswerHandler<T> for Pallet<T> {
fn on_answer(feed_id: FeedIdFor<T>, _: RoundData<T::BlockNumber, FeedValueFor<T>>) {
LatestAnswerTimestamp::<T>::insert(feed_id, T::Time::now());
}
}

/// Trait for the asset-index pallet extrinsic weights.
pub trait WeightInfo {
fn map_asset_price_feed() -> Weight;
Expand Down
Loading