From 2ab7bb6305e2b60522a4a88a7291e82266557478 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 5 May 2025 15:05:10 +0200 Subject: [PATCH 01/14] invert back the spot price for stableswap --- math/src/stableswap/math.rs | 5 +++-- pallets/stableswap/src/trade_execution.rs | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/math/src/stableswap/math.rs b/math/src/stableswap/math.rs index c10b344942..d2229fce1a 100644 --- a/math/src/stableswap/math.rs +++ b/math/src/stableswap/math.rs @@ -902,6 +902,7 @@ pub fn calculate_spot_price( fee, pegs, ) + .map(|p| p.reciprocal())? } (SHARE_ASSET, STABLE_ASSET) => { let asset_out_idx = asset_reserves.iter().position(|r| r.0 == asset_out)?; @@ -915,7 +916,7 @@ pub fn calculate_spot_price( pegs, )?; - FixedU128::checked_from_rational(shares, min_trade_amount) + FixedU128::checked_from_rational(min_trade_amount, shares) } (STABLE_ASSET, SHARE_ASSET) => { let added_asset = (asset_in, min_trade_amount); @@ -937,7 +938,7 @@ pub fn calculate_spot_price( pegs, )?; - FixedU128::checked_from_rational(min_trade_amount, shares_for_min_trade) + FixedU128::checked_from_rational(shares_for_min_trade, min_trade_amount) } _ => None, } diff --git a/pallets/stableswap/src/trade_execution.rs b/pallets/stableswap/src/trade_execution.rs index 12831c8430..8ea27ab2ba 100644 --- a/pallets/stableswap/src/trade_execution.rs +++ b/pallets/stableswap/src/trade_execution.rs @@ -6,7 +6,7 @@ use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; use hydradx_traits::stableswap::AssetAmount; use orml_traits::MultiCurrency; use sp_core::Get; -use sp_runtime::{ArithmeticError, DispatchError, FixedU128}; +use sp_runtime::{ArithmeticError, DispatchError, FixedPointNumber, FixedU128}; use sp_std::collections::btree_map::BTreeMap; use sp_std::vec; use sp_std::vec::Vec; @@ -322,6 +322,8 @@ where Some(trade_fee), &asset_pegs, ) + .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))? + .reciprocal() .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))?; Ok(spot_price) From f4e1e8cf87719bd68eaa244d130cdf466d172c3e Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 8 May 2025 20:16:26 +0200 Subject: [PATCH 02/14] bump versions --- Cargo.lock | 6 +++--- math/Cargo.toml | 2 +- pallets/stableswap/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76a99ad339..dacc73bbd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4495,7 +4495,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "10.0.1" +version = "10.0.2" dependencies = [ "approx", "criterion", @@ -4660,7 +4660,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "309.0.0" +version = "310.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -9050,7 +9050,7 @@ dependencies = [ [[package]] name = "pallet-stableswap" -version = "5.1.4" +version = "5.1.5" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", diff --git a/math/Cargo.toml b/math/Cargo.toml index 66cabda1ee..3c545c07e0 100644 --- a/math/Cargo.toml +++ b/math/Cargo.toml @@ -6,7 +6,7 @@ license = 'Apache-2.0' name = "hydra-dx-math" description = "A collection of utilities to make performing liquidity pool calculations more convenient." repository = 'https://github.com/galacticcouncil/hydradx-math' -version = "10.0.1" +version = "10.0.2" [dependencies] primitive-types = { workspace = true } diff --git a/pallets/stableswap/Cargo.toml b/pallets/stableswap/Cargo.toml index ef7ad5eda7..fab5e90af5 100644 --- a/pallets/stableswap/Cargo.toml +++ b/pallets/stableswap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-stableswap" -version = "5.1.4" +version = "5.1.5" description = "AMM for correlated assets" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index e14792f264..f70d6a57c8 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "309.0.0" +version = "310.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 9c68ef7472..d7b8a67844 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -118,7 +118,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 309, + spec_version: 310, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From ea3ea45a58c5c537dfd11002e2cb97280dce6f52 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 8 May 2025 20:35:52 +0200 Subject: [PATCH 03/14] bump versions --- Cargo.lock | 6 +++--- math/Cargo.toml | 2 +- pallets/stableswap/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d80ba66e83..da1bfc20f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4495,7 +4495,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "10.0.2" +version = "10.0.3" dependencies = [ "approx", "criterion", @@ -4660,7 +4660,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "310.0.0" +version = "311.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -9052,7 +9052,7 @@ dependencies = [ [[package]] name = "pallet-stableswap" -version = "5.1.5" +version = "5.1.6" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", diff --git a/math/Cargo.toml b/math/Cargo.toml index 3c545c07e0..a1ac1d70bc 100644 --- a/math/Cargo.toml +++ b/math/Cargo.toml @@ -6,7 +6,7 @@ license = 'Apache-2.0' name = "hydra-dx-math" description = "A collection of utilities to make performing liquidity pool calculations more convenient." repository = 'https://github.com/galacticcouncil/hydradx-math' -version = "10.0.2" +version = "10.0.3" [dependencies] primitive-types = { workspace = true } diff --git a/pallets/stableswap/Cargo.toml b/pallets/stableswap/Cargo.toml index fab5e90af5..c7bc4368eb 100644 --- a/pallets/stableswap/Cargo.toml +++ b/pallets/stableswap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-stableswap" -version = "5.1.5" +version = "5.1.6" description = "AMM for correlated assets" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 654e9f58a1..4ce2b4def4 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "310.0.0" +version = "311.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 296569e79c..a776a9d44e 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -119,7 +119,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 310, + spec_version: 311, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From b1b02a9b8aee92316e37cebc69696536df94e31c Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 3 Jun 2025 08:52:04 -0700 Subject: [PATCH 04/14] update lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4975202fb..781b02eb77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4666,7 +4666,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "317.0.0" +version = "318.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -9121,7 +9121,7 @@ dependencies = [ [[package]] name = "pallet-stableswap" -version = "5.3.0" +version = "5.3.1" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", From 6d06aa8cd3d78b95f9b58082ddc2f1813decc464 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 3 Jun 2025 16:05:27 -0700 Subject: [PATCH 05/14] inverse the passed spot price calcuation assets to remove hidden reciprocal --- .../src/tests/calculate_spot_price.rs | 67 +++++++++---------- pallets/stableswap/src/trade_execution.rs | 4 +- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/pallets/stableswap/src/tests/calculate_spot_price.rs b/pallets/stableswap/src/tests/calculate_spot_price.rs index 4d7400f0f0..31a44027d8 100644 --- a/pallets/stableswap/src/tests/calculate_spot_price.rs +++ b/pallets/stableswap/src/tests/calculate_spot_price.rs @@ -32,11 +32,11 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_6_decimals() { final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(1), + fee: Permill::from_parts(200), }, InitialLiquidity { account: ALICE, - assets: vec![AssetAmount::new(asset_a, 40 * ONE), AssetAmount::new(asset_b, 40 * ONE)], + assets: vec![AssetAmount::new(asset_a, 40 * ONE), AssetAmount::new(asset_b, 41 * ONE)], }, ) .build() @@ -48,7 +48,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_6_decimals() { let sell_amount = 10 * ONE; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 80000000000020000000000000; + let initial_issuance = 80999938873618218464277405; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -60,7 +60,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_6_decimals() { 0, )); - let expected = 9; + let expected = 10; assert_balance!(BOB, pool_id, bob_share_balance - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -101,13 +101,13 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(1), + fee: Permill::from_parts(200), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 4000 * ONE), - AssetAmount::new(asset_b, 4000 * ONE), + AssetAmount::new(asset_b, 4100 * ONE), ], }, ) @@ -120,7 +120,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() let sell_amount = ONE; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 8000000100000000000000; + let initial_issuance = 8099993987359821846427; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -132,7 +132,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() 0, )); - let expected = 994999; + let expected = 1000022; assert_balance!(BOB, pool_id, bob_share_balance - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -152,7 +152,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() let relative_difference = FixedU128::from_rational(difference, expected); let tolerated_difference = FixedU128::from_rational(1, 100); // The difference of the amount out calculated with spot price should be less than 1% - assert_eq!(relative_difference, FixedU128::from_float(0.001021106553875934)); + assert_eq!(relative_difference, FixedU128::from_float(0.000098997822047915)); assert!(relative_difference < tolerated_difference); }); } @@ -177,13 +177,13 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(1), + fee: Permill::from_parts(200), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 100000000 * ONE), - AssetAmount::new(asset_b, 100000000 * ONE), + AssetAmount::new(asset_b, 110000000 * ONE), ], }, ) @@ -196,7 +196,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() let sell_amount = 1000; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 200100000000000000000; + let initial_issuance = 210097637343078345703; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -208,7 +208,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() 0, )); - let expected = 991; + let expected = 996; let pool_account = pool_account(pool_id); @@ -216,7 +216,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() assert_balance!(BOB, asset_b, expected); let total_issuance = Tokens::total_issuance(pool_id); assert_eq!(total_issuance, initial_issuance - sell_amount); - assert_balance!(pool_account, asset_b, 100000000 * ONE - expected); + assert_balance!(pool_account, asset_b, 110000000 * ONE - expected); let spot_price = Stableswap::calculate_spot_price_with_fee(PoolType::Stableswap(pool_id), pool_id, asset_b).unwrap(); @@ -233,7 +233,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() // The difference of the amount out calculated with spot price should be less than 1% assert_eq_approx!( relative_difference, - FixedU128::from_float(0.004036326942482341), + FixedU128::from_float(0.005020080321285141), FixedU128::from((2, (ONE / 10_000))), "the relative difference is not as expected" ); @@ -264,14 +264,14 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(3), + fee: Permill::from_parts(200), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 150 * ONE), - AssetAmount::new(asset_b, 150 * ONE), - AssetAmount::new(asset_c, 150 * ONE), + AssetAmount::new(asset_b, 155 * ONE), + AssetAmount::new(asset_c, 160 * ONE), ], }, ) @@ -281,7 +281,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() let sell_amount = 1_000; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 450000000000000000000; + let initial_issuance = 464998401424513938794; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -293,7 +293,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() 0, )); - let expected = 986999999; + let expected = 1000326929; assert_balance!(BOB, asset_a, 200 * ONE - sell_amount); assert_balance!(BOB, pool_id, expected); @@ -314,7 +314,6 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() // The difference of the amount out calculated with spot price should be less than 0.1% let tolerated_difference = FixedU128::from_rational(1, 1000); - assert_eq!(relative_difference, FixedU128::from_float(0.000000000000000000)); assert!(relative_difference < tolerated_difference); }); @@ -340,7 +339,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_18_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(3), + fee: Permill::from_parts(200),//0.2% }, InitialLiquidity { account: ALICE, @@ -368,7 +367,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_18_decimals() 0, )); - let expected = 984938537439245; + let expected = 1002832951117544; assert_balance!(BOB, asset_a, 200000000 * ONE - sell_amount); assert_balance!(BOB, pool_id, expected); @@ -388,7 +387,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_18_decimals() let relative_difference = FixedU128::from_rational(difference, expected); // The difference of the amount out calculated with spot price should be less than 1% let tolerated_difference = FixedU128::from_rational(1, 1000); - assert_eq!(relative_difference, FixedU128::from_float(0.000952889346461269)); + assert_eq!(relative_difference, FixedU128::from_float(0.000166576978019961)); assert!(relative_difference < tolerated_difference); }); } @@ -409,13 +408,13 @@ fn spot_price_calculation_should_work_for_two_stableassets() { final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(1), + fee: Permill::from_parts(200), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 100 * ONE), - AssetAmount::new(asset_b, 100 * ONE), + AssetAmount::new(asset_b, 110 * ONE), ], }, ) @@ -434,7 +433,7 @@ fn spot_price_calculation_should_work_for_two_stableassets() { 0, )); - let expected = 989999901; + let expected = 1_000_747_331; assert_balance!(BOB, asset_a, 200 * ONE - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -444,13 +443,13 @@ fn spot_price_calculation_should_work_for_two_stableassets() { //Check if spot price calculation is correct let calculated_amount_out = spot_price.reciprocal().unwrap().checked_mul_int(sell_amount).unwrap(); - let difference = expected - calculated_amount_out; + let difference = calculated_amount_out - expected; let relative_difference = FixedU128::from_rational(difference, expected); let tolerated_difference = FixedU128::from_rational(1, 1000); // The difference of the amount out calculated with spot price should be less than 0.1% assert_eq_approx!( relative_difference, - FixedU128::from_float(0.000000097979807778), + FixedU128::from_float(0.000400025048880195), FixedU128::from((2, (ONE / 10_000))), "the relative difference is not as expected" ); @@ -483,7 +482,7 @@ fn spot_price_calculation_should_work_for_two_stableassets_on_different_position final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(2), + fee: Permill::from_parts(200), //0.2% }, InitialLiquidity { account: ALICE, @@ -509,7 +508,7 @@ fn spot_price_calculation_should_work_for_two_stableassets_on_different_position 0, )); - let expected = 968488820; + let expected = 988056247; assert_balance!(BOB, asset_c, 200 * ONE - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -528,7 +527,7 @@ fn spot_price_calculation_should_work_for_two_stableassets_on_different_position let tolerated_difference = FixedU128::from_rational(1, 1000); assert_eq_approx!( relative_difference, - FixedU128::from_float(0.000000038203848342), + FixedU128::from_float(0.000400081474309023), FixedU128::from((2, (ONE / 10_000))), "the relative difference is not as expected" ); @@ -567,13 +566,13 @@ mod invariants { final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_percent(1), + fee: Permill::from_parts(200), //0.2% }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 40000000 * ONE), - AssetAmount::new(asset_b, 40000000 * ONE), + AssetAmount::new(asset_b, 41000000 * ONE), ], }, ) diff --git a/pallets/stableswap/src/trade_execution.rs b/pallets/stableswap/src/trade_execution.rs index 8ea27ab2ba..9009334871 100644 --- a/pallets/stableswap/src/trade_execution.rs +++ b/pallets/stableswap/src/trade_execution.rs @@ -315,15 +315,13 @@ where pool_id.into(), assets_with_reserves, amp, - asset_a.into(), asset_b.into(), + asset_a.into(), share_issuance, min_trade_limit, Some(trade_fee), &asset_pegs, ) - .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))? - .reciprocal() .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))?; Ok(spot_price) From ac8b5b4b3c8427de5a2f0230f1cf12030d9eaf53 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 3 Jun 2025 16:05:36 -0700 Subject: [PATCH 06/14] remove unused stuff --- pallets/stableswap/src/trade_execution.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/stableswap/src/trade_execution.rs b/pallets/stableswap/src/trade_execution.rs index 9009334871..107d17fd72 100644 --- a/pallets/stableswap/src/trade_execution.rs +++ b/pallets/stableswap/src/trade_execution.rs @@ -6,7 +6,7 @@ use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; use hydradx_traits::stableswap::AssetAmount; use orml_traits::MultiCurrency; use sp_core::Get; -use sp_runtime::{ArithmeticError, DispatchError, FixedPointNumber, FixedU128}; +use sp_runtime::{ArithmeticError, DispatchError, FixedU128}; use sp_std::collections::btree_map::BTreeMap; use sp_std::vec; use sp_std::vec::Vec; From 1638369dd9bbf2f3c478f9dafce874560bc26f3b Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 3 Jun 2025 16:06:49 -0700 Subject: [PATCH 07/14] bump math version --- Cargo.lock | 2 +- math/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 781b02eb77..27d675d538 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4495,7 +4495,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "10.0.3" +version = "10.0.4" dependencies = [ "approx", "criterion", diff --git a/math/Cargo.toml b/math/Cargo.toml index cddf2665c4..93dc822a11 100644 --- a/math/Cargo.toml +++ b/math/Cargo.toml @@ -6,7 +6,7 @@ license = 'Apache-2.0' name = "hydra-dx-math" description = "A collection of utilities to make performing liquidity pool calculations more convenient." repository = 'https://github.com/galacticcouncil/hydradx-math' -version = "10.0.3" +version = "10.0.4" [dependencies] primitive-types = { workspace = true } From aefe841b3b922f52d4fa0aa3fe34c8ffadfc721d Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 3 Jun 2025 16:07:56 -0700 Subject: [PATCH 08/14] formatting --- pallets/stableswap/src/tests/calculate_spot_price.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/stableswap/src/tests/calculate_spot_price.rs b/pallets/stableswap/src/tests/calculate_spot_price.rs index 31a44027d8..7817617214 100644 --- a/pallets/stableswap/src/tests/calculate_spot_price.rs +++ b/pallets/stableswap/src/tests/calculate_spot_price.rs @@ -120,7 +120,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() let sell_amount = ONE; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 8099993987359821846427; + let initial_issuance = 8099993987359821846427; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -339,7 +339,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_18_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200),//0.2% + fee: Permill::from_parts(200), //0.2% }, InitialLiquidity { account: ALICE, @@ -443,7 +443,7 @@ fn spot_price_calculation_should_work_for_two_stableassets() { //Check if spot price calculation is correct let calculated_amount_out = spot_price.reciprocal().unwrap().checked_mul_int(sell_amount).unwrap(); - let difference = calculated_amount_out - expected; + let difference = calculated_amount_out - expected; let relative_difference = FixedU128::from_rational(difference, expected); let tolerated_difference = FixedU128::from_rational(1, 1000); // The difference of the amount out calculated with spot price should be less than 0.1% From 5a7efe5e046f56f3e4c3db1dc76c94b09b1a4f07 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 21 Aug 2025 12:13:04 +0200 Subject: [PATCH 09/14] fix stableswap tests with gettin the reciprocal the right way --- .../src/tests/calculate_spot_price.rs | 67 ++++++++++--------- pallets/stableswap/src/trade_execution.rs | 6 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/pallets/stableswap/src/tests/calculate_spot_price.rs b/pallets/stableswap/src/tests/calculate_spot_price.rs index 7817617214..4d7400f0f0 100644 --- a/pallets/stableswap/src/tests/calculate_spot_price.rs +++ b/pallets/stableswap/src/tests/calculate_spot_price.rs @@ -32,11 +32,11 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_6_decimals() { final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), + fee: Permill::from_percent(1), }, InitialLiquidity { account: ALICE, - assets: vec![AssetAmount::new(asset_a, 40 * ONE), AssetAmount::new(asset_b, 41 * ONE)], + assets: vec![AssetAmount::new(asset_a, 40 * ONE), AssetAmount::new(asset_b, 40 * ONE)], }, ) .build() @@ -48,7 +48,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_6_decimals() { let sell_amount = 10 * ONE; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 80999938873618218464277405; + let initial_issuance = 80000000000020000000000000; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -60,7 +60,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_6_decimals() { 0, )); - let expected = 10; + let expected = 9; assert_balance!(BOB, pool_id, bob_share_balance - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -101,13 +101,13 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), + fee: Permill::from_percent(1), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 4000 * ONE), - AssetAmount::new(asset_b, 4100 * ONE), + AssetAmount::new(asset_b, 4000 * ONE), ], }, ) @@ -120,7 +120,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() let sell_amount = ONE; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 8099993987359821846427; + let initial_issuance = 8000000100000000000000; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -132,7 +132,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() 0, )); - let expected = 1000022; + let expected = 994999; assert_balance!(BOB, pool_id, bob_share_balance - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -152,7 +152,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_12_decimals() let relative_difference = FixedU128::from_rational(difference, expected); let tolerated_difference = FixedU128::from_rational(1, 100); // The difference of the amount out calculated with spot price should be less than 1% - assert_eq!(relative_difference, FixedU128::from_float(0.000098997822047915)); + assert_eq!(relative_difference, FixedU128::from_float(0.001021106553875934)); assert!(relative_difference < tolerated_difference); }); } @@ -177,13 +177,13 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), + fee: Permill::from_percent(1), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 100000000 * ONE), - AssetAmount::new(asset_b, 110000000 * ONE), + AssetAmount::new(asset_b, 100000000 * ONE), ], }, ) @@ -196,7 +196,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() let sell_amount = 1000; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 210097637343078345703; + let initial_issuance = 200100000000000000000; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -208,7 +208,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() 0, )); - let expected = 996; + let expected = 991; let pool_account = pool_account(pool_id); @@ -216,7 +216,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() assert_balance!(BOB, asset_b, expected); let total_issuance = Tokens::total_issuance(pool_id); assert_eq!(total_issuance, initial_issuance - sell_amount); - assert_balance!(pool_account, asset_b, 110000000 * ONE - expected); + assert_balance!(pool_account, asset_b, 100000000 * ONE - expected); let spot_price = Stableswap::calculate_spot_price_with_fee(PoolType::Stableswap(pool_id), pool_id, asset_b).unwrap(); @@ -233,7 +233,7 @@ fn spot_price_calculation_should_work_when_asset_in_is_share_with_18_decimals() // The difference of the amount out calculated with spot price should be less than 1% assert_eq_approx!( relative_difference, - FixedU128::from_float(0.005020080321285141), + FixedU128::from_float(0.004036326942482341), FixedU128::from((2, (ONE / 10_000))), "the relative difference is not as expected" ); @@ -264,14 +264,14 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), + fee: Permill::from_percent(3), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 150 * ONE), - AssetAmount::new(asset_b, 155 * ONE), - AssetAmount::new(asset_c, 160 * ONE), + AssetAmount::new(asset_b, 150 * ONE), + AssetAmount::new(asset_c, 150 * ONE), ], }, ) @@ -281,7 +281,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() let sell_amount = 1_000; let total_issuance = Tokens::total_issuance(pool_id); - let initial_issuance = 464998401424513938794; + let initial_issuance = 450000000000000000000; assert_eq!(total_issuance, initial_issuance); assert_ok!(Stableswap::execute_sell( @@ -293,7 +293,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() 0, )); - let expected = 1000326929; + let expected = 986999999; assert_balance!(BOB, asset_a, 200 * ONE - sell_amount); assert_balance!(BOB, pool_id, expected); @@ -314,6 +314,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_12_decimals() // The difference of the amount out calculated with spot price should be less than 0.1% let tolerated_difference = FixedU128::from_rational(1, 1000); + assert_eq!(relative_difference, FixedU128::from_float(0.000000000000000000)); assert!(relative_difference < tolerated_difference); }); @@ -339,7 +340,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_18_decimals() final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), //0.2% + fee: Permill::from_percent(3), }, InitialLiquidity { account: ALICE, @@ -367,7 +368,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_18_decimals() 0, )); - let expected = 1002832951117544; + let expected = 984938537439245; assert_balance!(BOB, asset_a, 200000000 * ONE - sell_amount); assert_balance!(BOB, pool_id, expected); @@ -387,7 +388,7 @@ fn spot_price_calculation_should_work_when_asset_out_is_share_with_18_decimals() let relative_difference = FixedU128::from_rational(difference, expected); // The difference of the amount out calculated with spot price should be less than 1% let tolerated_difference = FixedU128::from_rational(1, 1000); - assert_eq!(relative_difference, FixedU128::from_float(0.000166576978019961)); + assert_eq!(relative_difference, FixedU128::from_float(0.000952889346461269)); assert!(relative_difference < tolerated_difference); }); } @@ -408,13 +409,13 @@ fn spot_price_calculation_should_work_for_two_stableassets() { final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), + fee: Permill::from_percent(1), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 100 * ONE), - AssetAmount::new(asset_b, 110 * ONE), + AssetAmount::new(asset_b, 100 * ONE), ], }, ) @@ -433,7 +434,7 @@ fn spot_price_calculation_should_work_for_two_stableassets() { 0, )); - let expected = 1_000_747_331; + let expected = 989999901; assert_balance!(BOB, asset_a, 200 * ONE - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -443,13 +444,13 @@ fn spot_price_calculation_should_work_for_two_stableassets() { //Check if spot price calculation is correct let calculated_amount_out = spot_price.reciprocal().unwrap().checked_mul_int(sell_amount).unwrap(); - let difference = calculated_amount_out - expected; + let difference = expected - calculated_amount_out; let relative_difference = FixedU128::from_rational(difference, expected); let tolerated_difference = FixedU128::from_rational(1, 1000); // The difference of the amount out calculated with spot price should be less than 0.1% assert_eq_approx!( relative_difference, - FixedU128::from_float(0.000400025048880195), + FixedU128::from_float(0.000000097979807778), FixedU128::from((2, (ONE / 10_000))), "the relative difference is not as expected" ); @@ -482,7 +483,7 @@ fn spot_price_calculation_should_work_for_two_stableassets_on_different_position final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), //0.2% + fee: Permill::from_percent(2), }, InitialLiquidity { account: ALICE, @@ -508,7 +509,7 @@ fn spot_price_calculation_should_work_for_two_stableassets_on_different_position 0, )); - let expected = 988056247; + let expected = 968488820; assert_balance!(BOB, asset_c, 200 * ONE - sell_amount); assert_balance!(BOB, asset_b, expected); @@ -527,7 +528,7 @@ fn spot_price_calculation_should_work_for_two_stableassets_on_different_position let tolerated_difference = FixedU128::from_rational(1, 1000); assert_eq_approx!( relative_difference, - FixedU128::from_float(0.000400081474309023), + FixedU128::from_float(0.000000038203848342), FixedU128::from((2, (ONE / 10_000))), "the relative difference is not as expected" ); @@ -566,13 +567,13 @@ mod invariants { final_amplification: NonZeroU16::new(100).unwrap(), initial_block: 0, final_block: 0, - fee: Permill::from_parts(200), //0.2% + fee: Permill::from_percent(1), }, InitialLiquidity { account: ALICE, assets: vec![ AssetAmount::new(asset_a, 40000000 * ONE), - AssetAmount::new(asset_b, 41000000 * ONE), + AssetAmount::new(asset_b, 40000000 * ONE), ], }, ) diff --git a/pallets/stableswap/src/trade_execution.rs b/pallets/stableswap/src/trade_execution.rs index 107d17fd72..8ea27ab2ba 100644 --- a/pallets/stableswap/src/trade_execution.rs +++ b/pallets/stableswap/src/trade_execution.rs @@ -6,7 +6,7 @@ use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; use hydradx_traits::stableswap::AssetAmount; use orml_traits::MultiCurrency; use sp_core::Get; -use sp_runtime::{ArithmeticError, DispatchError, FixedU128}; +use sp_runtime::{ArithmeticError, DispatchError, FixedPointNumber, FixedU128}; use sp_std::collections::btree_map::BTreeMap; use sp_std::vec; use sp_std::vec::Vec; @@ -315,13 +315,15 @@ where pool_id.into(), assets_with_reserves, amp, - asset_b.into(), asset_a.into(), + asset_b.into(), share_issuance, min_trade_limit, Some(trade_fee), &asset_pegs, ) + .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))? + .reciprocal() .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))?; Ok(spot_price) From ed96f98424f301f97eb65cae6d1a03a13f309998 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 21 Aug 2025 13:10:37 +0200 Subject: [PATCH 10/14] remove custom reciprocal from hsm as now hte spot price returns correct price --- integration-tests/src/hsm.rs | 26 +++++++++++++------------- pallets/hsm/src/lib.rs | 11 +---------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/integration-tests/src/hsm.rs b/integration-tests/src/hsm.rs index bb2128e233..260bd890ae 100644 --- a/integration-tests/src/hsm.rs +++ b/integration-tests/src/hsm.rs @@ -27,7 +27,7 @@ use pretty_assertions::assert_eq; use primitives::{AssetId, Balance}; use sp_core::{RuntimeDebug, H256, U256}; use sp_runtime::traits::One; -use sp_runtime::BoundedVec; +use sp_runtime::{BoundedVec, FixedPointNumber}; use sp_runtime::Perbill; use sp_runtime::Permill; use std::sync::Arc; @@ -1941,7 +1941,7 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); let mut last_spot_price = initial_spot_price; @@ -1964,7 +1964,7 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price > last_spot_price); last_spot_price = spot_price; @@ -1988,7 +1988,7 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); assert!(initial_spot_price < final_spot_price); }); } @@ -2111,7 +2111,7 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); let mut last_spot_price = initial_spot_price; @@ -2138,7 +2138,7 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price > last_spot_price); last_spot_price = spot_price; @@ -2162,7 +2162,7 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); assert!(initial_spot_price < final_spot_price); }); } @@ -2285,7 +2285,7 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); dbg!(initial_spot_price); let mut last_spot_price = initial_spot_price; @@ -2309,7 +2309,7 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price < last_spot_price); last_spot_price = spot_price; @@ -2333,7 +2333,7 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); assert!(initial_spot_price > final_spot_price); }); } @@ -2469,7 +2469,7 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); dbg!(initial_spot_price); let mut last_spot_price = initial_spot_price; @@ -2497,7 +2497,7 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price < last_spot_price); last_spot_price = spot_price; @@ -2521,7 +2521,7 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ); + ).unwrap().reciprocal(); assert!(initial_spot_price > final_spot_price); }); } diff --git a/pallets/hsm/src/lib.rs b/pallets/hsm/src/lib.rs index 4d1f794bf0..064e27152d 100644 --- a/pallets/hsm/src/lib.rs +++ b/pallets/hsm/src/lib.rs @@ -60,14 +60,7 @@ use pallet_stableswap::types::PoolSnapshot; use precompile_utils::evm::writer::{EvmDataReader, EvmDataWriter}; use precompile_utils::evm::Bytes; use sp_core::{offchain::Duration, Get, H256, U256}; -use sp_runtime::{ - helpers_128bit::multiply_by_rational_with_rounding, - offchain::storage_lock::{StorageLock, Time}, - traits::{AccountIdConversion, Zero}, - transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction}, - AccountId32, ArithmeticError, DispatchError, FixedU128, Perbill, Permill, Rounding, RuntimeDebug, - SaturatedConversion, -}; +use sp_runtime::{helpers_128bit::multiply_by_rational_with_rounding, offchain::storage_lock::{StorageLock, Time}, traits::{AccountIdConversion, Zero}, transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction}, AccountId32, ArithmeticError, DispatchError, FixedPointNumber, FixedU128, Perbill, Permill, Rounding, RuntimeDebug, SaturatedConversion}; use sp_std::vec::Vec; pub mod traits; @@ -1464,8 +1457,6 @@ where // just to be safe return None; } - let after_spot = FixedU128::one().div(after_spot); - if after_spot > sell_price { return Some(()); } From b87005d4477bfd85d9c6365ff1cfe692191121e7 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 21 Aug 2025 13:14:46 +0200 Subject: [PATCH 11/14] fix property test --- pallets/hsm/src/tests/arb.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/pallets/hsm/src/tests/arb.rs b/pallets/hsm/src/tests/arb.rs index 792dbebb53..b3177cf298 100644 --- a/pallets/hsm/src/tests/arb.rs +++ b/pallets/hsm/src/tests/arb.rs @@ -291,8 +291,6 @@ proptest! { &state.pegs, ).expect("Pool not found"); - let after_spot = FixedU128::one().div(after_spot); - assert_eq_approx!(sell_price,after_spot, FixedU128::from_float(0.01), "Price should converge"); } From 077363192e008fe08d6deca85e7e7f12414125c9 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 21 Aug 2025 13:17:28 +0200 Subject: [PATCH 12/14] formatting --- pallets/hsm/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pallets/hsm/src/lib.rs b/pallets/hsm/src/lib.rs index 064e27152d..410bb13cc3 100644 --- a/pallets/hsm/src/lib.rs +++ b/pallets/hsm/src/lib.rs @@ -60,7 +60,14 @@ use pallet_stableswap::types::PoolSnapshot; use precompile_utils::evm::writer::{EvmDataReader, EvmDataWriter}; use precompile_utils::evm::Bytes; use sp_core::{offchain::Duration, Get, H256, U256}; -use sp_runtime::{helpers_128bit::multiply_by_rational_with_rounding, offchain::storage_lock::{StorageLock, Time}, traits::{AccountIdConversion, Zero}, transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction}, AccountId32, ArithmeticError, DispatchError, FixedPointNumber, FixedU128, Perbill, Permill, Rounding, RuntimeDebug, SaturatedConversion}; +use sp_runtime::{ + helpers_128bit::multiply_by_rational_with_rounding, + offchain::storage_lock::{StorageLock, Time}, + traits::{AccountIdConversion, Zero}, + transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction}, + AccountId32, ArithmeticError, DispatchError, FixedPointNumber, FixedU128, Perbill, Permill, Rounding, RuntimeDebug, + SaturatedConversion, +}; use sp_std::vec::Vec; pub mod traits; From 6f745144df0fc96a8f3b29885e38e607caeb1dd6 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 21 Aug 2025 14:08:59 +0200 Subject: [PATCH 13/14] formatting --- integration-tests/src/hsm.rs | 50 ++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/integration-tests/src/hsm.rs b/integration-tests/src/hsm.rs index 260bd890ae..63605ff482 100644 --- a/integration-tests/src/hsm.rs +++ b/integration-tests/src/hsm.rs @@ -27,9 +27,9 @@ use pretty_assertions::assert_eq; use primitives::{AssetId, Balance}; use sp_core::{RuntimeDebug, H256, U256}; use sp_runtime::traits::One; -use sp_runtime::{BoundedVec, FixedPointNumber}; use sp_runtime::Perbill; use sp_runtime::Permill; +use sp_runtime::{BoundedVec, FixedPointNumber}; use std::sync::Arc; use xcm_emulator::{Network, TestExt}; @@ -1941,7 +1941,9 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); let mut last_spot_price = initial_spot_price; @@ -1964,7 +1966,9 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price > last_spot_price); last_spot_price = spot_price; @@ -1988,7 +1992,9 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); assert!(initial_spot_price < final_spot_price); }); } @@ -2111,7 +2117,9 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); let mut last_spot_price = initial_spot_price; @@ -2138,7 +2146,9 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price > last_spot_price); last_spot_price = spot_price; @@ -2162,7 +2172,9 @@ fn arb_should_repeg_continuously_when_less_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); assert!(initial_spot_price < final_spot_price); }); } @@ -2285,7 +2297,9 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); dbg!(initial_spot_price); let mut last_spot_price = initial_spot_price; @@ -2309,7 +2323,9 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price < last_spot_price); last_spot_price = spot_price; @@ -2333,7 +2349,9 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool() { 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); assert!(initial_spot_price > final_spot_price); }); } @@ -2469,7 +2487,9 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); dbg!(initial_spot_price); let mut last_spot_price = initial_spot_price; @@ -2497,7 +2517,9 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); println!("Block: {:?}: spot: {:?}", block_idx, spot_price); assert!(spot_price < last_spot_price); last_spot_price = spot_price; @@ -2521,7 +2543,9 @@ fn arb_should_repeg_continuously_when_more_hollar_in_pool_and_collateral_has_12_ 1_000_000_000_000_000_000, Some(state.fee), &state.pegs, - ).unwrap().reciprocal(); + ) + .unwrap() + .reciprocal(); assert!(initial_spot_price > final_spot_price); }); } From d8ddc3bfa110c0bb830a1e549750c362e972a806 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 22 Aug 2025 08:49:32 +0200 Subject: [PATCH 14/14] bump versions --- Cargo.lock | 10 +++++----- integration-tests/Cargo.toml | 2 +- math/Cargo.toml | 2 +- pallets/hsm/Cargo.toml | 2 +- pallets/stableswap/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16e4da60ef..f297110e45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4506,7 +4506,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "10.3.0" +version = "10.3.1" dependencies = [ "approx", "criterion", @@ -4674,7 +4674,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "340.0.0" +version = "341.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -8432,7 +8432,7 @@ dependencies = [ [[package]] name = "pallet-hsm" -version = "1.2.2" +version = "1.2.3" dependencies = [ "ethabi", "evm", @@ -9176,7 +9176,7 @@ dependencies = [ [[package]] name = "pallet-stableswap" -version = "5.4.3" +version = "5.4.4" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -12267,7 +12267,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.52.1" +version = "1.52.2" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 8b1723a5a1..789cd5ec10 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.52.1" +version = "1.52.2" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/math/Cargo.toml b/math/Cargo.toml index ec37c907ae..56f92bde35 100644 --- a/math/Cargo.toml +++ b/math/Cargo.toml @@ -6,7 +6,7 @@ license = 'Apache-2.0' name = "hydra-dx-math" description = "A collection of utilities to make performing liquidity pool calculations more convenient." repository = 'https://github.com/galacticcouncil/hydradx-math' -version = "10.3.0" +version = "10.3.1" [dependencies] primitive-types = { workspace = true } diff --git a/pallets/hsm/Cargo.toml b/pallets/hsm/Cargo.toml index 1e8df23d81..bbcd203cb4 100644 --- a/pallets/hsm/Cargo.toml +++ b/pallets/hsm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-hsm" -version = "1.2.2" +version = "1.2.3" edition = "2021" description = "Hollar stability module" authors = ["GalacticCouncil"] diff --git a/pallets/stableswap/Cargo.toml b/pallets/stableswap/Cargo.toml index 28c17955c2..9ba1b383db 100644 --- a/pallets/stableswap/Cargo.toml +++ b/pallets/stableswap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-stableswap" -version = "5.4.3" +version = "5.4.4" description = "AMM for correlated assets" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 17a05cbebb..e162e7d329 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "340.0.0" +version = "341.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index eaef59c9f0..65d2fb2ff4 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -120,7 +120,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 340, + spec_version: 341, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1,