From 71f4248e8057aad5af58ccb333bee736011af072 Mon Sep 17 00:00:00 2001 From: JanKuczma Date: Tue, 29 Oct 2024 12:16:32 +0100 Subject: [PATCH 1/2] support old pairs --- amm/contracts/router_v2/pair.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/amm/contracts/router_v2/pair.rs b/amm/contracts/router_v2/pair.rs index 69ceaf2..510c3d7 100644 --- a/amm/contracts/router_v2/pair.rs +++ b/amm/contracts/router_v2/pair.rs @@ -10,6 +10,8 @@ use traits::{Balance, MathError, Pair as PairTrait, RouterV2Error}; const PAIR_TRADING_FEE_DENOM: u128 = 1000; +const DEFAUT_PAIR_FEE: u8 = 3; + #[derive(scale::Decode, scale::Encode)] #[cfg_attr( feature = "std", @@ -28,15 +30,23 @@ impl Pair { /// Returns `None` if `pair_id` is not a Pair contract. pub fn try_new(pair_id: AccountId) -> Option { let contract_ref: contract_ref!(PairTrait, Env) = pair_id.into(); - // Assume that the `pair_id` is a Pair contract and try to get the fee value. + + // Assume that the `pair_id` is a Pair contract and try to get the token_0 address. // If the call is not successful return None indicating that the `pair_id` - // is not a Pair contract - let fee = match contract_ref.call().get_fee().try_invoke() { - Ok(Ok(fee)) => fee, + // is not a Pair contract. + let token_0 = match contract_ref.call().get_token_0().try_invoke() { + Ok(Ok(account)) => account, _ => return None, }; - let token_0 = contract_ref.get_token_0(); let token_1 = contract_ref.get_token_1(); + + // The `Pair` contracts that do not implement `get_fee()` + // have fee equal to the default value (3, i.e. 0.3%). + let fee = match contract_ref.call().get_fee().try_invoke() { + Ok(Ok(fee)) => fee, + _ => DEFAUT_PAIR_FEE, + }; + Some(Pair { id: pair_id, token_0, From d7ec451e5e659de912bcbd1805b91bac54e7e43b Mon Sep 17 00:00:00 2001 From: JanKuczma Date: Tue, 29 Oct 2024 12:33:35 +0100 Subject: [PATCH 2/2] fix scale version --- amm/contracts/factory/Cargo.toml | 4 ++-- amm/contracts/pair/Cargo.toml | 4 ++-- amm/contracts/router/Cargo.toml | 4 ++-- amm/contracts/router_v2/Cargo.toml | 4 ++-- amm/contracts/stable_pool/Cargo.toml | 4 ++-- amm/drink-tests/Cargo.toml | 2 +- amm/traits/Cargo.toml | 4 ++-- farm/contract/Cargo.toml | 4 ++-- farm/trait/Cargo.toml | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/amm/contracts/factory/Cargo.toml b/amm/contracts/factory/Cargo.toml index 69265bb..0782734 100644 --- a/amm/contracts/factory/Cargo.toml +++ b/amm/contracts/factory/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] ink = { version = "=4.3.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.9", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } diff --git a/amm/contracts/pair/Cargo.toml b/amm/contracts/pair/Cargo.toml index 7edb65f..c350345 100644 --- a/amm/contracts/pair/Cargo.toml +++ b/amm/contracts/pair/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] ink = { version = "=4.3.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.9", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } diff --git a/amm/contracts/router/Cargo.toml b/amm/contracts/router/Cargo.toml index 522072b..c498326 100755 --- a/amm/contracts/router/Cargo.toml +++ b/amm/contracts/router/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] ink = { version = "=4.3.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.9", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } diff --git a/amm/contracts/router_v2/Cargo.toml b/amm/contracts/router_v2/Cargo.toml index 8510ffb..81457da 100755 --- a/amm/contracts/router_v2/Cargo.toml +++ b/amm/contracts/router_v2/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] ink = { version = "=4.3.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.9", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } diff --git a/amm/contracts/stable_pool/Cargo.toml b/amm/contracts/stable_pool/Cargo.toml index ca8545d..8aad4a7 100644 --- a/amm/contracts/stable_pool/Cargo.toml +++ b/amm/contracts/stable_pool/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] ink = { version = "=4.3.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.9", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } diff --git a/amm/drink-tests/Cargo.toml b/amm/drink-tests/Cargo.toml index e0ea2e8..9b5a6cd 100644 --- a/amm/drink-tests/Cargo.toml +++ b/amm/drink-tests/Cargo.toml @@ -12,7 +12,7 @@ ink-wrapper-types = { version = "0.9.0", default-features = false, features = [ ] } ink_primitives = "4.3.0" -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } diff --git a/amm/traits/Cargo.toml b/amm/traits/Cargo.toml index 2dff33a..e3e50cb 100644 --- a/amm/traits/Cargo.toml +++ b/amm/traits/Cargo.toml @@ -8,10 +8,10 @@ edition = "2021" ink = { version = "=4.3.0", default-features = false } ink_metadata = { version = "=4.3.0", features = ["derive"], optional = true } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.9", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } diff --git a/farm/contract/Cargo.toml b/farm/contract/Cargo.toml index 31bc1bf..d9aded6 100644 --- a/farm/contract/Cargo.toml +++ b/farm/contract/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] ink = { version = "=4.3.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.3", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } diff --git a/farm/trait/Cargo.toml b/farm/trait/Cargo.toml index 812e674..8c1e467 100644 --- a/farm/trait/Cargo.toml +++ b/farm/trait/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] ink = { version = "=4.3.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ +scale = { package = "parity-scale-codec", version = "=3.6.9", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.5", default-features = false, features = [ +scale-info = { version = "=2.10.0", default-features = false, features = [ "derive", ], optional = true } psp22 = { version = "=0.2.2", default-features = false }