Skip to content

Commit 3216103

Browse files
committed
generic AssetId in swap router
1 parent 26ea50a commit 3216103

4 files changed

Lines changed: 29 additions & 14 deletions

File tree

example/runtime/src/weights/block_weights.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ pub mod constants {
3838
let w = super::constants::BlockExecutionWeight::get();
3939

4040
// At least 100 µs.
41-
assert!(w >= 100u64 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs.");
41+
assert!(
42+
w >= 100u64 * constants::WEIGHT_PER_MICROS,
43+
"Weight should be at least 100 µs."
44+
);
4245
// At most 50 ms.
4346
assert!(w <= 50u64 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
4447
}

example/runtime/src/zenlink.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ impl zenlink_swap_router::Config for Runtime {
167167
type Event = super::Event;
168168
type StablePoolId = PoolId;
169169
type Balance = Balance;
170-
type CurrencyId = CurrencyId;
170+
type StableCurrencyId = CurrencyId;
171+
type NormalCurrencyId = AssetId;
171172
type NormalAmm = ZenlinkProtocol;
172173
type StableAMM = ZenlinkStableAmm;
173174
type WeightInfo = ();

zenlink-swap-router/src/lib.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use frame_support::{
2727
transactional,
2828
};
2929

30-
use zenlink_protocol::{AssetBalance, AssetId, ExportZenlink};
30+
use zenlink_protocol::{AssetBalance, ExportZenlink};
3131
use zenlink_stable_amm::traits::StableAmmApi;
3232

3333
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)]
@@ -47,9 +47,9 @@ pub enum StableSwapMode {
4747
}
4848

4949
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)]
50-
pub enum Route<PoolId, CurrencyId> {
51-
Stable(StablePath<PoolId, CurrencyId>),
52-
Normal(Vec<AssetId>),
50+
pub enum Route<PoolId, StableCurrencyId, NormalCurrencyId> {
51+
Stable(StablePath<PoolId, StableCurrencyId>),
52+
Normal(Vec<NormalCurrencyId>),
5353
}
5454

5555
pub use pallet::*;
@@ -88,19 +88,29 @@ pub mod pallet {
8888
+ Into<AssetBalance>
8989
+ TypeInfo;
9090

91-
type CurrencyId: Parameter
91+
// The currency id use in stable amm
92+
type StableCurrencyId: Parameter
9293
+ Member
9394
+ Copy
9495
+ MaybeSerializeDeserialize
9596
+ Ord
9697
+ TypeInfo
9798
+ MaxEncodedLen;
9899

99-
type NormalAmm: ExportZenlink<AccountIdOf<Self>, AssetId>;
100+
// The currency id use in standard amm
101+
type NormalCurrencyId: Parameter
102+
+ Member
103+
+ Copy
104+
+ MaybeSerializeDeserialize
105+
+ Ord
106+
+ TypeInfo
107+
+ MaxEncodedLen;
108+
109+
type NormalAmm: ExportZenlink<AccountIdOf<Self>, Self::NormalCurrencyId>;
100110

101111
type StableAMM: StableAmmApi<
102112
Self::StablePoolId,
103-
Self::CurrencyId,
113+
Self::StableCurrencyId,
104114
AccountIdOf<Self>,
105115
Self::Balance,
106116
>;
@@ -135,7 +145,7 @@ pub mod pallet {
135145
origin: OriginFor<T>,
136146
amount_in: T::Balance,
137147
amount_out_min: T::Balance,
138-
routes: Vec<Route<T::StablePoolId, T::CurrencyId>>,
148+
routes: Vec<Route<T::StablePoolId, T::StableCurrencyId, T::NormalCurrencyId>>,
139149
to: T::AccountId,
140150
deadline: T::BlockNumber,
141151
) -> DispatchResult {
@@ -175,7 +185,7 @@ pub mod pallet {
175185
impl<T: Config> Pallet<T> {
176186
fn stable_swap(
177187
who: &T::AccountId,
178-
path: &StablePath<T::StablePoolId, T::CurrencyId>,
188+
path: &StablePath<T::StablePoolId, T::StableCurrencyId>,
179189
amount_in: T::Balance,
180190
to: &T::AccountId,
181191
) -> Result<T::Balance, DispatchError> {
@@ -235,7 +245,7 @@ impl<T: Config> Pallet<T> {
235245
fn swap(
236246
who: &T::AccountId,
237247
amount_in: T::Balance,
238-
path: &[AssetId],
248+
path: &[T::NormalCurrencyId],
239249
to: &T::AccountId,
240250
) -> DispatchResult {
241251
T::NormalAmm::inner_swap_exact_assets_for_assets(
@@ -249,7 +259,7 @@ impl<T: Config> Pallet<T> {
249259

250260
fn currency_index_from_stable_pool(
251261
pool_id: T::StablePoolId,
252-
currency_id: T::CurrencyId,
262+
currency_id: T::StableCurrencyId,
253263
) -> Result<u32, DispatchError> {
254264
T::StableAMM::currency_index(pool_id, currency_id)
255265
.ok_or_else(|| Error::<T>::MismatchPoolAndCurrencyId.into())

zenlink-swap-router/src/mock.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ impl Config for Test {
227227
type Event = Event;
228228
type StablePoolId = PoolId;
229229
type Balance = Balance;
230-
type CurrencyId = CurrencyId;
230+
type StableCurrencyId = CurrencyId;
231+
type NormalCurrencyId = AssetId;
231232
type NormalAmm = Zenlink;
232233
type StableAMM = StableAMM;
233234
type WeightInfo = ();

0 commit comments

Comments
 (0)