Skip to content

Commit

Permalink
Merge pull request #5 from Itheum/develop
Browse files Browse the repository at this point in the history
fix: audit fix issues: 1,4,5 and suggestion(2)
  • Loading branch information
bucurdavid authored Jun 13, 2024
2 parents 4af8a46 + 88f6efe commit 618d3cf
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 592 deletions.
21 changes: 0 additions & 21 deletions Cargo.lock

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

9 changes: 0 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@ path = "src/lib.rs"
[dependencies.multiversx-sc]
version = "0.50.3"

[dependencies.multiversx-sc-modules]
version = "0.50.3"

[dev-dependencies]
multiversx-wegld-swap-sc = "0.50.3"


[dev-dependencies.multiversx-sc-scenario]
version = "0.50.3"



[workspace]
members = [
".",
Expand Down
52 changes: 45 additions & 7 deletions interaction/devnet.snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ upgrade(){



addTokenToWhitelist(){
# $1 = token
# $2 = decimals

token="0x$(echo -n ${1} | xxd -p -u | tr -d '\n')"

mxpy --verbose contract call ${ADDRESS} \
--recall-nonce \
--pem=${WALLET} \
--gas-limit=6000000 \
--function "addTokenToWhitelist" \
--arguments $token $2 \
--proxy ${PROXY} \
--chain ${CHAIN_ID} \
--send || return

}



setAdministrator(){
# $1 = address

Expand Down Expand Up @@ -88,8 +108,6 @@ setFeeCollector(){
setFeeValue(){
# $1 = value



mxpy --verbose contract call ${ADDRESS} \
--recall-nonce \
--pem=${WALLET} \
Expand All @@ -102,17 +120,37 @@ setFeeValue(){

}

setWegldContractAddress(){
# $1 = address

address="0x$(mxpy wallet bech32 --decode ${1})"
setDepositLimits(){
# $1 = min
# $2 = max



mxpy --verbose contract call ${ADDRESS} \
--recall-nonce \
--pem=${WALLET} \
--gas-limit=6000000 \
--function "setWegldContractAddress" \
--arguments $address \
--function "setDepositLimits" \
--arguments $1 $2 \
--proxy ${PROXY} \
--chain ${CHAIN_ID} \
--send || return


}

setWegldTokenIdentifier(){
# $1 = token

token="0x$(echo -n ${1} | xxd -p -u | tr -d '\n')"

mxpy --verbose contract call ${ADDRESS} \
--recall-nonce \
--pem=${WALLET} \
--gas-limit=6000000 \
--function "setWegldTokenIdentifier" \
--arguments $token \
--proxy ${PROXY} \
--chain ${CHAIN_ID} \
--send || return
Expand Down
77 changes: 36 additions & 41 deletions src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,12 @@ pub trait AdminModule:
}

#[endpoint(setDepositLimits)]
fn set_deposit_limits(
&self,
token_identifier: TokenIdentifier,
minimum: BigUint,
maximum: BigUint,
) {
fn set_deposit_limits(&self, minimum: BigUint, maximum: BigUint) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
require!(
self.tokens_whitelist().contains(&token_identifier),
ERR_TOKEN_NOT_WHITELISTED
);
require!(minimum <= maximum, ERR_WRONG_VALUES);
self.set_deposit_limits_event(&token_identifier, &minimum, &maximum);
self.minimum_deposit(&token_identifier).set(minimum);
self.maximum_deposit(&token_identifier).set(maximum);
self.set_deposit_limits_event(&minimum, &maximum);
self.minimum_deposit().set(minimum);
self.maximum_deposit().set(maximum);
}

#[endpoint(setFeeCollector)]
Expand All @@ -119,55 +110,58 @@ pub trait AdminModule:
#[endpoint(setFeeValue)]
fn set_fee_value(&self, fee_value: BigUint) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
self.set_fee_value_event(&fee_value);
self.fee_value().set(fee_value);
}

#[endpoint(setWegldContractAddress)]
fn set_wegld_contract_address(&self, wegld_contract_address: ManagedAddress) {
#[endpoint(setWegldTokenIdentifier)]
fn set_wegld_contract_address(&self, wegld_token_identifier: TokenIdentifier) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
self.set_wegld_contract_address_event(&wegld_contract_address);
self.wegld_contract_address().set(wegld_contract_address);
self.set_wegld_token_identifier(&wegld_token_identifier);
self.wegld_token_identifier().set(wegld_token_identifier);
}

#[endpoint(addTokensToWhitelist)]
fn add_tokens_to_whitelist(
&self,
tokens: MultiValueEncoded<MultiValue2<TokenIdentifier, u32>>,
) {
#[endpoint(addTokenToWhitelist)]
fn add_tokens_to_whitelist(&self, token: TokenIdentifier, decimals: u32) {
only_privileged!(self, ERR_NOT_PRIVILEGED);

for token in tokens.into_iter() {
let (token_identifier, token_decimals) = token.into_tuple();
self.token_decimals(&token_identifier).set(token_decimals);
require!(
self.tokens_whitelist().insert(token_identifier),
ERR_TOKEN_ALREADY_IN_WHITELIST
);
self.add_token_to_whitelist_event(&token, &decimals);
if !self.token_whitelist().is_empty() {
self.token_decimals(&token).set(decimals);
self.token_whitelist().update(|whitelist_token| {
require!(*whitelist_token != token, ERR_TOKEN_ALREADY_IN_WHITELIST);
*whitelist_token = token
});
} else {
self.token_decimals(&token).set(decimals);
self.token_whitelist().set(token);
}
}

#[endpoint(removeTokensFromWhitelist)]
fn remove_tokens_from_whitelist(&self, tokens: MultiValueEncoded<TokenIdentifier>) {
#[endpoint(removeTokenFromWhitelist)]
fn remove_token_from_whitelist(&self, token: TokenIdentifier) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
self.remove_tokens_from_whitelist_event(&tokens.to_vec());
for token in tokens.into_iter() {
self.token_decimals(&token).clear();
require!(
self.tokens_whitelist().swap_remove(&token),
ERR_TOKEN_NOT_WHITELISTED
);
}

self.remove_token_from_whitelist_event(&token);
require!(
self.token_whitelist().get() == token,
ERR_TOKEN_NOT_WHITELISTED
);

self.token_decimals(&token).clear();
self.token_whitelist().clear();
}

#[endpoint(addToWhitelist)]
fn add_to_whitelist(&self, addresses: MultiValueEncoded<ManagedAddress>) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
for address in addresses.into_iter() {
require!(
self.whitelist().contains(&address) == false,
!self.whitelist().contains(&address),
ERR_ADDRESS_ALREADY_WHITELISTED
);
self.whitelist().add(&address);
self.add_to_whitelist_event(&address);
}
}

Expand All @@ -180,6 +174,7 @@ pub trait AdminModule:
ERR_ADDRESS_NOT_WHITELISTED
);
self.whitelist().remove(&address);
self.remove_from_whitelist_event(&address);
}
}

Expand All @@ -198,7 +193,7 @@ pub trait AdminModule:
let payment = self.call_value().single_esdt();

require!(
self.tokens_whitelist().contains(&payment.token_identifier),
self.token_whitelist().get() == payment.token_identifier,
ERR_TOKEN_NOT_WHITELISTED
);

Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ pub trait ConfigModule: storage::StorageModule + events::EventsModule {
is_ready = false;
}

if self.wegld_contract_address().is_empty() {
if self.wegld_token_identifier().is_empty() {
is_ready = false;
}
}

if self.relayer().is_empty() {
is_ready = false;
}
if self.tokens_whitelist().is_empty() {
if self.token_whitelist().is_empty() {
is_ready = false;
}
is_ready
Expand All @@ -103,8 +103,8 @@ pub trait ConfigModule: storage::StorageModule + events::EventsModule {
fn administrator(&self) -> SingleValueMapper<ManagedAddress>;

#[view(getTokensWhitelist)]
#[storage_mapper("tokens_whitelist")]
fn tokens_whitelist(&self) -> UnorderedSetMapper<TokenIdentifier>;
#[storage_mapper("token_whitelist")]
fn token_whitelist(&self) -> SingleValueMapper<TokenIdentifier>;

#[storage_mapper("whitelist")]
fn whitelist(&self) -> WhitelistMapper<ManagedAddress>;
Expand Down
31 changes: 15 additions & 16 deletions src/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use multiversx_sc::types::ManagedVec;

use crate::config::State;

#[multiversx_sc::module]
Expand All @@ -14,6 +12,12 @@ pub trait EventsModule {
#[indexed] destination_signature: &ManagedBuffer,
);

#[event("addToWhitelist")]
fn add_to_whitelist_event(&self, #[indexed] address: &ManagedAddress);

#[event("removeFromWhitelist")]
fn remove_from_whitelist_event(&self, #[indexed] address: &ManagedAddress);

#[event("sendFromLiquidityEvent")]
fn send_from_liquidity_event(
&self,
Expand All @@ -29,12 +33,6 @@ pub trait EventsModule {
#[event("setAdministratorEvent")]
fn set_administrator_event(&self, #[indexed] administrator: &ManagedAddress);

#[event("addTokensToWhitelistEvent")]
fn add_tokens_to_whitelist_event(&self, #[indexed] tokens: &ManagedVec<TokenIdentifier>);

#[event("removeTokensFromWhitelistEvent")]
fn remove_tokens_from_whitelist_event(&self, #[indexed] tokens: &ManagedVec<TokenIdentifier>);

#[event("setRelayerEvent")]
fn set_relayer_event(&self, #[indexed] relayer: &ManagedAddress);

Expand All @@ -58,21 +56,22 @@ pub trait EventsModule {
fn set_whitelist_state_event(&self, #[indexed] state: &State);

#[event("setDepositLimitsEvent")]
fn set_deposit_limits_event(
&self,
#[indexed] token_identifier: &TokenIdentifier,
#[indexed] minimum: &BigUint,
#[indexed] maximum: &BigUint,
);
fn set_deposit_limits_event(&self, #[indexed] minimum: &BigUint, #[indexed] maximum: &BigUint);

#[event("addTokenToWhitelistEvent")]
fn add_token_to_whitelist_event(&self, #[indexed] token: &TokenIdentifier, decimals: &u32);

#[event("removeTokenFromWhitelistEvent")]
fn remove_token_from_whitelist_event(&self, #[indexed] token: &TokenIdentifier);

#[event("setFeeCollectorEvent")]
fn set_fee_collector_event(&self, #[indexed] fee_collector: &ManagedAddress);

#[event("setFeeValueEvent")]
fn set_fee_value_event(&self, #[indexed] fee_value: &BigUint);

#[event("setWegldContractAddressEvent")]
fn set_wegld_contract_address_event(&self, #[indexed] wegld_contract_address: &ManagedAddress);
#[event("setWegldTokenIdentifier")]
fn set_wegld_token_identifier(&self, #[indexed] wegld_token_identifier: &TokenIdentifier);

#[event("setRelayerStateEvent")]
fn set_relayer_state_event(&self, #[indexed] state: &State);
Expand Down
Loading

0 comments on commit 618d3cf

Please sign in to comment.