From c9923091ae1e6f78f9640c238cf760021b152a46 Mon Sep 17 00:00:00 2001 From: Pacman Date: Tue, 13 Feb 2024 19:17:35 +0100 Subject: [PATCH 1/8] refactor!: revert incentives related changes to implementations::astroport --- Cargo.lock | 5 +- cw-dex/Cargo.toml | 3 +- .../src/implementations/astroport/staking.rs | 66 +++++++++++-------- .../astroport-test-contract/src/contract.rs | 1 - 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14e143b..5bb2670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -892,7 +892,6 @@ dependencies = [ "apollo-cw-asset", "apollo-utils", "astroport 2.9.0", - "astroport 3.11.1", "cosmwasm-schema", "cosmwasm-std", "cw-dex-test-contract", @@ -1642,9 +1641,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" +checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" [[package]] name = "hex" diff --git a/cw-dex/Cargo.toml b/cw-dex/Cargo.toml index ab29b55..54e2345 100644 --- a/cw-dex/Cargo.toml +++ b/cw-dex/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" default = [] osmosis = ["osmosis-std", "osmosis-test-tube", "cw-it/osmosis"] osmosis-test-tube = ["cw-it/osmosis-test-tube"] -astroport = ["dep:astroport", "dep:astroport_v3", "apollo-cw-asset/astroport", "dep:cw2", "cw-it/astroport", "cw-it/astroport-multi-test"] +astroport = ["dep:astroport", "apollo-cw-asset/astroport", "dep:cw2", "cw-it/astroport", "cw-it/astroport-multi-test"] # backtraces = ["cosmwasm-std/backtraces", "osmosis-std/backtraces"] [package.metadata.docs.rs] @@ -33,7 +33,6 @@ osmosis-std = { version = "0.19.2", optional = true } # Astroport astroport = { workspace = true, optional = true } -astroport_v3 = { workspace = true, optional = true } cw2 = { workspace = true, optional = true } [dev-dependencies] diff --git a/cw-dex/src/implementations/astroport/staking.rs b/cw-dex/src/implementations/astroport/staking.rs index 28bf9e9..2e9fa13 100644 --- a/cw-dex/src/implementations/astroport/staking.rs +++ b/cw-dex/src/implementations/astroport/staking.rs @@ -3,16 +3,16 @@ use apollo_utils::assets::separate_natives_and_cw20s; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_json_binary, Addr, CosmosMsg, Deps, Empty, Env, Event, QuerierWrapper, QueryRequest, - Response, Uint128, WasmMsg, WasmQuery, + to_binary, Addr, CosmosMsg, Deps, Empty, Env, Event, QuerierWrapper, QueryRequest, Response, + Uint128, WasmMsg, WasmQuery, }; use cw20::Cw20ExecuteMsg; -use apollo_cw_asset::AssetList; +use apollo_cw_asset::{Asset, AssetInfo, AssetList}; use astroport::asset::Asset as AstroAsset; -use astroport_v3::incentives::{ - Cw20Msg as IncentivesCw20Msg, ExecuteMsg as IncentivesExecuteMsg, - QueryMsg as IncentivesQueryMsg, +use astroport::generator::{ + Cw20HookMsg as GeneratorCw20HookMsg, ExecuteMsg as GeneratorExecuteMsg, PendingTokenResponse, + QueryMsg as GeneratorQueryMsg, }; use crate::traits::{Rewards, Stake, Staking, Unstake}; @@ -23,8 +23,10 @@ use crate::CwDexError; pub struct AstroportStaking { /// The address of the associated LP token contract pub lp_token_addr: Addr, - /// The address of the astroport incentives contract - pub incentives: Addr, + /// The address of the associated generator contract + pub generator_addr: Addr, + /// The address of the ASTRO token contract + pub astro_token: AssetInfo, } impl Staking for AstroportStaking {} @@ -33,10 +35,10 @@ impl Stake for AstroportStaking { fn stake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result { let stake_msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: self.lp_token_addr.to_string(), - msg: to_json_binary(&Cw20ExecuteMsg::Send { - contract: self.incentives.to_string(), + msg: to_binary(&Cw20ExecuteMsg::Send { + contract: self.generator_addr.to_string(), amount, - msg: to_json_binary(&IncentivesCw20Msg::Deposit { recipient: None })?, + msg: to_binary(&GeneratorCw20HookMsg::Deposit {})?, })?, funds: vec![], }); @@ -44,7 +46,7 @@ impl Stake for AstroportStaking { let event = Event::new("apollo/cw-dex/stake") .add_attribute("type", "astroport_staking") .add_attribute("asset", self.lp_token_addr.to_string()) - .add_attribute("incentives contract address", self.incentives.to_string()); + .add_attribute("generator_address", self.generator_addr.to_string()); Ok(Response::new().add_message(stake_msg).add_event(event)) } @@ -63,8 +65,8 @@ impl Rewards for AstroportStaking { } let claim_rewards_msg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: self.incentives.to_string(), - msg: to_json_binary(&IncentivesExecuteMsg::ClaimRewards { + contract_addr: self.generator_addr.to_string(), + msg: to_binary(&GeneratorExecuteMsg::ClaimRewards { lp_tokens: vec![self.lp_token_addr.to_string()], })?, funds: vec![], @@ -95,10 +97,10 @@ impl Rewards for AstroportStaking { // Unwrap the native token let unwrap_msg: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: cw20.address.to_string(), - msg: to_json_binary(&cw20::Cw20ExecuteMsg::Send { + msg: to_binary(&cw20::Cw20ExecuteMsg::Send { contract: wrapper_contract.to_string(), amount: cw20.amount, - msg: to_json_binary(&astroport::native_coin_wrapper::Cw20HookMsg::Unwrap {})?, + msg: to_binary(&astroport::native_coin_wrapper::Cw20HookMsg::Unwrap {})?, })?, funds: vec![], }); @@ -113,17 +115,25 @@ impl Rewards for AstroportStaking { querier: &QuerierWrapper, user: &Addr, ) -> Result { - let pending_rewards: Vec = querier - .query::>(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: self.incentives.to_string(), - msg: to_json_binary(&IncentivesQueryMsg::PendingRewards { - lp_token: self.lp_token_addr.to_string(), - user: user.to_string(), - })?, - }))? + let PendingTokenResponse { + pending: pending_astro, + pending_on_proxy, + } = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { + contract_addr: self.generator_addr.to_string(), + msg: to_binary(&GeneratorQueryMsg::PendingToken { + lp_token: self.lp_token_addr.to_string(), + user: user.to_string(), + })?, + }))?; + + let pending_rewards: Vec = pending_on_proxy + .unwrap_or_default() .into_iter() - .filter(|asset| !asset.amount.is_zero()) //TODO: Is this necessary? - .collect(); + .chain(vec![ + Asset::new(self.astro_token.clone(), pending_astro).into() + ]) + .filter(|asset| !asset.amount.is_zero()) + .collect::>(); Ok(pending_rewards.into()) } @@ -132,8 +142,8 @@ impl Rewards for AstroportStaking { impl Unstake for AstroportStaking { fn unstake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result { let unstake_msg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: self.incentives.to_string(), - msg: to_json_binary(&IncentivesExecuteMsg::Withdraw { + contract_addr: self.generator_addr.to_string(), + msg: to_binary(&GeneratorExecuteMsg::Withdraw { lp_token: self.lp_token_addr.to_string(), amount, })?, diff --git a/test-contracts/astroport-test-contract/src/contract.rs b/test-contracts/astroport-test-contract/src/contract.rs index b2c2a86..c6608e5 100644 --- a/test-contracts/astroport-test-contract/src/contract.rs +++ b/test-contracts/astroport-test-contract/src/contract.rs @@ -29,7 +29,6 @@ pub fn instantiate( deps.storage, &AstroportStaking { lp_token_addr: Addr::unchecked(msg.lp_token_addr), - incentives: Addr::unchecked(msg.incentives_addr), }, )?; From 05166a07ab1b93a0600f346591b1a1c454178f2e Mon Sep 17 00:00:00 2001 From: Pacman Date: Tue, 13 Feb 2024 19:22:27 +0100 Subject: [PATCH 2/8] chore: use to_json_binary --- .../src/implementations/astroport/staking.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cw-dex/src/implementations/astroport/staking.rs b/cw-dex/src/implementations/astroport/staking.rs index 2e9fa13..7e10529 100644 --- a/cw-dex/src/implementations/astroport/staking.rs +++ b/cw-dex/src/implementations/astroport/staking.rs @@ -3,8 +3,8 @@ use apollo_utils::assets::separate_natives_and_cw20s; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_binary, Addr, CosmosMsg, Deps, Empty, Env, Event, QuerierWrapper, QueryRequest, Response, - Uint128, WasmMsg, WasmQuery, + to_json_binary, Addr, CosmosMsg, Deps, Empty, Env, Event, QuerierWrapper, QueryRequest, + Response, Uint128, WasmMsg, WasmQuery, }; use cw20::Cw20ExecuteMsg; @@ -35,10 +35,10 @@ impl Stake for AstroportStaking { fn stake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result { let stake_msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: self.lp_token_addr.to_string(), - msg: to_binary(&Cw20ExecuteMsg::Send { + msg: to_json_binary(&Cw20ExecuteMsg::Send { contract: self.generator_addr.to_string(), amount, - msg: to_binary(&GeneratorCw20HookMsg::Deposit {})?, + msg: to_json_binary(&GeneratorCw20HookMsg::Deposit {})?, })?, funds: vec![], }); @@ -66,7 +66,7 @@ impl Rewards for AstroportStaking { let claim_rewards_msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: self.generator_addr.to_string(), - msg: to_binary(&GeneratorExecuteMsg::ClaimRewards { + msg: to_json_binary(&GeneratorExecuteMsg::ClaimRewards { lp_tokens: vec![self.lp_token_addr.to_string()], })?, funds: vec![], @@ -97,10 +97,10 @@ impl Rewards for AstroportStaking { // Unwrap the native token let unwrap_msg: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: cw20.address.to_string(), - msg: to_binary(&cw20::Cw20ExecuteMsg::Send { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::Send { contract: wrapper_contract.to_string(), amount: cw20.amount, - msg: to_binary(&astroport::native_coin_wrapper::Cw20HookMsg::Unwrap {})?, + msg: to_json_binary(&astroport::native_coin_wrapper::Cw20HookMsg::Unwrap {})?, })?, funds: vec![], }); @@ -120,7 +120,7 @@ impl Rewards for AstroportStaking { pending_on_proxy, } = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: self.generator_addr.to_string(), - msg: to_binary(&GeneratorQueryMsg::PendingToken { + msg: to_json_binary(&GeneratorQueryMsg::PendingToken { lp_token: self.lp_token_addr.to_string(), user: user.to_string(), })?, @@ -143,7 +143,7 @@ impl Unstake for AstroportStaking { fn unstake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result { let unstake_msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: self.generator_addr.to_string(), - msg: to_binary(&GeneratorExecuteMsg::Withdraw { + msg: to_json_binary(&GeneratorExecuteMsg::Withdraw { lp_token: self.lp_token_addr.to_string(), amount, })?, From 4e2991d5ea9295bc34ba9b3a55dacfedf297b60a Mon Sep 17 00:00:00 2001 From: Pacman Date: Tue, 13 Feb 2024 19:23:18 +0100 Subject: [PATCH 3/8] chore: bump cw-dex version to 0.5.3-rc.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- cw-dex/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bb2670..199945d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -887,7 +887,7 @@ dependencies = [ [[package]] name = "cw-dex" -version = "0.5.2" +version = "0.5.3-rc.1" dependencies = [ "apollo-cw-asset", "apollo-utils", diff --git a/Cargo.toml b/Cargo.toml index ab15557..6ba8efa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ test-case = "3.0.0" proptest = "1.0.0" # Workspace packages -cw-dex = { path = "cw-dex", version = "0.5.2" } +cw-dex = { path = "cw-dex", version = "0.5.3-rc.1" } cw-dex-astroport = { path = "cw-dex-astroport", version = "0.1.0" } cw-dex-osmosis = { path = "cw-dex-osmosis", version = "0.1.0" } cw-dex-test-contract = { path = "test-contracts/package" } diff --git a/cw-dex/Cargo.toml b/cw-dex/Cargo.toml index 54e2345..04db438 100644 --- a/cw-dex/Cargo.toml +++ b/cw-dex/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "MPL-2.0" name = "cw-dex" repository = "https://github.com/apollodao/cw-dex" -version = "0.5.2" +version = "0.5.3-rc.1" readme = "README.md" [features] From 9237b9faa03522abc397168962d6ff4f723dae57 Mon Sep 17 00:00:00 2001 From: Pacman Date: Tue, 13 Feb 2024 20:08:59 +0100 Subject: [PATCH 4/8] chore: prepare release v0.1.0 --- cw-dex-astroport/Cargo.toml | 4 ++-- cw-dex-astroport/README.md | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 cw-dex-astroport/README.md diff --git a/cw-dex-astroport/Cargo.toml b/cw-dex-astroport/Cargo.toml index 47fa60b..b90e8d9 100644 --- a/cw-dex-astroport/Cargo.toml +++ b/cw-dex-astroport/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" [features] default = [] -osmosis-test-tube = ["cw-it/osmosis-test-tube", "cw-dex-test-helpers/osmosis-test-tube"] +osmosis-test-tube = ["cw-it/osmosis-test-tube"] # backtraces = ["cosmwasm-std/backtraces", "osmosis-std/backtraces"] [package.metadata.docs.rs] @@ -35,7 +35,7 @@ cw2 = { workspace = true } cw-it = { workspace = true, features = ["astroport", "multi-test", "astroport-multi-test"] } test-case = { workspace = true } cw-dex-test-contract = { workspace = true } -cw-dex-test-helpers = { workspace = true, features = ["astroport"] } +cw-dex-test-helpers = { workspace = true, features = ["astroport", "osmosis-test-tube"] } proptest = { workspace = true } cw20-base = { workspace = true } cw20 = { workspace = true } diff --git a/cw-dex-astroport/README.md b/cw-dex-astroport/README.md new file mode 100644 index 0000000..a40aed4 --- /dev/null +++ b/cw-dex-astroport/README.md @@ -0,0 +1,3 @@ +# cw-dex-astroport + +This crate contains [cw-dex](https://crates.io/crates/cw-dex) implementations for Astroport. From 52cfba013d241ada08983298c9dc4b70f97b0694 Mon Sep 17 00:00:00 2001 From: Pacman Date: Tue, 13 Feb 2024 20:47:56 +0100 Subject: [PATCH 5/8] chore: bump cw-dex version to 0.5.3 and cw-dex-astroport to 0.2.0-rc.1 --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- cw-dex-astroport/Cargo.toml | 2 +- cw-dex/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 199945d..c21dc8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -887,7 +887,7 @@ dependencies = [ [[package]] name = "cw-dex" -version = "0.5.3-rc.1" +version = "0.5.3" dependencies = [ "apollo-cw-asset", "apollo-utils", @@ -909,7 +909,7 @@ dependencies = [ [[package]] name = "cw-dex-astroport" -version = "0.1.0" +version = "0.2.0-rc.1" dependencies = [ "apollo-cw-asset", "apollo-utils", diff --git a/Cargo.toml b/Cargo.toml index 6ba8efa..7a79169 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ test-case = "3.0.0" proptest = "1.0.0" # Workspace packages -cw-dex = { path = "cw-dex", version = "0.5.3-rc.1" } -cw-dex-astroport = { path = "cw-dex-astroport", version = "0.1.0" } +cw-dex = { path = "cw-dex", version = "0.5.3" } +cw-dex-astroport = { path = "cw-dex-astroport", version = "0.2.0-rc.1" } cw-dex-osmosis = { path = "cw-dex-osmosis", version = "0.1.0" } cw-dex-test-contract = { path = "test-contracts/package" } astroport-test-contract = { path = "test-contracts/astroport-test-contract" } diff --git a/cw-dex-astroport/Cargo.toml b/cw-dex-astroport/Cargo.toml index b90e8d9..b16c8e3 100644 --- a/cw-dex-astroport/Cargo.toml +++ b/cw-dex-astroport/Cargo.toml @@ -5,7 +5,7 @@ description = "Implementation of the cw-dex API for the Astroport AMM" edition = "2021" license = "MPL-2.0" repository = "https://github.com/apollodao/cw-dex" -version = "0.1.0" +version = "0.2.0-rc.1" readme = "README.md" [features] diff --git a/cw-dex/Cargo.toml b/cw-dex/Cargo.toml index 04db438..81022c8 100644 --- a/cw-dex/Cargo.toml +++ b/cw-dex/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "MPL-2.0" name = "cw-dex" repository = "https://github.com/apollodao/cw-dex" -version = "0.5.3-rc.1" +version = "0.5.3" readme = "README.md" [features] From 50aaa4c8e2afbdab717a2a2960f836ee34e6ec95 Mon Sep 17 00:00:00 2001 From: Sturdy <91910406+apollo-sturdy@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:18:46 +0100 Subject: [PATCH 6/8] fix: set cw-dex-astroport version to 0.1.1 --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- cw-dex-astroport/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c21dc8c..91cfe2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -909,7 +909,7 @@ dependencies = [ [[package]] name = "cw-dex-astroport" -version = "0.2.0-rc.1" +version = "0.1.1" dependencies = [ "apollo-cw-asset", "apollo-utils", @@ -975,9 +975,9 @@ dependencies = [ [[package]] name = "cw-it" -version = "0.3.0-rc.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8323a657163a204179a9a7a4a418794aa71f9c789b58b8c91974e2691f7db408" +checksum = "e1bd88c423ae22eefe99b1b008c8b2d7936def56cfb0c65f6ccf634a0988d7b0" dependencies = [ "anyhow", "apollo-cw-multi-test", diff --git a/Cargo.toml b/Cargo.toml index 7a79169..4067f65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ proptest = "1.0.0" # Workspace packages cw-dex = { path = "cw-dex", version = "0.5.3" } -cw-dex-astroport = { path = "cw-dex-astroport", version = "0.2.0-rc.1" } +cw-dex-astroport = { path = "cw-dex-astroport", version = "0.1.1" } cw-dex-osmosis = { path = "cw-dex-osmosis", version = "0.1.0" } cw-dex-test-contract = { path = "test-contracts/package" } astroport-test-contract = { path = "test-contracts/astroport-test-contract" } diff --git a/cw-dex-astroport/Cargo.toml b/cw-dex-astroport/Cargo.toml index b16c8e3..4122a02 100644 --- a/cw-dex-astroport/Cargo.toml +++ b/cw-dex-astroport/Cargo.toml @@ -5,7 +5,7 @@ description = "Implementation of the cw-dex API for the Astroport AMM" edition = "2021" license = "MPL-2.0" repository = "https://github.com/apollodao/cw-dex" -version = "0.2.0-rc.1" +version = "0.1.1" readme = "README.md" [features] From 3ab9d7aab8bad8410911e6a8359a102923add24a Mon Sep 17 00:00:00 2001 From: Sturdy <91910406+apollo-sturdy@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:19:30 +0100 Subject: [PATCH 7/8] chore: bump cw-it --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4067f65..f4a2de1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ serde = { version = "1.0.145", default-features = false, features = ["derive"] } thiserror = { version = "1.0.31" } apollo-cw-asset = "0.1.1" osmosis-std = "0.22.0" -cw-it = "0.3.0-rc.4" +cw-it = "0.3.0" apollo-utils = "0.1.0" astroport = "2.9.0" astroport_v3 = { package = "astroport", version = "3.11.1" } From 0a4e560d269553f8eadf12faf09d7b8dfaa79037 Mon Sep 17 00:00:00 2001 From: Sturdy <91910406+apollo-sturdy@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:25:28 +0100 Subject: [PATCH 8/8] ci: update cc check --- .github/workflows/cc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cc.yml b/.github/workflows/cc.yml index e9e3aee..cf7c23e 100644 --- a/.github/workflows/cc.yml +++ b/.github/workflows/cc.yml @@ -16,4 +16,4 @@ jobs: uses: actions/checkout@v3 - name: Check all commit messages for adherence - uses: bilalshaikh42/action-conventional-commits@v2.0.1 + uses: webiny/action-conventional-commits@v1.3.0