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

Added tests for OCEX and LMP Pallet #895

Merged
merged 17 commits into from
Feb 21, 2024
290 changes: 149 additions & 141 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ resolver = "2"
members = [
"client",
"nodes/mainnet",
# "nodes/parachain",
# "nodes/parachain",
"runtimes/mainnet",
# "runtimes/parachain",
# "runtimes/parachain",
"rpc/assets",
"rpc/swap",
"rpc/assets/runtime-api",
Expand Down Expand Up @@ -54,9 +54,9 @@ exclude = ["scripts/check-off-on-deviation"]
default-members = [
"client",
"nodes/mainnet",
# "nodes/parachain",
# "nodes/parachain",
"runtimes/mainnet",
# "runtimes/parachain",
# "runtimes/parachain",
"pallets/pdex-migration",
"pallets/pdex-migration",
"pallets/ocex",
Expand Down
2 changes: 1 addition & 1 deletion check-all-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ cargo build --features try-runtime || exit
cargo build --features runtime-benchmarks || exit
./target/debug/polkadex-node benchmark pallet --pallet "*" --extrinsic "*" --steps 2 --repeat 1 || exit
cargo clippy -- -D warnings || exit
cargo test || exit
RUSTFLAGS="-D warnings" cargo test || exit
48 changes: 33 additions & 15 deletions pallets/liquidity-mining/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,40 @@ frame-support = { workspace = true, default-features = false }
sp-std = { workspace = true, default-features = false }
sp-io = { workspace = true, default-features = false }
sp-runtime = { workspace = true, default-features = false }
orderbook-primitives = {path="../../primitives/orderbook", default-features = false}
polkadex-primitives = {path="../../primitives/polkadex", default-features = false}
rust_decimal = {workspace = true, default-features = false}
orderbook-primitives = { path = "../../primitives/orderbook", default-features = false }
polkadex-primitives = { path = "../../primitives/polkadex", default-features = false }
rust_decimal = { workspace = true, default-features = false }

[dev-dependencies]
pallet-ocex-lmp = { path = "../ocex", default-features = false }
pallet-assets = { workspace = true, default-features = false }
pallet-balances = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }
sp-application-crypto = { workspace = true }
sp-io = { workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false }

[features]
default = [ "std" ]
default = ["std"]
std = [
"log/std",
"parity-scale-codec/std",
"frame-system/std",
"frame-support/std",
"scale-info/std",
"orderbook-primitives/std",
"polkadex-primitives/std",
"rust_decimal/std",
"sp-runtime/std",
"sp-std/std",
"sp-io/std"
"log/std",
"parity-scale-codec/std",
"frame-system/std",
"frame-support/std",
"scale-info/std",
"orderbook-primitives/std",
"polkadex-primitives/std",
"rust_decimal/std",
"sp-runtime/std",
"sp-std/std",
"pallet-ocex-lmp/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-timestamp/std",
"sp-io/std",
"sp-application-crypto/std",
"sp-io/std",
"sp-core/std",
]
runtime-benchmarks = ["sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]
18 changes: 10 additions & 8 deletions pallets/liquidity-mining/src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ impl<T: Config> LiquidityMiningCrowdSourcePallet<T::AccountId> for Pallet<T> {

fn add_liquidity_success(
market: TradingPair,
pool: &T::AccountId,
market_maker: &T::AccountId,
lp: &T::AccountId,
shared_issued: Decimal,
price: Decimal,
total_inventory_in_quote: Decimal,
) -> DispatchResult {
let pool_config = <Pools<T>>::get(market, pool).ok_or(Error::<T>::UnknownPool)?;
let pool_config = <Pools<T>>::get(market, market_maker).ok_or(Error::<T>::UnknownPool)?;
let new_shared_issued = shared_issued
.saturating_mul(Decimal::from(UNIT_BALANCE))
.to_u128()
Expand Down Expand Up @@ -56,10 +56,10 @@ impl<T: Config> LiquidityMiningCrowdSourcePallet<T::AccountId> for Pallet<T> {

Self::deposit_event(Event::<T>::LiquidityAdded {
market,
pool: pool.clone(),
pool: market_maker.clone(),
lp: lp.clone(),
shares: new_shared_issued.saturated_into(),
share_id: pool_config.share_id,
share_id: polkadex_primitives::AssetId::Asset(pool_config.share_id),
price,
total_inventory_in_quote,
});
Expand Down Expand Up @@ -146,13 +146,14 @@ impl<T: Config> LiquidityMiningCrowdSourcePallet<T::AccountId> for Pallet<T> {

fn pool_force_close_success(
market: TradingPair,
pool: &T::AccountId,
market_maker: &T::AccountId,
base_freed: Decimal,
quote_freed: Decimal,
) -> DispatchResult {
let mut pool_config = <Pools<T>>::get(market, pool).ok_or(Error::<T>::UnknownPool)?;
let mut pool_config =
<Pools<T>>::get(market, market_maker).ok_or(Error::<T>::UnknownPool)?;
pool_config.force_closed = true;
<Pools<T>>::insert(market, pool, pool_config);
<Pools<T>>::insert(market, market_maker, pool_config);
let base_freed = base_freed
.saturating_mul(Decimal::from(UNIT_BALANCE))
.to_u128()
Expand All @@ -163,9 +164,10 @@ impl<T: Config> LiquidityMiningCrowdSourcePallet<T::AccountId> for Pallet<T> {
.to_u128()
.ok_or(Error::<T>::ConversionError)?
.saturated_into();
//FIXME: What are we doing with base_freed and quote_freed?
Copy link
Contributor

Choose a reason for hiding this comment

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

When it should be discussed and fixed? in scope of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be fixed in @Gauthamastro PR

Self::deposit_event(Event::<T>::PoolForceClosed {
market,
pool: pool.clone(),
pool: market_maker.clone(),
base_freed,
quote_freed,
});
Expand Down
Loading