Skip to content

Commit 00b2cfe

Browse files
committed
[Pablo] Minimal ConstantProductPool Integration
1 parent 58ff70c commit 00b2cfe

File tree

3 files changed

+380
-5
lines changed

3 files changed

+380
-5
lines changed

frame/composable-traits/src/dex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub trait SimpleExchange {
130130
) -> Result<Self::Balance, DispatchError>;
131131
}
132132

133-
#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, Default, PartialEq, RuntimeDebug)]
133+
#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, Default, PartialEq, Eq, RuntimeDebug)]
134134
pub struct ConstantProductPoolInfo<AccountId, AssetId> {
135135
/// Owner of pool
136136
pub owner: AccountId,

frame/pablo/src/lib.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ mod mock;
4242
mod stable_swap_tests;
4343

4444
mod stable_swap;
45+
mod uniswap;
4546

4647
#[frame_support::pallet]
4748
pub mod pallet {
49+
use crate::{uniswap::Uniswap, PoolConfiguration::ConstantProduct};
4850
use codec::{Codec, FullCodec};
4951
use composable_traits::{
50-
currency::CurrencyFactory,
52+
currency::{CurrencyFactory, LocalAssets},
5153
defi::CurrencyPair,
52-
dex::{Amm, StableSwapPoolInfo},
54+
dex::{Amm, ConstantProductPoolInfo, StableSwapPoolInfo},
5355
math::{SafeAdd, SafeSub},
5456
};
5557
use core::fmt::Debug;
@@ -80,13 +82,14 @@ pub mod pallet {
8082
#[derive(RuntimeDebug, Encode, Decode, MaxEncodedLen, Clone, PartialEq, Eq, TypeInfo)]
8183
pub enum PoolConfiguration<AccountId, AssetId> {
8284
StableSwap(StableSwapPoolInfo<AccountId, AssetId>),
85+
ConstantProduct(ConstantProductPoolInfo<AccountId, AssetId>),
8386
}
8487

8588
type AssetIdOf<T> = <T as Config>::AssetId;
8689
type BalanceOf<T> = <T as Config>::Balance;
8790
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
8891
type PoolIdOf<T> = <T as Config>::PoolId;
89-
type PoolConfigurationOf<T> =
92+
pub type PoolConfigurationOf<T> =
9093
PoolConfiguration<<T as frame_system::Config>::AccountId, <T as Config>::AssetId>;
9194
type PoolInitConfigurationOf<T> = PoolInitConfiguration<<T as Config>::AssetId>;
9295

@@ -110,7 +113,7 @@ pub mod pallet {
110113
quote_amount: T::Balance,
111114
},
112115
/// Liquidity added into the pool `T::PoolId`.
113-
LiquidityAdded {
116+
LiquidityAddedToStableSwapPool {
114117
/// Account id who added liquidity.
115118
who: T::AccountId,
116119
/// Pool id to which liquidity added.
@@ -122,6 +125,28 @@ pub mod pallet {
122125
/// Amount of minted lp tokens.
123126
mint_amount: T::Balance,
124127
},
128+
/// Liquidity added into the pool `T::PoolId`.
129+
LiquidityAddedToLiquidityBootstrappingPool {
130+
/// Pool id to which liquidity added.
131+
pool_id: T::PoolId,
132+
/// Amount of base asset deposited.
133+
base_amount: T::Balance,
134+
/// Amount of quote asset deposited.
135+
quote_amount: T::Balance,
136+
},
137+
/// Liquidity added into the pool `T::PoolId`.
138+
LiquidityAddedToConstantProductPool {
139+
/// Account id who added liquidity.
140+
who: T::AccountId,
141+
/// Pool id to which liquidity added.
142+
pool_id: T::PoolId,
143+
/// Amount of base asset deposited.
144+
base_amount: T::Balance,
145+
/// Amount of quote asset deposited.
146+
quote_amount: T::Balance,
147+
/// Amount of minted lp.
148+
minted_lp: T::Balance,
149+
},
125150
/// Liquidity removed from pool `T::PoolId` by `T::AccountId` in balanced way.
126151
LiquidityRemoved {
127152
/// Account id who removed liquidity.
@@ -167,6 +192,9 @@ pub mod pallet {
167192
InvalidPair,
168193
InvalidFees,
169194
AmpFactorMustBeGreaterThanZero,
195+
196+
// ConstantProduct Specific: Possibly rename
197+
MissingAmount,
170198
}
171199

172200
#[pallet::config]
@@ -388,6 +416,13 @@ pub mod pallet {
388416

389417
Ok(pool_id)
390418
},
419+
PoolInitConfiguration::ConstantProduct(constant_product_pool_info) =>
420+
Uniswap::<T>::do_create_pool(
421+
&constant_product_pool_info.owner,
422+
constant_product_pool_info.pair,
423+
constant_product_pool_info.fee,
424+
constant_product_pool_info.owner_fee,
425+
),
391426
}
392427
}
393428

0 commit comments

Comments
 (0)