Skip to content

Commit

Permalink
Merge pull request #696 from galacticcouncil/refactor/move_asset_pair…
Browse files Browse the repository at this point in the history
…_to_lbp

refactor: remove dependency on primitives from pallet-lbp
  • Loading branch information
Roznovjak authored Nov 2, 2023
2 parents 5d61f75 + d9082c9 commit aa0033c
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 47 deletions.
12 changes: 5 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.15.0"
version = "1.15.1"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
1 change: 0 additions & 1 deletion integration-tests/src/omnipool_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ fn removing_token_should_work_when_no_shares_remaining() {
position.shares,
));

let state = pallet_omnipool::Pallet::<hydradx_runtime::Runtime>::load_asset_state(DOT).unwrap();
let dot_balance = hydradx_runtime::Tokens::free_balance(DOT, &bob_account);
assert!(dot_balance <= dot_amount);
let lrna_balance = hydradx_runtime::Tokens::free_balance(LRNA, &bob_account);
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use pallet_omnipool::traits::OmnipoolHooks;
use pallet_omnipool::weights::WeightInfo as OmnipoolWeights;
use pallet_route_executor::AmmTradeWeights;

use primitives::asset::AssetPair;
use primitives::AssetId;

use frame_support::{assert_noop, assert_ok};
Expand Down Expand Up @@ -2237,7 +2236,7 @@ fn create_lbp_pool(accumulated_asset: u32, distributed_asset: u32) {
}

