From b99fb291166772b476406881bdfe2912cce4bf5c Mon Sep 17 00:00:00 2001 From: ByeongSu Hong Date: Thu, 25 Jan 2024 22:31:05 +0900 Subject: [PATCH] fix: reflect review of #67 (#68) * apply review https://github.com/many-things/ibcx-contracts/pull/67#discussion_r1464256364 * apply review https://github.com/many-things/ibcx-contracts/pull/67#discussion_r1464324068 * error prefix for determinism * redundant test --- .github/workflows/tester.yaml | 11 ++++------- contracts/periphery/src/error.rs | 4 ++-- contracts/periphery/src/query.rs | 13 ------------- packages/pool/src/sim/index_in.rs | 10 +++------- packages/pool/src/sim/index_out.rs | 10 +++------- 5 files changed, 12 insertions(+), 36 deletions(-) diff --git a/.github/workflows/tester.yaml b/.github/workflows/tester.yaml index 47da9e2..454d4ca 100644 --- a/.github/workflows/tester.yaml +++ b/.github/workflows/tester.yaml @@ -34,13 +34,10 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Install Rust - run: rustup default 1.72.0 - - - name: Install Rust - run: rustup update nightly - - - name: Install target - run: rustup target add wasm32-unknown-unknown + run: | + rustup default 1.72.0 + rustup update nightly + rustup target add wasm32-unknown-unknown - run: cargo fetch --verbose - run: cargo build diff --git a/contracts/periphery/src/error.rs b/contracts/periphery/src/error.rs index 856e179..4bbe098 100644 --- a/contracts/periphery/src/error.rs +++ b/contracts/periphery/src/error.rs @@ -27,10 +27,10 @@ pub enum ContractError { #[error("{0}")] CheckedFromRatioError(#[from] cosmwasm_std::CheckedFromRatioError), - #[error("{0}")] + #[error("ibcx-math: {0}")] IBCXMath(#[from] ibcx_math::MathError), - #[error("{0}")] + #[error("ibcx-pool: {0}")] IBCXPool(#[from] ibcx_pool::PoolError), #[error("Paused")] diff --git a/contracts/periphery/src/query.rs b/contracts/periphery/src/query.rs index eb77d5e..fe90d57 100644 --- a/contracts/periphery/src/query.rs +++ b/contracts/periphery/src/query.rs @@ -145,16 +145,3 @@ pub fn simulate_burn_exact_amount_out( swap_result_amount: coin(sim_res.max_token_out.u128(), output_asset.denom), }) } - -#[cfg(test)] -mod tests { - use cosmwasm_std::Decimal; - - #[test] - fn test_sad() { - let invert = Decimal::one() - .checked_div(Decimal::from_ratio(5u64, 1000u64)) - .unwrap(); - assert_eq!(invert, Decimal::from_ratio(200u64, 1u64)); - } -} diff --git a/packages/pool/src/sim/index_in.rs b/packages/pool/src/sim/index_in.rs index dae916b..24f15ba 100644 --- a/packages/pool/src/sim/index_in.rs +++ b/packages/pool/src/sim/index_in.rs @@ -148,12 +148,7 @@ impl<'a> Simulator<'a> { } }; - let mut loop_count = 0; - loop { - if loop_count >= MAX_LOOP { - return Err(PoolError::MaxLoopExceeded); - } - + for _ in 0..MAX_LOOP { acc_res = self.search_efficient_amount_for_output_f( desired_output.clone(), acc_res.max_token_out, @@ -175,7 +170,8 @@ impl<'a> Simulator<'a> { { return Ok(acc_res); } - loop_count += 1; } + + Err(PoolError::MaxLoopExceeded) } } diff --git a/packages/pool/src/sim/index_out.rs b/packages/pool/src/sim/index_out.rs index cc5d747..91e6bc3 100644 --- a/packages/pool/src/sim/index_out.rs +++ b/packages/pool/src/sim/index_out.rs @@ -150,12 +150,7 @@ impl<'a> Simulator<'a> { } }; - let mut loop_count = 0; - loop { - if loop_count >= MAX_LOOP { - return Err(PoolError::MaxLoopExceeded); - } - + for _ in 0..MAX_LOOP { acc_res = self.search_efficient_amount_for_input_f( desired_input.clone(), acc_res.est_min_token_out, @@ -178,7 +173,8 @@ impl<'a> Simulator<'a> { { return Ok(acc_res); } - loop_count += 1; } + + Err(PoolError::MaxLoopExceeded) } }