Skip to content

Commit

Permalink
Merge pull request #1 from Itheum/develop
Browse files Browse the repository at this point in the history
Fee collector + unwrap fee
  • Loading branch information
bucurdavid authored Jun 5, 2024
2 parents 2c70b2e + c784f13 commit ce2d7c3
Show file tree
Hide file tree
Showing 19 changed files with 854 additions and 70 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Coverage

on:
pull_request:
branches:
- main
- develop
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Making coverage dir
run: mkdir coverage
- name: Generate code coverage
run: cargo llvm-cov --lcov --output-path coverage/lcov.info --ignore-filename-regex '(storage.rs|events.rs|macros|errors.rs|proxies)'
- name: Generating report
uses: vebr/jest-lcov-reporter@v0.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: ./coverage/lcov.info
22 changes: 21 additions & 1 deletion Cargo.lock

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

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

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

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


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



[workspace]
members = [
".",
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ See `devnet.snippets.sh` for list of available endpoints for user testing.

### Setting up dev environment (project development bootstrap) + how to build (and upgrade)

- Uses `multiversx-sc-* 0.49.0` (In v2.0.0, we used0.49.0) SDK libs (see Cargo.toml)
- Uses `multiversx-sc-* 0.50.3` (In v2.0.0, we used0.50.3) SDK libs (see Cargo.toml)
- Building requires minimum **mxpy 9.5.1** (In v2.0.0, we used mxpy 9.5.1). Check version using `mxpy --version`
- To build the project, requires minimum Rust version `1.78.0-nightly` (In v2.0.0, we used 1.78.0-nightly). Check your Rust version by running `rustc --version`. To update your Rust, run `rustup update`. To set to nightly run `rustup default nightly`. Note that `mxpy deps install rust --overwrite` also brings in it's own compatible rust version so running `rustup default nightly` might have a higher rust version than what is used via `mxpy deps install rust --overwrite`.
- Uses `multiversx-sc-*0.49.0` (In v1.0.0, we used0.49.0) SDK libs (see Cargo.toml)
- To build the project, requires minimum Rust version `1.78.0` (In v2.0.0, we used 1.78.0). Check your Rust version by running `rustc --version`. To update your Rust, run `rustup update`. To set to nightly run `rustup default stable`. Note that `mxpy deps install rust --overwrite` also brings in it's own compatible rust version so running `rustup default stable` might have a higher rust version than what is used via `mxpy deps install rust --overwrite`.
- Uses `multiversx-sc-*0.50.3` (In v1.0.0, we used0.50.3) SDK libs (see Cargo.toml)
- Building requires minimum **mxpy 9.5.1** (In v1.0.0, we used mxpy 9.5.1). Check version using `mxpy --version`
- To build the project, requires minimum Rust version `1.78.0-nightly` (In v1.0.0, we used 1.78.0-nightly). Check your Rust version by running `rustc --version`. To update your Rust, run `rustup update`. To set to nightly run `rustup default nightly`. Note that `mxpy deps install rust --overwrite` also brings in it's own compatible rust version so running `rustup default nightly` might have a higher rust version than what is used via `mxpy deps install rust --overwrite`.
- To build the project, requires minimum Rust version `1.78.0` (In v1.0.0, we used 1.78.0-nightly). Check your Rust version by running `rustc --version`. To update your Rust, run `rustup update`. To set to nightly run `rustup default stable`. Note that `mxpy deps install rust --overwrite` also brings in it's own compatible rust version so running `rustup default nightly` might have a higher rust version than what is used via `mxpy deps install rust --overwrite`.

```
rustup default nightly
rustup default stable
mxpy deps install rust --overwrite
cargo clean
cargo build
Expand Down Expand Up @@ -58,7 +58,7 @@ Another way of running the tests is by using the rust-analyzer extension in Visu
Note: In order to run the tests, one has to use the rust nightly version. One can switch to the nightly version by using:

```shell
rustup default nightly
rustup default stable
```

### How to deploy
Expand Down
2 changes: 1 addition & 1 deletion coverage.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

cargo llvm-cov --ignore-filename-regex '(storage.rs|events.rs|macros|errors.rs)' --open
cargo llvm-cov --ignore-filename-regex '(storage.rs|events.rs|macros|errors.rs|proxies)' --open
38 changes: 30 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 @@ -86,6 +87,26 @@ pub trait AdminModule:
self.maximum_deposit(&token_identifier).set(maximum);
}

#[endpoint(setFeeCollector)]
fn set_fee_collector(&self, fee_collector: ManagedAddress) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
self.set_fee_collector_event(&fee_collector);
self.fee_collector().set(fee_collector);
}

#[endpoint(setFeeValue)]
fn set_fee_value(&self, fee_value: BigUint) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
self.fee_value().set(fee_value);
}

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

#[endpoint(addTokensToWhitelist)]
fn add_tokens_to_whitelist(
&self,
Expand All @@ -96,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 @@ -106,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 @@ -165,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
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ pub trait ConfigModule: storage::StorageModule + events::EventsModule {
if self.administrator().is_empty() {
is_ready = false;
}

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

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

if self.relayer().is_empty() {
is_ready = false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ pub const ERR_NOT_WHOLE_NUMBER: &str = "Not a whole number";
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";
9 changes: 9 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ pub trait EventsModule {
#[indexed] minimum: &BigUint,
#[indexed] maximum: &BigUint,
);

#[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);
}
Loading

0 comments on commit ce2d7c3

Please sign in to comment.