From 410b16416bc1996c60b8eaae8b9c626e6ccc4c85 Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:32:22 +0200 Subject: [PATCH 1/8] Add CI actions --- .github/workflows/check.yml | 75 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 37 +++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 00000000..2729b22c --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,75 @@ +name: Check Build and Tests + +on: + push: + branches: [ main ] + pull_request: + + workflow_dispatch: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.76.0 + override: true + components: rustfmt, clippy + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + + - name: Generate Schema + uses: actions-rs/cargo@v1 + with: + command: schema + args: --locked + + - name: Schema Changes + # fails if any changes not committed + run: git diff --exit-code schema + + test: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.76.0 + target: wasm32-unknown-unknown + override: true + + - name: Run unit tests + uses: actions-rs/cargo@v1 + with: + command: unit-test + args: --locked + env: + RUST_BACKTRACE: 1 + + - name: Compile WASM contract + uses: actions-rs/cargo@v1 + with: + command: wasm + args: --locked + env: + RUSTFLAGS: "-C link-arg=-s" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..75d045f1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release Contracts + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Install cargo-run-script + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-run-script + - name: Run cargo optimize + uses: actions-rs/cargo@v1 + with: + command: run-script + args: optimize + - name: Get release ID + id: get_release + uses: bruceadams/get-release@v1.3.2 + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Upload optimized wasm + uses: svenstaro/upload-release-action@2.9.0 + + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./artifacts/* + tag: ${{ github.ref }} + overwrite: true + file_glob: true \ No newline at end of file From 8d2b72c0b1c926fbb96e012a2ebc167fb946443b Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:34:54 +0200 Subject: [PATCH 2/8] cargo fmt --- contracts/services/rebalancer/src/rebalance.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/services/rebalancer/src/rebalance.rs b/contracts/services/rebalancer/src/rebalance.rs index 8c23f1ea..3bbfa9d8 100644 --- a/contracts/services/rebalancer/src/rebalance.rs +++ b/contracts/services/rebalancer/src/rebalance.rs @@ -108,8 +108,8 @@ pub fn execute_system_rebalance( for res in configs { let Ok((account, config)) = res else { - continue; - }; + continue; + }; last_addr = Some(account.clone()); @@ -131,7 +131,7 @@ pub fn execute_system_rebalance( cycle_period, ); let Ok((config, msg)) = rebalance_res else { - continue + continue; }; // Rebalacing does edit some config fields that are needed for future rebalancing @@ -673,7 +673,7 @@ fn generate_trades_msgs( token_buy.value_to_trade = Decimal::zero(); let Ok(msg) = construct_msg(deps, auction_manager, pair, coin) else { - return + return; }; msgs.push(msg); } else { @@ -689,7 +689,7 @@ fn generate_trades_msgs( token_sell.value_to_trade = Decimal::zero(); let Ok(msg) = construct_msg(deps, auction_manager, pair, coin) else { - return + return; }; msgs.push(msg); From b819970fd614d2f9e45193ae1d0bd374746c48d4 Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:37:49 +0200 Subject: [PATCH 3/8] Fix test action --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 2729b22c..e2507635 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -61,7 +61,7 @@ jobs: - name: Run unit tests uses: actions-rs/cargo@v1 with: - command: unit-test + command: test args: --locked env: RUST_BACKTRACE: 1 From 51a0987785fcc6d1503acd4c3f320b0d1696be24 Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:40:44 +0200 Subject: [PATCH 4/8] clippy fixes --- contracts/services/rebalancer/src/rebalance.rs | 4 ++-- contracts/services_manager/src/contract.rs | 1 - packages/valence-macros/src/macros_helpers.rs | 2 +- packages/valence-package/src/signed_decimal.rs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/contracts/services/rebalancer/src/rebalance.rs b/contracts/services/rebalancer/src/rebalance.rs index 3bbfa9d8..56970096 100644 --- a/contracts/services/rebalancer/src/rebalance.rs +++ b/contracts/services/rebalancer/src/rebalance.rs @@ -264,7 +264,7 @@ pub(crate) fn set_auction_min_amounts( to_sell: &mut Vec, min_amount_limits: &mut Vec<(String, Uint128)>, ) -> Result<(), ContractError> { - for mut sell_token in to_sell { + for sell_token in to_sell { match min_amount_limits .iter() .find(|min_amount| min_amount.0 == sell_token.target.denom) @@ -606,7 +606,7 @@ fn generate_trades_msgs( // This is the main loop where we match to_sell tokens with to_buy tokens to_sell.into_iter().for_each(|mut token_sell| { - to_buy.iter_mut().for_each(|mut token_buy| { + to_buy.iter_mut().for_each(|token_buy| { // If we already bought all we need for this token we continue to next buy token if token_buy.value_to_trade.is_zero() { return; diff --git a/contracts/services_manager/src/contract.rs b/contracts/services_manager/src/contract.rs index 6e9aab99..e6e44a58 100644 --- a/contracts/services_manager/src/contract.rs +++ b/contracts/services_manager/src/contract.rs @@ -217,7 +217,6 @@ pub fn query(deps: Deps, _env: Env, msg: ServicesManagerQueryMsg) -> StdResult>>()?; to_json_binary(&services) diff --git a/packages/valence-macros/src/macros_helpers.rs b/packages/valence-macros/src/macros_helpers.rs index 444658a3..e1328db5 100644 --- a/packages/valence-macros/src/macros_helpers.rs +++ b/packages/valence-macros/src/macros_helpers.rs @@ -28,7 +28,7 @@ pub(crate) fn merge_variants( }), ) = (&mut left.data, right.data) { - variants.extend(to_add.into_iter()); + variants.extend(to_add); quote! { #left }.into() } else { diff --git a/packages/valence-package/src/signed_decimal.rs b/packages/valence-package/src/signed_decimal.rs index 0fb95b06..ec18a1bc 100644 --- a/packages/valence-package/src/signed_decimal.rs +++ b/packages/valence-package/src/signed_decimal.rs @@ -275,7 +275,7 @@ impl<'de> de::Visitor<'de> for SignedDecimalVisitor { match SignedDecimal::from_str(v) { Ok(d) => Ok(d), Err(e) => { - return Err(E::custom(format!( + Err(E::custom(format!( "Error parsing signed decimal '{v}': {e}" ))) } From ec4cdbecbccaa5b8ad7dc5abb34d9d341543e7fc Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:41:53 +0200 Subject: [PATCH 5/8] cargo fmt --- packages/valence-package/src/signed_decimal.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/valence-package/src/signed_decimal.rs b/packages/valence-package/src/signed_decimal.rs index ec18a1bc..430fe6c9 100644 --- a/packages/valence-package/src/signed_decimal.rs +++ b/packages/valence-package/src/signed_decimal.rs @@ -274,11 +274,9 @@ impl<'de> de::Visitor<'de> for SignedDecimalVisitor { { match SignedDecimal::from_str(v) { Ok(d) => Ok(d), - Err(e) => { - Err(E::custom(format!( - "Error parsing signed decimal '{v}': {e}" - ))) - } + Err(e) => Err(E::custom(format!( + "Error parsing signed decimal '{v}': {e}" + ))), } } } From cab7339b516b41e159f2c94bcd56ce5afb31d4fe Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:44:32 +0200 Subject: [PATCH 6/8] add schema cmd alias --- .cargo/config | 1 + 1 file changed, 1 insertion(+) diff --git a/.cargo/config b/.cargo/config index 89599593..e4217881 100644 --- a/.cargo/config +++ b/.cargo/config @@ -2,3 +2,4 @@ wasm = "build --release --lib --target wasm32-unknown-unknown" wasm-debug = "build --lib --target wasm32-unknown-unknown" clippy-all = "clippy --all-targets -- -D warnings" +schema = "run --bin -schema" From d522423b1bba22a76d614aa3bfaa8530b8831844 Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:51:21 +0200 Subject: [PATCH 7/8] Disable CI schema checks for now --- .github/workflows/check.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e2507635..599214a0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -34,15 +34,15 @@ jobs: command: clippy args: -- -D warnings - - name: Generate Schema - uses: actions-rs/cargo@v1 - with: - command: schema - args: --locked + # - name: Generate Schema + # uses: actions-rs/cargo@v1 + # with: + # command: schema + # args: --locked - - name: Schema Changes - # fails if any changes not committed - run: git diff --exit-code schema + # - name: Schema Changes + # # fails if any changes not committed + # run: git diff --exit-code schema test: runs-on: ubuntu-latest From d8e765a318c547fec1903bff47fd5f0a0f645643 Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:56:21 +0200 Subject: [PATCH 8/8] Add CI badge to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6aec9715..53439b93 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Neutron Contracts +[![Check Set-Up & Build](https://github.com/timewave-computer/valence-services/actions/workflows/check.yml/badge.svg)](https://github.com/timewave-computer/valence-services/actions/workflows/check.yml) + ## Code ids - auctions manager = `1762`