Skip to content

Commit

Permalink
fix(PCL): correct last price if fee share is enabled (#425)
Browse files Browse the repository at this point in the history
* fix(PCL): correct last price if fee share is enabled

* add migration from PCL v3.0.0
  • Loading branch information
epanchee authored Jul 19, 2024
1 parent a0a71af commit e5193b3
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 33 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions contracts/pair_concentrated/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astroport-pair-concentrated"
version = "3.0.0"
version = "3.0.1"
authors = ["Astroport"]
edition = "2021"
description = "The Astroport concentrated liquidity pair"
Expand Down Expand Up @@ -29,7 +29,7 @@ library = []
astroport = { path = "../../packages/astroport", version = "4" }
astroport-factory = { path = "../factory", features = ["library"], version = "1" }
astroport-circular-buffer = { path = "../../packages/circular_buffer", version = "0.2" }
astroport-pcl-common = { path = "../../packages/astroport_pcl_common", version = "2" }
astroport-pcl-common = { path = "../../packages/astroport_pcl_common", version = "2.0.1-feeshare-fix" }
cw2.workspace = true
cw20 = "1.1"
cosmwasm-std.workspace = true
Expand Down
1 change: 1 addition & 0 deletions contracts/pair_concentrated/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ pub fn migrate(deps: DepsMut, env: Env, _msg: MigrateMsg) -> Result<Response, Co
"2.3.0" => {
migrate_config_v2(deps.storage, &env)?;
}
"3.0.0" => {}
_ => return Err(ContractError::MigrationError {}),
},
_ => return Err(ContractError::MigrationError {}),
Expand Down
33 changes: 33 additions & 0 deletions contracts/pair_concentrated/tests/pair_concentrated_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,17 @@ fn check_correct_fee_share() {
helper.give_me_money(&[offer_asset.clone()], &user);
helper.swap(&user, &offer_asset, None).unwrap();

let last_price = helper
.query_config()
.unwrap()
.pool_state
.price_state
.last_price;
assert_eq!(
last_price,
Decimal256::from_str("1.001187607454013938").unwrap()
);

// Check that the shared fees are sent
let expected_fee_share = 26081u128;
let recipient_balance = helper.coin_balance(&test_coins[1], &share_recipient);
Expand All @@ -1578,6 +1589,17 @@ fn check_correct_fee_share() {
helper.give_me_money(&[offer_asset.clone()], &user);
helper.swap(&user, &offer_asset, None).unwrap();

let last_price = helper
.query_config()
.unwrap()
.pool_state
.price_state
.last_price;
assert_eq!(
last_price,
Decimal256::from_str("0.998842355796925899").unwrap()
);

helper
.withdraw_liquidity(&provider, 999_999354, vec![])
.unwrap();
Expand All @@ -1586,6 +1608,17 @@ fn check_correct_fee_share() {
helper.give_me_money(&[offer_asset.clone()], &user);
helper.swap(&user, &offer_asset, None).unwrap();

let last_price = helper
.query_config()
.unwrap()
.pool_state
.price_state
.last_price;
assert_eq!(
last_price,
Decimal256::from_str("1.00118760696709103").unwrap()
);

// Disable fee share
let action = ConcentratedPoolUpdateParams::DisableFeeShare {};
helper.update_config(&owner, &action).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion contracts/periphery/liquidity_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cw20-base = { version = "1.1", features = ["library"] }
astroport-pair = { path = "../../pair", features = ["library"], version = "1.5" }
astroport-pair-stable = { path = "../../pair_stable", features = ["library"], version = "3" }
astroport-pair-concentrated = { path = "../../pair_concentrated", features = ["library"], version = "3" }
astroport-pcl-common = { path = "../../../packages/astroport_pcl_common", version = "2" }
astroport-pcl-common = { path = "../../../packages/astroport_pcl_common", version = "2.0.1-feeshare-fix" }
astroport-factory = { path = "../../factory", features = ["library"], version = "1" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion packages/astroport/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astroport"
version = "4.0.3"
version = "4.0.4"
authors = ["Astroport"]
edition = "2021"
description = "Common Astroport types, queriers and other utils"
Expand Down
2 changes: 1 addition & 1 deletion packages/astroport_pcl_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astroport-pcl-common"
version = "2.0.1"
version = "2.0.1-feeshare-fix"
edition = "2021"
description = "Common package contains math tools and utils for Astroport PCL pairs"
license = "GPL-3.0-only"
Expand Down
8 changes: 3 additions & 5 deletions packages/astroport_pcl_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,12 @@ pub struct SwapResult {
}

impl SwapResult {
/// Calculates **last price** and **last real price**.
/// Returns (last_price, last_real_price) where:
/// - last_price is a price for repeg algo,
/// Calculates **last price** for PCL repeg algo
pub fn calc_last_price(&self, offer_amount: Decimal256, offer_ind: usize) -> Decimal256 {
if offer_ind == 0 {
offer_amount / (self.dy + self.maker_fee)
offer_amount / (self.dy + self.maker_fee + self.share_fee)
} else {
(self.dy + self.maker_fee) / offer_amount
(self.dy + self.maker_fee + self.share_fee) / offer_amount
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "astroport-pair-concentrated",
"contract_version": "3.0.0",
"contract_version": "3.0.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down

0 comments on commit e5193b3

Please sign in to comment.