Skip to content

Commit

Permalink
Added more errors and refactored create_pool message
Browse files Browse the repository at this point in the history
  • Loading branch information
Sniezka1927 committed Nov 29, 2023
1 parent c0c236a commit 0a0f996
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/contracts/entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait Invariant {
#[ink(message)]
fn withdraw_protocol_fee(&mut self, pool_key: PoolKey) -> Result<(), InvariantError>;

/// Allows an authorized user to adjust the protocol fee.
/// Allows an admin to adjust the protocol fee.
///
/// # Parameters
/// - `protocol_fee`: The expected fee represented as a percentage.
Expand All @@ -36,7 +36,7 @@ pub trait Invariant {
#[ink(message)]
fn change_protocol_fee(&mut self, protocol_fee: Percentage) -> Result<(), InvariantError>;

/// Transfers fee receiver authorization to another user.
/// Allows admin to change current fee receiver.
///
/// # Parameters
/// - `pool_key`: A unique key that identifies the specified pool.
Expand Down Expand Up @@ -221,6 +221,7 @@ pub trait Invariant {
/// # Errors
/// - Fails if unable to deinitialize ticks.
/// - Fails if the DEX has insufficient balance to perform the transfer.
/// - Fails if Position cannot be found
#[ink(message)]
fn remove_position(&mut self, index: u32)
-> Result<(TokenAmount, TokenAmount), InvariantError>;
Expand Down Expand Up @@ -262,6 +263,7 @@ pub trait Invariant {
/// # Errors
/// - Fails if the specified fee tier cannot be found.
/// - Fails if the user attempts to create a pool for the same tokens.
/// - Fails if Pool with same tokens and fee tier already exist.
#[ink(message)]
fn create_pool(
&mut self,
Expand All @@ -280,6 +282,7 @@ pub trait Invariant {
///
/// # Errors
/// - Fails if the Pool key cannot be created.
/// - Fails if there is no pool associated with created key
#[ink(message)]
fn get_pool(
&self,
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,9 @@ pub mod contract {
.ok_or(InvariantError::FeeTierNotFound)?;

let pool_key = PoolKey::new(token_0, token_1, fee_tier)?;
if self.pools.get(pool_key).is_ok() {
return Err(InvariantError::PoolAlreadyExist);
};
let pool = Pool::create(init_tick, current_timestamp, self.state.admin);
self.pools.add(pool_key, &pool)?;

Expand Down Expand Up @@ -4011,5 +4014,13 @@ pub mod contract {
alice
);
}

#[ink_e2e::test]
#[should_panic]
async fn init_exactly_same_pools(mut client: ink_e2e::Client<C, E>) -> () {
let (dex, token_x, token_y) = init_dex_and_tokens!(client, ContractRef, TokenRef);
init_basic_pool!(client, ContractRef, TokenRef, dex, token_x, token_y);
init_basic_pool!(client, ContractRef, TokenRef, dex, token_x, token_y);
}
}
}

0 comments on commit 0a0f996

Please sign in to comment.