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

Presto: publish Crop Receipt #1294

Merged
merged 9 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions Cargo.lock

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

33 changes: 33 additions & 0 deletions common/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,39 @@ pub struct AssetInfo {
pub description: Option<Description>,
}

#[derive(
Encode,
Decode,
Eq,
PartialEq,
Copy,
Clone,
PartialOrd,
Ord,
Debug,
Hash,
scale_info::TypeInfo,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct OrderBookId<AssetId, DEXId> {
/// DEX id
pub dex_id: DEXId,
/// Base asset.
pub base: AssetId,
/// Quote asset. It should be a base asset of DEX.
pub quote: AssetId,
}

impl<AssetId, DEXId> From<OrderBookId<AssetId, DEXId>> for TradingPair<AssetId> {
fn from(order_book_id: OrderBookId<AssetId, DEXId>) -> Self {
Self {
base_asset_id: order_book_id.quote,
target_asset_id: order_book_id.base,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
59 changes: 58 additions & 1 deletion common/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::prelude::{
use crate::{
Amount, AssetId32, AssetName, AssetSymbol, AssetType, BalancePrecision, ContentSource,
Description, Fixed, LiquiditySourceFilter, LiquiditySourceId, LiquiditySourceType, Oracle,
PredefinedAssetId, PriceVariant, PswapRemintInfo, RewardReason,
OrderBookId, PredefinedAssetId, PriceVariant, PswapRemintInfo, RewardReason,
};

use frame_support::dispatch::{DispatchResult, DispatchResultWithPostInfo};
Expand Down Expand Up @@ -1554,3 +1554,60 @@ impl<AccountId, AssetId> AssetRegulator<AccountId, AssetId> for () {
Ok(())
}
}

/// Trait to manage and interact with order book
pub trait OrderBookManager<AccountId, AssetId, DEXId, Moment> {
fn assemble_order_book_id(
dex_id: DEXId,
input_asset_id: &AssetId,
output_asset_id: &AssetId,
) -> Option<OrderBookId<AssetId, DEXId>>;

fn initialize_orderbook(
order_book_id: &OrderBookId<AssetId, DEXId>,
tick_size: Balance,
step_lot_size: Balance,
min_lot_size: Balance,
max_lot_size: Balance,
) -> Result<(), DispatchError>;

fn place_limit_order(
owner: AccountId,
order_book_id: OrderBookId<AssetId, DEXId>,
price: Balance,
amount: Balance,
side: PriceVariant,
lifespan: Option<Moment>,
) -> Result<(), DispatchError>;
}

impl<AccountId, AssetId, DEXId, Moment> OrderBookManager<AccountId, AssetId, DEXId, Moment> for () {
fn assemble_order_book_id(
_dex_id: DEXId,
_input_asset_id: &AssetId,
_output_asset_id: &AssetId,
) -> Option<OrderBookId<AssetId, DEXId>> {
None
}

fn initialize_orderbook(
_order_book_id: &OrderBookId<AssetId, DEXId>,
_tick_size: Balance,
_step_lot_size: Balance,
_min_lot_size: Balance,
_max_lot_size: Balance,
) -> Result<(), DispatchError> {
Ok(())
}

fn place_limit_order(
_owner: AccountId,
_order_book_id: OrderBookId<AssetId, DEXId>,
_price: Balance,
_amount: Balance,
_side: PriceVariant,
_lifespan: Option<Moment>,
) -> Result<(), DispatchError> {
Ok(())
}
}
2 changes: 1 addition & 1 deletion pallets/liquidity-proxy/src/alt_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use qa_tools::pallet_tools::pool_xyk::AssetPairInput;
use qa_tools::pallet_tools::price_tools::AssetPrices;
use sp_std::vec;

pub type OrderBookId = order_book::OrderBookId<AssetIdOf<Runtime>, DexIdOf<Runtime>>;
pub type OrderBookId = common::OrderBookId<AssetIdOf<Runtime>, DexIdOf<Runtime>>;
pub const DEX: common::DEXId = common::DEXId::Polkaswap;

pub fn alice() -> AccountIdOf<Runtime> {
Expand Down
8 changes: 4 additions & 4 deletions pallets/order-book/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ use crate as order_book_benchmarking_imported;
#[cfg(test)]
use framenode_runtime::order_book_benchmarking as order_book_benchmarking_imported;

use common::{AssetIdOf, DEXId};
use common::{AssetIdOf, DEXId, OrderBookId};
use frame_system::EventRecord;
use order_book_imported::Pallet as OrderBookPallet;
use order_book_imported::{LimitOrder, MomentOf, OrderBookId};
use order_book_imported::{LimitOrder, MomentOf};

mod periphery;
#[cfg(test)]
Expand Down Expand Up @@ -148,8 +148,8 @@ mod benchmarks_inner {
use order_book_imported::test_utils::fill_tools::{AmountVariant, FillSettings};
use order_book_imported::test_utils::{accounts, create_and_fill_order_book};
use order_book_imported::{
CancelReason, Event, ExpirationScheduler, MarketRole, OrderBook, OrderBookId,
OrderBookStatus, OrderPrice, OrderVolume,
CancelReason, Event, ExpirationScheduler, MarketRole, OrderBook, OrderBookStatus,
OrderPrice, OrderVolume,
};
use periphery::presets::*;

Expand Down
4 changes: 2 additions & 2 deletions pallets/order-book/benchmarking/src/periphery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate as order_book_benchmarking_imported;
#[cfg(test)]
use framenode_runtime::order_book_benchmarking as order_book_benchmarking_imported;

use common::{AssetIdOf, AssetInfoProvider, PriceVariant, VAL, XOR};
use common::{AssetIdOf, AssetInfoProvider, OrderBookId, PriceVariant, VAL, XOR};
use frame_system::RawOrigin;
use order_book_benchmarking_imported::Config;
use order_book_imported::Pallet as OrderBookPallet;
Expand All @@ -55,7 +55,7 @@ use order_book_imported::{
fill_tools::{AmountVariant, FillSettings},
},
CancelReason, Event, LimitOrder, LimitOrders, MarketRole, MomentOf, OrderAmount, OrderBook,
OrderBookId, OrderBookStatus, OrderBooks, OrderPrice, OrderVolume,
OrderBookStatus, OrderBooks, OrderPrice, OrderVolume,
};

use crate::{assert_last_event, assert_orders_numbers, DEX};
Expand Down
4 changes: 2 additions & 2 deletions pallets/order-book/benchmarking/src/periphery/preparation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate as order_book_benchmarking_imported;
use framenode_runtime::order_book_benchmarking as order_book_benchmarking_imported;

use common::prelude::{QuoteAmount, Scalar};
use common::{balance, AssetIdOf, AssetManager, Balance, PriceVariant, ETH, VAL, XOR};
use common::{balance, AssetIdOf, AssetManager, Balance, OrderBookId, PriceVariant, ETH, VAL, XOR};
use frame_benchmarking::log::debug;
use frame_support::traits::Time;
use frame_system::RawOrigin;
Expand All @@ -55,7 +55,7 @@ use order_book_imported::test_utils::fill_tools::{
};
use order_book_imported::{
cache_data_layer::CacheDataLayer, traits::DataLayer, DealInfo, LimitOrder, MomentOf, OrderBook,
OrderBookId, OrderBooks, OrderPrice, OrderVolume,
OrderBooks, OrderPrice, OrderVolume,
};
use sp_runtime::traits::{CheckedMul, SaturatedConversion};
use sp_std::iter::Peekable;
Expand Down
5 changes: 2 additions & 3 deletions pallets/order-book/src/cache_data_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@

use crate::{
AggregatedAsks, AggregatedBids, Asks, Bids, Config, DataLayer, Error, LimitOrder, LimitOrders,
MarketSide, OrderBookId, OrderPrice, OrderVolume, PriceOrders, UserLimitOrders, UserOrders,
MarketSide, OrderPrice, OrderVolume, PriceOrders, UserLimitOrders, UserOrders,
};
use common::cache_storage::{CacheStorageDoubleMap, CacheStorageMap};
use common::AssetIdOf;
use common::PriceVariant;
use common::{AssetIdOf, OrderBookId, PriceVariant};
use frame_support::ensure;
use frame_support::sp_runtime::DispatchError;
use frame_support::traits::Len;
Expand Down
Loading