fn get_lbp_pair_account_id(asset_a: AssetId, asset_b: AssetId) -> AccountId {
let asset_pair = AssetPair {
let asset_pair = pallet_lbp::AssetPair {
asset_in: asset_a,
asset_out: asset_b,
};
Expand Down
4 changes: 1 addition & 3 deletions pallets/lbp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-lbp"
version = "4.6.16"
version = "4.7.0"
description = "HydraDX Liquidity Bootstrapping Pool Pallet"
authors = ["GalacticCouncil"]
edition = "2021"
Expand All @@ -23,7 +23,6 @@ serde = { features = ["derive"], optional = true, version = "1.0.136" }
## Local dependencies
hydra-dx-math = { workspace = true }
hydradx-traits = { workspace = true }
primitives = { workspace = true }

## ORML dependencies
orml-traits = { workspace = true }
Expand Down Expand Up @@ -63,7 +62,6 @@ std = [
"sp-runtime/std",
"sp-core/std",
"sp-std/std",
"primitives/std",
"hydradx-traits/std",
"scale-info/std",
"hydra-dx-math/std",
Expand Down
1 change: 0 additions & 1 deletion pallets/lbp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use super::*;
use crate::Pallet as LBP;

use hydradx_traits::router::{PoolType, TradeExecution};
use primitives::AssetId;

use frame_benchmarking::{account, benchmarks};
use frame_system::RawOrigin;
Expand Down
4 changes: 3 additions & 1 deletion pallets/lbp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]

pub use crate::types::{Amount, AssetId, AssetPair, Balance};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::sp_runtime::{
traits::{AtLeast32BitUnsigned, BlockNumberProvider, Saturating, Zero},
Expand All @@ -36,7 +37,6 @@ use frame_system::ensure_signed;
use hydra_dx_math::types::LBPWeight;
use hydradx_traits::{AMMTransfer, AssetPairAccountIdFor, CanCreatePool, LockedBalance, AMM};
use orml_traits::{MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency};
use primitives::{asset::AssetPair, Amount, AssetId, Balance};

use scale_info::TypeInfo;

Expand All @@ -58,7 +58,9 @@ pub mod weights;

#[cfg(test)]
mod invariants;

mod trade_execution;
pub mod types;

use weights::WeightInfo;
// Re-export pallet items so that they can be accessed from the crate namespace.
Expand Down
10 changes: 6 additions & 4 deletions pallets/lbp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
use super::*;

use crate as lbp;
use crate::{AssetPairAccountIdFor, Config};
use crate::{
types::{AssetId, AssetPair, Balance},
AssetPairAccountIdFor, Config,
};
use frame_support::parameter_types;
use frame_support::traits::{Everything, GenesisBuild, LockIdentifier, Nothing};
use hydradx_traits::LockedBalance;
use orml_traits::parameter_type_with_key;
use primitives::constants::chain::{AssetId, Balance, CORE_ASSET_ID};
use sp_core::H256;
use sp_runtime::{
testing::Header,
Expand All @@ -28,7 +30,7 @@ pub const ALICE: AccountId = 1;
pub const BOB: AccountId = 2;
pub const CHARLIE: AccountId = 3;

pub const HDX: AssetId = CORE_ASSET_ID;
pub const HDX: AssetId = 0;
pub const KUSD: AssetId = 2_000;
pub const BSX: AssetId = 3_000;
pub const ETH: AssetId = 4_000;
Expand Down Expand Up @@ -151,7 +153,7 @@ impl AssetPairAccountIdFor<AssetId, u64> for AssetPairAccountIdTest {
}

parameter_types! {
pub const NativeAssetId: AssetId = CORE_ASSET_ID;
pub const NativeAssetId: AssetId = HDX;
pub const MinTradingLimit: Balance = 1_000;
pub const MinPoolLiquidity: Balance = 1_000;
pub const MaxInRatio: u128 = 3;
Expand Down
11 changes: 4 additions & 7 deletions pallets/lbp/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ use hydradx_traits::{AMMTransfer, LockedBalance};
use sp_runtime::traits::BadOrigin;
use sp_std::convert::TryInto;

use primitives::asset::AssetPair;
use primitives::constants::chain::CORE_ASSET_ID;

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut ext = ExtBuilder::default().build();
ext.execute_with(|| set_block_number::<Test>(1));
Expand Down Expand Up @@ -2317,12 +2314,12 @@ fn buy_should_work() {
.into(),
frame_system::Event::NewAccount { account: pool_id2 }.into(),
mock::RuntimeEvent::Currency(orml_tokens::Event::Endowed {
currency_id: CORE_ASSET_ID,
currency_id: HDX,
who: HDX_BSX_POOL_ID,
amount: 1000000000,
}),
mock::RuntimeEvent::Currency(orml_tokens::Event::Transfer {
currency_id: CORE_ASSET_ID,
currency_id: HDX,
from: ALICE,
to: HDX_BSX_POOL_ID,
amount: 1000000000,
Expand Down Expand Up @@ -2544,12 +2541,12 @@ fn sell_should_work() {
.into(),
frame_system::Event::NewAccount { account: pool_id2 }.into(),
mock::RuntimeEvent::Currency(orml_tokens::Event::Endowed {
currency_id: CORE_ASSET_ID,
currency_id: HDX,
who: HDX_BSX_POOL_ID,
amount: 1000000000,
}),
mock::RuntimeEvent::Currency(orml_tokens::Event::Transfer {
currency_id: CORE_ASSET_ID,
currency_id: HDX,
from: ALICE,
to: HDX_BSX_POOL_ID,
amount: 1000000000,
Expand Down
4 changes: 1 addition & 3 deletions pallets/lbp/src/trade_execution.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::{Config, Error, Pallet, PoolData};
use crate::*;
use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution};
use hydradx_traits::AMM;
use orml_traits::MultiCurrency;
use primitives::asset::AssetPair;
use primitives::{AssetId, Balance};
use sp_runtime::traits::BlockNumberProvider;
use sp_runtime::DispatchError;

Expand Down
11 changes: 6 additions & 5 deletions primitives/src/asset.rs → pallets/lbp/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is part of Basilisk-node.
// This file is part of HydraDX-node.

// Copyright (C) 2020-2022 Intergalactic, Limited (GIB).
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -15,13 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::AssetId;
pub type AssetId = u32;
pub type Amount = i128;
pub type Balance = u128;

use codec::{Decode, Encode};

use sp_std::vec::Vec;

use scale_info::TypeInfo;
use sp_std::vec::Vec;

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
Expand All @@ -42,6 +42,7 @@ impl AssetPair {
pub fn new(asset_in: AssetId, asset_out: AssetId) -> Self {
Self { asset_in, asset_out }
}

/// Return ordered asset tuple (A,B) where A < B
/// Used in storage
pub fn ordered_pair(&self) -> (AssetId, AssetId) {
Expand Down
6 changes: 1 addition & 5 deletions pallets/xyk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-xyk'
version = "6.3.0"
version = "6.3.1"
description = 'XYK automated market maker'
authors = ['GalacticCouncil']
edition = '2021'
Expand All @@ -23,9 +23,6 @@ log = { version = "0.4.17", default-features = false }

hydra-dx-math = { workspace = true }

# Local dependencies
primitives = {path = '../../primitives', default-features = false}

# ORML dependencies
orml-tokens = { workspace = true }
orml-traits = { workspace = true }
Expand Down Expand Up @@ -65,7 +62,6 @@ std = [
'sp-core/std',
'sp-std/std',
'orml-traits/std',
'primitives/std',
"hydradx-traits/std",
'orml-tokens/std',
'frame-benchmarking/std',
Expand Down
2 changes: 1 addition & 1 deletion pallets/xyk/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use sp_std::prelude::*;

use crate::Pallet as XYK;

use crate::types::{AssetId, Balance};
use hydradx_traits::router::{PoolType, TradeExecution};
use primitives::{AssetId, Balance};

const SEED: u32 = 1;

Expand Down
3 changes: 1 addition & 2 deletions pallets/xyk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ use hydradx_traits::{
};
use sp_std::{vec, vec::Vec};

use crate::types::{AssetId, AssetPair, Balance};
use crate::types::{Amount, AssetId, AssetPair, Balance};
use hydra_dx_math::ratio::Ratio;
use orml_traits::{MultiCurrency, MultiCurrencyExtended};
use primitives::Amount;

#[cfg(test)]
mod tests;
Expand Down
1 change: 1 addition & 0 deletions pallets/xyk/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

pub type AssetId = u32;
pub type Amount = i128;
pub type Balance = u128;
pub type Price = FixedU128;

Expand Down
2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "primitives"
version = "5.8.5"
version = "6.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
repository = "https://github.com/galacticcouncil/HydraDX-node"
Expand Down
1 change: 0 additions & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use frame_support::sp_runtime::{
MultiSignature,
};

pub mod asset;
pub mod constants;

/// An index to a block.
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-runtime"
version = "186.0.0"
version = "187.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("hydradx"),
impl_name: create_runtime_str!("hydradx"),
authoring_version: 1,
spec_version: 186,
spec_version: 187,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit aa0033c

Please sign in to comment.