Skip to content

Commit

Permalink
router refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dorin-iancu committed Nov 18, 2024
1 parent 17b9601 commit 1645824
Show file tree
Hide file tree
Showing 18 changed files with 432 additions and 363 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion dex/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ edition = "2021"
publish = false

[lib]
path = "src/contract.rs"
path = "src/lib.rs"

[dependencies.token_send]
path = "../../common/modules/token_send"

[dependencies.pausable]
path = "../../common/modules/pausable"

[dependencies.common_structs]
path = "../../common/common_structs"

[dependencies.multiversx-sc]
version = "=0.53.2"
features = ["esdt-token-payment-legacy-decode"]
Expand Down
37 changes: 5 additions & 32 deletions dex/router/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use crate::{enable_swap_by_user::EnableSwapByUserConfig, factory::PairTokens};
use crate::pair_actions::create::PairTokens;
use pair::read_pair_storage;

#[multiversx_sc::module]
pub trait ConfigModule: read_pair_storage::ReadPairStorageModule {
fn is_active(&self) -> bool {
self.state().get()
#[only_owner]
#[endpoint(setPairTemplateAddress)]
fn set_pair_template_address(&self, address: ManagedAddress) {
self.pair_template_address().set(&address);
}

fn check_is_pair_sc(&self, pair_address: &ManagedAddress) {
Expand Down Expand Up @@ -40,46 +42,17 @@ pub trait ConfigModule: read_pair_storage::ReadPairStorageModule {
#[storage_mapper("pair_creation_enabled")]
fn pair_creation_enabled(&self) -> SingleValueMapper<bool>;

#[view(getState)]
#[storage_mapper("state")]
fn state(&self) -> SingleValueMapper<bool>;

#[view(getOwner)]
#[storage_mapper("owner")]
fn owner(&self) -> SingleValueMapper<ManagedAddress>;

#[only_owner]
#[endpoint(setTemporaryOwnerPeriod)]
fn set_temporary_owner_period(&self, period_blocks: u64) {
self.temporary_owner_period().set(period_blocks);
}

#[only_owner]
#[endpoint(setPairTemplateAddress)]
fn set_pair_template_address(&self, address: ManagedAddress) {
self.pair_template_address().set(&address);
}

#[storage_mapper("pair_map")]
fn pair_map(&self) -> MapMapper<PairTokens<Self::Api>, ManagedAddress>;

#[view(getPairTemplateAddress)]
#[storage_mapper("pair_template_address")]
fn pair_template_address(&self) -> SingleValueMapper<ManagedAddress>;

#[view(getTemporaryOwnerPeriod)]
#[storage_mapper("temporary_owner_period")]
fn temporary_owner_period(&self) -> SingleValueMapper<u64>;

#[storage_mapper("pair_temporary_owner")]
fn pair_temporary_owner(&self) -> MapMapper<ManagedAddress, (ManagedAddress, u64)>;

#[storage_mapper("enableSwapByUserConfig")]
fn enable_swap_by_user_config(
&self,
token_id: &TokenIdentifier,
) -> SingleValueMapper<EnableSwapByUserConfig<Self::Api>>;

#[view(getCommonTokensForUserPairs)]
#[storage_mapper("commonTokensForUserPairs")]
fn common_tokens_for_user_pairs(&self) -> UnorderedSetMapper<TokenIdentifier>;
Expand Down
26 changes: 15 additions & 11 deletions dex/router/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use common_structs::{Epoch, Percent};

use crate::Blocks;

multiversx_sc::imports!();
multiversx_sc::derive_imports!();

Expand All @@ -6,11 +10,11 @@ pub struct CreatePairEvent<M: ManagedTypeApi> {
caller: ManagedAddress<M>,
first_token_id: TokenIdentifier<M>,
second_token_id: TokenIdentifier<M>,
total_fee_percent: u64,
special_fee_percent: u64,
total_fee_percent: Percent,
special_fee_percent: Percent,
pair_address: ManagedAddress<M>,
block: u64,
epoch: u64,
block: Blocks,
epoch: Epoch,
timestamp: u64,
}

Expand All @@ -30,8 +34,8 @@ pub struct MultiPairSwapEvent<M: ManagedTypeApi> {
token_out: TokenIdentifier<M>,
amount_out: BigUint<M>,
payments_out: ManagedVec<M, EsdtTokenPayment<M>>,
block: u64,
epoch: u64,
block: Blocks,
epoch: Epoch,
timestamp: u64,
}

Expand All @@ -42,8 +46,8 @@ pub trait EventsModule {
caller: ManagedAddress,
first_token_id: TokenIdentifier,
second_token_id: TokenIdentifier,
total_fee_percent: u64,
special_fee_percent: u64,
total_fee_percent: Percent,
special_fee_percent: Percent,
pair_address: ManagedAddress,
) {
let epoch = self.blockchain().get_block_epoch();
Expand Down Expand Up @@ -131,7 +135,7 @@ pub trait EventsModule {
#[indexed] first_token_id: TokenIdentifier,
#[indexed] second_token_id: TokenIdentifier,
#[indexed] caller: ManagedAddress,
#[indexed] epoch: u64,
#[indexed] epoch: Epoch,
swap_event: CreatePairEvent<Self::Api>,
);

Expand All @@ -141,7 +145,7 @@ pub trait EventsModule {
#[indexed] first_token_id: TokenIdentifier,
#[indexed] second_token_id: TokenIdentifier,
#[indexed] caller: ManagedAddress,
#[indexed] epoch: u64,
#[indexed] epoch: Epoch,
swap_enabled_event: UserPairSwapEnabledEvent<Self::Api>,
);

Expand All @@ -153,7 +157,7 @@ pub trait EventsModule {
#[indexed] amount_in: BigUint,
#[indexed] token_out: TokenIdentifier,
#[indexed] amount_out: BigUint,
#[indexed] epoch: u64,
#[indexed] epoch: Epoch,
multi_pair_swap_event: MultiPairSwapEvent<Self::Api>,
);
}
180 changes: 0 additions & 180 deletions dex/router/src/factory.rs

This file was deleted.

Loading

0 comments on commit 1645824

Please sign in to comment.