Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Pair default fee in RouterV2 #122

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions amm/contracts/factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
ggawryal marked this conversation as resolved.
Show resolved Hide resolved
"derive",
], optional = true }

Expand Down
4 changes: 2 additions & 2 deletions amm/contracts/pair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions amm/contracts/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions amm/contracts/router_v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
20 changes: 15 additions & 5 deletions amm/contracts/router_v2/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -28,15 +30,23 @@ impl Pair {
/// Returns `None` if `pair_id` is not a Pair contract.
pub fn try_new(pair_id: AccountId) -> Option<Self> {
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() {
Copy link
Contributor

@woocash2 woocash2 Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why suddenly like this & why obtain token0 and token1 differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the Pair contract may not implement get_fee(), however, it must implement get_token_0() and get_token_1().
Given that get_token_0() call is successful, we assume that the contract is a Pair, and there's no need to control the invocation of the get_token_1().

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,
Expand Down
4 changes: 2 additions & 2 deletions amm/contracts/stable_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion amm/drink-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }

Expand Down
4 changes: 2 additions & 2 deletions amm/traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions farm/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions farm/trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down