From 6817f4ad4430120f0587653bbcf8dd58af69f36d Mon Sep 17 00:00:00 2001 From: Sturdy Date: Tue, 14 Feb 2023 20:14:35 +0100 Subject: [PATCH 1/2] fix: Make ForceUnlock ID be an option --- cw-dex/src/implementations/osmosis/staking.rs | 9 ++++++++- cw-dex/src/traits/staking.rs | 2 +- cw-dex/tests/osmosis_tests.rs | 2 +- test-contracts/osmosis-test-contract/src/contract.rs | 2 +- test-contracts/package/src/msg.rs | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cw-dex/src/implementations/osmosis/staking.rs b/cw-dex/src/implementations/osmosis/staking.rs index bc5ff65..cd2017d 100644 --- a/cw-dex/src/implementations/osmosis/staking.rs +++ b/cw-dex/src/implementations/osmosis/staking.rs @@ -170,9 +170,16 @@ impl ForceUnlock for OsmosisStaking { &self, _deps: Deps, env: &Env, - lockup_id: u64, + lockup_id: Option, amount: Uint128, ) -> Result { + let lockup_id = match lockup_id { + Some(id) => Ok(id), + None => self + .lock_id + .ok_or_else(|| StdError::generic_err("osmosis error: lock id not set")), + }?; + let coin_to_unlock = Coin::new(amount.u128(), self.lp_token_denom.clone()); let force_unlock_msg = MsgForceUnlock { diff --git a/cw-dex/src/traits/staking.rs b/cw-dex/src/traits/staking.rs index a52a8c8..1b932bf 100644 --- a/cw-dex/src/traits/staking.rs +++ b/cw-dex/src/traits/staking.rs @@ -93,7 +93,7 @@ pub trait ForceUnlock: LockedStaking { &self, deps: Deps, env: &Env, - lockup_id: u64, + lockup_id: Option, amount: Uint128, ) -> Result; } diff --git a/cw-dex/tests/osmosis_tests.rs b/cw-dex/tests/osmosis_tests.rs index 0c90cf3..bfe2847 100644 --- a/cw-dex/tests/osmosis_tests.rs +++ b/cw-dex/tests/osmosis_tests.rs @@ -298,7 +298,7 @@ mod tests { // Force unlock LP tokens let force_unlock_msg = ExecuteMsg::ForceUnlock { amount: unlock_amount, - lockup_id: 1, + lockup_id: Some(1), }; runner.execute_cosmos_msgs::( &[force_unlock_msg.into_cosmos_msg(contract_addr.clone(), vec![])], diff --git a/test-contracts/osmosis-test-contract/src/contract.rs b/test-contracts/osmosis-test-contract/src/contract.rs index e296c56..6d47af9 100644 --- a/test-contracts/osmosis-test-contract/src/contract.rs +++ b/test-contracts/osmosis-test-contract/src/contract.rs @@ -133,7 +133,7 @@ pub fn execute_force_unlock( env: Env, _info: MessageInfo, amount: Uint128, - lockup_id: u64, + lockup_id: Option, ) -> Result { let staking = STAKING.load(deps.storage)?; diff --git a/test-contracts/package/src/msg.rs b/test-contracts/package/src/msg.rs index 61e03cf..f64ba6c 100644 --- a/test-contracts/package/src/msg.rs +++ b/test-contracts/package/src/msg.rs @@ -37,7 +37,7 @@ pub enum ExecuteMsg { }, ForceUnlock { amount: Uint128, - lockup_id: u64, + lockup_id: Option, }, Swap { offer: Asset, From 0d32fa11eb88ba8c488b23837dc35c432ac16873 Mon Sep 17 00:00:00 2001 From: Sturdy Date: Tue, 14 Feb 2023 20:15:13 +0100 Subject: [PATCH 2/2] chore: bump version and add readme --- Cargo.lock | 2 +- cw-dex/Cargo.toml | 3 ++- cw-dex/README.md | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 cw-dex/README.md diff --git a/Cargo.lock b/Cargo.lock index 0ed2655..daaae3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,7 +665,7 @@ dependencies = [ [[package]] name = "cw-dex" -version = "0.1.0" +version = "0.1.1" dependencies = [ "apollo-cw-asset", "apollo-utils", diff --git a/cw-dex/Cargo.toml b/cw-dex/Cargo.toml index 96dfe3a..543184a 100644 --- a/cw-dex/Cargo.toml +++ b/cw-dex/Cargo.toml @@ -5,7 +5,8 @@ edition = "2021" license = "MPL-2.0" name = "cw-dex" repository = "https://github.com/apollodao/cw-dex" -version = "0.1.0" +version = "0.1.1" +readme = "README.md" [features] default = [] diff --git a/cw-dex/README.md b/cw-dex/README.md new file mode 100644 index 0000000..e6e0c85 --- /dev/null +++ b/cw-dex/README.md @@ -0,0 +1,10 @@ +# cw-dex +CosmWasm abstractions for decentralized exchanges. + +This crate defines a set of +traits to abstract out the common behavior of various decentralized exchanges so +that the same contract code can be used to interact with any of them. + +The currently supported decentralized exchanges are: +- [Osmosis](src/implementations/osmosis/) +- [Astroport](src/implementations/astroport/)