Skip to content

Commit

Permalink
fix: minor checks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Jun 5, 2024
1 parent dd92857 commit c784f13
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
18 changes: 10 additions & 8 deletions src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{
config::State,
errors::{
ERR_ADDRESS_ALREADY_WHITELISTED, ERR_ADDRESS_NOT_WHITELISTED, ERR_ALREADY_ACTIVE,
ERR_ALREADY_INACTIVE, ERR_NOT_PRIVILEGED, ERR_TOKEN_NOT_WHITELISTED, ERR_WRONG_VALUES,
ERR_ALREADY_INACTIVE, ERR_NOT_PRIVILEGED, ERR_TOKEN_ALREADY_IN_WHITELIST,
ERR_TOKEN_NOT_WHITELISTED, ERR_WRONG_VALUES,
},
events, only_privileged, storage,
};
Expand Down Expand Up @@ -116,7 +117,10 @@ pub trait AdminModule:
for token in tokens.into_iter() {
let (token_identifier, token_decimals) = token.into_tuple();
self.token_decimals(&token_identifier).set(token_decimals);
self.tokens_whitelist().insert(token_identifier);
require!(
self.tokens_whitelist().insert(token_identifier),
ERR_TOKEN_ALREADY_IN_WHITELIST
);
}
}

Expand All @@ -126,7 +130,10 @@ pub trait AdminModule:
self.remove_tokens_from_whitelist_event(&tokens.to_vec());
for token in tokens.into_iter() {
self.token_decimals(&token).clear();
self.tokens_whitelist().swap_remove(&token);
require!(
self.tokens_whitelist().swap_remove(&token),
ERR_TOKEN_NOT_WHITELISTED
);
}
}

Expand Down Expand Up @@ -185,11 +192,6 @@ pub trait AdminModule:
fn remove_from_liquidity(&self, token_identifier: TokenIdentifier, amount: BigUint) {
only_privileged!(self, ERR_NOT_PRIVILEGED);

require!(
self.tokens_whitelist().contains(&token_identifier),
ERR_TOKEN_NOT_WHITELISTED
);

let caller = self.blockchain().get_caller();

self.remove_from_liquidity_event(&caller, &token_identifier, &amount);
Expand Down
1 change: 1 addition & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pub const ERR_WRONG_VALUES: &str = "Wrong values";
pub const ERR_ADDRESS_NOT_WHITELISTED: &str = "Address not whitelisted";
pub const ERR_ADDRESS_ALREADY_WHITELISTED: &str = "Address already whitelisted";
pub const ERR_WRONG_FEE_TOKEN_IDENTIFIER: &str = "Wrong fee token identifier";
pub const ERR_TOKEN_ALREADY_IN_WHITELIST: &str = "Token already in whitelist";
13 changes: 5 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,19 @@ pub trait CoreMxBridgeSc:
let caller = self.blockchain().get_caller();
require!(self.relayer().get() == caller, ERR_NOT_PRIVILEGED);

require!(
self.liquidity(&token_identifier).get() >= amount,
ERR_NOT_ENOUGH_LIQUIDITY
);

self.send_from_liquidity_event(
&self.relayer().get(),
&token_identifier,
&amount,
&receiver,
);

self.liquidity(&token_identifier).update(|value| {
require!(*value >= amount, ERR_NOT_ENOUGH_LIQUIDITY);
*value -= &amount;
});

self.send()
.direct_esdt(&receiver, &token_identifier, 0u64, &amount);

self.liquidity(&token_identifier)
.update(|value| *value -= amount);
}
}
10 changes: 10 additions & 0 deletions wasm/Cargo.lock

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

0 comments on commit c784f13

Please sign in to comment.