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

feat(PCL duality): add PCL with Duality orderbook integration #438

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
382 changes: 341 additions & 41 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"contracts/pair_concentrated",
"contracts/pair_astro_converter",
"contracts/pair_transmuter",
"contracts/pair_concentrated_duality",
# "contracts/pair_concentrated_inj", TODO: rewrite OB liquidity deployment
"contracts/pair_xastro",
"contracts/pair_xyk_sale_tax",
Expand Down
2 changes: 1 addition & 1 deletion 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 = "4.1.0"
version = "4.1.1"
authors = ["Astroport"]
edition = "2021"
description = "The Astroport concentrated liquidity pair"
Expand Down
3 changes: 2 additions & 1 deletion contracts/pair_concentrated/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ pub fn execute(
.map_err(Into::into)
}
ExecuteMsg::WithdrawLiquidity { assets, .. } => withdraw_liquidity(deps, env, info, assets),
_ => Err(ContractError::NotSupported {}),
}
}

Expand Down Expand Up @@ -905,7 +906,7 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, Contra

match contract_version.contract.as_ref() {
"astroport-pair-concentrated" => match contract_version.version.as_ref() {
"4.0.0" | "4.0.1" => {}
"4.0.0" | "4.0.1" | "4.1.0" => {}
_ => return Err(ContractError::MigrationError {}),
},
_ => return Err(ContractError::MigrationError {}),
Expand Down
3 changes: 3 additions & 0 deletions contracts/pair_concentrated/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ pub enum ContractError {

#[error("Slippage is more than expected: received {0}, expected {1} LP tokens")]
ProvideSlippageViolation(Uint128, Uint128),

#[error("Operation is not supported")]
NotSupported {},
}
1 change: 1 addition & 0 deletions contracts/pair_concentrated/tests/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl Helper {
owner,
))
}
TestCoin::NativePrecise(..) => unimplemented!(),
};
(coin, asset_info)
})
Expand Down
6 changes: 6 additions & 0 deletions contracts/pair_concentrated_duality/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib"
integration-test = "test --test integration"
schema = "run --example pair_concentrated_schema"
11 changes: 11 additions & 0 deletions contracts/pair_concentrated_duality/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.rs]
indent_size = 4
53 changes: 53 additions & 0 deletions contracts/pair_concentrated_duality/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "astroport-pair-concentrated-duality"
version = "4.1.1" # must share the same version with the original PCL
authors = ["Astroport"]
edition = "2021"
description = "The Astroport concentrated liquidity pair with Duality orderbook integration"
license = "GPL-3.0-only"
repository = "https://github.com/astroport-fi/astroport"
homepage = "https://astroport.fi"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
test-tube = ["neutron-test-tube"]
library = []

[dependencies]
cosmwasm-std = { workspace = true, features = ["cosmwasm_1_1"] }
cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
cosmwasm-schema = { workspace = true }
itertools = { workspace = true }
cw-utils = { workspace = true }
cw2 = { workspace = true }

astroport = { path = "../../packages/astroport", version = "5.8", features = ["duality"] }
astroport-pcl-common = { path = "../../packages/astroport_pcl_common", version = "2" }

serde = { version = "1.0.203", features = ["derive"] }
semver = "1.0"

neutron-std = { git = "https://github.com/astroport-fi/neutron-std", branch = "backport/cosmwasm_v1" }
neutron-test-tube = { git = "https://github.com/astroport-fi/neutron-test-tube", optional = true, branch = "feat/neutron-v5-cosmwasm-v1", version = "4.2.2-rc" }

[dev-dependencies]
astroport-native-coin-registry = { version = "1.1", features = ["library"] }
astroport-test = { path = "../../packages/astroport_test", version = "0.1.0" }
astroport-factory = { path = "../factory", version = "1.8", features = ["library"] }
astroport-pair-concentrated = { path = "../pair_concentrated", version = "4.1.0", features = ["library"] }
anyhow = "1.0"
derivative = "2.2"
1 change: 1 addition & 0 deletions contracts/pair_concentrated_duality/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Astroport Concentrated Liquidity Pair with Duality Orderbook integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use cosmwasm_schema::write_api;

use astroport::pair::{ExecuteMsgExt, InstantiateMsg, QueryMsg};
use astroport::pair_concentrated_duality::DualityPairMsg;

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsgExt<DualityPairMsg>
}
}
15 changes: 15 additions & 0 deletions contracts/pair_concentrated_duality/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# stable
newline_style = "Unix"
hard_tabs = false
tab_spaces = 4

# unstable... should we require `rustup run nightly cargo fmt` ?
# or just update the style guide when they are stable?
#fn_single_line = true
#format_code_in_doc_comments = true
#overflow_delimited_expr = true
#reorder_impl_items = true
#struct_field_align_threshold = 20
#struct_lit_single_line = true
#report_todo = "Always"

80 changes: 80 additions & 0 deletions contracts/pair_concentrated_duality/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use cosmwasm_std::{ConversionOverflowError, OverflowError, StdError, Uint128};
use cw_utils::{ParseReplyError, PaymentError};
use thiserror::Error;

use astroport::asset::MINIMUM_LIQUIDITY_AMOUNT;
use astroport::pair::MAX_FEE_SHARE_BPS;
use astroport_pcl_common::error::PclError;

use crate::orderbook::error::OrderbookError;

/// This enum describes pair contract errors
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("{0}")]
PclError(#[from] PclError),

#[error("{0}")]
OrderbookError(#[from] OrderbookError),

#[error("{0}")]
ConversionOverflowError(#[from] ConversionOverflowError),

#[error("{0}")]
OverflowError(#[from] OverflowError),

#[error("{0}")]
ParseReplyError(#[from] ParseReplyError),

#[error("{0}")]
PaymentError(#[from] PaymentError),

#[error("Unauthorized")]
Unauthorized {},

#[error("You need to provide init params")]
InitParamsNotFound {},

#[error("The asset {0} does not belong to the pair")]
InvalidAsset(String),

#[error("Pair is not registered in the factory. Only swap and withdraw are allowed")]
PairIsNotRegistered {},

#[error("Invalid number of assets. This pair supports only {0} assets")]
InvalidNumberOfAssets(usize),

#[error("Initial provide can not be one-sided")]
InvalidZeroAmount {},

#[error("Initial liquidity must be more than {}", MINIMUM_LIQUIDITY_AMOUNT)]
MinimumLiquidityAmountError {},

#[error(
"Fee share is 0 or exceeds maximum allowed value of {} bps",
MAX_FEE_SHARE_BPS
)]
FeeShareOutOfBounds {},

#[error("Failed to parse or process reply message")]
FailedToParseReply {},

#[error("cw20 tokens are not supported")]
NonNativeAsset {},

#[error("Slippage is more than expected: received {0}, expected {1} LP tokens")]
ProvideSlippageViolation(Uint128, Uint128),

#[error("Received {received} {asset_name} but expected {expected}")]
WithdrawSlippageViolation {
asset_name: String,
received: Uint128,
expected: Uint128,
},

#[error("Wrong asset length: expected {expected}, actual {actual}")]
WrongAssetLength { expected: usize, actual: usize },
}
Loading
Loading