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

Issue/change price feed apollo #1277

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 2 additions & 5 deletions pallets/apollo-platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub mod pallet {
#[pallet::config]
pub trait Config:
frame_system::Config
+ price_tools::Config
+ liquidity_proxy::Config
+ trading_pair::Config
+ common::Config
Expand Down Expand Up @@ -1500,8 +1499,7 @@ pub mod pallet {
&APOLLO_ASSET_ID.into(),
SwapAmount::with_desired_input(rewards_amount, Balance::zero()),
LiquiditySourceFilter::empty(DEXId::Polkaswap.into()),
)
.unwrap();
)?;

let buyback_amount = outcome.amount;

Expand Down Expand Up @@ -1556,8 +1554,7 @@ pub mod pallet {
&CERES_ASSET_ID.into(),
SwapAmount::with_desired_input(ceres_amount, Balance::zero()),
LiquiditySourceFilter::empty(DEXId::Polkaswap.into()),
)
.unwrap();
)?;

T::AssetManager::burn(
RawOrigin::Signed(caller).into(),
Expand Down
47 changes: 47 additions & 0 deletions pallets/demeter-farming-platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ pub mod pallet {
bool,
Balance,
),
/// Removed pool activated [who, base_asset, pool_asset, reward_asset, is_farm]
RemovedPoolActivated(
AccountIdOf<T>,
AssetIdOf<T>,
AssetIdOf<T>,
AssetIdOf<T>,
bool,
),
}

#[pallet::error]
Expand Down Expand Up @@ -1044,6 +1052,45 @@ pub mod pallet {
// Return a successful DispatchResult
Ok(().into())
}

/// Activate removed pool
#[pallet::call_index(11)]
#[pallet::weight(<T as Config>::WeightInfo::activate_removed_pool())]
pub fn activate_removed_pool(
origin: OriginFor<T>,
base_asset: AssetIdOf<T>,
pool_asset: AssetIdOf<T>,
reward_asset: AssetIdOf<T>,
is_farm: bool,
) -> DispatchResultWithPostInfo {
let user = ensure_signed(origin)?;

if user != AuthorityAccount::<T>::get() {
return Err(Error::<T>::Unauthorized.into());
}

// Get pool info
let mut pool_infos = <Pools<T>>::get(&pool_asset, &reward_asset);
for pool_info in pool_infos.iter_mut() {
if pool_info.is_farm == is_farm && pool_info.base_asset == base_asset {
pool_info.is_removed = false;
}
}

<Pools<T>>::insert(&pool_asset, &reward_asset, &pool_infos);

// Emit an event
Self::deposit_event(Event::<T>::RemovedPoolActivated(
user,
base_asset,
pool_asset,
reward_asset,
is_farm,
));

// Return a successful DispatchResult
Ok(().into())
}
}

#[pallet::hooks]
Expand Down
64 changes: 64 additions & 0 deletions pallets/demeter-farming-platform/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3999,4 +3999,68 @@ mod tests {
}
});
}

#[test]
fn activate_removed_pool_ok() {
let mut ext = ExtBuilder::default().build();
ext.execute_with(|| {
let pool_asset = XOR;
let reward_asset = CERES_ASSET_ID;
let is_farm = true;

let pool_info = PoolData {
multiplier: 1,
deposit_fee: balance!(0),
is_core: true,
is_farm,
total_tokens_in_pool: 0,
rewards: 100,
rewards_to_be_distributed: 0,
is_removed: false,
base_asset: XOR,
};

demeter_farming_platform::Pools::<Runtime>::append(
&pool_asset,
&reward_asset,
&pool_info,
);

assert_ok!(demeter_farming_platform::Pallet::<Runtime>::remove_pool(
RuntimeOrigin::signed(demeter_farming_platform::AuthorityAccount::<Runtime>::get()),
pool_asset,
pool_asset,
reward_asset,
is_farm,
));

let mut pool_infos =
demeter_farming_platform::Pools::<Runtime>::get(&pool_asset, &reward_asset);
for pool_info in pool_infos.iter_mut() {
if pool_info.is_farm == is_farm && pool_info.base_asset == pool_asset {
assert_eq!(pool_info.is_removed, true);
}
}

assert_ok!(
demeter_farming_platform::Pallet::<Runtime>::activate_removed_pool(
RuntimeOrigin::signed(
demeter_farming_platform::AuthorityAccount::<Runtime>::get()
),
pool_asset,
pool_asset,
reward_asset,
is_farm,
)
);

let mut pool_infos =
demeter_farming_platform::Pools::<Runtime>::get(&pool_asset, &reward_asset);
for pool_info in pool_infos.iter_mut() {
if pool_info.is_farm == is_farm && pool_info.base_asset == pool_asset {
assert_eq!(pool_info.is_removed, false);
}
}
});
}
}
27 changes: 27 additions & 0 deletions pallets/demeter-farming-platform/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub trait WeightInfo {
fn change_total_tokens() -> Weight;
fn change_info() -> Weight;
fn change_token_info() -> Weight;
fn activate_removed_pool() -> Weight;
}

/// Weights for demeter_farming_platform using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -249,6 +250,19 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: DemeterFarmingPlatform AuthorityAccount (r:1 w:0)
/// Proof Skipped: DemeterFarmingPlatform AuthorityAccount (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: DemeterFarmingPlatform Pools (r:1 w:1)
/// Proof Skipped: DemeterFarmingPlatform Pools (max_values: None, max_size: None, mode: Measured)
fn activate_removed_pool() -> Weight {
// Proof Size summary in bytes:
// Measured: `268`
// Estimated: `3506`
// Minimum execution time: 30_569_000 picoseconds.
Weight::from_parts(30_867_000, 3506)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -426,4 +440,17 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: DemeterFarmingPlatform AuthorityAccount (r:1 w:0)
/// Proof Skipped: DemeterFarmingPlatform AuthorityAccount (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: DemeterFarmingPlatform Pools (r:1 w:1)
/// Proof Skipped: DemeterFarmingPlatform Pools (max_values: None, max_size: None, mode: Measured)
fn activate_removed_pool() -> Weight {
// Proof Size summary in bytes:
// Measured: `268`
// Estimated: `3506`
// Minimum execution time: 30_569_000 picoseconds.
Weight::from_parts(30_867_000, 3506)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,7 @@ parameter_types! {
impl apollo_platform::Config for Runtime {
const BLOCKS_PER_FIFTEEN_MINUTES: BlockNumber = 15 * MINUTES;
type RuntimeEvent = RuntimeEvent;
type PriceTools = PriceTools;
type PriceTools = price_tools::FastPriceTools<Runtime>;
type LiquidityProxyPallet = LiquidityProxy;
type UnsignedPriority = ApolloOffchainWorkerTxPriority;
type UnsignedLongevity = ApolloOffchainWorkerTxLongevity;
Expand Down
Loading